Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:58

0001 // @(#)root/tmva:$Id$
0002 // Author: Omar Zapata   2016
0003 
0004 /*************************************************************************
0005  * Copyright (C) 2016, Omar Andres Zapata Mesa                           *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 #ifndef ROOT_TMVA_Envelope
0012 #define ROOT_TMVA_Envelope
0013 
0014 #include <memory>
0015 #include <vector>
0016 
0017 #include <TString.h>
0018 #include <TROOT.h>
0019 #include <TStopwatch.h>
0020 
0021 #ifndef _MSC_VER
0022 #include <TProcPool.h>
0023 #endif
0024 
0025 #include <TMVA/OptionMap.h>
0026 #include <TMVA/Config.h>
0027 #include <TMVA/Tools.h>
0028 #include <TMVA/DataLoader.h>
0029 
0030 /*! \class TMVA::Envelope
0031  * Abstract base class for all high level ml algorithms,
0032  * you can book ml methods like BDT, MLP. SVM etc..
0033  * and set a TMVA::DataLoader object to run your code
0034  * in the overloaded method Evaluate.
0035 \ingroup TMVA
0036 
0037 Base class for all machine learning algorithms
0038 
0039 */
0040 
0041 namespace TMVA {
0042 
0043       class Envelope:public Configurable
0044       {
0045       protected:
0046          std::vector<OptionMap> fMethods;         ///<! Booked method information
0047          std::shared_ptr<DataLoader> fDataLoader; ///<! data
0048          std::shared_ptr<TFile> fFile;            ///<! file to save the results
0049          Bool_t fModelPersistence;                ///<! flag to save the trained model
0050          Bool_t fVerbose;                         ///<! flag for extra information
0051          TString fTransformations;                ///<! List of transformations to test
0052          Bool_t fSilentFile;                      ///<! if true dont produce file output
0053 #ifndef _MSC_VER
0054          TProcPool fWorkers;                      ///<! procpool object
0055 #endif
0056          UInt_t fJobs;                            ///<! number of jobs to run some high level algorithm in parallel
0057          TStopwatch fTimer;                       ///<! timer to measure the time.
0058 
0059          Envelope(const TString &name, DataLoader *dataloader = nullptr, TFile *file = nullptr,
0060                   const TString options = "");
0061 
0062       public:
0063           /**
0064            Default destructor
0065            */
0066           ~Envelope();
0067 
0068           virtual void BookMethod( TString methodname, TString methodtitle, TString options = "");
0069           virtual void BookMethod( Types::EMVA method,  TString methodtitle, TString options = "");
0070 
0071           // parse the internal option string
0072           virtual void ParseOptions();
0073 
0074           Bool_t  IsSilentFile();
0075           TFile* GetFile();
0076           void   SetFile(TFile *file);
0077           Bool_t HasMethod(TString methodname, TString methodtitle);
0078 
0079           DataLoader *GetDataLoader();
0080           void SetDataLoader(DataLoader *dalaloader);
0081           Bool_t IsModelPersistence();
0082           void SetModelPersistence(Bool_t status=kTRUE);
0083           Bool_t IsVerbose();
0084           void SetVerbose(Bool_t status);
0085 
0086           /**
0087             Virtual method to be implemented with your algorithm.
0088           */
0089           virtual void Evaluate() = 0;
0090 
0091           std::vector<OptionMap> &GetMethods();
0092 
0093        protected:
0094           /**
0095             Utility method to get TMVA::DataInputHandler reference from the DataLoader.
0096             \return TMVA::DataInputHandler reference.
0097           */
0098           DataInputHandler &GetDataLoaderDataInput() { return fDataLoader->DataInput(); }
0099 
0100           /**
0101             Utility method to get TMVA::DataSetInfo reference from the DataLoader.
0102             \return TMVA::DataSetInfo reference.
0103           */
0104           DataSetInfo &GetDataLoaderDataSetInfo() { return fDataLoader->GetDataSetInfo(); }
0105 
0106           /**
0107             Utility method to get TMVA::DataSetManager pointer from the DataLoader.
0108             \return TMVA::DataSetManager pointer.
0109           */
0110          DataSetManager *GetDataLoaderDataSetManager()
0111          {
0112             return fDataLoader->GetDataSetInfo().GetDataSetManager();
0113          }
0114 
0115           /**
0116             Utility method to get base dir directory from current file.
0117             \return TDirectory* pointer.
0118           */
0119           TDirectory *RootBaseDir() { return (TDirectory *)fFile.get(); }
0120 
0121           void WriteDataInformation(TMVA::DataSetInfo &fDataSetInfo, TMVA::Types::EAnalysisType fAnalysisType);
0122 
0123           ClassDef(Envelope, 0);
0124       };
0125 }
0126 
0127 #endif