71 std::string
name =
"OptimizeConfigParameters_";
75 Log() << kFATAL <<
" ERROR: Sorry, Regression is not yet implement for automatic parameter optimization"
76 <<
" --> exit" <<
Endl;
79 Log() << kINFO <<
"Automatic optimisation of tuning parameters in "
82 std::map<TString,TMVA::Interval*>::iterator it;
84 Log() << kINFO << it->first
85 <<
" in range from: " << it->second->GetMin()
86 <<
" to: " << it->second->GetMax()
87 <<
" in : " << it->second->GetNbins() <<
" steps"
133 <<
" that is not (yet) coded --> exit()" <<
Endl;
136 Log() << kINFO <<
"For " <<
GetMethod()->GetName() <<
" the optimized Parameters are: " <<
Endl;
137 std::map<TString,Double_t>::iterator it;
139 Log() << kINFO << it->first <<
" = " << it->second <<
Endl;
150 std::vector < int > indices;
152 indices.push_back(val % base[
i] );
153 val =
int( floor(
float(val) /
float(base[
i]) ) );
167 Double_t bestFOM=-1000000, currentFOM;
169 std::map<TString,Double_t> currentParameters;
170 std::map<TString,TMVA::Interval*>::iterator it;
174 currentParameters.clear();
178 currentParameters.insert(std::pair<TString,Double_t>(it->first,it->second->GetMin()));
179 fTunedParameters.insert(std::pair<TString,Double_t>(it->first,it->second->GetMin()));
186 std::vector< std::vector <Double_t> >
v;
188 std::vector< Double_t > tmp;
189 for (
Int_t k=0; k<it->second->GetNbins(); k++){
190 tmp.push_back(it->second->GetElement(k));
195 std::vector< int > Nindividual;
198 Nindividual.push_back(
v[
i].
size());
202 for (
int i=0;
i<Ntot;
i++){
206 currentParameters[it->first] =
v[
index][indices[
index]];
208 Log() << kINFO <<
"--------------------------" <<
Endl;
209 Log() << kINFO <<
"Settings being evaluated:" <<
Endl;
210 for (std::map<TString,Double_t>::iterator it_print=currentParameters.begin();
211 it_print!=currentParameters.end(); ++it_print){
212 Log() << kINFO <<
" " << it_print->first <<
" = " << it_print->second <<
Endl;
216 GetMethod()->SetTuneParameters(currentParameters);
219 if (
i==0)
GetMethod()->GetTransformationHandler().CalcTransformations(
220 GetMethod()->Data()->GetEventCollection());
225 Log() << kINFO <<
"FOM was found : " << currentFOM <<
"; current best is " << bestFOM <<
Endl;
227 if (currentFOM > bestFOM) {
228 bestFOM = currentFOM;
229 for (std::map<TString,Double_t>::iterator iter=currentParameters.begin();
230 iter != currentParameters.end(); ++iter){
245 std::vector<TMVA::Interval*> ranges;
246 std::map<TString, TMVA::Interval*>::iterator it;
247 std::vector<Double_t> pars;
251 pars.push_back( (it->second)->GetMean() );
257 GetMethod()->GetTransformationHandler().CalcTransformations(
GetMethod()->Data()->GetEventCollection());
264 TString opt=
"FitStrategy=0:UseImprove=False:UseMinos=False:Tolerance=100";
268 "FitterMinuit_BDTOptimize",
271 TString opt=
"PopSize=20:Steps=30:Cycles=3:ConvCrit=0.01:SaveBestCycle=5";
273 "FitterGA_BDTOptimize",
276 Log() << kWARNING <<
" you did not specify a valid OptimizationFitType "
277 <<
" will use the default (FitGA) " <<
Endl;
278 TString opt=
"PopSize=20:Steps=30:Cycles=3:ConvCrit=0.01:SaveBestCycle=5";
280 "FitterGA_BDTOptimize",
290 for (
UInt_t ipar=0; ipar<ranges.size(); ipar++)
delete ranges[ipar];
297 fTunedParameters.insert(std::pair<TString,Double_t>(it->first,pars[jcount++]));
309 std::map< std::vector<Double_t> ,
Double_t>::const_iterator iter;
318 std::map<TString,Double_t> currentParameters;
321 std::map<TString, TMVA::Interval*>::iterator it;
323 currentParameters[it->first] = pars[icount++];
326 GetMethod()->SetTuneParameters(currentParameters);
331 CalcTransformations(
GetMethod()->Data()->GetEventCollection());
362 <<
" is not a valid floating point number" <<
Endl;
369 std::cout <<
" ERROR: Sorry, Regression is not yet implement for automatic parameter optimisation"
370 <<
" --> exit" << std::endl;
379 Log()<< kFATAL <<
" ERROR, you've specified as Figure of Merit in the "
380 <<
" parameter optimisation " <<
fFOMType <<
" which has not"
381 <<
" been implemented yet!! ---> exit " <<
Endl;
413 UInt_t signalClassNr =
fMethod->DataInfo().GetClassInfo(
"Signal")->GetNumber();
417 for (
UInt_t iev=0; iev < events.size() ; iev++){
421 if (events[iev]->GetClass() == signalClassNr) {
422 fMvaSig->Fill(
fMethod->GetMvaValue(events[iev]),events[iev]->GetWeight());
425 fMvaBkg->Fill(
fMethod->GetMvaValue(events[iev]),events[iev]->GetWeight());
442 std::cout <<
"Separation calculation via histograms (not PDFs) seems to give still strange results!! Don't do that, check!!"<<std::endl;
482 std::cout <<
" Error in OptimizeConfigParameters GetROCIntegral, unequal histograms for sig and bkg.." << std::endl;
492 for (
Int_t ibin=1; ibin<=nbins; ibin++){
497 for (
Int_t ibin=1; ibin <= nbins; ibin++){
517 std::cout <<
" Error in OptimizeConfigParameters GetSigEffAt, unequal histograms for sig and bkg.." << std::endl;
532 while (bkgCumulator[nbins-ibin] > (1-bkgEff)) {
533 sigEff = sigCumulator[nbins]-sigCumulator[nbins-ibin];
554 std::cout <<
" Error in OptimizeConfigParameters GetBkgEffAt, unequal histograms for sig and bkg.." << std::endl;
570 while ( sigCumulator[nbins]-sigCumulator[nbins-ibin] < sigEff) {
571 bkgEff = bkgCumulator[nbins]-bkgCumulator[nbins-ibin];
591 std::cout <<
" Error in OptimizeConfigParameters GetBkgEffAt, unequal histograms for sig and bkg.." << std::endl;
607 while ( sigCumulator[nbins]-sigCumulator[nbins-ibin] < sigEff) {
608 bkgRej = bkgCumulator[nbins-ibin];
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint percent
A TGraph is an object made of two arrays X and Y with npoints each.
void SetName(const char *name="") override
Set graph name.
1-D histogram with a double per channel (see TH1 documentation)
2-D histogram with a double per channel (see TH1 documentation)
void CheckForUnusedOptions() const
checks for unused options in option string
static void SetIsTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
Base class for TMVA fitters.
Double_t Run()
estimator function interface for fitting
Fitter using a Genetic Algorithm.
The TMVA::Interval Class.
Virtual base Class for all MVA method.
const char * GetName() const
ostringstream derivative to redirect and format output
std::vector< int > GetScanIndices(int val, std::vector< int > base)
helper function to scan through the all the combinations in the parameter space
MsgLogger * fLogger
! message logger
Double_t GetBkgRejAtSigEff(Double_t sigEff=0.5)
calculate the background rejection for a given signal efficiency
std::map< TString, Double_t > fTunedParameters
parameters included in the tuning
virtual ~OptimizeConfigParameters()
the destructor (delete the OptimizeConfigParameters, store the graph and .. delete it)
Double_t GetBkgEffAtSigEff(Double_t sigEff=0.5)
calculate the background efficiency for a given signal efficiency
void optimizeScan()
do the actual optimization using a simple scan method, i.e.
OptimizeConfigParameters(MethodBase *const method, std::map< TString, TMVA::Interval * > tuneParameters, TString fomType="Separation", TString optimizationType="GA")
Constructor which sets either "Classification or Regression".
std::map< TString, TMVA::Interval * > fTuneParameters
parameters included in the tuning
MethodBase *const fMethod
The MVA method to be evaluated.
Bool_t fNotDoneYet
flat to indicate of Method Transformations have been obtained yet or not (normally done in MethodBase...
TString fOptimizationFitType
which type of optimisation procedure to be used
std::map< TString, Double_t > optimize()
Double_t GetSeparation()
return the separation between the signal and background MVA ouput distribution
TH1D * fMvaSig
MVA distribution for signal events, used for spline fit.
TString fFOMType
the FOM type (Separation, ROC integra.. whatever you implemented..
Double_t GetFOM()
Return the Figure of Merit (FOM) used in the parameter optimization process.
Double_t GetSigEffAtBkgEff(Double_t bkgEff=0.1)
calculate the signal efficiency for a given background efficiency
Double_t GetROCIntegral()
calculate the area (integral) under the ROC curve as a overall quality measure of the classification
TH1D * fMvaBkg
MVA distribution for bakgr. events, used for spline fit.
TH1D * fMvaBkgFineBin
MVA distribution for bakgr. events.
void GetMVADists()
fill the private histograms with the mva distributions for sig/bkg
Double_t EstimatorFunction(std::vector< Double_t > &)
return the estimator (from current FOM) for the fitting interface
std::vector< Float_t > fFOMvsIter
graph showing the development of the Figure Of Merit values during the fit
std::map< std::vector< Double_t >, Double_t > fAlreadyTrainedParCombination
save parameters for which the FOM is already known (GA seems to evaluate the same parameters several ...
TH1D * fMvaSigFineBin
MVA distribution for signal events.
PDF wrapper for histograms; uses user-defined spline interpolation.
Double_t GetVal(Double_t x) const
returns value PDF(x)
Double_t GetIntegral(Double_t xmin, Double_t xmax)
computes PDF integral within given ranges
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
MsgLogger & Endl(MsgLogger &ml)
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.