53 bool
TMVA::DecisionTreeNode::fgIsTraining =
false;
54 UInt_t TMVA::DecisionTreeNode::fgTmva_Version_Code = 0;
69 if (DecisionTreeNode::fgIsTraining){
110 fCutValue( n.fCutValue ),
111 fCutType ( n.fCutType ),
112 fSelector( n.fSelector ),
113 fResponse( n.fResponse ),
115 fNodeType( n.fNodeType ),
116 fPurity ( n.fPurity),
117 fIsTerminalNode( n.fIsTerminalNode )
151 if (GetNFisherCoeff() == 0){
153 result = (e.
GetValue(this->GetSelector()) >= this->GetCutValue() );
157 Double_t fisher = this->GetFisherCoeff(fFisherCoeff.size()-1);
158 for (
UInt_t ivar=0; ivar<fFisherCoeff.size()-1; ivar++)
159 fisher += this->GetFisherCoeff(ivar)*(e.
GetValue(ivar));
161 result = fisher > this->GetCutValue();
173 if (!this->GoesRight(e))
return kTRUE;
185 if ( ( this->GetNSigEvents() + this->GetNBkgEvents() ) > 0 ) {
186 fPurity = this->GetNSigEvents() / ( this->GetNSigEvents() + this->GetNBkgEvents());
189 Log() <<
kINFO <<
"Zero events in purity calcuation , return purity=0.5" <<
Endl;
202 os <<
"< *** " << std::endl;
203 os <<
" d: " << this->GetDepth()
204 << std::setprecision(6)
205 <<
"NCoef: " << this->GetNFisherCoeff();
206 for (
Int_t i=0; i< (
Int_t) this->GetNFisherCoeff(); i++) { os <<
"fC"<<i<<
": " << this->GetFisherCoeff(i);}
207 os <<
" ivar: " << this->GetSelector()
208 <<
" cut: " << this->GetCutValue()
209 <<
" cType: " << this->GetCutType()
210 <<
" s: " << this->GetNSigEvents()
211 <<
" b: " << this->GetNBkgEvents()
212 <<
" nEv: " << this->GetNEvents()
213 <<
" suw: " << this->GetNSigEvents_unweighted()
214 <<
" buw: " << this->GetNBkgEvents_unweighted()
215 <<
" nEvuw: " << this->GetNEvents_unweighted()
216 <<
" sepI: " << this->GetSeparationIndex()
217 <<
" sepG: " << this->GetSeparationGain()
218 <<
" nType: " << this->GetNodeType()
221 os <<
"My address is " << long(
this) <<
", ";
222 if (this->GetParent() !=
NULL) os <<
" parent at addr: " << long(this->GetParent()) ;
223 if (this->GetLeft() !=
NULL) os <<
" left daughter at addr: " << long(this->GetLeft());
224 if (this->GetRight() !=
NULL) os <<
" right daughter at addr: " << long(this->GetRight()) ;
226 os <<
" **** > " << std::endl;
234 os << this->GetDepth()
235 << std::setprecision(6)
236 <<
" " << this->GetPos()
237 <<
"NCoef: " << this->GetNFisherCoeff();
238 for (
Int_t i=0; i< (
Int_t) this->GetNFisherCoeff(); i++) {os <<
"fC"<<i<<
": " << this->GetFisherCoeff(i);}
239 os <<
" ivar: " << this->GetSelector()
240 <<
" cut: " << this->GetCutValue()
241 <<
" cType: " << this->GetCutType()
242 <<
" s: " << this->GetNSigEvents()
243 <<
" b: " << this->GetNBkgEvents()
244 <<
" nEv: " << this->GetNEvents()
245 <<
" suw: " << this->GetNSigEvents_unweighted()
246 <<
" buw: " << this->GetNBkgEvents_unweighted()
247 <<
" nEvuw: " << this->GetNEvents_unweighted()
248 <<
" sepI: " << this->GetSeparationIndex()
249 <<
" sepG: " << this->GetSeparationGain()
250 <<
" res: " << this->GetResponse()
251 <<
" rms: " << this->GetRMS()
252 <<
" nType: " << this->GetNodeType();
253 if (this->GetCC() > 10000000000000.) os <<
" CC: " << 100000. << std::endl;
254 else os <<
" CC: " << this->GetCC() << std::endl;
256 if (this->GetLeft() !=
NULL) this->GetLeft() ->PrintRec(os);
257 if (this->GetRight() !=
NULL) this->GetRight()->PrintRec(os);
265 fgTmva_Version_Code=tmva_Version_Code;
268 Float_t cutVal, cutType, nsig, nbkg, nEv, nsig_unweighted, nbkg_unweighted, nEv_unweighted;
269 Float_t separationIndex, separationGain, response(-99), cc(0);
270 Int_t depth, ivar, nodeType;
275 if ( depth==-1 ) {
return kFALSE; }
278 this->SetDepth(depth);
289 >> tmp >> nsig_unweighted
290 >> tmp >> nbkg_unweighted
291 >> tmp >> nEv_unweighted
292 >> tmp >> separationIndex
293 >> tmp >> separationGain
303 >> tmp >> nsig_unweighted
304 >> tmp >> nbkg_unweighted
305 >> tmp >> nEv_unweighted
306 >> tmp >> separationIndex
307 >> tmp >> separationGain
313 this->SetSelector((
UInt_t)ivar);
314 this->SetCutValue(cutVal);
315 this->SetCutType(cutType);
316 this->SetNodeType(nodeType);
318 this->SetNSigEvents(nsig);
319 this->SetNBkgEvents(nbkg);
320 this->SetNEvents(nEv);
321 this->SetNSigEvents_unweighted(nsig_unweighted);
322 this->SetNBkgEvents_unweighted(nbkg_unweighted);
323 this->SetNEvents_unweighted(nEv_unweighted);
324 this->SetSeparationIndex(separationIndex);
325 this->SetSeparationGain(separationGain);
342 SetNSigEvents_unweighted(0);
343 SetNBkgEvents_unweighted(0);
344 SetNEvents_unweighted(0);
345 SetSeparationIndex(-1);
346 SetSeparationGain(-1);
349 if (this->GetLeft() !=
NULL) ((
DecisionTreeNode*)(this->GetLeft()))->ClearNodeAndAllDaughters();
350 if (this->GetRight() !=
NULL) ((
DecisionTreeNode*)(this->GetRight()))->ClearNodeAndAllDaughters();
358 SetNBValidation( 0.0 );
359 SetNSValidation( 0.0 );
363 if(GetLeft() !=
NULL && GetRight() !=
NULL) {
364 GetLeft()->ResetValidationData();
365 GetRight()->ResetValidationData();
373 os <<
"----------------------" << std::endl
374 <<
"|~T_t| " << GetNTerminal() << std::endl
375 <<
"R(t): " << GetNodeR() << std::endl
376 <<
"R(T_t): " << GetSubTreeR() << std::endl
377 <<
"g(t): " << GetAlpha() << std::endl
378 <<
"G(t): " << GetAlphaMinSubtree() << std::endl;
385 this->PrintPrune(os);
386 if(this->GetLeft() !=
NULL && this->GetRight() !=
NULL) {
396 if (fTrainInfo) fTrainInfo->fCC = cc;
397 else Log() <<
kFATAL <<
"call to SetCC without trainingInfo" <<
Endl;
405 if (fTrainInfo && ivar < fTrainInfo->fSampleMin.size())
return fTrainInfo->fSampleMin[ivar];
406 else Log() <<
kFATAL <<
"You asked for Min of the event sample in node for variable "
407 << ivar <<
" that is out of range" <<
Endl;
416 if (fTrainInfo && ivar < fTrainInfo->fSampleMin.size())
return fTrainInfo->fSampleMax[ivar];
417 else Log() <<
kFATAL <<
"You asked for Max of the event sample in node for variable "
418 << ivar <<
" that is out of range" <<
Endl;
428 if ( ivar >= fTrainInfo->fSampleMin.size()) fTrainInfo->fSampleMin.resize(ivar+1);
429 fTrainInfo->fSampleMin[ivar]=
xmin;
438 if( ! fTrainInfo )
return;
439 if ( ivar >= fTrainInfo->fSampleMax.size() )
440 fTrainInfo->fSampleMax.resize(ivar+1);
441 fTrainInfo->fSampleMax[ivar]=
xmax;
448 Float_t tempNSigEvents,tempNBkgEvents;
451 if (
gTools().HasAttr(node,
"NCoef")){
453 this->SetNFisherCoeff(nCoef);
455 for (
Int_t i=0; i< (
Int_t) this->GetNFisherCoeff(); i++) {
457 this->SetFisherCoeff(i,tmp);
460 this->SetNFisherCoeff(0);
468 if(
gTools().HasAttr(node,
"purity") ) {
473 fPurity = tempNSigEvents / (tempNSigEvents + tempNBkgEvents);
486 for (
Int_t i=0; i< (
Int_t) this->GetNFisherCoeff(); i++)
508 if ((
Int_t) fFisherCoeff.size()<ivar+1) fFisherCoeff.resize(ivar+1) ;
509 fFisherCoeff[ivar]=coeff;
532 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
ClassImp(TIterator) Bool_t TIterator return false
Compare two iterator objects.
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)
Abstract ClassifierFactory template that handles arbitrary types.
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 ...