45 Envelope::Envelope(
const TString &name, DataLoader *dalaloader, TFile *file,
const TString options)
46 : Configurable(options), fDataLoader(dalaloader), fFile(file), fModelPersistence(kTRUE), fVerbose(kFALSE),
47 fTransformations(
"I"), fSilentFile(kFALSE), fJobs(1)
51 if (gTools().CheckForSilentOption(GetOptions()))
52 Log().InhibitOutput();
54 fModelPersistence = kTRUE;
55 DeclareOptionRef(fVerbose,
"V",
"Verbose flag");
57 DeclareOptionRef(fModelPersistence,
"ModelPersistence",
58 "Option to save the trained model in xml file or using serialization");
59 DeclareOptionRef(fTransformations,
"Transformations",
"List of transformations to test; formatting example: "
60 "\"Transformations=I;D;P;U;G,D\", for identity, "
61 "decorrelation, PCA, Uniform and Gaussianisation followed by "
62 "decorrelation transformations");
63 DeclareOptionRef(fJobs,
"Jobs",
"Option to run hign level algorithms in parallel with multi-thread");
76 Bool_t Envelope::IsSilentFile(){
return fFile==
nullptr;}
83 TFile* Envelope::GetFile(){
return fFile.get();}
91 void Envelope::SetFile(TFile *file){fFile=std::shared_ptr<TFile>(file);}
98 Bool_t Envelope::IsVerbose(){
return fVerbose;}
105 void Envelope::SetVerbose(Bool_t status){fVerbose=status;}
112 std::vector<OptionMap> &Envelope::GetMethods()
123 DataLoader *Envelope::GetDataLoader(){
return fDataLoader.get();}
131 void Envelope::SetDataLoader(DataLoader *dataloader)
133 fDataLoader = std::shared_ptr<DataLoader>(dataloader);
141 Bool_t TMVA::Envelope::IsModelPersistence(){
return fModelPersistence; }
148 void TMVA::Envelope::SetModelPersistence(Bool_t status){fModelPersistence=status;}
157 void TMVA::Envelope::BookMethod(Types::EMVA method, TString methodTitle, TString options){
158 BookMethod(Types::Instance().GetMethodName(method), methodTitle, options);
168 void TMVA::Envelope::BookMethod(TString methodName, TString methodTitle, TString options){
169 for (
auto &meth : fMethods) {
170 if (meth.GetValue<TString>(
"MethodName") == methodName && meth.GetValue<TString>(
"MethodTitle") == methodTitle) {
171 Log() << kFATAL <<
"Booking failed since method with title <" << methodTitle <<
"> already exists "
172 <<
"in with DataSet Name <" << fDataLoader->GetName() <<
"> " << Endl;
176 fMethod[
"MethodName"] = methodName;
177 fMethod[
"MethodTitle"] = methodTitle;
178 fMethod[
"MethodOptions"] = options;
180 fMethods.push_back(fMethod);
187 void TMVA::Envelope::ParseOptions()
190 Bool_t silent = kFALSE;
194 Bool_t color = kFALSE;
195 Bool_t drawProgressBar = kFALSE;
197 Bool_t color = !gROOT->IsBatch();
198 Bool_t drawProgressBar = kTRUE;
200 DeclareOptionRef(color,
"Color",
"Flag for coloured screen output (default: True, if in batch mode: False)");
201 DeclareOptionRef(drawProgressBar,
"DrawProgressBar",
202 "Draw progress bar to display training, testing and evaluation schedule (default: True)");
203 DeclareOptionRef(silent,
"Silent",
"Batch mode: boolean silent flag inhibiting any output from TMVA after the "
204 "creation of the factory class object (default: False)");
206 Configurable::ParseOptions();
207 CheckForUnusedOptions();
210 Log().SetMinType(kVERBOSE);
213 gConfig().SetUseColor(color);
214 gConfig().SetSilent(silent);
215 gConfig().SetDrawProgressBar(drawProgressBar);
225 Bool_t TMVA::Envelope::HasMethod(TString methodname, TString methodtitle)
227 for (
auto &meth : fMethods) {
228 if (meth.GetValue<TString>(
"MethodName") == methodname && meth.GetValue<TString>(
"MethodTitle") == methodtitle)
240 void TMVA::Envelope::WriteDataInformation(TMVA::DataSetInfo &fDataSetInfo, TMVA::Types::EAnalysisType fAnalysisType)
244 if (!RootBaseDir()->GetDirectory(fDataSetInfo.GetName()))
245 RootBaseDir()->mkdir(fDataSetInfo.GetName());
249 RootBaseDir()->cd(fDataSetInfo.GetName());
250 fDataSetInfo.GetDataSet();
253 const TMatrixD *m(0);
256 if (fAnalysisType == Types::kMulticlass) {
257 for (UInt_t cls = 0; cls < fDataSetInfo.GetNClasses(); cls++) {
258 m = fDataSetInfo.CorrelationMatrix(fDataSetInfo.GetClassInfo(cls)->GetName());
259 h = fDataSetInfo.CreateCorrelationMatrixHist(
260 m, TString(
"CorrelationMatrix") + fDataSetInfo.GetClassInfo(cls)->GetName(),
261 TString(
"Correlation Matrix (") + fDataSetInfo.GetClassInfo(cls)->GetName() + TString(
")"));
268 m = fDataSetInfo.CorrelationMatrix(
"Signal");
269 h = fDataSetInfo.CreateCorrelationMatrixHist(m,
"CorrelationMatrixS",
"Correlation Matrix (signal)");
275 m = fDataSetInfo.CorrelationMatrix(
"Background");
276 h = fDataSetInfo.CreateCorrelationMatrixHist(m,
"CorrelationMatrixB",
"Correlation Matrix (background)");
282 m = fDataSetInfo.CorrelationMatrix(
"Regression");
283 h = fDataSetInfo.CreateCorrelationMatrixHist(m,
"CorrelationMatrix",
"Correlation Matrix");
292 TString processTrfs =
"I";
295 processTrfs = fTransformations;
298 std::vector<TMVA::TransformationHandler *> trfs;
299 TransformationHandler *identityTrHandler = 0;
301 std::vector<TString> trfsDef = gTools().SplitString(processTrfs,
';');
302 std::vector<TString>::iterator trfsDefIt = trfsDef.begin();
303 for (; trfsDefIt != trfsDef.end(); ++trfsDefIt) {
304 trfs.push_back(
new TMVA::TransformationHandler(fDataSetInfo,
"Envelope"));
305 TString trfS = (*trfsDefIt);
308 Log() << kDEBUG <<
"current transformation string: '" << trfS.Data() <<
"'" << Endl;
309 TMVA::CreateVariableTransforms(trfS, fDataSetInfo, *(trfs.back()), Log());
311 if (trfS.BeginsWith(
'I'))
312 identityTrHandler = trfs.back();
315 const std::vector<Event *> &inputEvents = fDataSetInfo.GetDataSet()->GetEventCollection();
318 std::vector<TMVA::TransformationHandler *>::iterator trfIt = trfs.begin();
320 for (; trfIt != trfs.end(); ++trfIt) {
322 (*trfIt)->SetRootDir(RootBaseDir()->GetDirectory(fDataSetInfo.GetName()));
323 (*trfIt)->CalcTransformations(inputEvents);
325 if (identityTrHandler)
326 identityTrHandler->PrintVariableRanking();
329 for (trfIt = trfs.begin(); trfIt != trfs.end(); ++trfIt)