105 std::vector<TTreeFormula*>::iterator formIt =
fCatFormulas.begin();
106 std::vector<TTreeFormula*>::iterator lastF =
fCatFormulas.end();
107 for(;formIt!=lastF; ++formIt)
delete *formIt;
117 std::vector<IMethod*>::iterator itrMethod =
fMethods.begin();
120 for(; itrMethod !=
fMethods.end(); ++itrMethod ) {
121 if ( !(*itrMethod)->HasAnalysisType(type, numberClasses, numberTargets) )
145 Log() << kINFO <<
"Adding sub-classifier: " << addedMethodName <<
"::" << theTitle <<
Endl;
152 if(method==0)
return 0;
182 fVars.push_back(theVariables);
204 TString dsiName=theTitle+
"_dsi";
213 std::vector<VariableInfo>::iterator itrVarInfo;
225 std::vector<UInt_t> varMap;
229 std::vector<TString>::iterator itrVariables;
233 for (itrVariables =
variables.begin(); itrVariables !=
variables.end(); ++itrVariables) {
238 if((*itrVariables==itrVarInfo->GetLabel()) ) {
242 varMap.push_back(counter);
250 if((*itrVariables==itrVarInfo->GetLabel()) ) {
254 varMap.push_back(counter);
262 Log() << kFATAL <<
"The variable " << itrVariables->Data() <<
" was not found and could not be added " <<
Endl;
268 if (theVariables==
"") {
282 for (
UInt_t i=0; i<nClasses; i++) {
286 dsi->
AddCut(theCut,className);
297 splitOpt +=
":ScaleWithPreselEff";
320 std::vector<VariableInfo>::const_iterator viIt;
325 for (viIt = vars.begin(); viIt != vars.end(); ++viIt)
326 if( viIt->GetExternalLink() == 0 ) {
327 hasAllExternalLinks =
kFALSE;
330 for (viIt = specs.begin(); viIt != specs.end(); ++viIt)
331 if( viIt->GetExternalLink() == 0 ) {
332 hasAllExternalLinks =
kFALSE;
336 if(!hasAllExternalLinks)
return;
348 for (viIt = vars.begin(); viIt != vars.end(); ++viIt) {
352 for (viIt = specs.begin(); viIt != specs.end(); ++viIt) {
374 Log() << kINFO <<
"Train all sub-classifiers for "
379 Log() << kINFO <<
"...nothing found to train" <<
Endl;
383 std::vector<IMethod*>::iterator itrMethod;
386 for (itrMethod =
fMethods.begin(); itrMethod !=
fMethods.end(); ++itrMethod ) {
399 itrMethod =
fMethods.erase( itrMethod );
407 Log() << kINFO <<
"Training finished" <<
Endl;
412 <<
" not trained (training tree has less entries ["
416 Log() << kERROR <<
" w/o training/test events for that category, I better stop here and let you fix " <<
Endl;
417 Log() << kFATAL <<
"that one first, otherwise things get too messy later ... " <<
Endl;
425 Log() << kINFO <<
"Begin ranking of input variables..." <<
Endl;
426 for (itrMethod =
fMethods.begin(); itrMethod !=
fMethods.end(); ++itrMethod) {
429 const Ranking* ranking = (*itrMethod)->CreateRanking();
433 Log() << kINFO <<
"No variable ranking supplied by classifier: "
476 Log() << kINFO <<
"Recreating sub-classifiers from XML-file " <<
Endl;
479 for (
UInt_t i=0; i<nSubMethods; i++) {
485 methodType = fullMethodName(0,fullMethodName.
Index(
"::"));
486 if (methodType.
Contains(
" ")) methodType = methodType(methodType.
Last(
' ')+1,methodType.
Length());
489 titleLength = fullMethodName.
Length()-fullMethodName.
Index(
"::")-2;
490 methodTitle = fullMethodName(fullMethodName.
Index(
"::")+2,titleLength);
499 Log() << kFATAL <<
"Could not create sub-method " << method <<
" from XML." <<
Endl;
506 fVars.push_back(theVariables);
510 UInt_t spectatorIdx = 10000;
515 std::vector<VariableInfo>::iterator itrVarInfo;
518 for (itrVarInfo = spectators.begin(); itrVarInfo != spectators.end(); ++itrVarInfo, ++counter) {
519 if((specName==itrVarInfo->GetLabel()) || (specName==itrVarInfo->GetExpression())) {
520 spectatorIdx=counter;
551 Log() <<
"This method allows to define different categories of events. The" <<
Endl;
552 Log() <<
"categories are defined via cuts on the variables. For each" <<
Endl;
553 Log() <<
"category, a different classifier and set of variables can be" <<
Endl;
554 Log() <<
"specified. The categories which are defined for this method must" <<
Endl;
555 Log() <<
"be disjoint." <<
Endl;
575 Log() << kFATAL <<
"Large method index " << methodIdx <<
", number of category formulas = "
579 return f->EvalInstance(0) > 0.5;
586 Log() << kFATAL <<
"Unknown method index " << methodIdx <<
" maximum allowed index="
591 Bool_t pass = (specVal>0.5);
607 Int_t suitableCutsN = 0;
616 if (suitableCutsN == 0) {
617 Log() << kWARNING <<
"Event does not lie within the cut of any sub-classifier." <<
Endl;
621 if (suitableCutsN > 1) {
622 Log() << kFATAL <<
"The defined categories are not disjoint." <<
Endl;
631 Log() << kDEBUG <<
"Event is for method " << methodToUse <<
" spectator is " << ev->
GetSpectator(0) <<
" "
632 <<
fVarMaps[0][0] <<
" classID " <<
DataInfo().IsSignal(ev) <<
" value " << mvaValue
633 <<
" type " <<
Data()->GetCurrentType() <<
Endl;
645 std::vector<Double_t> result;
647 Info(
"GetMVaValues",
"Evaluate MethodCategory for %d events type %d on the dataset %s",
int(lastEvt - firstEvt),
656 std::vector<std::vector<Double_t>> mvaValues(
fMethods.size());
659 for (
UInt_t iev = firstEvt; iev < lastEvt; ++iev) {
660 data->SetCurrentEvent(iev);
669 result.resize(lastEvt - firstEvt);
671 for (
UInt_t iev = firstEvt; iev < lastEvt; ++iev)
673 data->SetCurrentEvent(iev);
678 Int_t suitableCutsN = 0;
687 if (suitableCutsN == 0) {
688 Log() << kWARNING <<
"Event does not lie within the cut of any sub-classifier." <<
Endl;
692 if (suitableCutsN > 1) {
693 Log() << kFATAL <<
"The defined categories are not disjoint." <<
Endl;
698 result[iev - firstEvt] = mvaValues[methodToUse][iev - firstEvt];
718 Int_t suitableCutsN = 0;
727 if (suitableCutsN == 0) {
728 Log() << kWARNING <<
"Event does not lie within the cut of any sub-classifier." <<
Endl;
732 if (suitableCutsN > 1) {
733 Log() << kFATAL <<
"The defined categories are not disjoint." <<
Endl;
738 Log() << kFATAL <<
"method not found in Category Regression method" <<
Endl;
759 Int_t suitableCutsN = 0;
768 if (suitableCutsN == 0) {
769 Log() << kWARNING <<
"Event does not lie within the cut of any sub-classifier." <<
Endl;
773 if (suitableCutsN > 1) {
774 Log() << kFATAL <<
"The defined categories are not disjoint." <<
Endl;
779 Log() << kFATAL <<
"method not found in Category Regression method" <<
Endl;
#define MinNoTrainingEvents
#define REGISTER_METHOD(CLASS)
for example
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).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
long long Long64_t
Portable signed long integer 8 bytes.
float Float_t
Float 4 bytes (float).
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
A specialized string object used for TTree selections.
TDirectory::TContext keeps track and restore the current directory.
Describe directory structure in memory.
IMethod * Create(const std::string &name, const TString &job, const TString &title, DataSetInfo &dsi, const TString &option)
creates the method if needed based on the method name using the creator function the factory has stor...
static ClassifierFactory & Instance()
access to the ClassifierFactory singleton creates the instance if needed
virtual void ParseOptions()
options parser
Class that contains all the data information.
const TString GetWeightExpression(Int_t i) const
std::vector< VariableInfo > & GetVariableInfos()
VariableInfo & AddVariable(const TString &expression, const TString &title="", const TString &unit="", Double_t min=0, Double_t max=0, char varType='F', Bool_t normalized=kTRUE, void *external=nullptr)
add a variable (can be a complex expression) to the set of variables used in the MV analysis
void SetSplitOptions(const TString &so)
ClassInfo * AddClass(const TString &className)
const TString & GetNormalization() const
std::vector< VariableInfo > & GetSpectatorInfos()
TDirectory * GetRootDir() const
void SetNormalization(const TString &norm)
UInt_t GetNClasses() const
const TString & GetSplitOptions() const
UInt_t GetNTargets() const
ClassInfo * GetClassInfo(Int_t clNum) const
VariableInfo & AddTarget(const TString &expression, const TString &title, const TString &unit, Double_t min, Double_t max, Bool_t normalized=kTRUE, void *external=nullptr)
add a variable (can be a complex expression) to the set of variables used in the MV analysis
const TCut & GetCut(Int_t i) const
void SetCut(const TCut &cut, const TString &className)
set the cut for the classes
std::vector< VariableInfo > & GetTargetInfos()
void SetRootDir(TDirectory *d)
VariableInfo & AddSpectator(const TString &expression, const TString &title, const TString &unit, Double_t min, Double_t max, char type='F', Bool_t normalized=kTRUE, void *external=nullptr)
add a spectator (can be a complex expression) to the set of spectator variables used in the MV analys...
void SetWeightExpression(const TString &exp, const TString &className="")
set the weight expressions for the classes if class name is specified, set only for this class if cla...
void AddCut(const TCut &cut, const TString &className)
set the cut for the classes
Long64_t GetNTrainingEvents() const
void SetVariableArrangement(std::vector< UInt_t > *const m) const
set the variable arrangement
Float_t GetSpectator(UInt_t ivar) const
return spectator content
Interface for all concrete MVA method implementations.
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)=0
Virtual base Class for all MVA method.
virtual const std::vector< Float_t > & GetRegressionValues()
const std::vector< Float_t > & GetRegressionValues(const TMVA::Event *const ev)
TString fFileDir
unix sub-directory for weight files (default: DataLoader's Name + "weights")
const char * GetName() const override
void SetSilentFile(Bool_t status)
void SetWeightFileDir(TString fileDir)
set directory of weight file
void WriteStateToXML(void *parent) const
general method used in writing the header of the weight files where the used variables,...
TString GetMethodTypeName() const
void DisableWriting(Bool_t setter)
virtual const std::vector< Float_t > & GetMulticlassValues()
Types::EAnalysisType GetAnalysisType() const
const TString & GetJobName() const
virtual std::vector< Double_t > GetDataMvaValues(DataSet *data=nullptr, Long64_t firstEvt=0, Long64_t lastEvt=-1, Bool_t logProgress=false)
get all the MVA values for the events of the given Data type
void SetupMethod()
setup of methods
TDirectory * BaseDir() const
returns the ROOT directory where info/histograms etc of the corresponding MVA method instance are sto...
virtual void SetAnalysisType(Types::EAnalysisType type)
const TString & GetMethodName() const
const Event * GetEvent() const
void ProcessSetup()
process all options the "CheckForUnusedOptions" is done in an independent call, since it may be overr...
DataSetInfo & DataInfo() const
Types::EAnalysisType fAnalysisType
Bool_t IsSilentFile() const
void SetFile(TFile *file)
void ReadStateFromXML(void *parent)
friend class MethodCategory
void SetMethodBaseDir(TDirectory *methodDir)
void SetModelPersistence(Bool_t status)
virtual void CheckSetup()
check may be overridden by derived class (sometimes, eg, fitters are used which can only be implement...
void InitCircularTree(const DataSetInfo &dsi)
initialize the circular tree
void DeclareOptions() override
options for this method
void ReadWeightsFromXML(void *wghtnode) override
read weights of sub-classifiers of MethodCategory from xml weight file
Bool_t PassesCut(const Event *ev, UInt_t methodIdx)
void Train(void) override
train all sub-classifiers
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t) override
check whether method category has analysis type the method type has to be the same for all sub-method...
MethodCategory(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
standard constructor
const Ranking * CreateRanking() override
no ranking
std::vector< std::vector< UInt_t > > fVarMaps
TMVA::DataSetInfo & CreateCategoryDSI(const TCut &, const TString &, const TString &)
create a DataSetInfo object for a sub-classifier
std::vector< IMethod * > fMethods
DataSetManager * fDataSetManager
std::vector< UInt_t > fCategorySpecIdx
std::vector< TString > fVars
TTree * fCatTree
! needed in conjunction with TTreeFormulas for evaluation category expressions
const std::vector< Float_t > & GetRegressionValues() override
returns the mva value of the right sub-classifier
void Init() override
initialize the method
virtual ~MethodCategory(void)
destructor
void AddWeightsXMLTo(void *parent) const override
create XML description of Category classifier
void ProcessOptions() override
process user options
std::vector< TTreeFormula * > fCatFormulas
std::vector< TCut > fCategoryCuts
TMVA::IMethod * AddMethod(const TCut &, const TString &theVariables, Types::EMVA theMethod, const TString &theTitle, const TString &theOptions)
adds sub-classifier for a category
void GetHelpMessage() const override
Get help message text.
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr) override
returns the mva value of the right sub-classifier
std::vector< Double_t > GetMvaValues(Long64_t firstEvt=0, Long64_t lastEvt=-1, Bool_t logProgress=false) override
returns the mva values of the right sub-classifier
const std::vector< Float_t > & GetMulticlassValues() override
returns the mva values of the multi-class right sub-classifier
MethodCompositeBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
Ranking for variables in method (implementation).
virtual void Print() const
get maximum length of variable names
Singleton class for Global types used by TMVA.
static Types & Instance()
The single instance of "Types" if existing already, or create it (Singleton).
Class for type info of MVA input variable.
const TString & GetExpression() const
void * GetExternalLink() const
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
const char * Data() const
Ssiz_t Last(char c) const
Find last occurrence of a character c.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
A TTree represents a columnar dataset.
create variable transformations
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
MsgLogger & Endl(MsgLogger &ml)