99 if( !local_root )
return nullptr;
101 Node *lr =
const_cast<Node*
>(local_root);
109 if( left_new_child ) left_new_child ->
setParent(new_local_root);
110 if( right_new_child ) right_new_child->setParent(new_local_root);
111 new_local_root->setLeftDaughter ( left_new_child );
112 new_local_root->setRightDaughter( right_new_child );
122 return new_local_root;
129 tn.push_back(local_root);
193 double totalSquaredError = 0;
197 totalSquaredError += (*it)->getTotalError();
207 double bestNodeErrorReduction = -1;
208 Node* nodeToSplit =
nullptr;
219 if( (*it)->getErrorReduction() > bestNodeErrorReduction )
221 bestNodeErrorReduction = (*it)->getErrorReduction();
229 if(nodeToSplit ==
nullptr)
return;
289 if(left ==
nullptr || right ==
nullptr)
return;
318 if(nextNode ==
nullptr)
return node;
336 if(left==
nullptr || right==
nullptr)
return;
376 if(left==
nullptr || right==
nullptr)
return;
383 std::cout <<
"ERROR: negative split variable for nonterminal node." << std::endl;
384 std::cout <<
"rankVarRecursive Split Variable = " << sv << std::endl;
406 template <
typename T>
410 std::stringstream ss;
432 TXMLEngine* xml =
new TXMLEngine();
442 XMLDocPointer_t
xmldoc = xml->NewDoc();
443 xml->DocSetRootElement(xmldoc, root);
446 xml->SaveDoc(xmldoc, c);
449 xml->FreeDoc(xmldoc);
460 if(l==
nullptr || r==
nullptr)
return;
463 XMLNodePointer_t left = xml->NewChild(np,
nullptr,
"left");
464 XMLNodePointer_t right = xml->NewChild(np,
nullptr,
"right");
480 TXMLEngine* xml =
new TXMLEngine;
483 XMLDocPointer_t
xmldoc = xml->ParseFile(filename);
491 XMLNodePointer_t mainnode = xml->DocGetRootElement(xmldoc);
496 if(
std::string(
"BinaryTree") == xml->GetNodeName(mainnode) ){
497 XMLAttrPointer_t attr = xml->GetFirstAttr(mainnode);
498 attr = xml->GetNextAttr(attr);
499 boostWeight = (attr ? strtod(xml->GetAttrValue(attr),
nullptr) : 0);
501 mainnode = xml->GetChild(mainnode);
511 xml->FreeDoc(xmldoc);
521 XMLAttrPointer_t attr = xml->GetFirstAttr(xnode);
522 std::vector<std::string> splitInfo(3);
524 for(
unsigned int i=0,j=0;
i<10;
i++)
526 if(
i==3 ||
i==4 ||
i==6){
527 splitInfo[j++] = xml->GetAttrValue(attr);
529 attr = xml->GetNextAttr(attr);
532 for(
unsigned int i=0;
i<3;
i++)
534 splitInfo[
i] = xml->GetAttrValue(attr);
535 attr = xml->GetNextAttr(attr);
545 converter << splitInfo[0];
546 converter >> splitVar;
550 converter << splitInfo[1];
551 converter >> splitVal;
555 converter << splitInfo[2];
566 XMLNodePointer_t xleft = xml->GetChild(xnode);
567 XMLNodePointer_t xright = xml->GetNext(xleft);
570 if(xleft ==
nullptr || xright ==
nullptr)
return;
606 if( node.
ileft >= tree.size() ||
607 node.
iright >= tree.size() )
return;
void setFitValue(double sFitValue)
Node * getRightDaughter()
Node * filterEventRecursive(Node *node, Event *e)
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()