53 : fLearningModel ( kFull )
54 , fImportanceCut ( 0 )
55 , fLinQuantile ( 0.025 )
57 , fAverageSupport ( 0.8 )
58 , fAverageRuleSigma( 0.4 )
62 , fRuleMinDist ( 1e-3 )
63 , fNRulesGenerated ( 0 )
65 , fEventCacheOK ( true )
69 , fRuleMapEvents ( 0 )
79 : fAverageSupport ( 1 )
92 : fLearningModel ( kFull )
93 , fImportanceCut ( 0 )
94 , fLinQuantile ( 0.025 )
96 , fImportanceRef ( 1.0 )
97 , fAverageSupport ( 0.8 )
98 , fAverageRuleSigma( 0.4 )
102 , fRuleMinDist ( 1e-3 )
103 , fNRulesGenerated ( 0 )
105 , fEventCacheOK ( true )
106 , fRuleMapOK ( true )
109 , fRuleMapEvents ( 0 )
120 for ( std::vector<Rule *>::iterator itrRule = fRules.begin(); itrRule != fRules.end(); itrRule++ ) {
132 SetAverageRuleSigma(0.4);
134 UInt_t nvars = GetMethodBase()->GetNvar();
135 fVarImportance.clear();
139 fVarImportance.resize( nvars,0.0 );
140 fLinPDFB.resize( nvars,0 );
141 fLinPDFS.resize( nvars,0 );
142 fImportanceRef = 1.0;
143 for (
UInt_t i=0; i<nvars; i++) {
144 fLinTermOK.push_back(
kTRUE);
151 fLogger->SetMinType(t);
162 return ( fRuleFit==0 ? 0:fRuleFit->GetMethodRuleFit());
172 return ( fRuleFit==0 ? 0:fRuleFit->GetMethodBase());
180 MakeRules( fRuleFit->GetForest() );
200 Int_t ncoeffs = fRules.size();
201 if (ncoeffs<1)
return 0;
205 for (
Int_t i=0; i<ncoeffs; i++) {
206 val = fRules[i]->GetCoefficient();
218 UInt_t nrules = fRules.size();
219 for (
UInt_t i=0; i<nrules; i++) {
220 fRules[i]->SetCoefficient(0.0);
229 UInt_t nrules = fRules.size();
230 if (v.size()!=nrules) {
231 Log() <<
kFATAL <<
"<SetCoefficients> - BUG TRAP - input vector worng size! It is = " << v.size()
232 <<
" when it should be = " << nrules <<
Endl;
234 for (
UInt_t i=0; i<nrules; i++) {
235 fRules[i]->SetCoefficient(v[i]);
244 UInt_t nrules = fRules.size();
246 if (nrules==0)
return;
248 for (
UInt_t i=0; i<nrules; i++) {
249 v[i] = (fRules[i]->GetCoefficient());
258 return &(fRuleFit->GetTrainingEvents());
266 return fRuleFit->GetTrainingEvent(i);
274 Log() <<
kVERBOSE <<
"Removing similar rules; distance = " << fRuleMinDist <<
Endl;
276 UInt_t nrulesIn = fRules.size();
278 std::vector< Char_t > removeMe( nrulesIn,
false );
284 for (
UInt_t i=0; i<nrulesIn; i++) {
287 for (
UInt_t k=i+1; k<nrulesIn; k++) {
293 remind = (r>0.5 ? k:i);
300 if (!removeMe[remind]) {
301 removeMe[remind] =
true;
311 for (
UInt_t i=0; i<nrulesIn; i++) {
313 theRule = fRules[ind];
315 fRules.erase( std::vector<Rule *>::iterator(&fRules[ind], &fRules) );
317 fRules.erase( fRules.begin() + ind );
324 UInt_t nrulesOut = fRules.size();
325 Log() <<
kVERBOSE <<
"Removed " << nrulesIn - nrulesOut <<
" out of " << nrulesIn <<
" rules" <<
Endl;
333 UInt_t nrules = fRules.size();
334 if (nrules==0)
return;
335 Log() <<
kVERBOSE <<
"Removing rules with relative importance < " << fImportanceCut <<
Endl;
336 if (fImportanceCut<=0)
return;
342 for (
UInt_t i=0; i<nrules; i++) {
343 if (fRules[ind]->GetRelImportance()<fImportanceCut) {
344 therule = fRules[ind];
346 fRules.erase( std::vector<Rule *>::iterator(&fRules[ind], &fRules) );
348 fRules.erase( fRules.begin() + ind );
355 Log() <<
kINFO <<
"Removed " << nrules-ind <<
" out of a total of " << nrules
356 <<
" rules with importance < " << fImportanceCut <<
Endl;
364 UInt_t nlin = fLinNorm.size();
366 Log() <<
kVERBOSE <<
"Removing linear terms with relative importance < " << fImportanceCut <<
Endl;
369 for (
UInt_t i=0; i<nlin; i++) {
370 fLinTermOK.push_back( (fLinImportance[i]/fImportanceRef > fImportanceCut) );
386 SetAverageRuleSigma(0.4);
387 const std::vector<const Event *> *events = GetTrainingEvents();
391 if ((nrules>0) && (events->size()>0)) {
392 for ( std::vector< Rule * >::iterator itrRule=fRules.begin(); itrRule!=fRules.end(); itrRule++ ) {
396 for ( std::vector<const Event * >::const_iterator itrEvent=events->begin(); itrEvent!=events->end(); itrEvent++ ) {
397 if ((*itrRule)->EvalEvent( *(*itrEvent) )) {
398 ew = (*itrEvent)->GetWeight();
400 if (GetMethodRuleFit()->DataInfo().IsSignal(*itrEvent)) ssig += ew;
405 s = s/fRuleFit->GetNEveEff();
407 t = (t<0 ? 0:
sqrt(t));
412 (*itrRule)->SetSupport(s);
413 (*itrRule)->SetNorm(t);
414 (*itrRule)->SetSSB( ssb );
415 (*itrRule)->SetSSBNeve(
Double_t(ssig+sbkg));
418 fAverageSupport = stot/nrules;
419 fAverageRuleSigma =
TMath::Sqrt(fAverageSupport*(1.0-fAverageSupport));
420 Log() <<
kVERBOSE <<
"Standard deviation of support = " << fAverageRuleSigma <<
Endl;
421 Log() <<
kVERBOSE <<
"Average rule support = " << fAverageSupport <<
Endl;
430 Double_t maxRuleImp = CalcRuleImportance();
431 Double_t maxLinImp = CalcLinImportance();
432 Double_t maxImp = (maxRuleImp>maxLinImp ? maxRuleImp : maxLinImp);
433 SetImportanceRef( maxImp );
441 for (
UInt_t i=0; i<fRules.size(); i++ ) {
442 fRules[i]->SetImportanceRef(impref);
444 fImportanceRef = impref;
453 Int_t nrules = fRules.size();
454 for (
int i=0; i<nrules; i++ ) {
455 fRules[i]->CalcImportance();
456 imp = fRules[i]->GetImportance();
457 if (imp>maxImp) maxImp = imp;
459 for (
Int_t i=0; i<nrules; i++ ) {
460 fRules[i]->SetImportanceRef(maxImp);
472 UInt_t nvars = fLinCoefficients.size();
473 fLinImportance.resize(nvars,0.0);
474 if (!DoLinear())
return maxImp;
484 for (
UInt_t i=0; i<nvars; i++ ) {
485 imp = fAverageRuleSigma*
TMath::Abs(fLinCoefficients[i]);
486 fLinImportance[i] = imp;
487 if (imp>maxImp) maxImp = imp;
501 UInt_t nrules = fRules.size();
502 if (GetMethodBase()==0)
Log() <<
kFATAL <<
"RuleEnsemble::CalcVarImportance() - should not be here!" <<
Endl;
503 UInt_t nvars = GetMethodBase()->GetNvar();
506 fVarImportance.resize(nvars,0);
509 for (
UInt_t ind=0; ind<nrules; ind++ ) {
510 rimp = fRules[ind]->GetImportance();
511 nvarsUsed = fRules[ind]->GetNumVarsUsed();
513 Log() <<
kFATAL <<
"<CalcVarImportance> Variables for importance calc!!!??? A BUG!" <<
Endl;
514 rimpN = (nvarsUsed > 0 ? rimp/nvarsUsed:0.0);
515 for (
UInt_t iv=0; iv<nvars; iv++ ) {
516 if (fRules[ind]->ContainsVariable(iv)) {
517 fVarImportance[iv] += rimpN;
524 for (
UInt_t iv=0; iv<fLinTermOK.size(); iv++ ) {
525 if (fLinTermOK[iv]) fVarImportance[iv] += fLinImportance[iv];
532 for (
UInt_t iv=0; iv<nvars; iv++ ) {
533 if ( fVarImportance[iv] > maximp ) maximp = fVarImportance[iv];
536 for (
UInt_t iv=0; iv<nvars; iv++ ) {
537 fVarImportance[iv] *= 1.0/maximp;
551 fRules.resize(rules.size());
552 for (
UInt_t i=0; i<fRules.size(); i++) {
553 fRules[i] = rules[i];
567 if (!DoRules())
return;
576 UInt_t ntrees = forest.size();
577 for (
UInt_t ind=0; ind<ntrees; ind++ ) {
579 MakeRulesFromTree( forest[ind] );
580 nrules = CalcNRules( forest[ind] );
581 nendn = (nrules/2) + 1;
583 sumn2 += nendn*nendn;
584 nrulesCheck += nrules;
586 Double_t nmean = (ntrees>0) ? sumnendn/ntrees : 0;
588 Double_t ndev = 2.0*(nmean-2.0-nsigm)/(nmean-2.0+nsigm);
590 Log() <<
kVERBOSE <<
"Average number of end nodes per tree = " << nmean <<
Endl;
591 if (ntrees>1)
Log() <<
kVERBOSE <<
"sigma of ditto ( ~= mean-2 ?) = "
594 Log() <<
kVERBOSE <<
"Deviation from exponential model = " << ndev <<
Endl;
595 Log() <<
kVERBOSE <<
"Corresponds to L (eq. 13, RuleFit ppr) = " << nmean <<
Endl;
597 if (nrulesCheck != static_cast<Int_t>(fRules.size())) {
599 <<
"BUG! number of generated and possible rules do not match! N(rules) = " << fRules.size()
600 <<
" != " << nrulesCheck <<
Endl;
602 Log() <<
kVERBOSE <<
"Number of generated rules: " << fRules.size() <<
Endl;
605 fNRulesGenerated = fRules.size();
607 RemoveSimilarRules();
621 if (!DoLinear())
return;
623 const std::vector<const Event *> *events = GetTrainingEvents();
624 UInt_t neve = events->size();
625 UInt_t nvars = ((*events)[0])->GetNVariables();
627 typedef std::pair< Double_t, Int_t> dataType;
628 typedef std::pair< Double_t, dataType > dataPoint;
630 std::vector< std::vector<dataPoint> > vardata(nvars);
631 std::vector< Double_t > varsum(nvars,0.0);
632 std::vector< Double_t > varsum2(nvars,0.0);
637 for (
UInt_t i=0; i<neve; i++) {
640 val = ((*events)[i])->GetValue(
v);
641 vardata[
v].push_back( dataPoint( val, dataType(ew,((*events)[i])->
GetClass()) ) );
647 fLinCoefficients.clear();
649 fLinDP.resize(nvars,0);
650 fLinDM.resize(nvars,0);
651 fLinCoefficients.resize(nvars,0);
652 fLinNorm.resize(nvars,0);
654 Double_t averageWeight = neve ? fRuleFit->GetNEveEff()/
static_cast<Double_t>(neve) : 0;
669 std::sort( vardata[
v].begin(),vardata[
v].end() );
670 nquant = fLinQuantile*fRuleFit->GetNEveEff();
674 while ( (ie<neve) && (neff<nquant) ) {
675 neff += vardata[
v][ie].second.first;
678 indquantM = (ie==0 ? 0:ie-1);
682 while ( (ie>0) && (neff<nquant) ) {
684 neff += vardata[
v][ie].second.first;
686 indquantP = (ie==neve ? ie=neve-1:ie);
688 fLinDM[
v] = vardata[
v][indquantM].first;
689 fLinDP[
v] = vardata[
v][indquantP].first;
690 if (fLinPDFB[
v])
delete fLinPDFB[
v];
691 if (fLinPDFS[v])
delete fLinPDFS[
v];
692 fLinPDFB[
v] =
new TH1F(
Form(
"bkgvar%d",v),
"bkg temphist",40,fLinDM[v],fLinDP[v]);
693 fLinPDFS[
v] =
new TH1F(
Form(
"sigvar%d",v),
"sig temphist",40,fLinDM[v],fLinDP[v]);
694 fLinPDFB[
v]->Sumw2();
695 fLinPDFS[
v]->Sumw2();
698 const Double_t w = 1.0/fRuleFit->GetNEveEff();
699 for (ie=0; ie<neve; ie++) {
700 val = vardata[
v][ie].first;
701 ew = vardata[
v][ie].second.first;
702 type = vardata[
v][ie].second.second;
705 varsum2[
v] += ew*lx*lx;
706 if (type==1) fLinPDFS[
v]->Fill(lx,w*ew);
707 else fLinPDFB[
v]->Fill(lx,w*ew);
712 stdl =
TMath::Sqrt( (varsum2[v] - (varsum[v]*varsum[v]/fRuleFit->GetNEveEff()))/(fRuleFit->GetNEveEff()-averageWeight) );
713 fLinNorm[
v] = CalcLinNorm(stdl);
717 fLinPDFS[
v]->Write();
718 fLinPDFB[
v]->Write();
730 UInt_t nvars=fLinDP.size();
738 Int_t bin = fLinPDFS[
v]->FindBin(val);
739 fstot += fLinPDFS[
v]->GetBinContent(bin);
740 fbtot += fLinPDFB[
v]->GetBinContent(bin);
742 if (nvars<1)
return 0;
743 ntot = (fstot+fbtot)/
Double_t(nvars);
745 return fstot/(fstot+fbtot);
762 UInt_t nrules = fRules.size();
763 for (
UInt_t ir=0; ir<nrules; ir++) {
764 if (fEventRuleVal[ir]>0) {
765 ssb = fEventRuleVal[ir]*GetRulesConst(ir)->GetSSB();
766 neve = GetRulesConst(ir)->GetSSBNeve();
776 if (ntot>0)
return nsig/ntot;
811 if (DoLinear()) pl = PdfLinear(nls, nlt);
812 if (DoRules()) pr = PdfRule(nrs, nrt);
814 if ((nlt>0) && (nrt>0)) nt=2.0;
826 const std::vector<const Event *> *events = GetTrainingEvents();
827 const UInt_t neve = events->size();
828 const UInt_t nvars = GetMethodBase()->GetNvar();
829 const UInt_t nrules = fRules.size();
830 const Event *eveData;
846 std::vector<Int_t> varcnt;
854 varcnt.resize(nvars,0);
855 fRuleVarFrac.clear();
856 fRuleVarFrac.resize(nvars,0);
858 for (
UInt_t i=0; i<nrules; i++ ) {
860 if (fRules[i]->ContainsVariable(
v)) varcnt[
v]++;
862 sigRule = fRules[i]->IsSignalRule();
876 for (
UInt_t e=0; e<neve; e++) {
877 eveData = (*events)[e];
878 tagged = fRules[i]->EvalEvent(*eveData);
879 sigTag = (tagged && sigRule);
880 bkgTag = (tagged && (!sigRule));
882 sigTrue = (eveData->
GetClass() == 0);
885 if (sigTag && sigTrue) nss++;
886 if (sigTag && !sigTrue) nsb++;
887 if (bkgTag && sigTrue) nbs++;
888 if (bkgTag && !sigTrue) nbb++;
892 if (ntag>0 && neve > 0) {
901 fRuleFSig = (nsig>0) ? static_cast<Double_t>(nsig)/
static_cast<Double_t>(nsig+nbkg) : 0;
912 const UInt_t nrules = fRules.size();
916 for (
UInt_t i=0; i<nrules; i++ ) {
917 nc =
static_cast<Double_t>(fRules[i]->GetNcuts());
924 fRuleNCave = sumNc/nrules;
934 Log() <<
kINFO <<
"-------------------RULE ENSEMBLE SUMMARY------------------------" <<
Endl;
936 if (mrf)
Log() <<
kINFO <<
"Tree training method : " << (mrf->
UseBoost() ?
"AdaBoost":
"Random") << Endl;
937 Log() <<
kINFO <<
"Number of events per tree : " << fRuleFit->GetNTreeSample() <<
Endl;
938 Log() <<
kINFO <<
"Number of trees : " << fRuleFit->GetForest().size() <<
Endl;
939 Log() <<
kINFO <<
"Number of generated rules : " << fNRulesGenerated <<
Endl;
940 Log() <<
kINFO <<
"Idem, after cleanup : " << fRules.size() <<
Endl;
941 Log() <<
kINFO <<
"Average number of cuts per rule : " <<
Form(
"%8.2f",fRuleNCave) <<
Endl;
942 Log() <<
kINFO <<
"Spread in number of cuts per rules : " <<
Form(
"%8.2f",fRuleNCsig) <<
Endl;
944 Log() <<
kINFO <<
"----------------------------------------------------------------" <<
Endl;
957 Log() << kmtype <<
"================================================================" <<
Endl;
958 Log() << kmtype <<
" M o d e l " <<
Endl;
959 Log() << kmtype <<
"================================================================" <<
Endl;
962 const UInt_t nvars = GetMethodBase()->GetNvar();
963 const Int_t nrules = fRules.size();
966 for (
UInt_t iv = 0; iv<fVarImportance.size(); iv++) {
967 if (GetMethodBase()->GetInputLabel(iv).Length() > maxL) maxL = GetMethodBase()->GetInputLabel(iv).Length();
972 for (
UInt_t iv = 0; iv<fVarImportance.size(); iv++) {
973 Log() <<
kDEBUG << std::setw(maxL) << GetMethodBase()->GetInputLabel(iv)
974 << std::resetiosflags(std::ios::right)
975 <<
" : " <<
Form(
" %3.3f",fVarImportance[iv]) <<
Endl;
979 Log() << kmtype <<
"Offset (a0) = " << fOffset <<
Endl;
982 if (fLinNorm.size() > 0) {
983 Log() << kmtype <<
"------------------------------------" <<
Endl;
984 Log() << kmtype <<
"Linear model (weights unnormalised)" <<
Endl;
985 Log() << kmtype <<
"------------------------------------" <<
Endl;
986 Log() << kmtype << std::setw(maxL) <<
"Variable"
987 << std::resetiosflags(std::ios::right) <<
" : "
988 << std::setw(11) <<
" Weights"
989 << std::resetiosflags(std::ios::right) <<
" : "
991 << std::resetiosflags(std::ios::right)
993 Log() << kmtype <<
"------------------------------------" <<
Endl;
994 for (
UInt_t i=0; i<fLinNorm.size(); i++ ) {
995 Log() << kmtype << std::setw(
std::max(maxL,8)) << GetMethodBase()->GetInputLabel(i);
998 << std::resetiosflags(std::ios::right)
999 <<
" : " <<
Form(
" %10.3e",fLinCoefficients[i]*fLinNorm[i])
1000 <<
" : " <<
Form(
" %3.3f",fLinImportance[i]/fImportanceRef) <<
Endl;
1003 Log() << kmtype <<
"-> importance below threshhold = "
1004 <<
Form(
" %3.3f",fLinImportance[i]/fImportanceRef) <<
Endl;
1007 Log() << kmtype <<
"------------------------------------" <<
Endl;
1010 else Log() << kmtype <<
"Linear terms were disabled" <<
Endl;
1012 if ((!DoRules()) || (nrules==0)) {
1014 Log() << kmtype <<
"Rule terms were disabled" <<
Endl;
1017 Log() << kmtype <<
"Eventhough rules were included in the model, none passed! " << nrules <<
Endl;
1021 Log() << kmtype <<
"Number of rules = " << nrules <<
Endl;
1023 Log() << kmtype <<
"N(cuts) in rules, average = " << fRuleNCave <<
Endl;
1024 Log() << kmtype <<
" RMS = " << fRuleNCsig <<
Endl;
1025 Log() << kmtype <<
"Fraction of signal rules = " << fRuleFSig <<
Endl;
1026 Log() << kmtype <<
"Fraction of rules containing a variable (%):" <<
Endl;
1028 Log() << kmtype <<
" " << std::setw(maxL) << GetMethodBase()->GetInputLabel(
v);
1029 Log() << kmtype <<
Form(
" = %2.2f",fRuleVarFrac[
v]*100.0) <<
" %" <<
Endl;
1035 std::list< std::pair<double,int> > sortedImp;
1036 for (
Int_t i=0; i<nrules; i++) {
1037 sortedImp.push_back( std::pair<double,int>( fRules[i]->GetImportance(),i ) );
1041 Log() << kmtype <<
"Printing the first " << printN <<
" rules, ordered in importance." <<
Endl;
1043 for ( std::list< std::pair<double,int> >::reverse_iterator itpair = sortedImp.rbegin();
1044 itpair != sortedImp.rend(); itpair++ ) {
1045 ind = itpair->second;
1049 fRules[ind]->PrintLogger(
Form(
"Rule %4d : ",pind+1));
1052 if (nrules==printN) {
1053 Log() << kmtype <<
"All rules printed" <<
Endl;
1056 Log() << kmtype <<
"Skipping the next " << nrules-printN <<
" rules" <<
Endl;
1062 Log() << kmtype <<
"================================================================" <<
Endl;
1071 Int_t dp = os.precision();
1072 UInt_t nrules = fRules.size();
1075 os <<
"ImportanceCut= " << fImportanceCut << std::endl;
1076 os <<
"LinQuantile= " << fLinQuantile << std::endl;
1077 os <<
"AverageSupport= " << fAverageSupport << std::endl;
1078 os <<
"AverageRuleSigma= " << fAverageRuleSigma << std::endl;
1079 os <<
"Offset= " << fOffset << std::endl;
1080 os <<
"NRules= " << nrules << std::endl;
1081 for (
UInt_t i=0; i<nrules; i++){
1082 os <<
"***Rule " << i << std::endl;
1083 (fRules[i])->PrintRaw(os);
1085 UInt_t nlinear = fLinNorm.size();
1087 os <<
"NLinear= " << fLinTermOK.size() << std::endl;
1088 for (
UInt_t i=0; i<nlinear; i++) {
1089 os <<
"***Linear " << i << std::endl;
1090 os << std::setprecision(10) << (fLinTermOK[i] ? 1:0) <<
" "
1091 << fLinCoefficients[i] <<
" "
1092 << fLinNorm[i] <<
" "
1095 << fLinImportance[i] <<
" " << std::endl;
1097 os << std::setprecision(dp);
1107 UInt_t nrules = fRules.size();
1108 UInt_t nlinear = fLinNorm.size();
1111 gTools().
AddAttr( re,
"LearningModel", (
int)fLearningModel );
1115 gTools().
AddAttr( re,
"AverageRuleSigma", fAverageRuleSigma );
1117 for (
UInt_t i=0; i<nrules; i++) fRules[i]->AddXMLTo(re);
1119 for (
UInt_t i=0; i<nlinear; i++) {
1139 Int_t iLearningModel;
1144 gTools().
ReadAttr( wghtnode,
"AverageSupport", fAverageSupport );
1145 gTools().
ReadAttr( wghtnode,
"AverageRuleSigma", fAverageRuleSigma );
1152 fRules.resize( nrules );
1154 for (i=0; i<nrules; i++) {
1155 fRules[i] =
new Rule();
1156 fRules[i]->SetRuleEnsemble(
this );
1157 fRules[i]->ReadFromXML( ch );
1163 fLinNorm .resize( nlinear );
1164 fLinTermOK .resize( nlinear );
1165 fLinCoefficients.resize( nlinear );
1166 fLinDP .resize( nlinear );
1167 fLinDM .resize( nlinear );
1168 fLinImportance .resize( nlinear );
1174 fLinTermOK[i] = (iok == 1);
1198 istr >> dummy >> fImportanceCut;
1199 istr >> dummy >> fLinQuantile;
1200 istr >> dummy >> fAverageSupport;
1201 istr >> dummy >> fAverageRuleSigma;
1202 istr >> dummy >> fOffset;
1203 istr >> dummy >> nrules;
1209 for (
UInt_t i=0; i<nrules; i++){
1210 istr >> dummy >> idum;
1211 fRules.push_back(
new Rule() );
1212 (fRules.back())->SetRuleEnsemble(
this );
1213 (fRules.back())->ReadRaw(istr);
1221 istr >> dummy >> nlinear;
1223 fLinNorm .resize( nlinear );
1224 fLinTermOK .resize( nlinear );
1225 fLinCoefficients.resize( nlinear );
1226 fLinDP .resize( nlinear );
1227 fLinDM .resize( nlinear );
1228 fLinImportance .resize( nlinear );
1232 for (
UInt_t i=0; i<nlinear; i++) {
1233 istr >> dummy >> idum;
1235 fLinTermOK[i] = (iok==1);
1236 istr >> fLinCoefficients[i];
1237 istr >> fLinNorm[i];
1240 istr >> fLinImportance[i];
1249 if(
this != &other) {
1276 if (dtree==0)
return 0;
1278 Int_t nendnodes = 0;
1279 FindNEndNodes( node, nendnodes );
1280 return 2*(nendnodes-1);
1288 if (node==0)
return;
1295 FindNEndNodes( nodeR, nendnodes );
1296 FindNEndNodes( nodeL, nendnodes );
1313 if (node==0)
return;
1319 Rule *rule = MakeTheRule(node);
1321 fRules.push_back( rule );
1326 Log() <<
kFATAL <<
"<AddRule> - ERROR failed in creating a rule! BUG!" <<
Endl;
1343 Log() <<
kFATAL <<
"<MakeTheRule> Input node is NULL. Should not happen. BUG!" <<
Endl;
1351 std::vector< const Node * > nodeVec;
1352 const Node *parent = node;
1357 nodeVec.push_back( node );
1360 if (!parent)
continue;
1363 nodeVec.insert( nodeVec.begin(), parent );
1366 if (nodeVec.size()<2) {
1367 Log() <<
kFATAL <<
"<MakeTheRule> BUG! Inconsistent Rule!" <<
Endl;
1370 Rule *rule =
new Rule(
this, nodeVec );
1382 if (events==0) events = GetTrainingEvents();
1383 if ((ifirst==0) || (ilast==0) || (ifirst>ilast)) {
1385 ilast = events->size()-1;
1388 if ((events!=fRuleMapEvents) ||
1389 (ifirst!=fRuleMapInd0) ||
1390 (ilast !=fRuleMapInd1)) {
1398 fRuleMapEvents = events;
1399 fRuleMapInd0 = ifirst;
1400 fRuleMapInd1 = ilast;
1402 UInt_t nrules = GetNRules();
1411 std::vector<UInt_t> ruleind;
1413 for (
UInt_t i=ifirst; i<=ilast; i++) {
1415 fRuleMap.push_back( ruleind );
1417 if (fRules[
r]->EvalEvent(*((*events)[i]))) {
1418 fRuleMap.back().push_back(
r);
1423 Log() <<
kVERBOSE <<
"Made rule map for event# " << ifirst <<
" : " << ilast <<
Endl;
1431 os <<
"DON'T USE THIS - TO BE REMOVED" << std::endl;
const std::vector< const TMVA::Event * > * GetTrainingEvents() const
get list of training events from the rule fitter
Double_t GetImportanceCut() const
Double_t PdfLinear(Double_t &nsig, Double_t &ntot) const
This function returns Pr( y = 1 | x ) for the linear terms.
MsgLogger & Endl(MsgLogger &ml)
ELearningModel GetLearningModel() const
const std::vector< Double_t > & GetVarImportance() const
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
bool equal(double d1, double d2, double stol=10000)
RuleEnsemble()
constructor
Rule * MakeTheRule(const Node *node)
Make a Rule from a given Node.
Int_t CalcNRules(const TMVA::DecisionTree *dtree)
calculate the number of rules
virtual ~RuleEnsemble()
destructor
1-D histogram with a float per channel (see TH1 documentation)}
Short_t Min(Short_t a, Short_t b)
Double_t GetLinQuantile() const
void Print() const
print function
void PrintRuleGen() const
print rule generation info
void CleanupLinear()
cleanup linear model
void MakeRuleMap(const std::vector< const TMVA::Event * > *events=0, UInt_t ifirst=0, UInt_t ilast=0)
Makes rule map for all events.
virtual DecisionTreeNode * GetRoot() const
Bool_t Equal(const Rule &other, Bool_t useCutValue, Double_t maxdist) const
Compare two rules.
void SetMsgType(EMsgType t)
const Event * GetTrainingEvent(UInt_t i) const
get the training event from the rule fitter
void SetImportanceRef(Double_t impref)
set reference importance
void RuleResponseStats()
calculate various statistics for this rule
Double_t PdfRule(Double_t &nsig, Double_t &ntot) const
This function returns Pr( y = 1 | x ) for rules.
void RemoveSimilarRules()
remove rules that behave similar
void Copy(RuleEnsemble const &other)
copy function
void PrintRaw(std::ostream &os) const
write rules to stream
const MethodRuleFit * GetMethodRuleFit() const
Get a pointer to the original MethodRuleFit.
void CalcImportance()
calculate the importance of each rule
void CleanupRules()
cleanup rules
Double_t FStar() const
We want to estimate F* = argmin Eyx( L(y,F(x) ), min wrt F(x) F(x) = FL(x) + FR(x) ...
void CalcVarImportance()
Calculates variable importance using eq (35) in RuleFit paper by Friedman et.al.
const RuleFit * GetRuleFit() const
Double_t CalcRuleImportance()
calculate importance of each rule
void MakeRulesFromTree(const DecisionTree *dtree)
create rules from the decsision tree structure
Double_t CoefficientRadius()
Calculates sqrt(Sum(a_i^2)), i=1..N (NOTE do not include a0)
void AddRule(const Node *node)
add a new rule to the tree
char * Form(const char *fmt,...)
void RuleStatistics()
calculate various statistics for this rule
void MakeRules(const std::vector< const TMVA::DecisionTree * > &forest)
Makes rules from the given decision tree.
Double_t GetWeight(Double_t x) const
const std::vector< TMVA::Rule * > & GetRulesConst() const
R__EXTERN TRandom * gRandom
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
print the tree recursinvely using the << operator
void ReadFromXML(void *wghtnode)
read rules from XML
void FindNEndNodes(const TMVA::Node *node, Int_t &nendnodes)
find the number of leaf nodes
void Initialize(const RuleFit *rf)
Initializes all member variables with default values.
void SetCoefficients(const std::vector< Double_t > &v)
set all rule coefficients
static RooMathCoreReg dummy
virtual Node * GetParent() const
void MakeLinearTerms()
Make the linear terms as in eq 25, ref 2 For this the b and (1-b) quatiles are needed.
virtual Node * GetRight() const
Double_t fAverageRuleSigma
void CalcRuleSupport()
calculate the support for all rules
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Double_t GetRuleMinDist() const
void MakeModel()
create model
Short_t GetSelector() const
void SetRules(const std::vector< TMVA::Rule * > &rules)
set rules
void SetMsgType(EMsgType t)
Short_t Max(Short_t a, Short_t b)
void ResetCoefficients()
reset all rule coefficients
void * AddXMLTo(void *parent) const
write rules to XML
void GetCoefficients(std::vector< Double_t > &v)
Retrieve all rule coefficients.
Double_t Sqrt(Double_t x)
Double_t CalcLinImportance()
calculate the linear importance for each rule
const MethodBase * GetMethodBase() const
Get a pointer to the original MethodRuleFit.
Double_t GetOffset() const
virtual Node * GetLeft() const
void ReadRaw(std::istream &istr)
read rule ensemble from stream