59 bool TMVA::DecisionTreeNode::fgIsTraining = false;
60 UInt_t TMVA::DecisionTreeNode::fgTmva_Version_Code = 0;
75 if (DecisionTreeNode::fgIsTraining){
116 fCutValue( n.fCutValue ),
117 fCutType ( n.fCutType ),
118 fSelector( n.fSelector ),
119 fResponse( n.fResponse ),
121 fNodeType( n.fNodeType ),
122 fPurity ( n.fPurity),
123 fIsTerminalNode( n.fIsTerminalNode )
157 if (GetNFisherCoeff() == 0){
159 result = (e.
GetValue(this->GetSelector()) >= this->GetCutValue() );
163 Double_t fisher = this->GetFisherCoeff(fFisherCoeff.size()-1);
164 for (
UInt_t ivar=0; ivar<fFisherCoeff.size()-1; ivar++)
165 fisher += this->GetFisherCoeff(ivar)*(e.
GetValue(ivar));
167 result = fisher > this->GetCutValue();
179 if (!this->GoesRight(e))
return kTRUE;
191 if ( ( this->GetNSigEvents() + this->GetNBkgEvents() ) > 0 ) {
192 fPurity = this->GetNSigEvents() / ( this->GetNSigEvents() + this->GetNBkgEvents());
195 Log() <<
kINFO <<
"Zero events in purity calcuation , return purity=0.5" <<
Endl;
196 std::ostringstream oss;
210 os <<
"< *** " << std::endl;
211 os <<
" d: " << this->GetDepth()
212 << std::setprecision(6)
213 <<
"NCoef: " << this->GetNFisherCoeff();
214 for (
Int_t i=0; i< (
Int_t) this->GetNFisherCoeff(); i++) { os <<
"fC"<<i<<
": " << this->GetFisherCoeff(i);}
215 os <<
" ivar: " << this->GetSelector()
216 <<
" cut: " << this->GetCutValue()
217 <<
" cType: " << this->GetCutType()
218 <<
" s: " << this->GetNSigEvents()
219 <<
" b: " << this->GetNBkgEvents()
220 <<
" nEv: " << this->GetNEvents()
221 <<
" suw: " << this->GetNSigEvents_unweighted()
222 <<
" buw: " << this->GetNBkgEvents_unweighted()
223 <<
" nEvuw: " << this->GetNEvents_unweighted()
224 <<
" sepI: " << this->GetSeparationIndex()
225 <<
" sepG: " << this->GetSeparationGain()
226 <<
" nType: " << this->GetNodeType()
229 os <<
"My address is " << long(
this) <<
", ";
230 if (this->GetParent() !=
NULL) os <<
" parent at addr: " << long(this->GetParent()) ;
231 if (this->GetLeft() !=
NULL) os <<
" left daughter at addr: " << long(this->GetLeft());
232 if (this->GetRight() !=
NULL) os <<
" right daughter at addr: " << long(this->GetRight()) ;
234 os <<
" **** > " << std::endl;
242 os << this->GetDepth()
243 << std::setprecision(6)
244 <<
" " << this->GetPos()
245 <<
"NCoef: " << this->GetNFisherCoeff();
246 for (
Int_t i=0; i< (
Int_t) this->GetNFisherCoeff(); i++) {os <<
"fC"<<i<<
": " << this->GetFisherCoeff(i);}
247 os <<
" ivar: " << this->GetSelector()
248 <<
" cut: " << this->GetCutValue()
249 <<
" cType: " << this->GetCutType()
250 <<
" s: " << this->GetNSigEvents()
251 <<
" b: " << this->GetNBkgEvents()
252 <<
" nEv: " << this->GetNEvents()
253 <<
" suw: " << this->GetNSigEvents_unweighted()
254 <<
" buw: " << this->GetNBkgEvents_unweighted()
255 <<
" nEvuw: " << this->GetNEvents_unweighted()
256 <<
" sepI: " << this->GetSeparationIndex()
257 <<
" sepG: " << this->GetSeparationGain()
258 <<
" res: " << this->GetResponse()
259 <<
" rms: " << this->GetRMS()
260 <<
" nType: " << this->GetNodeType();
261 if (this->GetCC() > 10000000000000.) os <<
" CC: " << 100000. << std::endl;
262 else os <<
" CC: " << this->GetCC() << std::endl;
264 if (this->GetLeft() !=
NULL) this->GetLeft() ->PrintRec(os);
265 if (this->GetRight() !=
NULL) this->GetRight()->PrintRec(os);
273 fgTmva_Version_Code=tmva_Version_Code;
276 Float_t cutVal, cutType, nsig, nbkg, nEv, nsig_unweighted, nbkg_unweighted, nEv_unweighted;
277 Float_t separationIndex, separationGain, response(-99), cc(0);
278 Int_t depth, ivar, nodeType;
283 if ( depth==-1 ) {
return kFALSE; }
286 this->SetDepth(depth);
297 >> tmp >> nsig_unweighted
298 >> tmp >> nbkg_unweighted
299 >> tmp >> nEv_unweighted
300 >> tmp >> separationIndex
301 >> tmp >> separationGain
311 >> tmp >> nsig_unweighted
312 >> tmp >> nbkg_unweighted
313 >> tmp >> nEv_unweighted
314 >> tmp >> separationIndex
315 >> tmp >> separationGain
321 this->SetSelector((
UInt_t)ivar);
322 this->SetCutValue(cutVal);
323 this->SetCutType(cutType);
324 this->SetNodeType(nodeType);
326 this->SetNSigEvents(nsig);
327 this->SetNBkgEvents(nbkg);
328 this->SetNEvents(nEv);
329 this->SetNSigEvents_unweighted(nsig_unweighted);
330 this->SetNBkgEvents_unweighted(nbkg_unweighted);
331 this->SetNEvents_unweighted(nEv_unweighted);
332 this->SetSeparationIndex(separationIndex);
333 this->SetSeparationGain(separationGain);
350 SetNSigEvents_unweighted(0);
351 SetNBkgEvents_unweighted(0);
352 SetNEvents_unweighted(0);
353 SetSeparationIndex(-1);
354 SetSeparationGain(-1);
357 if (this->GetLeft() !=
NULL) ((
DecisionTreeNode*)(this->GetLeft()))->ClearNodeAndAllDaughters();
358 if (this->GetRight() !=
NULL) ((
DecisionTreeNode*)(this->GetRight()))->ClearNodeAndAllDaughters();
366 SetNBValidation( 0.0 );
367 SetNSValidation( 0.0 );
371 if(GetLeft() !=
NULL && GetRight() !=
NULL) {
372 GetLeft()->ResetValidationData();
373 GetRight()->ResetValidationData();
381 os <<
"----------------------" << std::endl
382 <<
"|~T_t| " << GetNTerminal() << std::endl
383 <<
"R(t): " << GetNodeR() << std::endl
384 <<
"R(T_t): " << GetSubTreeR() << std::endl
385 <<
"g(t): " << GetAlpha() << std::endl
386 <<
"G(t): " << GetAlphaMinSubtree() << std::endl;
393 this->PrintPrune(os);
394 if(this->GetLeft() !=
NULL && this->GetRight() !=
NULL) {
404 if (fTrainInfo) fTrainInfo->fCC = cc;
405 else Log() <<
kFATAL <<
"call to SetCC without trainingInfo" <<
Endl;
413 if (fTrainInfo && ivar < fTrainInfo->fSampleMin.size())
return fTrainInfo->fSampleMin[ivar];
414 else Log() <<
kFATAL <<
"You asked for Min of the event sample in node for variable "
415 << ivar <<
" that is out of range" <<
Endl;
424 if (fTrainInfo && ivar < fTrainInfo->fSampleMin.size())
return fTrainInfo->fSampleMax[ivar];
425 else Log() <<
kFATAL <<
"You asked for Max of the event sample in node for variable "
426 << ivar <<
" that is out of range" <<
Endl;
436 if ( ivar >= fTrainInfo->fSampleMin.size()) fTrainInfo->fSampleMin.resize(ivar+1);
437 fTrainInfo->fSampleMin[ivar]=
xmin;
446 if( ! fTrainInfo )
return;
447 if ( ivar >= fTrainInfo->fSampleMax.size() )
448 fTrainInfo->fSampleMax.resize(ivar+1);
449 fTrainInfo->fSampleMax[ivar]=
xmax;
456 Float_t tempNSigEvents,tempNBkgEvents;
459 if (
gTools().HasAttr(node,
"NCoef")){
461 this->SetNFisherCoeff(nCoef);
463 for (
Int_t i=0; i< (
Int_t) this->GetNFisherCoeff(); i++) {
465 this->SetFisherCoeff(i,tmp);
468 this->SetNFisherCoeff(0);
476 if(
gTools().HasAttr(node,
"purity") ) {
481 fPurity = tempNSigEvents / (tempNSigEvents + tempNBkgEvents);
494 for (
Int_t i=0; i< (
Int_t) this->GetNFisherCoeff(); i++)
516 if ((
Int_t) fFisherCoeff.size()<ivar+1) fFisherCoeff.resize(ivar+1) ;
517 fFisherCoeff[ivar]=coeff;
540 TTHREAD_TLS_DECL_ARG(
MsgLogger,logger,
"DecisionTreeNode");
virtual void ReadAttributes(void *node, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)
DTNodeTrainingInfo * fTrainInfo
flag to set node as terminal (i.e., without deleting its descendants)
MsgLogger & Endl(MsgLogger &ml)
void SetFisherCoeff(Int_t ivar, Double_t coeff)
set fisher coefficients
virtual void AddContentToNode(std::stringstream &s) const
adding attributes to tree node (well, was used in BinarySearchTree, and somehow I guess someone progr...
virtual void ReadContent(std::stringstream &s)
reading attributes from tree node (well, was used in BinarySearchTree, and somehow I guess someone pr...
virtual DecisionTreeNode * GetRight() const
virtual void AddAttributesToNode(void *node) const
add attribute to xml
DecisionTreeNode()
constructor of an essentially "empty" node floating in space
virtual void SetRight(Node *r)
virtual DecisionTreeNode * GetLeft() const
DecisionTreeNode(const DecisionTreeNode &n, DecisionTreeNode *parent=NULL)
copy constructor of a node.
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
virtual Bool_t GoesLeft(const Event &) const
test event if it decends the tree at this node to the left
void PrintRecPrune(std::ostream &os) const
recursive printout of the node and its daughters
void ResetValidationData()
temporary stored node values (number of events, etc.) that originate not from the training but from t...
void PrintPrune(std::ostream &os) const
printout of the node (can be read in with ReadDataRecord)
virtual void SetLeft(Node *l)
void SetSampleMin(UInt_t ivar, Float_t xmin)
set the minimum of variable ivar from the training sample that pass/end up in this node ...
char * Form(const char *fmt,...)
void SetPurity(void)
return the S/(S+B) (purity) for the node REM: even if nodes with purity 0.01 are very PURE background...
Float_t GetSampleMin(UInt_t ivar) const
return the minimum of variable ivar from the training sample that pass/end up in this node ...
virtual void SetParent(Node *p)
void SetSampleMax(UInt_t ivar, Float_t xmax)
set the maximum of variable ivar from the training sample that pass/end up in this node ...
#define TMVA_VERSION(a, b, c)
void Print(std::ostream &os, const OptionType &opt)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
virtual Bool_t ReadDataRecord(std::istream &is, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)
Read the data block.
virtual void Print(std::ostream &os) const
print the node
void ClearNodeAndAllDaughters()
clear the nodes (their S/N, Nevents etc), just keep the structure of the tree
virtual Bool_t GoesRight(const Event &) const
test event if it decends the tree at this node to the right
virtual void PrintRec(std::ostream &os) const
recursively print the node and its daughters (–> print the 'tree')
virtual ~DecisionTreeNode()
destructor
Float_t GetSampleMax(UInt_t ivar) const
return the maximum of variable ivar from the training sample that pass/end up in this node ...