98 if( !local_root )
return nullptr;
100 Node *lr =
const_cast<Node*
>(local_root);
108 if( left_new_child ) left_new_child ->
setParent(new_local_root);
109 if( right_new_child ) 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;
128 tn.push_back(local_root);
192 double totalSquaredError = 0;
196 totalSquaredError += (*it)->getTotalError();
206 double bestNodeErrorReduction = -1;
207 Node* nodeToSplit =
nullptr;
218 if( (*it)->getErrorReduction() > bestNodeErrorReduction )
220 bestNodeErrorReduction = (*it)->getErrorReduction();
228 if(nodeToSplit ==
nullptr)
return;
288 if(left ==
nullptr || right ==
nullptr)
return;
317 if(nextNode ==
nullptr)
return node;
335 if(left==
nullptr || right==
nullptr)
return;
375 if(left==
nullptr || right==
nullptr)
return;
382 std::cout <<
"ERROR: negative split variable for nonterminal node." << std::endl;
383 std::cout <<
"rankVarRecursive Split Variable = " << sv << std::endl;
405 template <
typename T>
409 std::stringstream ss;
431 TXMLEngine* xml =
new TXMLEngine();
441 XMLDocPointer_t
xmldoc = xml->NewDoc();
442 xml->DocSetRootElement(xmldoc, root);
445 xml->SaveDoc(xmldoc, c);
448 xml->FreeDoc(xmldoc);
459 if(l==
nullptr || r==
nullptr)
return;
462 XMLNodePointer_t left = xml->NewChild(np,
nullptr,
"left");
463 XMLNodePointer_t right = xml->NewChild(np,
nullptr,
"right");
479 TXMLEngine* xml =
new TXMLEngine;
482 XMLDocPointer_t
xmldoc = xml->ParseFile(filename);
490 XMLNodePointer_t mainnode = xml->DocGetRootElement(xmldoc);
495 if(
std::string(
"BinaryTree") == xml->GetNodeName(mainnode) ){
496 XMLAttrPointer_t attr = xml->GetFirstAttr(mainnode);
497 attr = xml->GetNextAttr(attr);
498 boostWeight = (attr ? strtod(xml->GetAttrValue(attr),
nullptr) : 0);
500 mainnode = xml->GetChild(mainnode);
510 xml->FreeDoc(xmldoc);
520 XMLAttrPointer_t attr = xml->GetFirstAttr(xnode);
521 std::vector<std::string> splitInfo(3);
523 for(
unsigned int i=0,j=0;
i<10;
i++)
525 if(
i==3 ||
i==4 ||
i==6){
526 splitInfo[j++] = xml->GetAttrValue(attr);
528 attr = xml->GetNextAttr(attr);
531 for(
unsigned int i=0;
i<3;
i++)
533 splitInfo[
i] = xml->GetAttrValue(attr);
534 attr = xml->GetNextAttr(attr);
544 converter << splitInfo[0];
545 converter >> splitVar;
549 converter << splitInfo[1];
550 converter >> splitVal;
554 converter << splitInfo[2];
565 XMLNodePointer_t xleft = xml->GetChild(xnode);
566 XMLNodePointer_t xright = xml->GetNext(xleft);
569 if(xleft ==
nullptr || xright ==
nullptr)
return;
605 if( node.
ileft >= tree.size() ||
606 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()