ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RMethodBase.cxx
Go to the documentation of this file.
1 // @(#)root/tmva/rmva $Id$
2 // Author: Omar Zapata,Lorenzo Moneta, Sergei Gleyzer 2015
3 
4 
5 /**********************************************************************************
6  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
7  * Package: TMVA *
8  * Class : RMethodBase *
9  * *
10  * Description: *
11  * Virtual base class for all MVA method based on ROOTR *
12  * *
13  **********************************************************************************/
14 
15 #include<TMVA/RMethodBase.h>
16 #include <TMVA/DataSetInfo.h>
17 #include<TApplication.h>
18 using namespace TMVA;
19 
21 
22 //_______________________________________________________________________
23 RMethodBase::RMethodBase(const TString &jobName,
24  Types::EMVA methodType,
25  const TString &methodTitle,
26  DataSetInfo &dsi,
27  const TString &theOption ,
28  TDirectory *theBaseDir , ROOT::R::TRInterface &_r): MethodBase(jobName, methodType, methodTitle, dsi, theOption, theBaseDir),
29  r(_r)
30 {
31  LoadData();
32 }
33 
34 //_______________________________________________________________________
36  DataSetInfo &dsi,
37  const TString &weightFile,
38  TDirectory *theBaseDir, ROOT::R::TRInterface &_r): MethodBase(methodType, dsi, weightFile, theBaseDir),
39  r(_r)
40 {
41  LoadData();
42 }
43 
44 //_______________________________________________________________________
46 {
47  ///////////////////////////
48  //Loading Training Data //
49  ///////////////////////////
50  const UInt_t nvar = DataInfo().GetNVariables();
51 
52  const UInt_t ntrains = Data()->GetNTrainingEvents();
53 
54  //array of columns for every var to create a dataframe for training
55  std::vector<std::vector<Float_t> > fArrayTrain(nvar);
56 // Data()->SetCurrentEvent(1);
57 // Data()->SetCurrentType(Types::ETreeType::kTraining);
58 
59  fWeightTrain.ResizeTo(ntrains);
60  for (UInt_t j = 0; j < ntrains; j++) {
61  const Event *ev = Data()->GetEvent(j, Types::ETreeType::kTraining);
62 // const Event *ev=Data()->GetEvent( j );
63  //creating array with class type(signal or background) for factor required
64  if (ev->GetClass() == Types::kSignal) fFactorTrain.push_back("signal");
65  else fFactorTrain.push_back("background");
66 
67  fWeightTrain[j] = ev->GetWeight();
68 
69  //filling vector of columns for training
70  for (UInt_t i = 0; i < nvar; i++) {
71  fArrayTrain[i].push_back(ev->GetValue(i));
72  }
73 
74  }
75  for (UInt_t i = 0; i < nvar; i++) {
76  fDfTrain[DataInfo().GetListOfVariables()[i].Data()] = fArrayTrain[i];
77  }
78  ////////////////////////
79  //Loading Test Data //
80  ////////////////////////
81 
82  const UInt_t ntests = Data()->GetNTestEvents();
83  const UInt_t nspectators = DataInfo().GetNSpectators(kTRUE);
84 
85  //array of columns for every var to create a dataframe for testing
86  std::vector<std::vector<Float_t> > fArrayTest(nvar);
87  //array of columns for every spectator to create a dataframe for testing
88  std::vector<std::vector<Float_t> > fArraySpectators(nvar);
89  fWeightTest.ResizeTo(ntests);
90 // Data()->SetCurrentType(Types::ETreeType::kTesting);
91  for (UInt_t j = 0; j < ntests; j++) {
92  const Event *ev = Data()->GetEvent(j, Types::ETreeType::kTesting);
93 // const Event *ev=Data()->GetEvent(j);
94  //creating array with class type(signal or background) for factor required
95  if (ev->GetClass() == Types::kSignal) fFactorTest.push_back("signal");
96  else fFactorTest.push_back("background");
97 
98  fWeightTest[j] = ev->GetWeight();
99 
100  for (UInt_t i = 0; i < nvar; i++) {
101  fArrayTest[i].push_back(ev->GetValue(i));
102  }
103  for (UInt_t i = 0; i < nspectators; i++) {
104  fArraySpectators[i].push_back(ev->GetSpectator(i));
105  }
106  }
107  for (UInt_t i = 0; i < nvar; i++) {
108  fDfTest[DataInfo().GetListOfVariables()[i].Data()] = fArrayTest[i];
109  }
110  for (UInt_t i = 0; i < nspectators; i++) {
111  fDfSpectators[DataInfo().GetSpectatorInfo(i).GetLabel().Data()] = fArraySpectators[i];
112  }
113 
114 }
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
Definition: TVectorT.cxx:291
Long64_t GetNTestEvents() const
Definition: DataSet.h:91
std::vector< std::string > fFactorTest
Definition: RMethodBase.h:99
ROOT::R::TRDataFrame fDfTest
Definition: RMethodBase.h:95
DataSet * Data() const
Definition: MethodBase.h:363
RMethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="", TDirectory *theBaseDir=0, ROOT::R::TRInterface &_r=ROOT::R::TRInterface::Instance())
Basic string class.
Definition: TString.h:137
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
Definition: Event.cxx:376
Float_t GetSpectator(UInt_t ivar) const
return spectator content
Definition: Event.cxx:256
UInt_t GetNVariables() const
Definition: DataSetInfo.h:128
const char * Data() const
Definition: TString.h:349
TVectorD fWeightTrain
Definition: RMethodBase.h:96
ROOT::R::TRDataFrame fDfSpectators
Definition: RMethodBase.h:100
std::vector< std::string > fFactorTrain
Definition: RMethodBase.h:98
TVectorD fWeightTest
Definition: RMethodBase.h:97
ROOT::R::TRInterface & r
Definition: Object.C:4
unsigned int UInt_t
Definition: RtypesCore.h:42
const Event * GetEvent() const
Definition: DataSet.cxx:186
Describe directory structure in memory.
Definition: TDirectory.h:44
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Definition: Event.cxx:231
VariableInfo & GetSpectatorInfo(Int_t i)
Definition: DataSetInfo.h:124
DataSetInfo & DataInfo() const
Definition: MethodBase.h:364
UInt_t GetClass() const
Definition: Event.h:86
ROOT::R::TRDataFrame fDfTrain
Definition: RMethodBase.h:94
UInt_t GetNSpectators(bool all=kTRUE) const
ClassImp(RMethodBase) RMethodBase
Definition: RMethodBase.cxx:20
std::vector< TString > GetListOfVariables() const
returns list of variables
Long64_t GetNTrainingEvents() const
Definition: DataSet.h:90
const TString & GetLabel() const
Definition: VariableInfo.h:64
const Bool_t kTRUE
Definition: Rtypes.h:91
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28