77 , fGDPathStep ( 0.01 )
78 , fGDNPathSteps ( 1000 )
103 if (fNTCoeff) {
delete fNTCoeff; fNTCoeff = 0; }
104 if (fNTLinCoeff) {
delete fNTLinCoeff;fNTLinCoeff = 0; }
113 if (fRuleFit==0)
return;
114 if (fRuleFit->GetMethodRuleFit()==0) {
115 Log() <<
kFATAL <<
"RuleFitParams::Init() - MethodRuleFit ptr is null" <<
Endl;
117 UInt_t neve = fRuleFit->GetTrainingEvents().size();
119 fRuleEnsemble = fRuleFit->GetRuleEnsemblePtr();
120 fNRules = fRuleEnsemble->GetNRules();
121 fNLinear = fRuleEnsemble->GetNLinear();
130 fPerfIdx2 =
static_cast<UInt_t>((neve-1)*fRuleFit->GetMethodRuleFit()->GetGDValidEveFrac());
135 ofs = neve - fPerfIdx2 - 1;
145 fPathIdx2 =
static_cast<UInt_t>((neve-1)*fRuleFit->GetMethodRuleFit()->GetGDPathEveFrac());
154 for (
UInt_t ie=fPathIdx1; ie<fPathIdx2+1; ie++) {
155 fNEveEffPath += fRuleFit->GetTrainingEventWeight(ie);
159 for (
UInt_t ie=fPerfIdx1; ie<fPerfIdx2+1; ie++) {
160 fNEveEffPerf += fRuleFit->GetTrainingEventWeight(ie);
163 Log() <<
kVERBOSE <<
"Path constr. - event index range = [ " << fPathIdx1 <<
", " << fPathIdx2 <<
" ]"
164 <<
", effective N(events) = " << fNEveEffPath <<
Endl;
165 Log() <<
kVERBOSE <<
"Error estim. - event index range = [ " << fPerfIdx1 <<
", " << fPerfIdx2 <<
" ]"
166 <<
", effective N(events) = " << fNEveEffPerf <<
Endl;
168 if (fRuleEnsemble->DoRules())
169 Log() <<
kDEBUG <<
"Number of rules in ensemble: " << fNRules <<
Endl;
173 if (fRuleEnsemble->DoLinear())
174 Log() <<
kDEBUG <<
"Number of linear terms: " << fNLinear <<
Endl;
184 fGDNtuple=
new TTree(
"MonitorNtuple_RuleFitParams",
"RuleFit path search");
185 fGDNtuple->Branch(
"risk", &fNTRisk,
"risk/D");
186 fGDNtuple->Branch(
"error", &fNTErrorRate,
"error/D");
187 fGDNtuple->Branch(
"nuval", &fNTNuval,
"nuval/D");
188 fGDNtuple->Branch(
"coefrad", &fNTCoefRad,
"coefrad/D");
189 fGDNtuple->Branch(
"offset", &fNTOffset,
"offset/D");
191 fNTCoeff = (fNRules >0 ?
new Double_t[fNRules] : 0);
192 fNTLinCoeff = (fNLinear>0 ?
new Double_t[fNLinear] : 0);
194 for (
UInt_t i=0; i<fNRules; i++) {
195 fGDNtuple->Branch(
Form(
"a%d",i+1),&fNTCoeff[i],
Form(
"a%d/D",i+1));
197 for (
UInt_t i=0; i<fNLinear; i++) {
198 fGDNtuple->Branch(
Form(
"b%d",i+1),&fNTLinCoeff[i],
Form(
"b%d/D",i+1));
206 std::vector<Double_t> &avsel,
207 std::vector<Double_t> &avrul )
209 UInt_t neve = ind2-ind1+1;
211 Log() <<
kFATAL <<
"<EvaluateAverage> - no events selected for path search -> BUG!" <<
Endl;
217 if (fNLinear>0) avsel.resize(fNLinear,0);
218 if (fNRules>0) avrul.resize(fNRules,0);
219 const std::vector<UInt_t> *eventRuleMap=0;
225 if (fRuleEnsemble->IsRuleMapOK()) {
226 for (
UInt_t i=ind1; i<ind2+1; i++) {
227 ew = fRuleFit->GetTrainingEventWeight(i);
229 for (
UInt_t sel=0; sel<fNLinear; sel++ ) {
230 avsel[sel] += ew*fRuleEnsemble->EvalLinEvent(i,sel);
234 if (fRuleEnsemble->DoRules()) {
235 eventRuleMap = &(fRuleEnsemble->GetEventRuleMap(i));
236 nrules = (*eventRuleMap).size();
239 avrul[(*eventRuleMap)[
r]] += ew;
244 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
245 for (
UInt_t i=ind1; i<ind2+1; i++) {
246 ew = fRuleFit->GetTrainingEventWeight(i);
249 fRuleEnsemble->EvalLinEvent(*((*events)[i]));
250 fRuleEnsemble->EvalEvent(*((*events)[i]));
252 for (
UInt_t sel=0; sel<fNLinear; sel++ ) {
253 avsel[sel] += ew*fRuleEnsemble->GetEventLinearValNorm(sel);
257 avrul[
r] += ew*fRuleEnsemble->GetEventRuleVal(
r);
262 for (
UInt_t sel=0; sel<fNLinear; sel++ ) {
263 avsel[sel] = avsel[sel] / sumew;
267 avrul[
r] = avrul[
r] / sumew;
278 Double_t diff = (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal(&e)?1:-1) - h;
290 Double_t diff = (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal(fRuleEnsemble->GetRuleMapEvent( evtidx ))?1:-1) -
h;
292 return diff*diff*fRuleFit->GetTrainingEventWeight(evtidx);
301 Double_t e = fRuleEnsemble->EvalEvent( evtidx , fGDOfsTst[itau], fGDCoefTst[itau], fGDCoefLinTst[itau]);
303 Double_t diff = (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal(fRuleEnsemble->GetRuleMapEvent( evtidx ))?1:-1) -
h;
305 return diff*diff*fRuleFit->GetTrainingEventWeight(evtidx);
313 UInt_t neve = ind2-ind1+1;
315 Log() <<
kFATAL <<
"<Risk> Invalid start/end indices! BUG!!!" <<
Endl;
320 for (
UInt_t i=ind1; i<ind2+1; i++) {
333 UInt_t neve = ind2-ind1+1;
335 Log() <<
kFATAL <<
"<Risk> Invalid start/end indices! BUG!!!" <<
Endl;
340 for (
UInt_t i=ind1; i<ind2+1; i++) {
355 Log() <<
kWARNING <<
"<Penalty> Using unverified code! Check!" <<
Endl;
357 const std::vector<Double_t> *lincoeff = & (fRuleEnsemble->GetLinCoefficients());
358 for (
UInt_t i=0; i<fNRules; i++) {
359 rval +=
TMath::Abs(fRuleEnsemble->GetRules(i)->GetCoefficient());
361 for (
UInt_t i=0; i<fNLinear; i++) {
388 fGDTauVec.resize( fGDNTau );
390 fGDTauVec[0] = fGDTau;
394 Double_t dtau = (fGDTauMax - fGDTauMin)/static_cast<Double_t>(fGDNTau-1);
395 for (
UInt_t itau=0; itau<fGDNTau; itau++) {
396 fGDTauVec[itau] =
static_cast<Double_t>(itau)*dtau + fGDTauMin;
397 if (fGDTauVec[itau]>1.0) fGDTauVec[itau]=1.0;
405 fGradVecLinTst.clear();
410 fGDCoefLinTst.clear();
414 fGDCoefTst.resize(fGDNTau);
415 fGradVec.resize(fNRules,0);
416 fGradVecTst.resize(fGDNTau);
417 for (
UInt_t i=0; i<fGDNTau; i++) {
418 fGradVecTst[i].resize(fNRules,0);
419 fGDCoefTst[i].resize(fNRules,0);
424 fGDCoefLinTst.resize(fGDNTau);
425 fGradVecLin.resize(fNLinear,0);
426 fGradVecLinTst.resize(fGDNTau);
427 for (
UInt_t i=0; i<fGDNTau; i++) {
428 fGradVecLinTst[i].resize(fNLinear,0);
429 fGDCoefLinTst[i].resize(fNLinear,0);
434 fGDErrTst.resize(fGDNTau,0);
435 fGDErrTstOK.resize(fGDNTau,
kTRUE);
436 fGDOfsTst.resize(fGDNTau,0);
437 fGDNTauTstOK = fGDNTau;
448 if (fGDNTau<2)
return 0;
449 if (fGDTauScan==0)
return 0;
451 if (fGDOfsTst.size()<1)
452 Log() <<
kFATAL <<
"BUG! FindGDTau() has been called BEFORE InitGD()." <<
Endl;
454 Log() <<
kINFO <<
"Estimating the cutoff parameter tau. The estimated time is a pessimistic maximum." <<
Endl;
457 UInt_t nscan = fGDTauScan;
477 MakeTstGradientVector();
479 UpdateTstCoefficients();
483 if ( (ip==0) || ((ip+1)%netst==0) ) {
485 itauMin = RiskPerfTst();
487 <<
" => error rate = " << fGDErrTst[itauMin] <<
Endl;
490 doloop = ((ip<nscan) && (fGDNTauTstOK>3));
500 Log() <<
kERROR <<
"<FindGDTau> number of scanned loops is zero! Should NOT see this message." <<
Endl;
502 fGDTau = fGDTauVec[itauMin];
503 fRuleEnsemble->SetCoefficients( fGDCoefTst[itauMin] );
504 fRuleEnsemble->SetLinCoefficients( fGDCoefLinTst[itauMin] );
505 fRuleEnsemble->SetOffset( fGDOfsTst[itauMin] );
506 Log() <<
kINFO <<
"Best path found with tau = " <<
Form(
"%4.4f",fGDTau)
536 Log() <<
kINFO <<
"GD path scan - the scan stops when the max num. of steps is reached or a min is found"
538 Log() <<
kVERBOSE <<
"Number of events used per path step = " << fPathIdx2-fPathIdx1+1 <<
Endl;
539 Log() <<
kVERBOSE <<
"Number of events used for error estimation = " << fPerfIdx2-fPerfIdx1+1 <<
Endl;
549 EvaluateAveragePath();
550 EvaluateAveragePerf();
558 Log() <<
kVERBOSE <<
" tau range = [ " << fGDTauVec[0] <<
" , " << fGDTauVec[fGDNTau-1] <<
" ]" <<
Endl;
561 if (isDebug) InitNtuple();
573 std::vector<Double_t> coefsMin;
574 std::vector<Double_t> lincoefsMin;
589 std::vector<Double_t> valx;
590 std::vector<Double_t> valy;
591 std::vector<Double_t> valxy;
601 int imod = fGDNPathSteps/100;
602 if (imod<100) imod = std::min(100,fGDNPathSteps);
603 if (imod>100) imod=100;
606 fAverageTruth = -CalcAverageTruth();
607 offsetMin = fAverageTruth;
608 fRuleEnsemble->SetOffset(offsetMin);
609 fRuleEnsemble->ClearCoefficients(0);
610 fRuleEnsemble->ClearLinCoefficients(0);
611 for (
UInt_t i=0; i<fGDOfsTst.size(); i++) {
612 fGDOfsTst[i] = offsetMin;
614 Log() <<
kVERBOSE <<
"Obtained initial offset = " << offsetMin <<
Endl;
617 Int_t nprescan = FindGDTau();
632 Int_t stopCondition=0;
640 if (isVerbose) t0 = clock();
641 MakeGradientVector();
643 tgradvec =
Double_t(clock()-t0)/CLOCKS_PER_SEC;
644 stgradvec += tgradvec;
648 if (isVerbose) t0 = clock();
649 UpdateCoefficients();
651 tupgrade =
Double_t(clock()-t0)/CLOCKS_PER_SEC;
652 stupgrade += tupgrade;
656 docheck = ((iloop==0) ||((iloop+1)%imod==0));
662 fNTNuval =
Double_t(iloop)*fGDPathStep;
667 if (isDebug) FillCoefficients();
668 fNTCoefRad = fRuleEnsemble->CoefficientRadius();
672 fNTRisk = RiskPath();
673 trisk =
Double_t(clock()-t0)/CLOCKS_PER_SEC;
680 if (fNTRisk>=rprev) {
683 Log() <<
"Risk(i+1)>=Risk(i) in path" <<
Endl;
684 riskFlat=(nbadrisk>3);
687 Log() <<
"--- STOPPING MINIMISATION ---" <<
Endl;
688 Log() <<
"This may be OK if minimum is already found" <<
Endl;
698 if (isVerbose) t0 = clock();
708 fNTErrorRate = errroc;
711 tperf =
Double_t(clock()-t0)/CLOCKS_PER_SEC;
718 if (fNTErrorRate<=errmin) {
719 errmin = fNTErrorRate;
722 fRuleEnsemble->GetCoefficients(coefsMin);
723 lincoefsMin = fRuleEnsemble->GetLinCoefficients();
724 offsetMin = fRuleEnsemble->GetOffset();
726 if ( fNTErrorRate > fGDErrScale*errmin) found =
kTRUE;
730 if (valx.size()==npreg) {
731 valx.erase(valx.begin());
732 valy.erase(valy.begin());
733 valxy.erase(valxy.begin());
735 valx.push_back(fNTNuval);
736 valy.push_back(fNTErrorRate);
737 valxy.push_back(fNTErrorRate*fNTNuval);
742 if (isDebug) fGDNtuple->Fill();
746 <<
Form(
"%8d",iloop+1) <<
" "
747 <<
Form(
"%4.4f",fNTRisk) <<
" "
748 <<
Form(
"%4.4f",riskPerf) <<
" "
749 <<
Form(
"%4.4f",fNTRisk+riskPerf) <<
" "
765 Bool_t endOfLoop = (iloop==fGDNPathSteps);
766 if ( ((riskFlat) || (endOfLoop)) && (!found) ) {
770 else if (endOfLoop) {
774 Log() <<
kWARNING <<
"BUG TRAP: should not be here - still, this bug is harmless;)" <<
Endl;
775 errmin = fNTErrorRate;
778 fRuleEnsemble->GetCoefficients(coefsMin);
779 lincoefsMin = fRuleEnsemble->GetLinCoefficients();
780 offsetMin = fRuleEnsemble->GetOffset();
788 Log() <<
kINFO <<
"----------------------------------------------------------------" <<
Endl;
789 Log() <<
kINFO <<
"Found minimum at step " << indMin+1 <<
" with error = " << errmin <<
Endl;
790 Log() <<
kINFO <<
"Reason for ending loop: ";
791 switch (stopCondition) {
793 Log() <<
kINFO <<
"clear minima found";
796 Log() <<
kINFO <<
"chaotic behaviour of risk";
799 Log() <<
kINFO <<
"end of loop reached";
806 Log() <<
kINFO <<
"----------------------------------------------------------------" <<
Endl;
811 Log() <<
"Check results and maybe decrease GDStep size" <<
Endl;
821 Log() <<
kINFO <<
"The error rate was still decreasing at the end of the path" <<
Endl;
822 Log() <<
kINFO <<
"Increase number of steps (GDNSteps)." <<
Endl;
828 fRuleEnsemble->SetCoefficients( coefsMin );
829 fRuleEnsemble->SetLinCoefficients( lincoefsMin );
830 fRuleEnsemble->SetOffset( offsetMin );
833 Log() <<
kFATAL <<
"BUG TRAP: minimum not found in MakeGDPath()" <<
Endl;
840 Double_t stloop = strisk +stupgrade + stgradvec + stperf;
858 if (isDebug) fGDNtuple->
Write();
866 fNTOffset = fRuleEnsemble->GetOffset();
868 for (
UInt_t i=0; i<fNRules; i++) {
869 fNTCoeff[i] = fRuleEnsemble->GetRules(i)->GetCoefficient();
871 for (
UInt_t i=0; i<fNLinear; i++) {
872 fNTLinCoeff[i] = fRuleEnsemble->GetLinCoefficients(i);
884 Log() <<
kWARNING <<
"<CalcFStar> Using unverified code! Check!" <<
Endl;
885 UInt_t neve = fPerfIdx2-fPerfIdx1+1;
887 Log() <<
kFATAL <<
"<CalcFStar> Invalid start/end indices!" <<
Endl;
891 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
894 std::vector<Double_t> fstarSorted;
897 for (
UInt_t i=fPerfIdx1; i<fPerfIdx2+1; i++) {
898 const Event&
e = *(*events)[i];
899 fstarVal = fRuleEnsemble->FStar(e);
900 fFstar.push_back(fstarVal);
901 fstarSorted.push_back(fstarVal);
905 std::sort( fstarSorted.begin(), fstarSorted.end() );
908 fFstarMedian = 0.5*(fstarSorted[ind]+fstarSorted[ind-1]);
911 fFstarMedian = fstarSorted[ind];
925 Log() <<
kWARNING <<
"<Optimism> Using unverified code! Check!" <<
Endl;
926 UInt_t neve = fPerfIdx2-fPerfIdx1+1;
928 Log() <<
kFATAL <<
"<Optimism> Invalid start/end indices!" <<
Endl;
931 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
942 for (
UInt_t i=fPerfIdx1; i<fPerfIdx2+1; i++) {
943 const Event&
e = *(*events)[i];
944 yhat = fRuleEnsemble->EvalEvent(i);
945 y = (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal(&e) ? 1.0:-1.0);
946 w = fRuleFit->GetTrainingEventWeight(i)/fNEveEffPerf;
949 sumyhaty += w*yhat*
y;
954 Double_t cov = sumyhaty - sumyhat*sumy;
967 Log() <<
kWARNING <<
"<ErrorRateReg> Using unverified code! Check!" <<
Endl;
968 UInt_t neve = fPerfIdx2-fPerfIdx1+1;
970 Log() <<
kFATAL <<
"<ErrorRateReg> Invalid start/end indices!" <<
Endl;
972 if (fFstar.size()!=neve) {
973 Log() <<
kFATAL <<
"--- RuleFitParams::ErrorRateReg() - F* not initialized! BUG!!!"
974 <<
" Fstar.size() = " << fFstar.size() <<
" , N(events) = " << neve <<
Endl;
979 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
988 for (
UInt_t i=fPerfIdx1; i<fPerfIdx2+1; i++) {
989 const Event&
e = *(*events)[i];
990 sF = fRuleEnsemble->EvalEvent( e );
992 sumdf +=
TMath::Abs(fFstar[i-fPerfIdx1] - sF);
993 sumdfmed +=
TMath::Abs(fFstar[i-fPerfIdx1] - fFstarMedian);
998 return sumdf/sumdfmed;
1012 Log() <<
kWARNING <<
"<ErrorRateBin> Using unverified code! Check!" <<
Endl;
1013 UInt_t neve = fPerfIdx2-fPerfIdx1+1;
1015 Log() <<
kFATAL <<
"<ErrorRateBin> Invalid start/end indices!" <<
Endl;
1018 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
1025 for (
UInt_t i=fPerfIdx1; i<fPerfIdx2+1; i++) {
1026 const Event&
e = *(*events)[i];
1027 sF = fRuleEnsemble->EvalEvent( e );
1029 signF = (sF>0 ? +1:-1);
1031 signy = (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal(&e) ? +1:-1);
1042 std::vector<Double_t> & sFbkg )
1050 std::sort(sFsig.begin(), sFsig.end());
1051 std::sort(sFbkg.begin(), sFbkg.end());
1052 const Double_t minsig = sFsig.front();
1053 const Double_t minbkg = sFbkg.front();
1054 const Double_t maxsig = sFsig.back();
1055 const Double_t maxbkg = sFbkg.back();
1056 const Double_t minf = std::min(minsig,minbkg);
1057 const Double_t maxf = std::max(maxsig,maxbkg);
1060 const Int_t np = std::min((nsig+nbkg)/4,50);
1061 const Double_t df = (maxf-minf)/(np-1);
1066 std::vector<Double_t>::const_iterator indit;
1081 for (
Int_t i=0; i<np; i++) {
1083 indit = std::find_if( sFsig.begin(), sFsig.end(), std::bind2nd(std::greater_equal<Double_t>(), fcut));
1084 nesig = sFsig.end()-indit;
1087 indit = std::find_if( sFbkg.begin(), sFbkg.end(), std::bind2nd(std::greater_equal<Double_t>(), fcut));
1088 nrbkg = indit-sFbkg.begin();
1100 area += 0.5*(1+rejb)*effs;
1115 Log() <<
kWARNING <<
"<ErrorRateRoc> Should not be used in the current version! Check!" <<
Endl;
1116 UInt_t neve = fPerfIdx2-fPerfIdx1+1;
1118 Log() <<
kFATAL <<
"<ErrorRateRoc> Invalid start/end indices!" <<
Endl;
1121 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
1125 std::vector<Double_t> sFsig;
1126 std::vector<Double_t> sFbkg;
1132 for (
UInt_t i=fPerfIdx1; i<fPerfIdx2+1; i++) {
1133 const Event&
e = *(*events)[i];
1134 sF = fRuleEnsemble->EvalEvent(i);
1135 if (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal(&e)) {
1136 sFsig.push_back(sF);
1141 sFbkg.push_back(sF);
1146 fsigave = sumfsig/sFsig.size();
1147 fbkgave = sumfbkg/sFbkg.size();
1151 return ErrorRateRocRaw( sFsig, sFbkg );
1165 Log() <<
kWARNING <<
"<ErrorRateRocTst> Should not be used in the current version! Check!" <<
Endl;
1166 UInt_t neve = fPerfIdx2-fPerfIdx1+1;
1168 Log() <<
kFATAL <<
"<ErrorRateRocTst> Invalid start/end indices!" <<
Endl;
1172 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
1176 std::vector< std::vector<Double_t> > sFsig;
1177 std::vector< std::vector<Double_t> > sFbkg;
1179 sFsig.resize( fGDNTau );
1180 sFbkg.resize( fGDNTau );
1183 for (
UInt_t i=fPerfIdx1; i<fPerfIdx2+1; i++) {
1184 for (
UInt_t itau=0; itau<fGDNTau; itau++) {
1187 sF = fRuleEnsemble->EvalEvent( i, fGDOfsTst[itau], fGDCoefTst[itau], fGDCoefLinTst[itau] );
1188 if (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal((*events)[i])) {
1189 sFsig[itau].push_back(sF);
1192 sFbkg[itau].push_back(sF);
1198 for (
UInt_t itau=0; itau<fGDNTau; itau++) {
1199 err = ErrorRateRocRaw( sFsig[itau], sFbkg[itau] );
1200 fGDErrTst[itau] = err;
1213 UInt_t neve = fPerfIdx2-fPerfIdx1+1;
1215 Log() <<
kFATAL <<
"<ErrorRateRocTst> Invalid start/end indices!" <<
Endl;
1225 for (
UInt_t itau=0; itau<fGDNTau; itau++) {
1226 if (fGDErrTstOK[itau]) {
1228 fGDErrTst[itau] = RiskPerf(itau);
1229 sumx += fGDErrTst[itau];
1230 sumx2 += fGDErrTst[itau]*fGDErrTst[itau];
1231 if (fGDErrTst[itau]>maxx) maxx=fGDErrTst[itau];
1232 if (fGDErrTst[itau]<minx) {
1233 minx=fGDErrTst[itau];
1243 for (
UInt_t itau=0; itau<fGDNTau; itau++) {
1244 if (fGDErrTstOK[itau]) {
1245 if (fGDErrTst[itau] > maxacc) {
1246 fGDErrTstOK[itau] =
kFALSE;
1271 UInt_t neve = fPathIdx1-fPathIdx2+1;
1273 Log() <<
kFATAL <<
"<MakeTstGradientVector> Invalid start/end indices!" <<
Endl;
1279 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
1282 for (
UInt_t itau=0; itau<fGDNTau; itau++) {
1283 if (fGDErrTstOK[itau]) {
1284 for (
UInt_t ir=0; ir<fNRules; ir++) {
1285 fGradVecTst[itau][ir]=0;
1287 for (
UInt_t il=0; il<fNLinear; il++) {
1288 fGradVecLinTst[itau][il]=0;
1297 const std::vector<UInt_t> *eventRuleMap=0;
1303 for (
UInt_t i=fPathIdx1; i<fPathIdx2+1; i++) {
1304 const Event *
e = (*events)[i];
1306 if (fRuleEnsemble->DoRules()) {
1307 eventRuleMap = &(fRuleEnsemble->GetEventRuleMap(i));
1308 nrules = (*eventRuleMap).size();
1310 for (
UInt_t itau=0; itau<fGDNTau; itau++) {
1313 if (fGDErrTstOK[itau]) {
1314 sF = fRuleEnsemble->EvalEvent( i, fGDOfsTst[itau], fGDCoefTst[itau], fGDCoefLinTst[itau] );
1318 y = (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal(e)?1.0:-1.0);
1319 r = norm*(y - sF) * fRuleFit->GetTrainingEventWeight(i);
1321 for (
UInt_t ir=0; ir<nrules; ir++) {
1322 rind = (*eventRuleMap)[ir];
1323 fGradVecTst[itau][rind] +=
r;
1326 for (
UInt_t il=0; il<fNLinear; il++) {
1327 fGradVecLinTst[itau][il] += r*fRuleEnsemble->EvalLinEventRaw( il,i,
kTRUE );
1344 for (
UInt_t itau=0; itau<fGDNTau; itau++) {
1345 if (fGDErrTstOK[itau]) {
1347 maxr = ( (fNRules>0 ?
1348 TMath::Abs(*(std::max_element( fGradVecTst[itau].begin(), fGradVecTst[itau].end(),
AbsValue()))):0) );
1349 maxl = ( (fNLinear>0 ?
1350 TMath::Abs(*(std::max_element( fGradVecLinTst[itau].begin(), fGradVecLinTst[itau].end(),
AbsValue()))):0) );
1353 Double_t maxv = (maxr>maxl ? maxr:maxl);
1354 cthresh = maxv * fGDTauVec[itau];
1364 for (
UInt_t i=0; i<fNRules; i++) {
1365 val = fGradVecTst[itau][i];
1367 if (TMath::Abs(val)>=cthresh) {
1368 fGDCoefTst[itau][i] += fGDPathStep*val*stepScale;
1372 for (
UInt_t i=0; i<fNLinear; i++) {
1373 val = fGradVecLinTst[itau][i];
1374 if (TMath::Abs(val)>=cthresh) {
1375 fGDCoefLinTst[itau][i] += fGDPathStep*val*stepScale/fRuleEnsemble->GetLinNorm(i);
1382 CalcTstAverageResponse();
1395 UInt_t neve = fPathIdx2-fPathIdx1+1;
1397 Log() <<
kFATAL <<
"<MakeGradientVector> Invalid start/end indices!" <<
Endl;
1403 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
1406 for (
UInt_t ir=0; ir<fNRules; ir++) {
1409 for (
UInt_t il=0; il<fNLinear; il++) {
1417 const std::vector<UInt_t> *eventRuleMap=0;
1422 for (
UInt_t i=fPathIdx1; i<fPathIdx2+1; i++) {
1423 const Event *
e = (*events)[i];
1426 sF = fRuleEnsemble->EvalEvent( i );
1430 if (fRuleEnsemble->DoRules()) {
1431 eventRuleMap = &(fRuleEnsemble->GetEventRuleMap(i));
1432 nrules = (*eventRuleMap).size();
1434 y = (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal(e)?1.0:-1.0);
1435 r = norm*(y - sF) * fRuleFit->GetTrainingEventWeight(i);
1437 for (
UInt_t ir=0; ir<nrules; ir++) {
1438 rind = (*eventRuleMap)[ir];
1439 fGradVec[rind] +=
r;
1444 for (
UInt_t il=0; il<fNLinear; il++) {
1445 fGradVecLin[il] += r*fRuleEnsemble->EvalLinEventRaw( il, i,
kTRUE );
1459 Double_t maxr = ( (fRuleEnsemble->DoRules() ?
1461 Double_t maxl = ( (fRuleEnsemble->DoLinear() ?
1462 TMath::Abs(*(std::max_element( fGradVecLin.begin(), fGradVecLin.end(),
AbsValue()))):0) );
1464 Double_t maxv = (maxr>maxl ? maxr:maxl);
1472 useRThresh = cthresh;
1473 useLThresh = cthresh;
1481 for (
UInt_t i=0; i<fGradVec.size(); i++) {
1484 coef = fRuleEnsemble->GetRulesConst(i)->GetCoefficient() + fGDPathStep*gval;
1485 fRuleEnsemble->GetRules(i)->SetCoefficient(coef);
1490 for (
UInt_t i=0; i<fGradVecLin.size(); i++) {
1491 lval = fGradVecLin[i];
1493 lcoef = fRuleEnsemble->GetLinCoefficients(i) + (fGDPathStep*lval/fRuleEnsemble->GetLinNorm(i));
1494 fRuleEnsemble->SetLinCoefficient(i,lcoef);
1498 Double_t offset = CalcAverageResponse();
1499 fRuleEnsemble->SetOffset( offset );
1509 for (
UInt_t itau=0; itau<fGDNTau; itau++) {
1510 if (fGDErrTstOK[itau]) {
1511 fGDOfsTst[itau] = 0;
1512 for (
UInt_t s=0; s<fNLinear; s++) {
1513 fGDOfsTst[itau] -= fGDCoefLinTst[itau][s] * fAverageSelectorPath[s];
1516 fGDOfsTst[itau] -= fGDCoefTst[itau][
r] * fAverageRulePath[
r];
1531 for (
UInt_t s=0; s<fNLinear; s++) {
1532 ofs -= fRuleEnsemble->GetLinCoefficients(s) * fAverageSelectorPath[s];
1535 ofs -= fRuleEnsemble->GetRules(
r)->GetCoefficient() * fAverageRulePath[
r];
1545 if (fPathIdx2<=fPathIdx1) {
1546 Log() <<
kFATAL <<
"<CalcAverageTruth> Invalid start/end indices!" <<
Endl;
1552 const std::vector<const Event *> *events = &(fRuleFit->GetTrainingEvents());
1553 for (
UInt_t i=fPathIdx1; i<fPathIdx2+1; i++) {
1554 Double_t ew = fRuleFit->GetTrainingEventWeight(i);
1555 if (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal((*events)[i])) ensig += ew;
1557 sum += ew*(fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal((*events)[i])?1.0:-1.0);
1559 Log() <<
kVERBOSE <<
"Effective number of signal / background = " << ensig <<
" / " << enbkg <<
Endl;
1561 return sum/fNEveEffPath;
1567 return (fRuleFit->GetMethodRuleFit()->DataInfo().IsSignal(e) ? 1:-1);
1574 fLogger->SetMinType(t);
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
static long int sum(long int i)
MsgLogger & Endl(MsgLogger &ml)
void MakeGradientVector()
make gradient vector
void FillCoefficients()
helper function to store the rule coefficients in local arrays
Double_t Penalty() const
This is the "lasso" penalty To be used for regression.
void DrawProgressBar(Int_t, const TString &comment="")
draws progress bar in color or B&W caution:
Short_t Min(Short_t a, Short_t b)
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
TString GetElapsedTime(Bool_t Scientific=kTRUE)
void ErrorRateRocTst()
Estimates the error rate with the current set of parameters.
void MakeTstGradientVector()
make test gradient vector for all tau same algorithm as MakeGradientVector()
#define rprev(otri1, otri2)
Int_t FindGDTau()
This finds the cutoff parameter tau by scanning several different paths.
Double_t CalcAverageTruth()
calulate the average truth
Double_t ErrorRateBin()
Estimates the error rate with the current set of parameters It uses a binary estimate of (y-F*(x)) (y...
void SetMsgType(EMsgType t)
Int_t Type(const Event *e) const
Double_t ErrorRateReg()
Estimates the error rate with the current set of parameters This code is pretty messy at the moment...
Double_t ErrorRateRoc()
Estimates the error rate with the current set of parameters.
Double_t Optimism()
implementation of eq.
char * Form(const char *fmt,...)
Double_t LossFunction(const Event &e) const
Implementation of squared-error ramp loss function (eq 39,40 in ref 1) This is used for binary Classi...
void InitNtuple()
initializes the ntuple
void CalcFStar()
Estimates F* (optimum scoring function) for all events for the given sets.
virtual ~RuleFitParams()
destructor
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
void UpdateCoefficients()
Establish maximum gradient for rules, linear terms and the offset.
Double_t ErrorRateRocRaw(std::vector< Double_t > &sFsig, std::vector< Double_t > &sFbkg)
RuleFitParams()
constructor
Short_t Max(Short_t a, Short_t b)
void Init()
Initializes all parameters using the RuleEnsemble and the training tree.
Double_t CalcAverageResponse()
calulate the average response - TODO : rewrite bad dependancy on EvaluateAverage() ! ...
Double_t Risk(UInt_t ind1, UInt_t ind2, Double_t neff) const
risk asessment
void InitGD()
Initialize GD path search.
A TTree object has a header with a name and a title.
void UpdateTstCoefficients()
Establish maximum gradient for rules, linear terms and the offset for all taus TODO: do not need inde...
UInt_t RiskPerfTst()
Estimates the error rate with the current set of parameters.
Double_t Sqrt(Double_t x)
void EvaluateAverage(UInt_t ind1, UInt_t ind2, std::vector< Double_t > &avsel, std::vector< Double_t > &avrul)
evaluate the average of each variable and f(x) in the given range
void MakeGDPath()
The following finds the gradient directed path in parameter space.
double norm(double *x, double *p)
void CalcTstAverageResponse()
calc average response for all test paths - TODO: see comment under CalcAverageResponse() note that 0 ...