149 using std::make_pair;
155 const
Int_t TMVA::MethodBDT::fgDebugLevel = 0;
164 TMVA::
MethodBase( jobName,
Types::kBDT, methodTitle, theData, theOption)
167 , fSigToBkgFraction(0)
172 , fBaggedGradBoost(kFALSE)
176 , fMinNodeSizeS("5%")
179 , fMinLinCorrForFisher(.8)
180 , fUseExclusiveVars(0)
181 , fUseYesNoLeaf(kFALSE)
182 , fNodePurityLimit(0)
187 , fFValidationEvents(0)
189 , fRandomisedTrees(kFALSE)
191 , fUsePoissonNvars(0)
192 , fUseNTrainEvents(0)
193 , fBaggedSampleFraction(0)
194 , fNoNegWeightsInTraining(kFALSE)
195 , fInverseBoostNegWeights(kFALSE)
196 , fPairNegWeightsGlobal(kFALSE)
197 , fTrainWithNegWeights(kFALSE)
198 , fDoBoostMonitor(kFALSE)
206 , fDoPreselection(kFALSE)
207 , fSkipNormalization(kFALSE)
208 , fHistoricBool(kFALSE)
210 fMonitorNtuple =
NULL;
221 , fSigToBkgFraction(0)
226 , fBaggedGradBoost(
kFALSE)
230 , fMinNodeSizeS(
"5%")
233 , fMinLinCorrForFisher(.8)
234 , fUseExclusiveVars(0)
236 , fNodePurityLimit(0)
241 , fFValidationEvents(0)
243 , fRandomisedTrees(
kFALSE)
245 , fUsePoissonNvars(0)
246 , fUseNTrainEvents(0)
247 , fBaggedSampleFraction(0)
248 , fNoNegWeightsInTraining(
kFALSE)
249 , fInverseBoostNegWeights(
kFALSE)
250 , fPairNegWeightsGlobal(
kFALSE)
251 , fTrainWithNegWeights(
kFALSE)
261 , fSkipNormalization(
kFALSE)
325 DeclareOptionRef(fNTrees,
"NTrees",
"Number of trees in the forest");
326 if (DoRegression()) {
327 DeclareOptionRef(fMaxDepth=50,
"MaxDepth",
"Max depth of the decision tree allowed");
329 DeclareOptionRef(fMaxDepth=3,
"MaxDepth",
"Max depth of the decision tree allowed");
332 TString tmp=
"5%";
if (DoRegression()) tmp=
"0.2%";
333 DeclareOptionRef(fMinNodeSizeS=tmp,
"MinNodeSize",
"Minimum percentage of training events required in a leaf node (default: Classification: 5%, Regression: 0.2%)");
335 DeclareOptionRef(fNCuts,
"nCuts",
"Number of grid points in variable range used in finding optimal cut in node splitting");
337 DeclareOptionRef(fBoostType,
"BoostType",
"Boosting type for the trees in the forest (note: AdaCost is still experimental)");
339 AddPreDefVal(
TString(
"AdaBoost"));
340 AddPreDefVal(
TString(
"RealAdaBoost"));
341 AddPreDefVal(
TString(
"AdaCost"));
342 AddPreDefVal(
TString(
"Bagging"));
344 AddPreDefVal(
TString(
"AdaBoostR2"));
346 if (DoRegression()) {
347 fBoostType =
"AdaBoostR2";
349 fBoostType =
"AdaBoost";
351 DeclareOptionRef(fAdaBoostR2Loss=
"Quadratic",
"AdaBoostR2Loss",
"Type of Loss function in AdaBoostR2");
352 AddPreDefVal(
TString(
"Linear"));
353 AddPreDefVal(
TString(
"Quadratic"));
354 AddPreDefVal(
TString(
"Exponential"));
356 DeclareOptionRef(fBaggedBoost=
kFALSE,
"UseBaggedBoost",
"Use only a random subsample of all events for growing the trees in each boost iteration.");
357 DeclareOptionRef(fShrinkage=1.0,
"Shrinkage",
"Learning rate for GradBoost algorithm");
358 DeclareOptionRef(fAdaBoostBeta=.5,
"AdaBoostBeta",
"Learning rate for AdaBoost algorithm");
359 DeclareOptionRef(fRandomisedTrees,
"UseRandomisedTrees",
"Determine at each node splitting the cut variable only as the best out of a random subset of variables (like in RandomForests)");
360 DeclareOptionRef(fUseNvars,
"UseNvars",
"Size of the subset of variables used with RandomisedTree option");
361 DeclareOptionRef(fUsePoissonNvars,
"UsePoissonNvars",
"Interpret \"UseNvars\" not as fixed number but as mean of a Possion distribution in each split with RandomisedTree option");
362 DeclareOptionRef(fBaggedSampleFraction=.6,
"BaggedSampleFraction",
"Relative size of bagged event sample to original size of the data sample (used whenever bagging is used (i.e. UseBaggedBoost, Bagging,)" );
364 DeclareOptionRef(fUseYesNoLeaf=
kTRUE,
"UseYesNoLeaf",
365 "Use Sig or Bkg categories, or the purity=S/(S+B) as classification of the leaf node -> Real-AdaBoost");
366 if (DoRegression()) {
370 DeclareOptionRef(fNegWeightTreatment=
"InverseBoostNegWeights",
"NegWeightTreatment",
"How to treat events with negative weights in the BDT training (particular the boosting) : IgnoreInTraining; Boost With inverse boostweight; Pair events with negative and positive weights in traning sample and *annihilate* them (experimental!)");
371 AddPreDefVal(
TString(
"InverseBoostNegWeights"));
372 AddPreDefVal(
TString(
"IgnoreNegWeightsInTraining"));
373 AddPreDefVal(
TString(
"NoNegWeightsInTraining"));
374 AddPreDefVal(
TString(
"PairNegWeightsGlobal"));
379 DeclareOptionRef(fCss=1.,
"Css",
"AdaCost: cost of true signal selected signal");
380 DeclareOptionRef(fCts_sb=1.,
"Cts_sb",
"AdaCost: cost of true signal selected bkg");
381 DeclareOptionRef(fCtb_ss=1.,
"Ctb_ss",
"AdaCost: cost of true bkg selected signal");
382 DeclareOptionRef(fCbb=1.,
"Cbb",
"AdaCost: cost of true bkg selected bkg ");
384 DeclareOptionRef(fNodePurityLimit=0.5,
"NodePurityLimit",
"In boosting/pruning, nodes with purity > NodePurityLimit are signal; background otherwise.");
387 DeclareOptionRef(fSepTypeS,
"SeparationType",
"Separation criterion for node splitting");
388 AddPreDefVal(
TString(
"CrossEntropy"));
389 AddPreDefVal(
TString(
"GiniIndex"));
390 AddPreDefVal(
TString(
"GiniIndexWithLaplace"));
391 AddPreDefVal(
TString(
"MisClassificationError"));
392 AddPreDefVal(
TString(
"SDivSqrtSPlusB"));
393 AddPreDefVal(
TString(
"RegressionVariance"));
394 if (DoRegression()) {
395 fSepTypeS =
"RegressionVariance";
397 fSepTypeS =
"GiniIndex";
400 DeclareOptionRef(fRegressionLossFunctionBDTGS =
"Huber",
"RegressionLossFunctionBDTG",
"Loss function for BDTG regression.");
401 AddPreDefVal(
TString(
"Huber"));
402 AddPreDefVal(
TString(
"AbsoluteDeviation"));
403 AddPreDefVal(
TString(
"LeastSquares"));
405 DeclareOptionRef(fHuberQuantile = 0.7,
"HuberQuantile",
"In the Huber loss function this is the quantile that separates the core from the tails in the residuals distribution.");
407 DeclareOptionRef(fDoBoostMonitor=
kFALSE,
"DoBoostMonitor",
"Create control plot with ROC integral vs tree number");
409 DeclareOptionRef(fUseFisherCuts=
kFALSE,
"UseFisherCuts",
"Use multivariate splits using the Fisher criterion");
410 DeclareOptionRef(fMinLinCorrForFisher=.8,
"MinLinCorrForFisher",
"The minimum linear correlation between two variables demanded for use in Fisher criterion in node splitting");
411 DeclareOptionRef(fUseExclusiveVars=
kFALSE,
"UseExclusiveVars",
"Variables already used in fisher criterion are not anymore analysed individually for node splitting");
414 DeclareOptionRef(fDoPreselection=
kFALSE,
"DoPreselection",
"and and apply automatic pre-selection for 100% efficient signal (bkg) cuts prior to training");
417 DeclareOptionRef(fSigToBkgFraction=1,
"SigToBkgFraction",
"Sig to Bkg ratio used in Training (similar to NodePurityLimit, which cannot be used in real adaboost");
419 DeclareOptionRef(fPruneMethodS,
"PruneMethod",
"Note: for BDTs use small trees (e.g.MaxDepth=3) and NoPruning: Pruning: Method used for pruning (removal) of statistically insignificant branches ");
420 AddPreDefVal(
TString(
"NoPruning"));
421 AddPreDefVal(
TString(
"ExpectedError"));
422 AddPreDefVal(
TString(
"CostComplexity"));
424 DeclareOptionRef(fPruneStrength,
"PruneStrength",
"Pruning strength");
426 DeclareOptionRef(fFValidationEvents=0.5,
"PruningValFraction",
"Fraction of events to use for optimizing automatic pruning.");
428 DeclareOptionRef(fSkipNormalization=
kFALSE,
"SkipNormalization",
"Skip normalization at initialization, to keep expectation value of BDT output according to the fraction of events");
431 DeclareOptionRef(fMinNodeEvents=0,
"nEventsMin",
"deprecated: Use MinNodeSize (in % of training events) instead");
433 DeclareOptionRef(fBaggedGradBoost=
kFALSE,
"UseBaggedGrad",
"deprecated: Use *UseBaggedBoost* instead: Use only a random subsample of all events for growing the trees in each iteration.");
434 DeclareOptionRef(fBaggedSampleFraction,
"GradBaggingFraction",
"deprecated: Use *BaggedSampleFraction* instead: Defines the fraction of events to be used in each iteration, e.g. when UseBaggedGrad=kTRUE. ");
435 DeclareOptionRef(fUseNTrainEvents,
"UseNTrainEvents",
"deprecated: Use *BaggedSampleFraction* instead: Number of randomly picked training events used in randomised (and bagged) trees");
436 DeclareOptionRef(fNNodesMax,
"NNodesMax",
"deprecated: Use MaxDepth instead to limit the tree size" );
448 DeclareOptionRef(fHistoricBool=
kTRUE,
"UseWeightedTrees",
449 "Use weighted trees or simple average in classification from the forest");
450 DeclareOptionRef(fHistoricBool=
kFALSE,
"PruneBeforeBoost",
"Flag to prune the tree before applying boosting algorithm");
451 DeclareOptionRef(fHistoricBool=
kFALSE,
"RenormByClass",
"Individually re-normalize each event class to the original size after boosting");
453 AddPreDefVal(
TString(
"NegWeightTreatment"),
TString(
"IgnoreNegWeights"));
467 else if (fSepTypeS ==
"giniindex") fSepType =
new GiniIndex();
469 else if (fSepTypeS ==
"crossentropy") fSepType =
new CrossEntropy();
470 else if (fSepTypeS ==
"sdivsqrtsplusb") fSepType =
new SdivSqrtSplusB();
471 else if (fSepTypeS ==
"regressionvariance") fSepType =
NULL;
474 Log() <<
kFATAL <<
"<ProcessOptions> unknown Separation Index option " << fSepTypeS <<
" called" <<
Endl;
477 if(!(fHuberQuantile >= 0.0 && fHuberQuantile <= 1.0)){
479 Log() <<
kFATAL <<
"<ProcessOptions> Huber Quantile must be in range [0,1]. Value given, " << fHuberQuantile <<
", does not match this criteria" <<
Endl;
482 fRegressionLossFunctionBDTGS.ToLower();
483 if (fRegressionLossFunctionBDTGS ==
"huber") fRegressionLossFunctionBDTG =
new HuberLossFunctionBDT(fHuberQuantile);
488 Log() <<
kFATAL <<
"<ProcessOptions> unknown Regression Loss Function BDT option " << fRegressionLossFunctionBDTGS <<
" called" <<
Endl;
491 fPruneMethodS.ToLower();
497 Log() <<
kFATAL <<
"<ProcessOptions> unknown PruneMethod " << fPruneMethodS <<
" option called" <<
Endl;
503 <<
"Sorry autmoatic pruning strength determination is not implemented yet for ExpectedErrorPruning" <<
Endl;
507 if (fMinNodeEvents > 0){
508 fMinNodeSize =
Double_t(fMinNodeEvents*100.) /
Data()->GetNTrainingEvents();
509 Log() <<
kWARNING <<
"You have explicitly set ** nEventsMin = " << fMinNodeEvents<<
" ** the min ablsolut number \n"
510 <<
"of events in a leaf node. This is DEPRECATED, please use the option \n"
511 <<
"*MinNodeSize* giving the relative number as percentage of training \n"
512 <<
"events instead. \n"
513 <<
"nEventsMin="<<fMinNodeEvents<<
"--> MinNodeSize="<<fMinNodeSize<<
"%"
515 Log() <<
kWARNING <<
"Note also that explicitly setting *nEventsMin* so far OVERWRITES the option recomeded \n"
516 <<
" *MinNodeSize* = " << fMinNodeSizeS <<
" option !!" <<
Endl ;
517 fMinNodeSizeS =
Form(
"%F3.2",fMinNodeSize);
520 SetMinNodeSize(fMinNodeSizeS);
524 fAdaBoostR2Loss.ToLower();
526 if (fBoostType==
"Grad") {
528 if (fNegWeightTreatment==
"InverseBoostNegWeights"){
529 Log() <<
kINFO <<
"the option *InverseBoostNegWeights* does not exist for BoostType=Grad --> change" <<
Endl;
530 Log() <<
kINFO <<
"to new default for GradBoost *Pray*" <<
Endl;
531 Log() <<
kDEBUG <<
"i.e. simply keep them as if which should work fine for Grad Boost" <<
Endl;
532 fNegWeightTreatment=
"Pray";
533 fNoNegWeightsInTraining=
kFALSE;
535 }
else if (fBoostType==
"RealAdaBoost"){
536 fBoostType =
"AdaBoost";
538 }
else if (fBoostType==
"AdaCost"){
542 if (fFValidationEvents < 0.0) fFValidationEvents = 0.0;
543 if (fAutomatic && fFValidationEvents > 0.5) {
544 Log() <<
kWARNING <<
"You have chosen to use more than half of your training sample "
545 <<
"to optimize the automatic pruning algorithm. This is probably wasteful "
546 <<
"and your overall results will be degraded. Are you sure you want this?"
551 if (this->
Data()->HasNegativeEventWeights()){
552 Log() <<
kINFO <<
" You are using a Monte Carlo that has also negative weights. "
553 <<
"That should in principle be fine as long as on average you end up with "
554 <<
"something positive. For this you have to make sure that the minimal number "
555 <<
"of (un-weighted) events demanded for a tree node (currently you use: MinNodeSize="
556 << fMinNodeSizeS <<
" ("<< fMinNodeSize <<
"%)"
557 <<
", (or the deprecated equivalent nEventsMin) you can set this via the "
558 <<
"BDT option string when booking the "
559 <<
"classifier) is large enough to allow for reasonable averaging!!! "
560 <<
" If this does not help.. maybe you want to try the option: IgnoreNegWeightsInTraining "
561 <<
"which ignores events with negative weight in the training. " <<
Endl
562 <<
Endl <<
"Note: You'll get a WARNING message during the training if that should ever happen" <<
Endl;
565 if (DoRegression()) {
566 if (fUseYesNoLeaf && !IsConstructedFromWeightFile()){
567 Log() <<
kWARNING <<
"Regression Trees do not work with fUseYesNoLeaf=TRUE --> I will set it to FALSE" <<
Endl;
571 if (fSepType !=
NULL){
572 Log() <<
kWARNING <<
"Regression Trees do not work with Separation type other than <RegressionVariance> --> I will use it instead" <<
Endl;
576 Log() <<
kWARNING <<
"Sorry, UseFisherCuts is not available for regression analysis, I will ignore it!" <<
Endl;
580 Log() <<
kWARNING <<
"Sorry, the option of nCuts<0 using a more elaborate node splitting algorithm " <<
Endl;
581 Log() <<
kWARNING <<
"is not implemented for regression analysis ! " <<
Endl;
582 Log() <<
kWARNING <<
"--> I switch do default nCuts = 20 and use standard node splitting"<<
Endl;
586 if (fRandomisedTrees){
587 Log() <<
kINFO <<
" Randomised trees use no pruning" <<
Endl;
592 if (fUseFisherCuts) {
593 Log() <<
kWARNING <<
"When using the option UseFisherCuts, the other option nCuts<0 (i.e. using" <<
Endl;
594 Log() <<
" a more elaborate node splitting algorithm) is not implemented. " <<
Endl;
601 Log() <<
kERROR <<
" Zero Decision Trees demanded... that does not work !! "
602 <<
" I set it to 1 .. just so that the program does not crash"
607 fNegWeightTreatment.ToLower();
608 if (fNegWeightTreatment ==
"ignorenegweightsintraining") fNoNegWeightsInTraining =
kTRUE;
609 else if (fNegWeightTreatment ==
"nonegweightsintraining") fNoNegWeightsInTraining =
kTRUE;
610 else if (fNegWeightTreatment ==
"inverseboostnegweights") fInverseBoostNegWeights =
kTRUE;
611 else if (fNegWeightTreatment ==
"pairnegweightsglobal") fPairNegWeightsGlobal =
kTRUE;
612 else if (fNegWeightTreatment ==
"pray")
Log() <<
kDEBUG <<
"Yes, good luck with praying " <<
Endl;
615 Log() <<
kFATAL <<
"<ProcessOptions> unknown option for treating negative event weights during training " << fNegWeightTreatment <<
" requested" <<
Endl;
618 if (fNegWeightTreatment ==
"pairnegweightsglobal")
619 Log() <<
kWARNING <<
" you specified the option NegWeightTreatment=PairNegWeightsGlobal : This option is still considered EXPERIMENTAL !! " <<
Endl;
626 while (tmp < fNNodesMax){
630 Log() <<
kWARNING <<
"You have specified a deprecated option *NNodesMax="<<fNNodesMax
631 <<
"* \n this has been translated to MaxDepth="<<fMaxDepth<<
Endl;
635 if (fUseNTrainEvents>0){
636 fBaggedSampleFraction = (
Double_t) fUseNTrainEvents/
Data()->GetNTrainingEvents();
637 Log() <<
kWARNING <<
"You have specified a deprecated option *UseNTrainEvents="<<fUseNTrainEvents
638 <<
"* \n this has been translated to BaggedSampleFraction="<<fBaggedSampleFraction<<
"(%)"<<
Endl;
641 if (fBoostType==
"Bagging") fBaggedBoost =
kTRUE;
642 if (fBaggedGradBoost){
643 fBaggedBoost =
kTRUE;
644 Log() <<
kWARNING <<
"You have specified a deprecated option *UseBaggedGrad* --> please use *UseBaggedBoost* instead" <<
Endl;
653 if (sizeInPercent > 0 && sizeInPercent < 50){
654 fMinNodeSize=sizeInPercent;
657 Log() <<
kFATAL <<
"you have demanded a minimal node size of "
658 << sizeInPercent <<
"% of the training events.. \n"
659 <<
" that somehow does not make sense "<<
Endl;
668 if (sizeInPercent.
IsFloat()) SetMinNodeSize(sizeInPercent.
Atof());
670 Log() <<
kFATAL <<
"I had problems reading the option MinNodeEvents, which "
671 <<
"after removing a possible % sign now reads " << sizeInPercent <<
Endl;
685 fBoostType =
"AdaBoost";
686 if(DataInfo().GetNClasses()!=0)
690 fBoostType =
"AdaBoostR2";
691 fAdaBoostR2Loss =
"Quadratic";
692 if(DataInfo().GetNClasses()!=0)
698 fPruneMethodS =
"NoPruning";
702 fFValidationEvents = 0.5;
703 fRandomisedTrees =
kFALSE;
706 fUsePoissonNvars =
kTRUE;
711 SetSignalReferenceCut( 0 );
724 for (
UInt_t i=0; i<fForest.size(); i++)
delete fForest[i];
727 fBoostWeights.clear();
728 if (fMonitorNtuple) { fMonitorNtuple->Delete(); fMonitorNtuple=
NULL; }
729 fVariableImportance.clear();
731 fLossFunctionEventInfo.clear();
736 Log() <<
kDEBUG <<
" successfully(?) reset the method " <<
Endl;
749 for (
UInt_t i=0; i<fForest.size(); i++)
delete fForest[i];
757 if (!HasTrainingTree())
Log() <<
kFATAL <<
"<Init> Data().TrainingTree() is zero pointer" <<
Endl;
759 if (fEventSample.size() > 0) {
761 for (
UInt_t iev=0; iev<fEventSample.size(); iev++) fEventSample[iev]->SetBoostWeight(1.);
764 UInt_t nevents =
Data()->GetNTrainingEvents();
766 std::vector<const TMVA::Event*> tmpEventSample;
767 for (
Long64_t ievt=0; ievt<nevents; ievt++) {
769 Event*
event =
new Event( *GetTrainingEvent(ievt) );
770 tmpEventSample.push_back(event);
773 if (!DoRegression()) DeterminePreselectionCuts(tmpEventSample);
774 else fDoPreselection =
kFALSE;
776 for (
UInt_t i=0; i<tmpEventSample.size(); i++)
delete tmpEventSample[i];
781 for (
Long64_t ievt=0; ievt<nevents; ievt++) {
784 Event*
event =
new Event( *GetTrainingEvent(ievt) );
785 if (fDoPreselection){
786 if (
TMath::Abs(ApplyPreselectionCuts(event)) > 0.05) {
792 if (event->GetWeight() < 0 && (IgnoreEventsWithNegWeightsInTraining() || fNoNegWeightsInTraining)){
793 if (firstNegWeight) {
794 Log() <<
kWARNING <<
" Note, you have events with negative event weight in the sample, but you've chosen to ignore them" <<
Endl;
798 }
else if (event->GetWeight()==0){
799 if (firstZeroWeight) {
801 Log() <<
"Events with weight == 0 are going to be simply ignored " <<
Endl;
805 if (event->GetWeight() < 0) {
806 fTrainWithNegWeights=
kTRUE;
809 if (fPairNegWeightsGlobal){
810 Log() <<
kWARNING <<
"Events with negative event weights are found and "
811 <<
" will be removed prior to the actual BDT training by global "
812 <<
" paring (and subsequent annihilation) with positiv weight events"
815 Log() <<
kWARNING <<
"Events with negative event weights are USED during "
816 <<
"the BDT training. This might cause problems with small node sizes "
817 <<
"or with the boosting. Please remove negative events from training "
818 <<
"using the option *IgnoreEventsWithNegWeightsInTraining* in case you "
819 <<
"observe problems with the boosting"
826 Double_t modulo = 1.0/(fFValidationEvents);
827 Int_t imodulo =
static_cast<Int_t>( fmod(modulo,1.0) > 0.5 ?
ceil(modulo) :
floor(modulo) );
828 if (ievt % imodulo == 0) fValidationSample.push_back( event );
829 else fEventSample.push_back( event );
832 fEventSample.push_back(event);
838 Log() <<
kINFO <<
"<InitEventSample> Internally I use " << fEventSample.size()
839 <<
" for Training and " << fValidationSample.size()
840 <<
" for Pruning Validation (" << ((
Float_t)fValidationSample.size())/((
Float_t)fEventSample.size()+fValidationSample.size())*100.0
841 <<
"% of training used for validation)" << Endl;
845 if (fPairNegWeightsGlobal) PreProcessNegativeEventWeights();
848 if (!DoRegression() && !fSkipNormalization){
849 Log() <<
kDEBUG <<
"\t<InitEventSample> For classification trees, "<<
Endl;
850 Log() <<
kDEBUG <<
" \tthe effective number of backgrounds is scaled to match "<<
Endl;
851 Log() <<
kDEBUG <<
" \tthe signal. Otherwise the first boosting step would do 'just that'!"<<
Endl;
865 Double_t nevents = fEventSample.size();
867 Int_t sumSig=0, sumBkg=0;
868 for (
UInt_t ievt=0; ievt<fEventSample.size(); ievt++) {
869 if ((DataInfo().IsSignal(fEventSample[ievt])) ) {
870 sumSigW += fEventSample[ievt]->GetWeight();
873 sumBkgW += fEventSample[ievt]->GetWeight();
877 if (sumSigW && sumBkgW){
878 Double_t normSig = nevents/((1+fSigToBkgFraction)*sumSigW)*fSigToBkgFraction;
879 Double_t normBkg = nevents/((1+fSigToBkgFraction)*sumBkgW); ;
880 Log() <<
kDEBUG <<
"\tre-normalise events such that Sig and Bkg have respective sum of weights = "
881 << fSigToBkgFraction <<
Endl;
882 Log() <<
kDEBUG <<
" \tsig->sig*"<<normSig <<
"ev. bkg->bkg*"<<normBkg <<
"ev." <<
Endl;
883 Log() <<
kHEADER <<
"#events: (reweighted) sig: "<< sumSigW*normSig <<
" bkg: " << sumBkgW*normBkg <<
Endl;
884 Log() <<
kINFO <<
"#events: (unweighted) sig: "<< sumSig <<
" bkg: " << sumBkg <<
Endl;
885 for (
Long64_t ievt=0; ievt<nevents; ievt++) {
886 if ((DataInfo().IsSignal(fEventSample[ievt])) ) fEventSample[ievt]->SetBoostWeight(normSig);
887 else fEventSample[ievt]->SetBoostWeight(normBkg);
890 Log() <<
kINFO <<
"--> could not determine scaleing factors as either there are " <<
Endl;
891 Log() <<
kINFO <<
" no signal events (sumSigW="<<sumSigW<<
") or no bkg ev. (sumBkgW="<<sumBkgW<<
")"<<
Endl;
896 fTrainSample = &fEventSample;
898 GetBaggedSubSample(fEventSample);
899 fTrainSample = &fSubSample;
925 std::vector<const Event*> negEvents;
926 for (
UInt_t iev = 0; iev < fEventSample.size(); iev++){
927 if (fEventSample[iev]->GetWeight() < 0) {
928 totalNegWeights += fEventSample[iev]->GetWeight();
929 negEvents.push_back(fEventSample[iev]);
931 totalPosWeights += fEventSample[iev]->GetWeight();
933 totalWeights += fEventSample[iev]->GetWeight();
935 if (totalNegWeights == 0 ) {
936 Log() <<
kINFO <<
"no negative event weights found .. no preprocessing necessary" <<
Endl;
939 Log() <<
kINFO <<
"found a total of " << totalNegWeights <<
" of negative event weights which I am going to try to pair with positive events to annihilate them" <<
Endl;
940 Log() <<
kINFO <<
"found a total of " << totalPosWeights <<
" of events with positive weights" <<
Endl;
941 Log() <<
kINFO <<
"--> total sum of weights = " << totalWeights <<
" = " << totalNegWeights+totalPosWeights <<
Endl;
948 for (
Int_t i=0; i<2; i++){
949 invCov = ((*cov)[i]);
951 std::cout <<
"<MethodBDT::PreProcessNeg...> matrix is almost singular with deterninant="
953 <<
" did you use the variables that are linear combinations or highly correlated?"
957 std::cout <<
"<MethodBDT::PreProcessNeg...> matrix is singular with determinant="
959 <<
" did you use the variables that are linear combinations?"
968 Log() <<
kINFO <<
"Found a total of " << totalNegWeights <<
" in negative weights out of " << fEventSample.size() <<
" training events " <<
Endl;
969 Timer timer(negEvents.size(),
"Negative Event paired");
970 for (
UInt_t nev = 0; nev < negEvents.size(); nev++){
971 timer.DrawProgressBar( nev );
972 Double_t weight = negEvents[nev]->GetWeight();
973 UInt_t iClassID = negEvents[nev]->GetClass();
974 invCov = ((*cov)[iClassID]);
980 for (
UInt_t iev = 0; iev < fEventSample.size(); iev++){
981 if (iClassID==fEventSample[iev]->
GetClass() && fEventSample[iev]->GetWeight() > 0){
983 for (
UInt_t ivar=0; ivar < GetNvar(); ivar++){
984 for (
UInt_t jvar=0; jvar<GetNvar(); jvar++){
985 dist += (negEvents[nev]->GetValue(ivar)-fEventSample[iev]->GetValue(ivar))*
986 (*invCov)[ivar][jvar]*
987 (negEvents[nev]->GetValue(jvar)-fEventSample[iev]->GetValue(jvar));
990 if (dist < minDist) { iMin=iev; minDist=
dist;}
996 Double_t newWeight = (negEvents[nev]->GetWeight() + fEventSample[iMin]->GetWeight());
998 negEvents[nev]->SetBoostWeight( 0 );
999 fEventSample[iMin]->SetBoostWeight( newWeight/fEventSample[iMin]->GetOriginalWeight() );
1001 negEvents[nev]->SetBoostWeight( newWeight/negEvents[nev]->GetOriginalWeight() );
1002 fEventSample[iMin]->SetBoostWeight( 0 );
1005 }
else Log() <<
kFATAL <<
"preprocessing didn't find event to pair with the negative weight ... probably a bug" <<
Endl;
1006 weight = negEvents[nev]->GetWeight();
1009 Log() <<
kINFO <<
"<Negative Event Pairing> took: " <<
timer.GetElapsedTime()
1013 totalNegWeights = 0;
1014 totalPosWeights = 0;
1021 std::vector<const Event*> newEventSample;
1023 for (
UInt_t iev = 0; iev < fEventSample.size(); iev++){
1024 if (fEventSample[iev]->GetWeight() < 0) {
1025 totalNegWeights += fEventSample[iev]->GetWeight();
1026 totalWeights += fEventSample[iev]->GetWeight();
1028 totalPosWeights += fEventSample[iev]->GetWeight();
1029 totalWeights += fEventSample[iev]->GetWeight();
1031 if (fEventSample[iev]->GetWeight() > 0) {
1032 newEventSample.push_back(
new Event(*fEventSample[iev]));
1033 if (fEventSample[iev]->
GetClass() == fSignalClass){
1034 sigWeight += fEventSample[iev]->GetWeight();
1037 bkgWeight += fEventSample[iev]->GetWeight();
1042 if (totalNegWeights < 0)
Log() <<
kFATAL <<
" compenstion of negative event weights with positive ones did not work " << totalNegWeights <<
Endl;
1044 for (
UInt_t i=0; i<fEventSample.size(); i++)
delete fEventSample[i];
1045 fEventSample = newEventSample;
1047 Log() <<
kINFO <<
" after PreProcessing, the Event sample is left with " << fEventSample.size() <<
" events (unweighted), all with positive weights, adding up to " << totalWeights <<
Endl;
1048 Log() <<
kINFO <<
" nSig="<<nSig <<
" sigWeight="<<sigWeight <<
" nBkg="<<nBkg <<
" bkgWeight="<<bkgWeight <<
Endl;
1062 std::map<TString,TMVA::Interval*> tuneParameters;
1063 std::map<TString,Double_t> tunedParameters;
1072 tuneParameters.insert(std::pair<TString,Interval*>(
"NTrees",
new Interval(10,1000,5)));
1073 tuneParameters.insert(std::pair<TString,Interval*>(
"MaxDepth",
new Interval(2,4,3)));
1074 tuneParameters.insert(std::pair<TString,Interval*>(
"MinNodeSize",
new LogInterval(1,30,30)));
1079 if (fBoostType==
"AdaBoost"){
1080 tuneParameters.insert(std::pair<TString,Interval*>(
"AdaBoostBeta",
new Interval(.2,1.,5)));
1082 }
else if (fBoostType==
"Grad"){
1083 tuneParameters.insert(std::pair<TString,Interval*>(
"Shrinkage",
new Interval(0.05,0.50,5)));
1085 }
else if (fBoostType==
"Bagging" && fRandomisedTrees){
1088 tuneParameters.insert(std::pair<TString,Interval*>(
"UseNvars",
new Interval(min_var,max_var,4)));
1092 Log()<<
kINFO <<
" the following BDT parameters will be tuned on the respective *grid*\n"<<
Endl;
1093 std::map<TString,TMVA::Interval*>::iterator it;
1094 for(it=tuneParameters.begin(); it!= tuneParameters.end(); it++){
1096 std::ostringstream oss;
1097 (it->second)->
Print(oss);
1103 tunedParameters=optimize.
optimize();
1105 return tunedParameters;
1114 std::map<TString,Double_t>::iterator it;
1115 for(it=tuneParameters.begin(); it!= tuneParameters.end(); it++){
1117 if (it->first ==
"MaxDepth" ) SetMaxDepth ((
Int_t)it->second);
1118 else if (it->first ==
"MinNodeSize" ) SetMinNodeSize (it->second);
1119 else if (it->first ==
"NTrees" ) SetNTrees ((
Int_t)it->second);
1120 else if (it->first ==
"NodePurityLimit") SetNodePurityLimit (it->second);
1121 else if (it->first ==
"AdaBoostBeta" ) SetAdaBoostBeta (it->second);
1122 else if (it->first ==
"Shrinkage" ) SetShrinkage (it->second);
1123 else if (it->first ==
"UseNvars" ) SetUseNvars ((
Int_t)it->second);
1124 else if (it->first ==
"BaggedSampleFraction" ) SetBaggedSampleFraction (it->second);
1125 else Log() <<
kFATAL <<
" SetParameter for " << it->first <<
" not yet implemented " <<
Endl;
1144 Log() <<
kERROR <<
" Zero Decision Trees demanded... that does not work !! "
1145 <<
" I set it to 1 .. just so that the program does not crash"
1150 if (fInteractive && fInteractive->NotInitialized()){
1151 std::vector<TString> titles = {
"Boost weight",
"Error Fraction"};
1152 fInteractive->Init(titles);
1154 fIPyMaxIter = fNTrees;
1155 fExitFromTraining =
false;
1159 if (IsNormalised())
Log() <<
kFATAL <<
"\"Normalise\" option cannot be used with BDT; "
1160 <<
"please remove the option from the configuration string, or "
1161 <<
"use \"!Normalise\""
1165 Log() <<
kINFO <<
"Regression Loss Function: "<< fRegressionLossFunctionBDTG->Name() <<
Endl;
1167 Log() <<
kINFO <<
"Training "<< fNTrees <<
" Decision Trees ... patience please" <<
Endl;
1169 Log() <<
kDEBUG <<
"Training with maximal depth = " <<fMaxDepth
1170 <<
", MinNodeEvents=" << fMinNodeEvents
1171 <<
", NTrees="<<fNTrees
1172 <<
", NodePurityLimit="<<fNodePurityLimit
1173 <<
", AdaBoostBeta="<<fAdaBoostBeta
1179 TString hname =
"AdaBooost weight distribution";
1185 if (DoRegression()) {
1189 hname=
"Boost event weights distribution";
1195 TH1* nodesBeforePruningVsTree =
new TH1I(
Form(
"%s_NodesBeforePruning",DataInfo().
GetName()),
"nodes before pruning",fNTrees,0,fNTrees);
1196 TH1* nodesAfterPruningVsTree =
new TH1I(
Form(
"%s_NodesAfterPruning",DataInfo().
GetName()),
"nodes after pruning",fNTrees,0,fNTrees);
1200 if(!DoMulticlass()){
1204 results->
Store(h,
"BoostWeights");
1208 if (fDoBoostMonitor){
1209 TH2* boostMonitor =
new TH2F(
"BoostMonitor",
"ROC Integral Vs iTree",2,0,fNTrees,2,0,1.05);
1211 boostMonitor->
SetYTitle(
"ROC Integral");
1212 results->
Store(boostMonitor,
"BoostMonitor");
1214 boostMonitorGraph->
SetName(
"BoostMonitorGraph");
1215 boostMonitorGraph->
SetTitle(
"ROCIntegralVsNTrees");
1216 results->
Store(boostMonitorGraph,
"BoostMonitorGraph");
1220 h =
new TH1F(
"BoostWeightVsTree",
"Boost weights vs tree",fNTrees,0,fNTrees);
1223 results->
Store(h,
"BoostWeightsVsTree");
1226 h =
new TH1F(
"ErrFractHist",
"error fraction vs tree number",fNTrees,0,fNTrees);
1229 results->
Store(h,
"ErrorFrac");
1232 nodesBeforePruningVsTree->
SetXTitle(
"#tree");
1233 nodesBeforePruningVsTree->
SetYTitle(
"#tree nodes");
1234 results->
Store(nodesBeforePruningVsTree);
1237 nodesAfterPruningVsTree->
SetXTitle(
"#tree");
1238 nodesAfterPruningVsTree->
SetYTitle(
"#tree nodes");
1239 results->
Store(nodesAfterPruningVsTree);
1243 fMonitorNtuple=
new TTree(
"MonitorNtuple",
"BDT variables");
1244 fMonitorNtuple->Branch(
"iTree",&fITree,
"iTree/I");
1245 fMonitorNtuple->Branch(
"boostWeight",&fBoostWeight,
"boostWeight/D");
1246 fMonitorNtuple->Branch(
"errorFraction",&fErrorFraction,
"errorFraction/D");
1249 Int_t nNodesBeforePruningCount = 0;
1250 Int_t nNodesAfterPruningCount = 0;
1252 Int_t nNodesBeforePruning = 0;
1253 Int_t nNodesAfterPruning = 0;
1256 if(fBoostType==
"Grad"){
1257 InitGradBoost(fEventSample);
1263 while (itree < fNTrees && continueBoost){
1264 if (fExitFromTraining)
break;
1265 fIPyCurrentIter = itree;
1278 if (fBoostType!=
"Grad"){
1279 Log() <<
kFATAL <<
"Multiclass is currently only supported by gradient boost. "
1280 <<
"Please change boost option accordingly (GradBoost)."
1283 UInt_t nClasses = DataInfo().GetNClasses();
1284 for (
UInt_t i=0;i<nClasses;i++){
1285 fForest.push_back(
new DecisionTree( fSepType, fMinNodeSize, fNCuts, &(DataInfo()), i,
1286 fRandomisedTrees, fUseNvars, fUsePoissonNvars, fMaxDepth,
1287 itree*nClasses+i, fNodePurityLimit, itree*nClasses+1));
1288 fForest.back()->SetNVars(GetNvar());
1289 if (fUseFisherCuts) {
1290 fForest.back()->SetUseFisherCuts();
1291 fForest.back()->SetMinLinCorrForFisher(fMinLinCorrForFisher);
1292 fForest.back()->SetUseExclusiveVars(fUseExclusiveVars);
1296 nNodesBeforePruning = fForest.back()->BuildTree(*fTrainSample);
1297 Double_t bw = this->Boost(*fTrainSample, fForest.back(),i);
1299 fBoostWeights.push_back(bw);
1301 fBoostWeights.push_back(0);
1309 fForest.push_back(
new DecisionTree( fSepType, fMinNodeSize, fNCuts, &(DataInfo()), fSignalClass,
1310 fRandomisedTrees, fUseNvars, fUsePoissonNvars, fMaxDepth,
1311 itree, fNodePurityLimit, itree));
1312 fForest.back()->SetNVars(GetNvar());
1313 if (fUseFisherCuts) {
1314 fForest.back()->SetUseFisherCuts();
1315 fForest.back()->SetMinLinCorrForFisher(fMinLinCorrForFisher);
1316 fForest.back()->SetUseExclusiveVars(fUseExclusiveVars);
1319 nNodesBeforePruning = fForest.back()->BuildTree(*fTrainSample);
1321 if (fUseYesNoLeaf && !DoRegression() && fBoostType!=
"Grad") {
1322 nNodesBeforePruning = fForest.back()->CleanTree();
1325 nNodesBeforePruningCount += nNodesBeforePruning;
1326 nodesBeforePruningVsTree->
SetBinContent(itree+1,nNodesBeforePruning);
1328 fForest.back()->SetPruneMethod(fPruneMethod);
1329 fForest.back()->SetPruneStrength(fPruneStrength);
1331 std::vector<const Event*> * validationSample =
NULL;
1332 if(fAutomatic) validationSample = &fValidationSample;
1334 Double_t bw = this->Boost(*fTrainSample, fForest.back());
1336 fBoostWeights.push_back(bw);
1338 fBoostWeights.push_back(0);
1350 if (fUseYesNoLeaf && !DoRegression() && fBoostType!=
"Grad"){
1351 fForest.back()->CleanTree();
1353 nNodesAfterPruning = fForest.back()->GetNNodes();
1354 nNodesAfterPruningCount += nNodesAfterPruning;
1355 nodesAfterPruningVsTree->
SetBinContent(itree+1,nNodesAfterPruning);
1358 fInteractive->AddPoint(itree, fBoostWeight, fErrorFraction);
1361 fMonitorNtuple->Fill();
1362 if (fDoBoostMonitor){
1363 if (! DoRegression() ){
1364 if ( itree==fNTrees-1 || (!(itree%500)) ||
1365 (!(itree%250) && itree <1000)||
1366 (!(itree%100) && itree < 500)||
1367 (!(itree%50) && itree < 250)||
1368 (!(itree%25) && itree < 150)||
1369 (!(itree%10) && itree < 50)||
1370 (!(itree%5) && itree < 20)
1371 ) BoostMonitor(itree);
1382 Log() <<
kDEBUG <<
"\t<Train> average number of nodes (w/o pruning) : "
1383 << nNodesBeforePruningCount/GetNTrees() <<
Endl;
1386 Log() <<
kDEBUG <<
"\t<Train> average number of nodes before/after pruning : "
1387 << nNodesBeforePruningCount/GetNTrees() <<
" / "
1388 << nNodesAfterPruningCount/GetNTrees()
1396 Log() <<
kDEBUG <<
"Now I delete the privat data sample"<<
Endl;
1397 for (
UInt_t i=0; i<fEventSample.size(); i++)
delete fEventSample[i];
1398 for (
UInt_t i=0; i<fValidationSample.size(); i++)
delete fValidationSample[i];
1399 fEventSample.clear();
1400 fValidationSample.clear();
1402 if (!fExitFromTraining) fIPyMaxIter = fIPyCurrentIter;
1413 for (
UInt_t itree=0; itree<nTrees; itree++) {
1415 sum += fForest[itree]->CheckEvent(e,
kFALSE);
1418 return 2.0/(1.0+
exp(-2.0*sum))-1;
1427 UInt_t nClasses = DataInfo().GetNClasses();
1428 for (std::vector<const TMVA::Event*>::iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1429 fResiduals[*
e].at(cls)+=fForest.back()->CheckEvent(*
e,
kFALSE);
1430 if(cls == nClasses-1){
1431 for(
UInt_t i=0;i<nClasses;i++){
1433 for(
UInt_t j=0;j<nClasses;j++){
1435 norm+=
exp(fResiduals[*
e].at(j)-fResiduals[*
e].at(i));
1438 Double_t res = ((*e)->GetClass()==i)?(1.0-p_cls):(-p_cls);
1445 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1446 fResiduals[*
e].at(0)+=fForest.back()->CheckEvent(*
e,
kFALSE);
1447 Double_t p_sig=1.0/(1.0+
exp(-2.0*fResiduals[*
e].at(0)));
1448 Double_t res = (DataInfo().IsSignal(*
e)?1:0)-p_sig;
1460 for (std::vector<const TMVA::Event*>::const_iterator
e=fEventSample.begin();
e!=fEventSample.end();
e++) {
1461 fLossFunctionEventInfo[*
e].predictedValue += fForest.back()->CheckEvent(*
e,
kFALSE);
1465 fRegressionLossFunctionBDTG->SetTargets(eventSample, fLossFunctionEventInfo);
1473 std::map<TMVA::DecisionTreeNode*,std::vector<Double_t> > leaves;
1474 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1475 Double_t weight = (*e)->GetWeight();
1477 if ((leaves[node]).empty()){
1478 (leaves[node]).push_back((*e)->GetTarget(cls)* weight);
1479 (leaves[node]).push_back(
fabs((*e)->GetTarget(cls))*(1.0-
fabs((*e)->GetTarget(cls))) * weight* weight);
1482 (leaves[node])[0]+=((*e)->GetTarget(cls)* weight);
1483 (leaves[node])[1]+=
fabs((*e)->GetTarget(cls))*(1.0-
fabs((*e)->GetTarget(cls))) * weight* weight;
1487 iLeave!=leaves.end();++iLeave){
1488 if ((iLeave->second)[1]<1
e-30) (iLeave->second)[1]=1
e-30;
1490 (iLeave->first)->SetResponse(fShrinkage/DataInfo().GetNClasses()*(iLeave->second)[0]/((iLeave->second)[1]));
1495 DoMulticlass() ? UpdateTargets(fEventSample, cls) : UpdateTargets(fEventSample);
1506 std::map<TMVA::DecisionTreeNode*,vector< TMVA::LossFunctionEventInfo > > leaves;
1507 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1509 (leaves[node]).push_back(fLossFunctionEventInfo[*
e]);
1514 for (std::map<
TMVA::DecisionTreeNode*,vector< TMVA::LossFunctionEventInfo > >::iterator iLeave=leaves.begin();
1515 iLeave!=leaves.end();++iLeave){
1516 Double_t fit = fRegressionLossFunctionBDTG->Fit(iLeave->second);
1517 (iLeave->first)->SetResponse(fShrinkage*fit);
1520 UpdateTargetsRegression(*fTrainSample);
1534 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1538 fRegressionLossFunctionBDTG->Init(fLossFunctionEventInfo, fBoostWeights);
1539 UpdateTargetsRegression(*fTrainSample,
kTRUE);
1542 else if(DoMulticlass()){
1543 UInt_t nClasses = DataInfo().GetNClasses();
1544 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1545 for (
UInt_t i=0;i<nClasses;i++){
1547 Double_t r = (*e)->GetClass()==i?(1-1.0/nClasses):(-1.0/nClasses);
1549 fResiduals[*
e].push_back(0);
1554 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1555 Double_t r = (DataInfo().IsSignal(*
e)?1:0)-0.5;
1557 fResiduals[*
e].push_back(0);
1568 for (
UInt_t ievt=0; ievt<fValidationSample.size(); ievt++) {
1569 Bool_t isSignalType= (dt->
CheckEvent(fValidationSample[ievt]) > fNodePurityLimit ) ? 1 : 0;
1571 if (isSignalType == (DataInfo().IsSignal(fValidationSample[ievt])) ) {
1572 ncorrect += fValidationSample[ievt]->GetWeight();
1575 nfalse += fValidationSample[ievt]->GetWeight();
1579 return ncorrect / (ncorrect + nfalse);
1590 if (fBoostType==
"AdaBoost") returnVal = this->AdaBoost (eventSample, dt);
1591 else if (fBoostType==
"AdaCost") returnVal = this->AdaCost (eventSample, dt);
1592 else if (fBoostType==
"Bagging") returnVal = this->Bagging ( );
1593 else if (fBoostType==
"RegBoost") returnVal = this->RegBoost (eventSample, dt);
1594 else if (fBoostType==
"AdaBoostR2") returnVal = this->AdaBoostR2(eventSample, dt);
1595 else if (fBoostType==
"Grad"){
1597 returnVal = this->GradBoostRegression(eventSample, dt);
1598 else if(DoMulticlass())
1599 returnVal = this->GradBoost (eventSample, dt, cls);
1601 returnVal = this->GradBoost (eventSample, dt);
1605 Log() <<
kFATAL <<
"<Boost> unknown boost option " << fBoostType<<
" called" <<
Endl;
1609 GetBaggedSubSample(fEventSample);
1624 TH1F *tmpS =
new TH1F(
"tmpS",
"", 100 , -1., 1.00001 );
1625 TH1F *tmpB =
new TH1F(
"tmpB",
"", 100 , -1., 1.00001 );
1629 UInt_t signalClassNr = DataInfo().GetClassInfo(
"Signal")->GetNumber();
1640 for (
UInt_t iev=0; iev < nevents; iev++){
1641 const Event*
event = GetTestingEvent(iev);
1643 if (event->GetClass() == signalClassNr) {tmp=tmpS;}
1645 tmp->
Fill(PrivateGetMvaValue(event),event->GetWeight());
1649 std::vector<TH1F*> hS;
1650 std::vector<TH1F*> hB;
1651 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++){
1652 hS.push_back(
new TH1F(
Form(
"SigVar%dAtTree%d",ivar,iTree),
Form(
"SigVar%dAtTree%d",ivar,iTree),100,DataInfo().GetVariableInfo(ivar).GetMin(),DataInfo().GetVariableInfo(ivar).GetMax()));
1653 hB.push_back(
new TH1F(
Form(
"BkgVar%dAtTree%d",ivar,iTree),
Form(
"BkgVar%dAtTree%d",ivar,iTree),100,DataInfo().GetVariableInfo(ivar).GetMin(),DataInfo().GetVariableInfo(ivar).GetMax()));
1654 results->
Store(hS.back(),hS.back()->GetTitle());
1655 results->
Store(hB.back(),hB.back()->GetTitle());
1659 for (
UInt_t iev=0; iev < fEventSample.size(); iev++){
1660 if (fEventSample[iev]->GetBoostWeight() > max) max = 1.01*fEventSample[iev]->GetBoostWeight();
1662 TH1F *tmpBoostWeightsS =
new TH1F(
Form(
"BoostWeightsInTreeS%d",iTree),
Form(
"BoostWeightsInTreeS%d",iTree),100,0.,max);
1663 TH1F *tmpBoostWeightsB =
new TH1F(
Form(
"BoostWeightsInTreeB%d",iTree),
Form(
"BoostWeightsInTreeB%d",iTree),100,0.,max);
1664 results->
Store(tmpBoostWeightsS,tmpBoostWeightsS->
GetTitle());
1665 results->
Store(tmpBoostWeightsB,tmpBoostWeightsB->
GetTitle());
1667 TH1F *tmpBoostWeights;
1668 std::vector<TH1F*> *
h;
1670 for (
UInt_t iev=0; iev < fEventSample.size(); iev++){
1671 if (fEventSample[iev]->
GetClass() == signalClassNr) {
1672 tmpBoostWeights=tmpBoostWeightsS;
1675 tmpBoostWeights=tmpBoostWeightsB;
1678 tmpBoostWeights->
Fill(fEventSample[iev]->GetBoostWeight());
1679 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++){
1680 (*h)[ivar]->Fill(fEventSample[iev]->GetValue(ivar),fEventSample[iev]->GetWeight());
1716 Double_t err=0, sumGlobalw=0, sumGlobalwfalse=0, sumGlobalwfalse2=0;
1718 std::vector<Double_t> sumw(DataInfo().GetNClasses(),0);
1719 std::map<Node*,Int_t> sigEventsInNode;
1722 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1725 UInt_t iclass=(*e)->GetClass();
1728 if ( DoRegression() ) {
1730 sumGlobalwfalse += w * tmpDev;
1731 sumGlobalwfalse2 += w * tmpDev*tmpDev;
1732 if (tmpDev > maxDev) maxDev = tmpDev;
1737 if (!(isSignalType == DataInfo().IsSignal(*
e))) {
1738 sumGlobalwfalse+= w;
1743 if (DataInfo().IsSignal(*
e)) trueType = 1;
1745 sumGlobalwfalse+= w*trueType*dtoutput;
1750 err = sumGlobalwfalse/sumGlobalw ;
1751 if ( DoRegression() ) {
1753 if (fAdaBoostR2Loss==
"linear"){
1754 err = sumGlobalwfalse/maxDev/sumGlobalw ;
1756 else if (fAdaBoostR2Loss==
"quadratic"){
1757 err = sumGlobalwfalse2/maxDev/maxDev/sumGlobalw ;
1759 else if (fAdaBoostR2Loss==
"exponential"){
1761 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1764 err += w * (1 -
exp (-tmpDev/maxDev)) / sumGlobalw;
1769 Log() <<
kFATAL <<
" you've chosen a Loss type for Adaboost other than linear, quadratic or exponential "
1770 <<
" namely " << fAdaBoostR2Loss <<
"\n"
1771 <<
"and this is not implemented... a typo in the options ??" <<
Endl;
1775 Log() <<
kDEBUG <<
"BDT AdaBoos wrong/all: " << sumGlobalwfalse <<
"/" << sumGlobalw <<
Endl;
1779 std::vector<Double_t> newSumw(sumw.size(),0);
1782 if (err >= 0.5 && fUseYesNoLeaf) {
1786 Log() <<
kERROR <<
" YOUR tree has only 1 Node... kind of a funny *tree*. I cannot "
1787 <<
"boost such a thing... if after 1 step the error rate is == 0.5"
1789 <<
"please check why this happens, maybe too many events per node requested ?"
1793 Log() <<
kERROR <<
" The error rate in the BDT boosting is > 0.5. ("<< err
1794 <<
") That should not happen, please check your code (i.e... the BDT code), I "
1795 <<
" stop boosting here" <<
Endl;
1799 }
else if (err < 0) {
1800 Log() <<
kERROR <<
" The error rate in the BDT boosting is < 0. That can happen"
1801 <<
" due to improper treatment of negative weights in a Monte Carlo.. (if you have"
1802 <<
" an idea on how to do it in a better way, please let me know (Helge.Voss@cern.ch)"
1803 <<
" for the time being I set it to its absolute value.. just to continue.." <<
Endl;
1807 boostWeight =
TMath::Log((1.-err)/err)*fAdaBoostBeta;
1809 boostWeight =
TMath::Log((1.+err)/(1-err))*fAdaBoostBeta;
1812 Log() <<
kDEBUG <<
"BDT AdaBoos wrong/all: " << sumGlobalwfalse <<
"/" << sumGlobalw <<
" 1-err/err="<<boostWeight<<
" log.."<<
TMath::Log(boostWeight)<<
Endl;
1817 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1819 if (fUseYesNoLeaf||DoRegression()){
1820 if ((!( (dt->
CheckEvent(*
e,fUseYesNoLeaf) > fNodePurityLimit ) == DataInfo().IsSignal(*
e))) || DoRegression()) {
1824 if ( (*e)->GetWeight() > 0 ){
1825 (*e)->SetBoostWeight( (*e)->GetBoostWeight() * boostfactor);
1827 if (DoRegression()) results->
GetHist(
"BoostWeights")->
Fill(boostfactor);
1829 if ( fInverseBoostNegWeights )(*e)->ScaleBoostWeight( 1. / boostfactor);
1830 else (*e)->SetBoostWeight( (*e)->GetBoostWeight() * boostfactor);
1838 if (DataInfo().IsSignal(*
e)) trueType = 1;
1842 if ( (*e)->GetWeight() > 0 ){
1843 (*e)->SetBoostWeight( (*e)->GetBoostWeight() * boostfactor);
1845 if (DoRegression()) results->
GetHist(
"BoostWeights")->
Fill(boostfactor);
1847 if ( fInverseBoostNegWeights )(*e)->ScaleBoostWeight( 1. / boostfactor);
1848 else (*e)->SetBoostWeight( (*e)->GetBoostWeight() * boostfactor);
1851 newSumGlobalw+=(*e)->GetWeight();
1852 newSumw[(*e)->GetClass()] += (*e)->GetWeight();
1858 Log() <<
kDEBUG <<
"new Nsig="<<newSumw[0]*globalNormWeight <<
" new Nbkg="<<newSumw[1]*globalNormWeight <<
Endl;
1861 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1865 if (DataInfo().IsSignal(*
e))(*e)->ScaleBoostWeight( globalNormWeight * fSigToBkgFraction );
1866 else (*e)->ScaleBoostWeight( globalNormWeight );
1869 if (!(DoRegression()))results->
GetHist(
"BoostWeights")->
Fill(boostWeight);
1873 fBoostWeight = boostWeight;
1874 fErrorFraction = err;
1902 Double_t err=0, sumGlobalWeights=0, sumGlobalCost=0;
1904 std::vector<Double_t> sumw(DataInfo().GetNClasses(),0);
1905 std::map<Node*,Int_t> sigEventsInNode;
1907 for (vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1909 sumGlobalWeights += w;
1910 UInt_t iclass=(*e)->GetClass();
1914 if ( DoRegression() ) {
1915 Log() <<
kFATAL <<
" AdaCost not implemented for regression"<<
Endl;
1920 Bool_t isTrueSignal = DataInfo().IsSignal(*
e);
1921 Bool_t isSelectedSignal = (dtoutput>0);
1922 if (isTrueSignal) trueType = 1;
1926 if (isTrueSignal && isSelectedSignal) cost=Css;
1927 else if (isTrueSignal && !isSelectedSignal) cost=Cts_sb;
1928 else if (!isTrueSignal && isSelectedSignal) cost=Ctb_ss;
1929 else if (!isTrueSignal && !isSelectedSignal) cost=Cbb;
1930 else Log() <<
kERROR <<
"something went wrong in AdaCost" <<
Endl;
1932 sumGlobalCost+= w*trueType*dtoutput*cost;
1937 if ( DoRegression() ) {
1938 Log() <<
kFATAL <<
" AdaCost not implemented for regression"<<
Endl;
1943 sumGlobalCost /= sumGlobalWeights;
1948 vector<Double_t> newSumClassWeights(sumw.size(),0);
1950 Double_t boostWeight =
TMath::Log((1+sumGlobalCost)/(1-sumGlobalCost)) * fAdaBoostBeta;
1954 for (vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1957 Bool_t isTrueSignal = DataInfo().IsSignal(*
e);
1958 Bool_t isSelectedSignal = (dtoutput>0);
1959 if (isTrueSignal) trueType = 1;
1963 if (isTrueSignal && isSelectedSignal) cost=Css;
1964 else if (isTrueSignal && !isSelectedSignal) cost=Cts_sb;
1965 else if (!isTrueSignal && isSelectedSignal) cost=Ctb_ss;
1966 else if (!isTrueSignal && !isSelectedSignal) cost=Cbb;
1967 else Log() <<
kERROR <<
"something went wrong in AdaCost" <<
Endl;
1970 if (DoRegression())
Log() <<
kFATAL <<
" AdaCost not implemented for regression"<<
Endl;
1971 if ( (*e)->GetWeight() > 0 ){
1972 (*e)->SetBoostWeight( (*e)->GetBoostWeight() * boostfactor);
1974 if (DoRegression())
Log() <<
kFATAL <<
" AdaCost not implemented for regression"<<
Endl;
1976 if ( fInverseBoostNegWeights )(*e)->ScaleBoostWeight( 1. / boostfactor);
1979 newSumGlobalWeights+=(*e)->GetWeight();
1980 newSumClassWeights[(*e)->GetClass()] += (*e)->GetWeight();
1985 Double_t globalNormWeight=
Double_t(eventSample.size())/newSumGlobalWeights;
1986 Log() <<
kDEBUG <<
"new Nsig="<<newSumClassWeights[0]*globalNormWeight <<
" new Nbkg="<<newSumClassWeights[1]*globalNormWeight <<
Endl;
1989 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
1992 if (DataInfo().IsSignal(*
e))(*e)->ScaleBoostWeight( globalNormWeight * fSigToBkgFraction );
1993 else (*e)->ScaleBoostWeight( globalNormWeight );
1997 if (!(DoRegression()))results->
GetHist(
"BoostWeights")->
Fill(boostWeight);
2001 fBoostWeight = boostWeight;
2002 fErrorFraction = err;
2030 if (!fSubSample.empty()) fSubSample.clear();
2032 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
2033 n = trandom->
PoissonD(fBaggedSampleFraction);
2034 for (
Int_t i=0;i<
n;i++) fSubSample.push_back(*
e);
2069 if ( !DoRegression() )
Log() <<
kFATAL <<
"Somehow you chose a regression boost method for a classification job" <<
Endl;
2071 Double_t err=0, sumw=0, sumwfalse=0, sumwfalse2=0;
2073 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
2078 sumwfalse += w * tmpDev;
2079 sumwfalse2 += w * tmpDev*tmpDev;
2080 if (tmpDev > maxDev) maxDev = tmpDev;
2084 if (fAdaBoostR2Loss==
"linear"){
2085 err = sumwfalse/maxDev/sumw ;
2087 else if (fAdaBoostR2Loss==
"quadratic"){
2088 err = sumwfalse2/maxDev/maxDev/sumw ;
2090 else if (fAdaBoostR2Loss==
"exponential"){
2092 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
2095 err += w * (1 -
exp (-tmpDev/maxDev)) / sumw;
2100 Log() <<
kFATAL <<
" you've chosen a Loss type for Adaboost other than linear, quadratic or exponential "
2101 <<
" namely " << fAdaBoostR2Loss <<
"\n"
2102 <<
"and this is not implemented... a typo in the options ??" <<
Endl;
2110 Log() <<
kERROR <<
" YOUR tree has only 1 Node... kind of a funny *tree*. I cannot "
2111 <<
"boost such a thing... if after 1 step the error rate is == 0.5"
2113 <<
"please check why this happens, maybe too many events per node requested ?"
2117 Log() <<
kERROR <<
" The error rate in the BDT boosting is > 0.5. ("<< err
2118 <<
") That should not happen, but is possible for regression trees, and"
2119 <<
" should trigger a stop for the boosting. please check your code (i.e... the BDT code), I "
2120 <<
" stop boosting " <<
Endl;
2124 }
else if (err < 0) {
2125 Log() <<
kERROR <<
" The error rate in the BDT boosting is < 0. That can happen"
2126 <<
" due to improper treatment of negative weights in a Monte Carlo.. (if you have"
2127 <<
" an idea on how to do it in a better way, please let me know (Helge.Voss@cern.ch)"
2128 <<
" for the time being I set it to its absolute value.. just to continue.." <<
Endl;
2132 Double_t boostWeight = err / (1.-err);
2137 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
2139 results->
GetHist(
"BoostWeights")->
Fill(boostfactor);
2141 if ( (*e)->GetWeight() > 0 ){
2142 Float_t newBoostWeight = (*e)->GetBoostWeight() * boostfactor;
2143 Float_t newWeight = (*e)->GetWeight() * (*e)->GetBoostWeight() * boostfactor;
2144 if (newWeight == 0) {
2145 Log() <<
kINFO <<
"Weight= " << (*e)->GetWeight() <<
Endl;
2146 Log() <<
kINFO <<
"BoostWeight= " << (*e)->GetBoostWeight() <<
Endl;
2147 Log() <<
kINFO <<
"boostweight="<<boostWeight <<
" err= " <<err <<
Endl;
2148 Log() <<
kINFO <<
"NewBoostWeight= " << newBoostWeight <<
Endl;
2149 Log() <<
kINFO <<
"boostfactor= " << boostfactor <<
Endl;
2152 Log() <<
kINFO <<
"target = " << (*e)->GetTarget(0) <<
Endl;
2155 (*e)->SetBoostWeight( newBoostWeight );
2158 (*e)->SetBoostWeight( (*e)->GetBoostWeight() / boostfactor);
2160 newSumw+=(*e)->GetWeight();
2164 Double_t normWeight = sumw / newSumw;
2165 for (std::vector<const TMVA::Event*>::const_iterator
e=eventSample.begin();
e!=eventSample.end();
e++) {
2168 (*e)->SetBoostWeight( (*e)->GetBoostWeight() * normWeight );
2175 fBoostWeight = boostWeight;
2176 fErrorFraction = err;
2188 if (fDoPreselection){
2189 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++){
2190 gTools().
AddAttr( wght,
Form(
"PreselectionLowBkgVar%d",ivar), fIsLowBkgCut[ivar]);
2191 gTools().
AddAttr( wght,
Form(
"PreselectionLowBkgVar%dValue",ivar), fLowBkgCut[ivar]);
2192 gTools().
AddAttr( wght,
Form(
"PreselectionLowSigVar%d",ivar), fIsLowSigCut[ivar]);
2193 gTools().
AddAttr( wght,
Form(
"PreselectionLowSigVar%dValue",ivar), fLowSigCut[ivar]);
2194 gTools().
AddAttr( wght,
Form(
"PreselectionHighBkgVar%d",ivar), fIsHighBkgCut[ivar]);
2195 gTools().
AddAttr( wght,
Form(
"PreselectionHighBkgVar%dValue",ivar),fHighBkgCut[ivar]);
2196 gTools().
AddAttr( wght,
Form(
"PreselectionHighSigVar%d",ivar), fIsHighSigCut[ivar]);
2197 gTools().
AddAttr( wght,
Form(
"PreselectionHighSigVar%dValue",ivar),fHighSigCut[ivar]);
2203 gTools().
AddAttr( wght,
"AnalysisType", fForest.back()->GetAnalysisType() );
2205 for (
UInt_t i=0; i< fForest.size(); i++) {
2206 void* trxml = fForest[i]->AddXMLTo(wght);
2217 for (i=0; i<fForest.size(); i++)
delete fForest[i];
2219 fBoostWeights.clear();
2226 if (
gTools().HasAttr( parent,
Form(
"PreselectionLowBkgVar%d",0))) {
2227 fIsLowBkgCut.resize(GetNvar());
2228 fLowBkgCut.resize(GetNvar());
2229 fIsLowSigCut.resize(GetNvar());
2230 fLowSigCut.resize(GetNvar());
2231 fIsHighBkgCut.resize(GetNvar());
2232 fHighBkgCut.resize(GetNvar());
2233 fIsHighSigCut.resize(GetNvar());
2234 fHighSigCut.resize(GetNvar());
2238 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++){
2240 fIsLowBkgCut[ivar]=tmpBool;
2242 fLowBkgCut[ivar]=tmpDouble;
2244 fIsLowSigCut[ivar]=tmpBool;
2246 fLowSigCut[ivar]=tmpDouble;
2248 fIsHighBkgCut[ivar]=tmpBool;
2250 fHighBkgCut[ivar]=tmpDouble;
2252 fIsHighSigCut[ivar]=tmpBool;
2254 fHighSigCut[ivar]=tmpDouble;
2261 if(
gTools().HasAttr(parent,
"TreeType")) {
2272 fForest.back()->SetTreeID(i++);
2274 fBoostWeights.push_back(boostWeight);
2286 Int_t analysisType(0);
2289 istr >> dummy >> fNTrees;
2290 Log() <<
kINFO <<
"Read " << fNTrees <<
" Decision trees" <<
Endl;
2292 for (
UInt_t i=0;i<fForest.size();i++)
delete fForest[i];
2294 fBoostWeights.clear();
2297 for (
int i=0;i<fNTrees;i++) {
2298 istr >> dummy >> iTree >> dummy >> boostWeight;
2300 fForest.back()->Print( std::cout );
2301 Log() <<
kFATAL <<
"Error while reading weight file; mismatch iTree="
2302 << iTree <<
" i=" << i
2303 <<
" dummy " << dummy
2304 <<
" boostweight " << boostWeight
2309 fForest.back()->SetTreeID(i);
2310 fForest.back()->
Read(istr, GetTrainingTMVAVersionCode());
2311 fBoostWeights.push_back(boostWeight);
2318 return this->GetMvaValue( err, errUpper, 0 );
2328 const Event* ev = GetEvent();
2329 if (fDoPreselection) {
2330 Double_t val = ApplyPreselectionCuts(ev);
2333 return PrivateGetMvaValue(ev, err, errUpper, useNTrees);
2344 NoErrorCalc(err, errUpper);
2348 UInt_t nTrees = fForest.size();
2350 if (useNTrees > 0 ) nTrees = useNTrees;
2352 if (fBoostType==
"Grad")
return GetGradBoostMVA(ev,nTrees);
2356 for (
UInt_t itree=0; itree<nTrees; itree++) {
2358 myMVA += fBoostWeights[itree] * fForest[itree]->CheckEvent(ev,fUseYesNoLeaf);
2359 norm += fBoostWeights[itree];
2371 if (fMulticlassReturnVal ==
NULL) fMulticlassReturnVal =
new std::vector<Float_t>();
2372 fMulticlassReturnVal->clear();
2374 std::vector<double> temp;
2376 UInt_t nClasses = DataInfo().GetNClasses();
2377 for(
UInt_t iClass=0; iClass<nClasses; iClass++){
2378 temp.push_back(0.0);
2379 for(
UInt_t itree = iClass; itree<fForest.size(); itree+=nClasses){
2380 temp[iClass] += fForest[itree]->CheckEvent(e,
kFALSE);
2384 for(
UInt_t iClass=0; iClass<nClasses; iClass++){
2386 for(
UInt_t j=0;j<nClasses;j++){
2388 norm+=
exp(temp[j]-temp[iClass]);
2390 (*fMulticlassReturnVal).push_back(1.0/(1.0+norm));
2394 return *fMulticlassReturnVal;
2406 if (fRegressionReturnVal ==
NULL) fRegressionReturnVal =
new std::vector<Float_t>();
2407 fRegressionReturnVal->clear();
2409 const Event * ev = GetEvent();
2414 if (fBoostType==
"AdaBoostR2") {
2425 vector< Double_t > response(fForest.size());
2426 vector< Double_t > weight(fForest.size());
2429 for (
UInt_t itree=0; itree<fForest.size(); itree++) {
2430 response[itree] = fForest[itree]->CheckEvent(ev,
kFALSE);
2431 weight[itree] = fBoostWeights[itree];
2432 totalSumOfWeights += fBoostWeights[itree];
2435 std::vector< std::vector<Double_t> > vtemp;
2436 vtemp.push_back( response );
2437 vtemp.push_back( weight );
2442 while (sumOfWeights <= totalSumOfWeights/2.) {
2443 sumOfWeights += vtemp[1][t];
2457 else if(fBoostType==
"Grad"){
2458 for (
UInt_t itree=0; itree<fForest.size(); itree++) {
2459 myMVA += fForest[itree]->CheckEvent(ev,
kFALSE);
2462 evT->
SetTarget(0, myMVA+fBoostWeights[0] );
2465 for (
UInt_t itree=0; itree<fForest.size(); itree++) {
2467 myMVA += fBoostWeights[itree] * fForest[itree]->CheckEvent(ev,
kFALSE);
2468 norm += fBoostWeights[itree];
2476 const Event* evT2 = GetTransformationHandler().InverseTransform( evT );
2477 fRegressionReturnVal->push_back( evT2->
GetTarget(0) );
2482 return *fRegressionReturnVal;
2491 Log() <<
kDEBUG <<
"\tWrite monitoring histograms to file: " << BaseDir()->GetPath() <<
Endl;
2495 fMonitorNtuple->
Write();
2506 fVariableImportance.resize(GetNvar());
2507 for (
UInt_t ivar = 0; ivar < GetNvar(); ivar++) {
2508 fVariableImportance[ivar]=0;
2511 for (
UInt_t itree = 0; itree < GetNTrees(); itree++) {
2512 std::vector<Double_t> relativeImportance(fForest[itree]->GetVariableImportance());
2513 for (
UInt_t i=0; i< relativeImportance.size(); i++) {
2514 fVariableImportance[i] += fBoostWeights[itree] * relativeImportance[i];
2518 for (
UInt_t ivar=0; ivar< fVariableImportance.size(); ivar++){
2519 fVariableImportance[ivar] =
TMath::Sqrt(fVariableImportance[ivar]);
2520 sum += fVariableImportance[ivar];
2522 for (
UInt_t ivar=0; ivar< fVariableImportance.size(); ivar++) fVariableImportance[ivar] /= sum;
2524 return fVariableImportance;
2534 std::vector<Double_t> relativeImportance = this->GetVariableImportance();
2535 if (ivar < (
UInt_t)relativeImportance.size())
return relativeImportance[ivar];
2536 else Log() <<
kFATAL <<
"<GetVariableImportance> ivar = " << ivar <<
" is out of range " <<
Endl;
2548 vector< Double_t> importance(this->GetVariableImportance());
2550 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
2552 fRanking->AddRank(
Rank( GetInputLabel(ivar), importance[ivar] ) );
2569 Log() <<
"Boosted Decision Trees are a collection of individual decision" <<
Endl;
2570 Log() <<
"trees which form a multivariate classifier by (weighted) majority " <<
Endl;
2571 Log() <<
"vote of the individual trees. Consecutive decision trees are " <<
Endl;
2572 Log() <<
"trained using the original training data set with re-weighted " <<
Endl;
2573 Log() <<
"events. By default, the AdaBoost method is employed, which gives " <<
Endl;
2574 Log() <<
"events that were misclassified in the previous tree a larger " <<
Endl;
2575 Log() <<
"weight in the training of the following tree." <<
Endl;
2577 Log() <<
"Decision trees are a sequence of binary splits of the data sample" <<
Endl;
2578 Log() <<
"using a single descriminant variable at a time. A test event " <<
Endl;
2579 Log() <<
"ending up after the sequence of left-right splits in a final " <<
Endl;
2580 Log() <<
"(\"leaf\") node is classified as either signal or background" <<
Endl;
2581 Log() <<
"depending on the majority type of training events in that node." <<
Endl;
2585 Log() <<
"By the nature of the binary splits performed on the individual" <<
Endl;
2586 Log() <<
"variables, decision trees do not deal well with linear correlations" <<
Endl;
2587 Log() <<
"between variables (they need to approximate the linear split in" <<
Endl;
2588 Log() <<
"the two dimensional space by a sequence of splits on the two " <<
Endl;
2589 Log() <<
"variables individually). Hence decorrelation could be useful " <<
Endl;
2590 Log() <<
"to optimise the BDT performance." <<
Endl;
2594 Log() <<
"The two most important parameters in the configuration are the " <<
Endl;
2595 Log() <<
"minimal number of events requested by a leaf node as percentage of the " <<
Endl;
2596 Log() <<
" number of training events (option \"MinNodeSize\" replacing the actual number " <<
Endl;
2597 Log() <<
" of events \"nEventsMin\" as given in earlier versions" <<
Endl;
2598 Log() <<
"If this number is too large, detailed features " <<
Endl;
2599 Log() <<
"in the parameter space are hard to be modelled. If it is too small, " <<
Endl;
2600 Log() <<
"the risk to overtrain rises and boosting seems to be less effective" <<
Endl;
2601 Log() <<
" typical values from our current expericience for best performance " <<
Endl;
2602 Log() <<
" are between 0.5(%) and 10(%) " <<
Endl;
2604 Log() <<
"The default minimal number is currently set to " <<
Endl;
2605 Log() <<
" max(20, (N_training_events / N_variables^2 / 10)) " <<
Endl;
2606 Log() <<
"and can be changed by the user." <<
Endl;
2608 Log() <<
"The other crucial parameter, the pruning strength (\"PruneStrength\")," <<
Endl;
2609 Log() <<
"is also related to overtraining. It is a regularisation parameter " <<
Endl;
2610 Log() <<
"that is used when determining after the training which splits " <<
Endl;
2611 Log() <<
"are considered statistically insignificant and are removed. The" <<
Endl;
2612 Log() <<
"user is advised to carefully watch the BDT screen output for" <<
Endl;
2613 Log() <<
"the comparison between efficiencies obtained on the training and" <<
Endl;
2614 Log() <<
"the independent test sample. They should be equal within statistical" <<
Endl;
2615 Log() <<
"errors, in order to minimize statistical fluctuations in different samples." <<
Endl;
2627 fout <<
" std::vector<"<<nodeName<<
"*> fForest; // i.e. root nodes of decision trees" << std::endl;
2628 fout <<
" std::vector<double> fBoostWeights; // the weights applied in the individual boosts" << std::endl;
2629 fout <<
"};" << std::endl << std::endl;
2630 fout <<
"double " << className <<
"::GetMvaValue__( const std::vector<double>& inputValues ) const" << std::endl;
2631 fout <<
"{" << std::endl;
2632 fout <<
" double myMVA = 0;" << std::endl;
2633 if (fDoPreselection){
2634 for (
UInt_t ivar = 0; ivar< fIsLowBkgCut.size(); ivar++){
2635 if (fIsLowBkgCut[ivar]){
2636 fout <<
" if (inputValues["<<ivar<<
"] < " << fLowBkgCut[ivar] <<
") return -1; // is background preselection cut" << std::endl;
2638 if (fIsLowSigCut[ivar]){
2639 fout <<
" if (inputValues["<<ivar<<
"] < "<< fLowSigCut[ivar] <<
") return 1; // is signal preselection cut" << std::endl;
2641 if (fIsHighBkgCut[ivar]){
2642 fout <<
" if (inputValues["<<ivar<<
"] > "<<fHighBkgCut[ivar] <<
") return -1; // is background preselection cut" << std::endl;
2644 if (fIsHighSigCut[ivar]){
2645 fout <<
" if (inputValues["<<ivar<<
"] > "<<fHighSigCut[ivar]<<
") return 1; // is signal preselection cut" << std::endl;
2650 if (fBoostType!=
"Grad"){
2651 fout <<
" double norm = 0;" << std::endl;
2653 fout <<
" for (unsigned int itree=0; itree<fForest.size(); itree++){" << std::endl;
2654 fout <<
" "<<nodeName<<
" *current = fForest[itree];" << std::endl;
2655 fout <<
" while (current->GetNodeType() == 0) { //intermediate node" << std::endl;
2656 fout <<
" if (current->GoesRight(inputValues)) current=("<<nodeName<<
"*)current->GetRight();" << std::endl;
2657 fout <<
" else current=("<<nodeName<<
"*)current->GetLeft();" << std::endl;
2658 fout <<
" }" << std::endl;
2659 if (fBoostType==
"Grad"){
2660 fout <<
" myMVA += current->GetResponse();" << std::endl;
2662 if (fUseYesNoLeaf) fout <<
" myMVA += fBoostWeights[itree] * current->GetNodeType();" << std::endl;
2663 else fout <<
" myMVA += fBoostWeights[itree] * current->GetPurity();" << std::endl;
2664 fout <<
" norm += fBoostWeights[itree];" << std::endl;
2666 fout <<
" }" << std::endl;
2667 if (fBoostType==
"Grad"){
2668 fout <<
" return 2.0/(1.0+exp(-2.0*myMVA))-1.0;" << std::endl;
2670 else fout <<
" return myMVA /= norm;" << std::endl;
2671 fout <<
"};" << std::endl << std::endl;
2672 fout <<
"void " << className <<
"::Initialize()" << std::endl;
2673 fout <<
"{" << std::endl;
2675 for (
UInt_t itree=0; itree<GetNTrees(); itree++) {
2676 fout <<
" // itree = " << itree << std::endl;
2677 fout <<
" fBoostWeights.push_back(" << fBoostWeights[itree] <<
");" << std::endl;
2678 fout <<
" fForest.push_back( " << std::endl;
2679 this->MakeClassInstantiateNode((
DecisionTreeNode*)fForest[itree]->GetRoot(), fout, className);
2680 fout <<
" );" << std::endl;
2682 fout <<
" return;" << std::endl;
2683 fout <<
"};" << std::endl;
2684 fout <<
" " << std::endl;
2685 fout <<
"// Clean up" << std::endl;
2686 fout <<
"inline void " << className <<
"::Clear() " << std::endl;
2687 fout <<
"{" << std::endl;
2688 fout <<
" for (unsigned int itree=0; itree<fForest.size(); itree++) { " << std::endl;
2689 fout <<
" delete fForest[itree]; " << std::endl;
2690 fout <<
" }" << std::endl;
2691 fout <<
"}" << std::endl;
2703 fout <<
"#define NN new "<<nodeName << std::endl;
2705 fout <<
" " << std::endl;
2706 fout <<
"#ifndef "<<nodeName<<
"__def" << std::endl;
2707 fout <<
"#define "<<nodeName<<
"__def" << std::endl;
2708 fout <<
" " << std::endl;
2709 fout <<
"class "<<nodeName<<
" {" << std::endl;
2710 fout <<
" " << std::endl;
2711 fout <<
"public:" << std::endl;
2712 fout <<
" " << std::endl;
2713 fout <<
" // constructor of an essentially \"empty\" node floating in space" << std::endl;
2714 fout <<
" "<<nodeName<<
" ( "<<nodeName<<
"* left,"<<nodeName<<
"* right," << std::endl;
2715 if (fUseFisherCuts){
2716 fout <<
" int nFisherCoeff," << std::endl;
2717 for (
UInt_t i=0;i<GetNVariables()+1;i++){
2718 fout <<
" double fisherCoeff"<<i<<
"," << std::endl;
2721 fout <<
" int selector, double cutValue, bool cutType, " << std::endl;
2722 fout <<
" int nodeType, double purity, double response ) :" << std::endl;
2723 fout <<
" fLeft ( left )," << std::endl;
2724 fout <<
" fRight ( right )," << std::endl;
2725 if (fUseFisherCuts) fout <<
" fNFisherCoeff ( nFisherCoeff )," << std::endl;
2726 fout <<
" fSelector ( selector )," << std::endl;
2727 fout <<
" fCutValue ( cutValue )," << std::endl;
2728 fout <<
" fCutType ( cutType )," << std::endl;
2729 fout <<
" fNodeType ( nodeType )," << std::endl;
2730 fout <<
" fPurity ( purity )," << std::endl;
2731 fout <<
" fResponse ( response ){" << std::endl;
2732 if (fUseFisherCuts){
2733 for (
UInt_t i=0;i<GetNVariables()+1;i++){
2734 fout <<
" fFisherCoeff.push_back(fisherCoeff"<<i<<
");" << std::endl;
2737 fout <<
" }" << std::endl << std::endl;
2738 fout <<
" virtual ~"<<nodeName<<
"();" << std::endl << std::endl;
2739 fout <<
" // test event if it decends the tree at this node to the right" << std::endl;
2740 fout <<
" virtual bool GoesRight( const std::vector<double>& inputValues ) const;" << std::endl;
2741 fout <<
" "<<nodeName<<
"* GetRight( void ) {return fRight; };" << std::endl << std::endl;
2742 fout <<
" // test event if it decends the tree at this node to the left " << std::endl;
2743 fout <<
" virtual bool GoesLeft ( const std::vector<double>& inputValues ) const;" << std::endl;
2744 fout <<
" "<<nodeName<<
"* GetLeft( void ) { return fLeft; }; " << std::endl << std::endl;
2745 fout <<
" // return S/(S+B) (purity) at this node (from training)" << std::endl << std::endl;
2746 fout <<
" double GetPurity( void ) const { return fPurity; } " << std::endl;
2747 fout <<
" // return the node type" << std::endl;
2748 fout <<
" int GetNodeType( void ) const { return fNodeType; }" << std::endl;
2749 fout <<
" double GetResponse(void) const {return fResponse;}" << std::endl << std::endl;
2750 fout <<
"private:" << std::endl << std::endl;
2751 fout <<
" "<<nodeName<<
"* fLeft; // pointer to the left daughter node" << std::endl;
2752 fout <<
" "<<nodeName<<
"* fRight; // pointer to the right daughter node" << std::endl;
2753 if (fUseFisherCuts){
2754 fout <<
" int fNFisherCoeff; // =0 if this node doesn use fisher, else =nvar+1 " << std::endl;
2755 fout <<
" std::vector<double> fFisherCoeff; // the fisher coeff (offset at the last element)" << std::endl;
2757 fout <<
" int fSelector; // index of variable used in node selection (decision tree) " << std::endl;
2758 fout <<
" double fCutValue; // cut value appplied on this node to discriminate bkg against sig" << std::endl;
2759 fout <<
" bool fCutType; // true: if event variable > cutValue ==> signal , false otherwise" << std::endl;
2760 fout <<
" int fNodeType; // Type of node: -1 == Bkg-leaf, 1 == Signal-leaf, 0 = internal " << std::endl;
2761 fout <<
" double fPurity; // Purity of node from training"<< std::endl;
2762 fout <<
" double fResponse; // Regression response value of node" << std::endl;
2763 fout <<
"}; " << std::endl;
2764 fout <<
" " << std::endl;
2765 fout <<
"//_______________________________________________________________________" << std::endl;
2766 fout <<
" "<<nodeName<<
"::~"<<nodeName<<
"()" << std::endl;
2767 fout <<
"{" << std::endl;
2768 fout <<
" if (fLeft != NULL) delete fLeft;" << std::endl;
2769 fout <<
" if (fRight != NULL) delete fRight;" << std::endl;
2770 fout <<
"}; " << std::endl;
2771 fout <<
" " << std::endl;
2772 fout <<
"//_______________________________________________________________________" << std::endl;
2773 fout <<
"bool "<<nodeName<<
"::GoesRight( const std::vector<double>& inputValues ) const" << std::endl;
2774 fout <<
"{" << std::endl;
2775 fout <<
" // test event if it decends the tree at this node to the right" << std::endl;
2776 fout <<
" bool result;" << std::endl;
2777 if (fUseFisherCuts){
2778 fout <<
" if (fNFisherCoeff == 0){" << std::endl;
2779 fout <<
" result = (inputValues[fSelector] > fCutValue );" << std::endl;
2780 fout <<
" }else{" << std::endl;
2781 fout <<
" double fisher = fFisherCoeff.at(fFisherCoeff.size()-1);" << std::endl;
2782 fout <<
" for (unsigned int ivar=0; ivar<fFisherCoeff.size()-1; ivar++)" << std::endl;
2783 fout <<
" fisher += fFisherCoeff.at(ivar)*inputValues.at(ivar);" << std::endl;
2784 fout <<
" result = fisher > fCutValue;" << std::endl;
2785 fout <<
" }" << std::endl;
2787 fout <<
" result = (inputValues[fSelector] > fCutValue );" << std::endl;
2789 fout <<
" if (fCutType == true) return result; //the cuts are selecting Signal ;" << std::endl;
2790 fout <<
" else return !result;" << std::endl;
2791 fout <<
"}" << std::endl;
2792 fout <<
" " << std::endl;
2793 fout <<
"//_______________________________________________________________________" << std::endl;
2794 fout <<
"bool "<<nodeName<<
"::GoesLeft( const std::vector<double>& inputValues ) const" << std::endl;
2795 fout <<
"{" << std::endl;
2796 fout <<
" // test event if it decends the tree at this node to the left" << std::endl;
2797 fout <<
" if (!this->GoesRight(inputValues)) return true;" << std::endl;
2798 fout <<
" else return false;" << std::endl;
2799 fout <<
"}" << std::endl;
2800 fout <<
" " << std::endl;
2801 fout <<
"#endif" << std::endl;
2802 fout <<
" " << std::endl;
2811 Log() <<
kFATAL <<
"MakeClassInstantiateNode: started with undefined node" <<
Endl;
2814 fout <<
"NN("<<std::endl;
2821 fout <<
", " <<std::endl;
2828 fout <<
", " << std::endl
2829 << std::setprecision(6);
2830 if (fUseFisherCuts){
2832 for (
UInt_t i=0; i< GetNVariables()+1; i++) {
2857 Int_t nTotS_unWeighted = 0, nTotB_unWeighted = 0;
2859 std::vector<TMVA::BDTEventWrapper> bdtEventSample;
2861 fIsLowSigCut.assign(GetNvar(),
kFALSE);
2862 fIsLowBkgCut.assign(GetNvar(),
kFALSE);
2863 fIsHighSigCut.assign(GetNvar(),
kFALSE);
2864 fIsHighBkgCut.assign(GetNvar(),
kFALSE);
2866 fLowSigCut.assign(GetNvar(),0.);
2867 fLowBkgCut.assign(GetNvar(),0.);
2868 fHighSigCut.assign(GetNvar(),0.);
2869 fHighBkgCut.assign(GetNvar(),0.);
2874 for( std::vector<const TMVA::Event*>::const_iterator it = eventSample.begin(); it != eventSample.end(); ++it ) {
2875 if (DataInfo().IsSignal(*it)){
2876 nTotS += (*it)->GetWeight();
2880 nTotB += (*it)->GetWeight();
2886 for(
UInt_t ivar = 0; ivar < GetNvar(); ivar++ ) {
2888 std::sort( bdtEventSample.begin(),bdtEventSample.end() );
2890 Double_t bkgWeightCtr = 0.0, sigWeightCtr = 0.0;
2891 std::vector<TMVA::BDTEventWrapper>::iterator it = bdtEventSample.begin(), it_end = bdtEventSample.end();
2892 for( ; it != it_end; ++it ) {
2893 if (DataInfo().IsSignal(**it))
2894 sigWeightCtr += (**it)->GetWeight();
2896 bkgWeightCtr += (**it)->GetWeight();
2898 it->SetCumulativeWeight(
false,bkgWeightCtr);
2899 it->SetCumulativeWeight(
true,sigWeightCtr);
2904 Double_t dVal = (DataInfo().GetVariableInfo(ivar).GetMax() - DataInfo().GetVariableInfo(ivar).GetMin())/100. ;
2905 Double_t nSelS, nSelB, effS=0.05, effB=0.05, rejS=0.05, rejB=0.05;
2906 Double_t tmpEffS, tmpEffB, tmpRejS, tmpRejB;
2911 for(
UInt_t iev = 1; iev < bdtEventSample.size(); iev++) {
2914 nSelS = bdtEventSample[iev].GetCumulativeWeight(
true);
2915 nSelB = bdtEventSample[iev].GetCumulativeWeight(
false);
2917 tmpEffS=nSelS/nTotS;
2918 tmpEffB=nSelB/nTotB;
2921 if (nSelS==0 && tmpEffB>effB) {effB=tmpEffB; fLowBkgCut[ivar] = bdtEventSample[iev].GetVal() - dVal; fIsLowBkgCut[ivar]=
kTRUE;}
2922 else if (nSelB==0 && tmpEffS>effS) {effS=tmpEffS; fLowSigCut[ivar] = bdtEventSample[iev].GetVal() - dVal; fIsLowSigCut[ivar]=
kTRUE;}
2923 else if (nSelB==nTotB && tmpRejS>rejS) {rejS=tmpRejS; fHighSigCut[ivar] = bdtEventSample[iev].GetVal() + dVal; fIsHighSigCut[ivar]=
kTRUE;}
2924 else if (nSelS==nTotS && tmpRejB>rejB) {rejB=tmpRejB; fHighBkgCut[ivar] = bdtEventSample[iev].GetVal() + dVal; fIsHighBkgCut[ivar]=
kTRUE;}
2929 Log() <<
kDEBUG <<
" \tfound and suggest the following possible pre-selection cuts " <<
Endl;
2930 if (fDoPreselection)
Log() <<
kDEBUG <<
"\tthe training will be done after these cuts... and GetMVA value returns +1, (-1) for a signal (bkg) event that passes these cuts" <<
Endl;
2931 else Log() <<
kDEBUG <<
"\tas option DoPreselection was not used, these cuts however will not be performed, but the training will see the full sample"<<
Endl;
2932 for (
UInt_t ivar=0; ivar < GetNvar(); ivar++ ) {
2933 if (fIsLowBkgCut[ivar]){
2934 Log() <<
kDEBUG <<
" \tfound cut: Bkg if var " << ivar <<
" < " << fLowBkgCut[ivar] <<
Endl;
2936 if (fIsLowSigCut[ivar]){
2937 Log() <<
kDEBUG <<
" \tfound cut: Sig if var " << ivar <<
" < " << fLowSigCut[ivar] <<
Endl;
2939 if (fIsHighBkgCut[ivar]){
2940 Log() <<
kDEBUG <<
" \tfound cut: Bkg if var " << ivar <<
" > " << fHighBkgCut[ivar] <<
Endl;
2942 if (fIsHighSigCut[ivar]){
2943 Log() <<
kDEBUG <<
" \tfound cut: Sig if var " << ivar <<
" > " << fHighSigCut[ivar] <<
Endl;
2958 for (
UInt_t ivar=0; ivar < GetNvar(); ivar++ ) {
2959 if (fIsLowBkgCut[ivar]){
2960 if (ev->
GetValue(ivar) < fLowBkgCut[ivar]) result = -1;
2962 if (fIsLowSigCut[ivar]){
2963 if (ev->
GetValue(ivar) < fLowSigCut[ivar]) result = 1;
2965 if (fIsHighBkgCut[ivar]){
2966 if (ev->
GetValue(ivar) > fHighBkgCut[ivar]) result = -1;
2968 if (fIsHighSigCut[ivar]){
2969 if (ev->
GetValue(ivar) > fHighSigCut[ivar]) result = 1;
Double_t AdaCost(std::vector< const TMVA::Event * > &, DecisionTree *dt)
the AdaCost boosting algorithm takes a simple cost Matrix (currently fixed for all events...
void Train(void)
BDT training.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual const char * GetTitle() const
Returns title of object.
std::string GetName(const std::string &scope_name)
void PreProcessNegativeEventWeights()
o.k.
Double_t AdaBoostR2(std::vector< const TMVA::Event * > &, DecisionTree *dt)
adaption of the AdaBoost to regression problems (see H.Drucker 1997)
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
double dist(Rotation3D const &r1, Rotation3D const &r2)
static long int sum(long int i)
Random number generator class based on M.
THist< 1, int, THistStatContent > TH1I
virtual Double_t PoissonD(Double_t mean)
Generates a random number according to a Poisson law.
MsgLogger & Endl(MsgLogger &ml)
Double_t Boost(std::vector< const TMVA::Event * > &, DecisionTree *dt, UInt_t cls=0)
apply the boosting alogrithim (the algorithm is selecte via the the "option" given in the constructor...
TH1 * GetHist(const TString &alias) const
void WriteMonitoringHistosToFile(void) const
Here we could write some histograms created during the processing to the output file.
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
void AddWeightsXMLTo(void *parent) const
write weights to XML
Double_t GradBoost(std::vector< const TMVA::Event * > &, DecisionTree *dt, UInt_t cls=0)
Calculate the desired response value for each region.
const Ranking * CreateRanking()
Compute ranking of input variables.
void MakeClassSpecificHeader(std::ostream &, const TString &) const
specific class header
void BDT(TString dataset, const TString &fin="TMVA.root")
TString & ReplaceAll(const TString &s1, const TString &s2)
virtual void SetName(const char *name)
Set the name of the TNamed.
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
void DeclareOptions()
define the options (their key words) that can be set in the option string know options: nTrees number...
Double_t Atof() const
Return floating-point value contained in string.
UInt_t GetNFisherCoeff() const
virtual DecisionTreeNode * GetRight() const
TMVA::DecisionTreeNode * GetEventNode(const TMVA::Event &e) const
get the pointer to the leaf node where a particular event ends up in...
Double_t Bagging()
call it boot-strapping, re-sampling or whatever you like, in the end it is nothing else but applying ...
void DrawProgressBar(Int_t, const TString &comment="")
draws progress bar in color or B&W caution:
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Short_t Min(Short_t a, Short_t b)
Int_t GetNodeType(void) const
virtual void SetYTitle(const char *title)
virtual void SetTitle(const char *title="")
Set graph title.
void DeterminePreselectionCuts(const std::vector< const TMVA::Event * > &eventSample)
find useful preselection cuts that will be applied before and Decision Tree training.
void ProcessOptions()
the option string is decoded, for available options see "DeclareOptions"
void UpdateTargetsRegression(std::vector< const TMVA::Event * > &, Bool_t first=kFALSE)
Calculate current residuals for all events and update targets for next iteration. ...
Int_t FloorNint(Double_t x)
virtual DecisionTreeNode * GetLeft() const
TString GetElapsedTime(Bool_t Scientific=kTRUE)
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
void GetHelpMessage() const
Get help message text.
Double_t GetGradBoostMVA(const TMVA::Event *e, UInt_t nTrees)
returns MVA value: -1 for background, 1 for signal
virtual void SetTuneParameters(std::map< TString, Double_t > tuneParameters)
set the tuning parameters accoding to the argument
virtual Double_t Determinant() const
Float_t GetPurity(void) const
Bool_t GetCutType(void) const
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
BDT can handle classification with multiple classes and regression with one regression-target.
void Reset(void)
reset the method, as if it had just been instantiated (forget all training etc.)
TString & Append(const char *cs)
std::vector< std::vector< double > > Data
Double_t RegBoost(std::vector< const TMVA::Event * > &, DecisionTree *dt)
a special boosting only for Regression ...
void SetMinNodeSize(Double_t sizeInPercent)
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
void MakeClassInstantiateNode(DecisionTreeNode *n, std::ostream &fout, const TString &className) const
recursively descends a tree and writes the node instance to the output streem
const std::vector< Float_t > & GetMulticlassValues()
get the multiclass MVA response for the BDT classifier
Double_t GradBoostRegression(std::vector< const TMVA::Event * > &, DecisionTree *dt)
Implementation of M_TreeBoost using any loss function as desribed by Friedman 1999.
void InitGradBoost(std::vector< const TMVA::Event * > &)
initialize targets for first tree
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...
const std::vector< Float_t > & GetRegressionValues()
get the regression value generated by the BDTs
void InitEventSample()
initialize the event sample (i.e. reset the boost-weights... etc)
virtual void Delete(Option_t *option="")
Delete this object.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
std::string GetMethodName(TCppMethod_t)
Service class for 2-Dim histogram classes.
std::map< TString, Double_t > optimize()
void BoostMonitor(Int_t iTree)
fills the ROCIntegral vs Itree from the testSample for the monitoring plots during the training ...
Double_t GetFisherCoeff(Int_t ivar) const
virtual ~MethodBDT(void)
destructor Note: fEventSample and ValidationSample are already deleted at the end of TRAIN When they ...
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Double_t PrivateGetMvaValue(const TMVA::Event *ev, Double_t *err=0, Double_t *errUpper=0, UInt_t useNTrees=0)
Return the MVA value (range [-1;1]) that classifies the event according to the majority vote from the...
char * Form(const char *fmt,...)
void SetTarget(UInt_t itgt, Float_t value)
set the target value (dimension itgt) to value
SeparationBase * fSepType
void Init(void)
common initialisation with defaults for the BDT-Method
void ReadWeightsFromXML(void *parent)
reads the BDT from the xml file
Double_t AdaBoost(std::vector< const TMVA::Event * > &, DecisionTree *dt)
the AdaBoost implementation.
Double_t TestTreeQuality(DecisionTree *dt)
test the tree quality.. in terms of Miscalssification
static void SetVarIndex(Int_t iVar)
TGraph * GetGraph(const TString &alias) const
void Print(std::ostream &os, const OptionType &opt)
void ReadWeightsFromStream(std::istream &istr)
read the weights (BDT coefficients)
Double_t ApplyPreselectionCuts(const Event *ev)
aply the preselection cuts before even bothing about any Decision Trees in the GetMVA ...
void UpdateTargets(std::vector< const TMVA::Event * > &, UInt_t cls=0)
Calculate residua for all events;.
static DecisionTree * CreateFromXML(void *node, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)
re-create a new tree (decision tree or search tree) from XML
static RooMathCoreReg dummy
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
TMatrixTSym< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant Notice that the LU decomposition is used instead of B...
Float_t GetTarget(UInt_t itgt) const
virtual std::map< TString, Double_t > OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="FitGA")
call the Optimzier with the set of paremeters and ranges that are meant to be tuned.
Short_t GetSelector() const
#define REGISTER_METHOD(CLASS)
for example
void GetBaggedSubSample(std::vector< const TMVA::Event * > &)
fills fEventSample with fBaggedSampleFraction*NEvents random training events
virtual void SetXTitle(const char *title)
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
Short_t Max(Short_t a, Short_t b)
A Graph is a graphics object made of two arrays X and Y with npoints each.
std::vector< Double_t > GetVariableImportance()
Return the relative variable importance, normalized to all variables together having the importance 1...
A TTree object has a header with a name and a title.
void Store(TObject *obj, const char *alias=0)
Double_t Sqrt(Double_t x)
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
double norm(double *x, double *p)
Float_t GetResponse(void) const
void MakeClassSpecific(std::ostream &, const TString &) const
make ROOT-independent C++ class for classifier response (classifier-specific implementation) ...
Int_t CeilNint(Double_t x)
Float_t GetCutValue(void) const
MethodBDT(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
the standard constructor for the "boosted decision trees"