35 :
TMVA::
MethodBase(jobName,
Types::kCrossValidation, methodTitle, theData, theOption), fSplitExpr(nullptr)
56 DeclareOptionRef(fEncapsulatedMethodName,
"EncapsulatedMethodName",
"");
57 DeclareOptionRef(fEncapsulatedMethodTypeName,
"EncapsulatedMethodTypeName",
"");
58 DeclareOptionRef(fNumFolds,
"NumFolds",
"Number of folds to generate");
59 DeclareOptionRef(fOutputEnsembling =
TString(
"None"),
"OutputEnsembling",
60 "Combines output from contained methods. If None, no combination is performed. (default None)");
63 DeclareOptionRef(fSplitExprString,
"SplitExpr",
"The expression used to assign events to folds");
79 Log() << kDEBUG <<
"ProcessOptions -- fNumFolds: " << fNumFolds <<
Endl;
80 Log() << kDEBUG <<
"ProcessOptions -- fEncapsulatedMethodName: " << fEncapsulatedMethodName <<
Endl;
81 Log() << kDEBUG <<
"ProcessOptions -- fEncapsulatedMethodTypeName: " << fEncapsulatedMethodTypeName <<
Endl;
83 if (fSplitExprString !=
TString(
"")) {
84 fSplitExpr = std::unique_ptr<CvSplitKFoldsExpr>(
new CvSplitKFoldsExpr(DataInfo(), fSplitExprString));
87 for (
UInt_t iFold = 0; iFold < fNumFolds; ++iFold) {
88 TString weightfile = GetWeightFileNameForFold(iFold);
90 Log() << kINFO <<
"Reading weightfile: " << weightfile <<
Endl;
91 MethodBase *fold_method = InstantiateMethodFromXML(fEncapsulatedMethodTypeName, weightfile);
92 fEncapsulatedMethods.push_back(fold_method);
101 fMulticlassValues = std::vector<Float_t>(DataInfo().GetNClasses());
102 fRegressionValues = std::vector<Float_t>(DataInfo().GetNTargets());
116 if (iFold >= fNumFolds) {
117 Log() << kFATAL << iFold <<
" out of range. "
118 <<
"Should be < " << fNumFolds <<
"." <<
Endl;
123 TString weightfile = fileDir +
"/" + fJobName +
"_" + fEncapsulatedMethodName +
"_" + foldStr +
".weights.xml";
160 Log() << kFATAL <<
"MethodCategory not supported for the moment." <<
Endl;
164 m->SetWeightFileDir(fileDir);
167 m->SetAnalysisType(fAnalysisType);
169 m->ReadStateFromFile();
185 gTools().
AddAttr(wght,
"EncapsulatedMethodName", fEncapsulatedMethodName);
186 gTools().
AddAttr(wght,
"EncapsulatedMethodTypeName", fEncapsulatedMethodTypeName);
187 gTools().
AddAttr(wght,
"OutputEnsembling", fOutputEnsembling);
189 for (
UInt_t iFold = 0; iFold < fNumFolds; ++iFold) {
190 TString weightfile = GetWeightFileNameForFold(iFold);
213 gTools().
ReadAttr(parent,
"EncapsulatedMethodName", fEncapsulatedMethodName);
214 gTools().
ReadAttr(parent,
"EncapsulatedMethodTypeName", fEncapsulatedMethodTypeName);
218 for (
UInt_t iFold = 0; iFold < fNumFolds; ++iFold) {
219 TString weightfile = GetWeightFileNameForFold(iFold);
221 Log() << kINFO <<
"Reading weightfile: " << weightfile <<
Endl;
222 MethodBase *fold_method = InstantiateMethodFromXML(fEncapsulatedMethodTypeName, weightfile);
223 fEncapsulatedMethods.push_back(fold_method);
227 if (fSplitExprString !=
TString(
"")) {
228 fSplitExpr = std::unique_ptr<CvSplitKFoldsExpr>(
new CvSplitKFoldsExpr(DataInfo(), fSplitExprString));
230 Log() << kFATAL <<
"MethodCrossValidation supports XML reading only for deterministic splitting !" <<
Endl;
240 Log() << kFATAL <<
"CrossValidation currently supports only reading from XML." <<
Endl;
248 const Event *ev = GetEvent();
250 if (fOutputEnsembling ==
"None") {
251 if (fSplitExpr !=
nullptr) {
253 UInt_t iFold = fSplitExpr->Eval(fNumFolds, ev);
254 return fEncapsulatedMethods.at(iFold)->GetMvaValue(err, errUpper);
257 UInt_t iFold = fEventToFoldMapping.at(Data()->GetEvent());
258 return fEncapsulatedMethods.at(iFold)->GetMvaValue(err, errUpper);
260 }
else if (fOutputEnsembling ==
"Avg") {
262 for (
auto &
m : fEncapsulatedMethods) {
263 val +=
m->GetMvaValue(err, errUpper);
265 return val / fEncapsulatedMethods.size();
267 Log() << kFATAL <<
"Ensembling type " << fOutputEnsembling <<
" unknown" <<
Endl;
277 const Event *ev = GetEvent();
279 if (fOutputEnsembling ==
"None") {
280 if (fSplitExpr !=
nullptr) {
282 UInt_t iFold = fSplitExpr->Eval(fNumFolds, ev);
283 return fEncapsulatedMethods.at(iFold)->GetMulticlassValues();
286 UInt_t iFold = fEventToFoldMapping.at(Data()->GetEvent());
287 return fEncapsulatedMethods.at(iFold)->GetMulticlassValues();
289 }
else if (fOutputEnsembling ==
"Avg") {
291 for (
auto &
e : fMulticlassValues) {
295 for (
auto &
m : fEncapsulatedMethods) {
296 auto methodValues =
m->GetMulticlassValues();
297 for (
size_t i = 0; i < methodValues.size(); ++i) {
298 fMulticlassValues[i] += methodValues[i];
302 for (
auto &
e : fMulticlassValues) {
303 e /= fEncapsulatedMethods.size();
306 return fMulticlassValues;
309 Log() << kFATAL <<
"Ensembling type " << fOutputEnsembling <<
" unknown" <<
Endl;
310 return fMulticlassValues;
319 const Event *ev = GetEvent();
321 if (fOutputEnsembling ==
"None") {
322 if (fSplitExpr !=
nullptr) {
324 UInt_t iFold = fSplitExpr->Eval(fNumFolds, ev);
325 return fEncapsulatedMethods.at(iFold)->GetRegressionValues();
328 UInt_t iFold = fEventToFoldMapping.at(Data()->GetEvent());
329 return fEncapsulatedMethods.at(iFold)->GetRegressionValues();
331 }
else if (fOutputEnsembling ==
"Avg") {
333 for (
auto &
e : fRegressionValues) {
337 for (
auto &
m : fEncapsulatedMethods) {
338 auto methodValues =
m->GetRegressionValues();
339 for (
size_t i = 0; i < methodValues.size(); ++i) {
340 fRegressionValues[i] += methodValues[i];
344 for (
auto &
e : fRegressionValues) {
345 e /= fEncapsulatedMethods.size();
348 return fRegressionValues;
351 Log() << kFATAL <<
"Ensembling type " << fOutputEnsembling <<
" unknown" <<
Endl;
352 return fRegressionValues;
373 <<
"Method CrossValidation should not be created manually,"
374 " only as part of using TMVA::Reader."
402 Log() << kWARNING <<
"MakeClassSpecific not implemented for CrossValidation" <<
Endl;
410 Log() << kWARNING <<
"MakeClassSpecificHeader not implemented for CrossValidation" <<
Endl;
#define REGISTER_METHOD(CLASS)
for example
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
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
Class that contains all the data information.
Virtual base Class for all MVA method.
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
friend class MethodCrossValidation
void GetHelpMessage() const
void MakeClassSpecific(std::ostream &, const TString &) const
Make ROOT-independent C++ class for classifier response (classifier-specific implementation).
void AddWeightsXMLTo(void *parent) const
Write weights to XML.
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
void Init(void)
Common initialisation with defaults for the Method.
void MakeClassSpecificHeader(std::ostream &, const TString &) const
Specific class header.
void Reset(void)
Reset the method, as if it had just been instantiated (forget all training etc.).
const Ranking * CreateRanking()
TString GetWeightFileNameForFold(UInt_t iFold) const
Returns filename of weight file for a given fold.
const std::vector< Float_t > & GetRegressionValues()
Get the regression value generated by the containing methods.
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
MethodBase * InstantiateMethodFromXML(TString methodTypeName, TString weightfile) const
Reads in a weight file an instantiates the corresponding method.
void Train(void)
Call the Optimizer with the set of parameters and ranges that are meant to be tuned.
const std::vector< Float_t > & GetMulticlassValues()
Get the multiclass MVA response.
void ReadWeightsFromXML(void *parent)
Reads from the xml file.
void DeclareCompatibilityOptions()
Options that are used ONLY for the READER to ensure backward compatibility.
void WriteMonitoringHistosToFile(void) const
write special monitoring histograms to file dummy implementation here --------------—
virtual ~MethodCrossValidation(void)
Destructor.
void ReadWeightsFromStream(std::istream &istr)
Read the weights.
void ProcessOptions()
The option string is decoded, for available options see "DeclareOptions".
Ranking for variables in method (implementation)
Singleton class for Global types used by TMVA.
const char * Data() const
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
create variable transformations
MsgLogger & Endl(MsgLogger &ml)