70 std::string
name =
"OptimizeConfigParameters_";
74 Log() << kFATAL <<
" ERROR: Sorry, Regression is not yet implement for automatic parameter optimization"
75 <<
" --> exit" <<
Endl;
78 Log() << kINFO <<
"Automatic optimisation of tuning parameters in "
81 std::map<TString,TMVA::Interval*>::iterator it;
83 Log() << kINFO << it->first
84 <<
" in range from: " << it->second->GetMin()
85 <<
" to: " << it->second->GetMax()
86 <<
" in : " << it->second->GetNbins() <<
" steps"
132 <<
" that is not (yet) coded --> exit()" <<
Endl;
135 Log() << kINFO <<
"For " <<
GetMethod()->GetName() <<
" the optimized Parameters are: " <<
Endl;
136 std::map<TString,Double_t>::iterator it;
138 Log() << kINFO << it->first <<
" = " << it->second <<
Endl;
149 std::vector < int > indices;
150 for (
UInt_t i=0; i< base.size(); i++){
151 indices.push_back(val % base[i] );
152 val =
int( floor(
float(val) /
float(base[i]) ) );
166 Double_t bestFOM=-1000000, currentFOM;
168 std::map<TString,Double_t> currentParameters;
169 std::map<TString,TMVA::Interval*>::iterator it;
173 currentParameters.clear();
177 currentParameters.insert(std::pair<TString,Double_t>(it->first,it->second->GetMin()));
178 fTunedParameters.insert(std::pair<TString,Double_t>(it->first,it->second->GetMin()));
185 std::vector< std::vector <Double_t> >
v;
187 std::vector< Double_t > tmp;
188 for (
Int_t k=0; k<it->second->GetNbins(); k++){
189 tmp.push_back(it->second->GetElement(k));
194 std::vector< int > Nindividual;
195 for (
UInt_t i=0; i<
v.size(); i++) {
197 Nindividual.push_back(
v[i].
size());
201 for (
int i=0; i<Ntot; i++){
204 for (it=
fTuneParameters.begin(), index=0; index< indices.size(); ++index, ++it){
205 currentParameters[it->first] =
v[index][indices[index]];
207 Log() << kINFO <<
"--------------------------" <<
Endl;
208 Log() << kINFO <<
"Settings being evaluated:" <<
Endl;
209 for (std::map<TString,Double_t>::iterator it_print=currentParameters.begin();
210 it_print!=currentParameters.end(); ++it_print){
211 Log() << kINFO <<
" " << it_print->first <<
" = " << it_print->second <<
Endl;
215 GetMethod()->SetTuneParameters(currentParameters);
218 if (i==0)
GetMethod()->GetTransformationHandler().CalcTransformations(
219 GetMethod()->Data()->GetEventCollection());
224 Log() << kINFO <<
"FOM was found : " << currentFOM <<
"; current best is " << bestFOM <<
Endl;
226 if (currentFOM > bestFOM) {
227 bestFOM = currentFOM;
228 for (std::map<TString,Double_t>::iterator iter=currentParameters.begin();
229 iter != currentParameters.end(); ++iter){
244 std::vector<TMVA::Interval*> ranges;
245 std::map<TString, TMVA::Interval*>::iterator it;
246 std::vector<Double_t> pars;
250 pars.push_back( (it->second)->GetMean() );
256 GetMethod()->GetTransformationHandler().CalcTransformations(
GetMethod()->Data()->GetEventCollection());
263 TString opt=
"FitStrategy=0:UseImprove=False:UseMinos=False:Tolerance=100";
267 "FitterMinuit_BDTOptimize",
270 TString opt=
"PopSize=20:Steps=30:Cycles=3:ConvCrit=0.01:SaveBestCycle=5";
272 "FitterGA_BDTOptimize",
275 Log() << kWARNING <<
" you did not specify a valid OptimizationFitType "
276 <<
" will use the default (FitGA) " <<
Endl;
277 TString opt=
"PopSize=20:Steps=30:Cycles=3:ConvCrit=0.01:SaveBestCycle=5";
279 "FitterGA_BDTOptimize",
289 for (
UInt_t ipar=0; ipar<ranges.size(); ipar++)
delete ranges[ipar];
296 fTunedParameters.insert(std::pair<TString,Double_t>(it->first,pars[jcount++]));
308 std::map< std::vector<Double_t> ,
Double_t>::const_iterator iter;
317 std::map<TString,Double_t> currentParameters;
320 std::map<TString, TMVA::Interval*>::iterator it;
322 currentParameters[it->first] = pars[icount++];
325 GetMethod()->SetTuneParameters(currentParameters);
330 CalcTransformations(
GetMethod()->Data()->GetEventCollection());
358 return percent.
Atof();
360 Log() << kFATAL <<
" ERROR, " << percent <<
" in " <<
fFOMType
361 <<
" is not a valid floating point number" <<
Endl;
368 std::cout <<
" ERROR: Sorry, Regression is not yet implement for automatic parameter optimisation"
369 <<
" --> exit" << std::endl;
378 Log()<< kFATAL <<
" ERROR, you've specified as Figure of Merit in the "
379 <<
" parameter optimisation " <<
fFOMType <<
" which has not"
380 <<
" been implemented yet!! ---> exit " <<
Endl;
412 UInt_t signalClassNr =
fMethod->DataInfo().GetClassInfo(
"Signal")->GetNumber();
416 for (
UInt_t iev=0; iev < events.size() ; iev++){
420 if (events[iev]->GetClass() == signalClassNr) {
421 fMvaSig->Fill(
fMethod->GetMvaValue(events[iev]),events[iev]->GetWeight());
424 fMvaBkg->Fill(
fMethod->GetMvaValue(events[iev]),events[iev]->GetWeight());
441 std::cout <<
"Separation calculation via histograms (not PDFs) seems to give still strange results!! Don't do that, check!!"<<std::endl;
472 for (
UInt_t i=0; i<nsteps; i++){
481 std::cout <<
" Error in OptimizeConfigParameters GetROCIntegral, unequal histograms for sig and bkg.." << std::endl;
491 for (
Int_t ibin=1; ibin<=nbins; ibin++){
496 for (
Int_t ibin=1; ibin <= nbins; ibin++){
516 std::cout <<
" Error in OptimizeConfigParameters GetSigEffAt, unequal histograms for sig and bkg.." << std::endl;
531 while (bkgCumulator[nbins-ibin] > (1-bkgEff)) {
532 sigEff = sigCumulator[nbins]-sigCumulator[nbins-ibin];
553 std::cout <<
" Error in OptimizeConfigParameters GetBkgEffAt, unequal histograms for sig and bkg.." << std::endl;
569 while ( sigCumulator[nbins]-sigCumulator[nbins-ibin] < sigEff) {
570 bkgEff = bkgCumulator[nbins]-bkgCumulator[nbins-ibin];
590 std::cout <<
" Error in OptimizeConfigParameters GetBkgEffAt, unequal histograms for sig and bkg.." << std::endl;
606 while ( sigCumulator[nbins]-sigCumulator[nbins-ibin] < sigEff) {
607 bkgRej = bkgCumulator[nbins-ibin];
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
void SetName(const char *name="") override
Set the name of the TNamed.
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 override
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".
Double_t EstimatorFunction(std::vector< Double_t > &) override
return the estimator (from current FOM) for the fitting interface
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
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.
TString & Insert(Ssiz_t pos, const char *s)
Double_t Atof() const
Return floating-point value contained in string.
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
Int_t CountChar(Int_t c) const
Return number of times character c occurs in the string.
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.