139 , fNodePurityLimit(0)
145 , fRandomisedTrees(
kFALSE)
147 , fUsePoissonNvars(0)
148 , fDeltaPruneStrength(0)
157 const TString& theWeightFile) :
165 , fNodePurityLimit(0)
171 , fRandomisedTrees(
kFALSE)
173 , fDeltaPruneStrength(0)
215 DeclareOptionRef(fRandomisedTrees,
"UseRandomisedTrees",
"Choose at each node splitting a random set of variables and *bagging*");
216 DeclareOptionRef(fUseNvars,
"UseNvars",
"Number of variables used if randomised Tree option is chosen");
217 DeclareOptionRef(fUsePoissonNvars,
"UsePoissonNvars",
"Interpret \"UseNvars\" not as fixed number but as mean of a Poisson distribution in each split with RandomisedTree option");
218 DeclareOptionRef(fUseYesNoLeaf=
kTRUE,
"UseYesNoLeaf",
219 "Use Sig or Bkg node type or the ratio S/B as classification in the leaf node");
220 DeclareOptionRef(fNodePurityLimit=0.5,
"NodePurityLimit",
"In boosting/pruning, nodes with purity > NodePurityLimit are signal; background otherwise.");
221 DeclareOptionRef(fSepTypeS=
"GiniIndex",
"SeparationType",
"Separation criterion for node splitting");
222 AddPreDefVal(
TString(
"MisClassificationError"));
223 AddPreDefVal(
TString(
"GiniIndex"));
224 AddPreDefVal(
TString(
"CrossEntropy"));
225 AddPreDefVal(
TString(
"SDivSqrtSPlusB"));
226 DeclareOptionRef(fMinNodeEvents=-1,
"nEventsMin",
"deprecated !!! Minimum number of events required in a leaf node");
227 DeclareOptionRef(fMinNodeSizeS,
"MinNodeSize",
"Minimum percentage of training events required in a leaf node (default: Classification: 10%, Regression: 1%)");
228 DeclareOptionRef(fNCuts,
"nCuts",
"Number of steps during node cut optimisation");
229 DeclareOptionRef(fPruneStrength,
"PruneStrength",
"Pruning strength (negative value == automatic adjustment)");
230 DeclareOptionRef(fPruneMethodS=
"NoPruning",
"PruneMethod",
"Pruning method: NoPruning (switched off), ExpectedError or CostComplexity");
232 AddPreDefVal(
TString(
"NoPruning"));
233 AddPreDefVal(
TString(
"ExpectedError"));
234 AddPreDefVal(
TString(
"CostComplexity"));
236 if (DoRegression()) {
237 DeclareOptionRef(fMaxDepth=50,
"MaxDepth",
"Max depth of the decision tree allowed");
239 DeclareOptionRef(fMaxDepth=3,
"MaxDepth",
"Max depth of the decision tree allowed");
250 DeclareOptionRef(fPruneBeforeBoost=
kFALSE,
"PruneBeforeBoost",
251 "--> removed option .. only kept for reader backward compatibility");
261 else if (fSepTypeS ==
"giniindex") fSepType =
new GiniIndex();
262 else if (fSepTypeS ==
"crossentropy") fSepType =
new CrossEntropy();
263 else if (fSepTypeS ==
"sdivsqrtsplusb") fSepType =
new SdivSqrtSplusB();
265 Log() << kINFO << GetOptions() <<
Endl;
266 Log() << kFATAL <<
"<ProcessOptions> unknown Separation Index option called" <<
Endl;
271 fPruneMethodS.ToLower();
276 Log() << kINFO << GetOptions() <<
Endl;
277 Log() << kFATAL <<
"<ProcessOptions> unknown PruneMethod option:" << fPruneMethodS <<
" called" <<
Endl;
280 if (fPruneStrength < 0) fAutomatic =
kTRUE;
284 <<
"Sorry automatic pruning strength determination is not implemented yet for ExpectedErrorPruning" <<
Endl;
288 if (this->Data()->HasNegativeEventWeights()){
289 Log() << kINFO <<
" You are using a Monte Carlo that has also negative weights. "
290 <<
"That should in principle be fine as long as on average you end up with "
291 <<
"something positive. For this you have to make sure that the minimal number "
292 <<
"of (un-weighted) events demanded for a tree node (currently you use: MinNodeSize="
294 <<
", (or the deprecated equivalent nEventsMin) you can set this via the "
295 <<
"MethodDT option string when booking the "
296 <<
"classifier) is large enough to allow for reasonable averaging!!! "
297 <<
" If this does not help.. maybe you want to try the option: IgnoreNegWeightsInTraining "
298 <<
"which ignores events with negative weight in the training. " <<
Endl
299 <<
Endl <<
"Note: You'll get a WARNING message during the training if that should ever happen" <<
Endl;
302 if (fRandomisedTrees){
303 Log() << kINFO <<
" Randomised trees should use *bagging* as *boost* method. Did you set this in the *MethodBoost* ? . Here I can enforce only the *no pruning*" <<
Endl;
308 if (fMinNodeEvents > 0){
309 fMinNodeSize = fMinNodeEvents / Data()->GetNTrainingEvents() * 100;
310 Log() << kWARNING <<
"You have explicitly set *nEventsMin*, the min absolute number \n"
311 <<
"of events in a leaf node. This is DEPRECATED, please use the option \n"
312 <<
"*MinNodeSize* giving the relative number as percentage of training \n"
313 <<
"events instead. \n"
314 <<
"nEventsMin="<<fMinNodeEvents<<
"--> MinNodeSize="<<fMinNodeSize<<
"%"
317 SetMinNodeSize(fMinNodeSizeS);
322 if (sizeInPercent > 0 && sizeInPercent < 50){
323 fMinNodeSize=sizeInPercent;
326 Log() << kERROR <<
"you have demanded a minimal node size of "
327 << sizeInPercent <<
"% of the training events.. \n"
328 <<
" that somehow does not make sense "<<
Endl;
334 if (sizeInPercent.
IsAlnum()) SetMinNodeSize(sizeInPercent.
Atof());
336 Log() << kERROR <<
"I had problems reading the option MinNodeEvents, which\n"
337 <<
"after removing a possible % sign now reads " << sizeInPercent <<
Endl;
348 fMinNodeSizeS =
"5%";
352 fDeltaPruneStrength=0.1;
354 fUseNvars = GetNvar();
355 fUsePoissonNvars =
kTRUE;
358 SetSignalReferenceCut( 0 );
379 fTree =
new DecisionTree( fSepType, fMinNodeSize, fNCuts, &(DataInfo()), 0,
380 fRandomisedTrees, fUseNvars, fUsePoissonNvars,fMaxDepth,0 );
381 fTree->SetNVars(GetNvar());
382 if (fRandomisedTrees)
Log()<<kWARNING<<
" randomised Trees do not work yet in this framework,"
383 <<
" as I do not know how to give each tree a new random seed, now they"
384 <<
" will be all the same and that is not good " <<
Endl;
385 fTree->SetAnalysisType( GetAnalysisType() );
389 UInt_t nevents = Data()->GetNTrainingEvents();
390 std::vector<const TMVA::Event*> tmp;
391 for (
Long64_t ievt=0; ievt<nevents; ievt++) {
392 const Event *
event = GetEvent(ievt);
393 tmp.push_back(event);
395 fTree->BuildTree(tmp);
417 for(
UInt_t i = 0; i < nodes.size(); i++)
418 fTree->PruneNode(nodes[i]);
502 return fPruneStrength;
512 for (
Long64_t ievt=0; ievt<Data()->GetNEvents(); ievt++)
514 const Event * ev = Data()->GetEvent(ievt);
519 return SumCorrect / (SumCorrect + SumWrong);
526 fTree->AddXMLTo(parent);
537 fTree->ReadXML(wghtnode,GetTrainingTMVAVersionCode());
555 NoErrorCalc(err, errUpper);
557 return fTree->CheckEvent(GetEvent(),fUseYesNoLeaf);
#define REGISTER_METHOD(CLASS)
for example
A helper class to prune a decision tree using the Cost Complexity method (see Classification and Regr...
void SetPruneStrength(Float_t alpha=-1.0)
void Optimize()
determine the pruning sequence
std::vector< TMVA::DecisionTreeNode * > GetOptimalPruneSequence() const
return the prune strength (=alpha) corresponding to the prune sequence
Float_t GetOptimalPruneStrength() const
Implementation of the CrossEntropy as separation criterion.
Class that contains all the data information.
Implementation of a Decision Tree.
Double_t GetNodePurityLimit() const
Double_t CheckEvent(const TMVA::Event *, Bool_t UseYesNoLeaf=kFALSE) const
the event e is put into the decision tree (starting at the root node) and the output is NodeType (sig...
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not.
Implementation of the GiniIndex as separation criterion.
Virtual base Class for all MVA method.
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
Analysis of Boosted Decision Trees.
virtual ~MethodDT(void)
destructor
MethodDT(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
the standard constructor for just an ordinar "decision trees"
Double_t TestTreeQuality(DecisionTree *dt)
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
FDA can handle classification with 2 classes and regression with one regression-target.
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns MVA value
const Ranking * CreateRanking()
void ReadWeightsFromXML(void *wghtnode)
void GetHelpMessage() const
void AddWeightsXMLTo(void *parent) const
Double_t PruneTree()
prune the decision tree if requested (good for individual trees that are best grown out,...
void ReadWeightsFromStream(std::istream &istr)
void DeclareOptions()
Define the options (their key words) that can be set in the option string.
void Init(void)
common initialisation with defaults for the DT-Method
void SetMinNodeSize(Double_t sizeInPercent)
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
void ProcessOptions()
the option string is decoded, for available options see "DeclareOptions"
Implementation of the MisClassificationError as separation criterion.
Ranking for variables in method (implementation)
Implementation of the SdivSqrtSplusB as separation criterion.
Singleton class for Global types used by TMVA.
Double_t Atof() const
Return floating-point value contained in string.
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t IsAlnum() const
Returns true if all characters in string are alphanumeric.
create variable transformations
MsgLogger & Endl(MsgLogger &ml)