98 Node* lr =
const_cast<Node*
>(local_root);
107 left_new_child->
setParent(new_local_root);
109 right_new_child->setParent(new_local_root);
110 new_local_root->setLeftDaughter(left_new_child);
111 new_local_root->setRightDaughter(right_new_child);
121 return new_local_root;
127 tn.push_back(local_root);
175 double totalSquaredError = 0;
178 totalSquaredError += (*it)->getTotalError();
187 double bestNodeErrorReduction = -1;
188 Node* nodeToSplit =
nullptr;
197 if ((*it)->getErrorReduction() > bestNodeErrorReduction) {
198 bestNodeErrorReduction = (*it)->getErrorReduction();
206 if (nodeToSplit ==
nullptr)
265 if (left ==
nullptr || right ==
nullptr)
292 if (nextNode ==
nullptr)
309 if (left ==
nullptr || right ==
nullptr)
344 if (left ==
nullptr || right ==
nullptr)
351 std::cout <<
"ERROR: negative split variable for nonterminal node." << std::endl;
352 std::cout <<
"rankVarRecursive Split Variable = " << sv << std::endl;
370 template <
typename T>
373 std::stringstream
ss;
392 TXMLEngine* xml =
new TXMLEngine();
395 XMLNodePointer_t root = xml->NewChild(
nullptr,
nullptr,
rootNode->
getName().c_str());
402 XMLDocPointer_t
xmldoc = xml->NewDoc();
403 xml->DocSetRootElement(xmldoc, root);
406 xml->SaveDoc(xmldoc, c);
409 xml->FreeDoc(xmldoc);
419 if (l ==
nullptr || r ==
nullptr)
423 XMLNodePointer_t left = xml->NewChild(np,
nullptr,
"left");
424 XMLNodePointer_t right = xml->NewChild(np,
nullptr,
"right");
439 TXMLEngine* xml =
new TXMLEngine;
442 XMLDocPointer_t
xmldoc = xml->ParseFile(filename);
443 if (xmldoc ==
nullptr) {
449 XMLNodePointer_t mainnode = xml->DocGetRootElement(xmldoc);
454 if (
std::string(
"BinaryTree") == xml->GetNodeName(mainnode)) {
455 XMLAttrPointer_t attr = xml->GetFirstAttr(mainnode);
456 attr = xml->GetNextAttr(attr);
457 boostWeight = (attr ? strtod(xml->GetAttrValue(attr),
nullptr) : 0);
459 mainnode = xml->GetChild(mainnode);
469 xml->FreeDoc(xmldoc);
477 XMLAttrPointer_t attr = xml->GetFirstAttr(xnode);
478 std::vector<std::string> splitInfo(3);
480 for (
unsigned int i = 0,
j = 0;
i < 10;
i++) {
481 if (
i == 3 ||
i == 4 ||
i == 6) {
482 splitInfo[
j++] = xml->GetAttrValue(attr);
484 attr = xml->GetNextAttr(attr);
487 for (
unsigned int i = 0;
i < 3;
i++) {
488 splitInfo[
i] = xml->GetAttrValue(attr);
489 attr = xml->GetNextAttr(attr);
494 std::stringstream converter;
499 converter << splitInfo[0];
500 converter >> splitVar;
504 converter << splitInfo[1];
505 converter >> splitVal;
509 converter << splitInfo[2];
520 XMLNodePointer_t xleft = xml->GetChild(xnode);
521 XMLNodePointer_t xright = xml->GetNext(xleft);
524 if (xleft ==
nullptr || xright ==
nullptr)
563 if (node.
ileft >= tree.size() || node.
iright >= tree.size())
void setFitValue(double sFitValue)
Node * getRightDaughter()
Node * filterEventRecursive(Node *node, Event *e)
const edm::EventSetup & c
std::list< Node * > terminalNodes
void buildTree(int nodeLimit)
void getSplitValues(std::vector< std::vector< double >> &v)
void loadFromXMLRecursive(TXMLEngine *xml, XMLNodePointer_t node, Node *tnode)
int getNumTerminalNodes()
void addXMLAttributes(TXMLEngine *xml, Node *node, XMLNodePointer_t np)
void loadFromCondPayloadRecursive(const L1TMuonEndCapForest::DTree &tree, const L1TMuonEndCapForest::DTreeNode &node, Node *tnode)
Tree & operator=(const Tree &tree)
void setTerminalNodes(std::list< Node * > &sTNodes)
void findLeafs(Node *local_root, std::list< Node * > &tn)
void loadFromCondPayload(const L1TMuonEndCapForest::DTree &tree)
Node * filterEventToDaughter(Event *e)
void rankVariables(std::vector< double > &v)
void rankVariablesRecursive(Node *node, std::vector< double > &v)
void setEvents(std::vector< std::vector< Event * > > &sEvents)
std::vector< std::vector< Event * > > & getEvents()
void saveToXMLRecursive(TXMLEngine *xml, Node *node, XMLNodePointer_t np)
std::vector< DTreeNode > DTree
std::list< Node * > & getTerminalNodes()
Node * copyFrom(const Node *local_root)
void setParent(Node *sParent)
void filterEventsRecursive(Node *node)
void setSplitVariable(int sSplitVar)
Node * filterEvent(Event *e)
void loadFromXML(const char *filename)
void saveToXML(const char *filename)
double getErrorReduction()
void filterEventsToDaughters()
std::string numToStr(T num)
void filterEvents(std::vector< Event * > &tEvents)
void setRootNode(Node *sRootNode)
void getSplitValuesRecursive(Node *node, std::vector< std::vector< double >> &v)
void setSplitValue(double sSplitValue)
void theMiracleOfChildBirth()