Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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>
18using namespace TMVA;
19
20
21//_______________________________________________________________________
23 Types::EMVA methodType,
24 const TString &methodTitle,
25 DataSetInfo &dsi,
26 const TString &theOption , ROOT::R::TRInterface &_r): MethodBase(jobName, methodType, methodTitle, dsi, theOption),
27 r(_r)
28{
29 LoadData();
30}
31
32//_______________________________________________________________________
34 DataSetInfo &dsi,
35 const TString &weightFile,ROOT::R::TRInterface &_r): MethodBase(methodType, dsi, weightFile),
36 r(_r)
37{
38 LoadData();
39}
40
41//_______________________________________________________________________
43{
44 ///////////////////////////
45 //Loading Training Data //
46 ///////////////////////////
47 const UInt_t nvar = DataInfo().GetNVariables();
48
49 const UInt_t ntrains = Data()->GetNTrainingEvents();
50
51 //array of columns for every var to create a dataframe for training
52 std::vector<std::vector<Float_t> > fArrayTrain(nvar);
53// Data()->SetCurrentEvent(1);
54// Data()->SetCurrentType(Types::ETreeType::kTraining);
55
56 fWeightTrain.ResizeTo(ntrains);
57 for (UInt_t j = 0; j < ntrains; j++) {
59// const Event *ev=Data()->GetEvent( j );
60 //creating array with class type(signal or background) for factor required
61 if (ev->GetClass() == Types::kSignal) fFactorTrain.push_back("signal");
62 else fFactorTrain.push_back("background");
63
64 fWeightTrain[j] = ev->GetWeight();
65
66 //filling vector of columns for training
67 for (UInt_t i = 0; i < nvar; i++) {
68 fArrayTrain[i].push_back(ev->GetValue(i));
69 }
70
71 }
72 for (UInt_t i = 0; i < nvar; i++) {
73 fDfTrain[DataInfo().GetListOfVariables()[i].Data()] = fArrayTrain[i];
74 }
75 ////////////////////////
76 //Loading Test Data //
77 ////////////////////////
78
79 const UInt_t ntests = Data()->GetNTestEvents();
80 const UInt_t nspectators = DataInfo().GetNSpectators(kTRUE);
81
82 //array of columns for every var to create a dataframe for testing
83 std::vector<std::vector<Float_t> > fArrayTest(nvar);
84 //array of columns for every spectator to create a dataframe for testing
85 std::vector<std::vector<Float_t> > fArraySpectators(nvar);
86 fWeightTest.ResizeTo(ntests);
87// Data()->SetCurrentType(Types::ETreeType::kTesting);
88 for (UInt_t j = 0; j < ntests; j++) {
90// const Event *ev=Data()->GetEvent(j);
91 //creating array with class type(signal or background) for factor required
92 if (ev->GetClass() == Types::kSignal) fFactorTest.push_back("signal");
93 else fFactorTest.push_back("background");
94
95 fWeightTest[j] = ev->GetWeight();
96
97 for (UInt_t i = 0; i < nvar; i++) {
98 fArrayTest[i].push_back(ev->GetValue(i));
99 }
100 for (UInt_t i = 0; i < nspectators; i++) {
101 fArraySpectators[i].push_back(ev->GetSpectator(i));
102 }
103 }
104 for (UInt_t i = 0; i < nvar; i++) {
105 fDfTest[DataInfo().GetListOfVariables()[i].Data()] = fArrayTest[i];
106 }
107 for (UInt_t i = 0; i < nspectators; i++) {
108 fDfSpectators[DataInfo().GetSpectatorInfo(i).GetLabel().Data()] = fArraySpectators[i];
109 }
110
111}
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT R was implemented using the R Project library and the modules Rcpp and RInside.
Class that contains all the data information.
Definition DataSetInfo.h:62
UInt_t GetNVariables() const
UInt_t GetNSpectators(bool all=kTRUE) const
std::vector< TString > GetListOfVariables() const
returns list of variables
VariableInfo & GetSpectatorInfo(Int_t i)
Long64_t GetNTestEvents() const
Definition DataSet.h:69
const Event * GetEvent() const
returns event without transformations
Definition DataSet.cxx:202
Long64_t GetNTrainingEvents() const
Definition DataSet.h:68
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Definition Event.cxx:236
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not.
Definition Event.cxx:389
Float_t GetSpectator(UInt_t ivar) const
return spectator content
Definition Event.cxx:261
UInt_t GetClass() const
Definition Event.h:86
MethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="")
standard constructor
DataSetInfo & DataInfo() const
Definition MethodBase.h:413
DataSet * Data() const
Definition MethodBase.h:412
std::vector< std::string > fFactorTrain
Definition RMethodBase.h:75
ROOT::R::TRInterface & r
Definition RMethodBase.h:52
ROOT::R::TRDataFrame fDfTrain
Definition RMethodBase.h:71
RMethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="", ROOT::R::TRInterface &_r=ROOT::R::TRInterface::Instance())
TVectorD fWeightTrain
Definition RMethodBase.h:73
ROOT::R::TRDataFrame fDfTest
Definition RMethodBase.h:72
TVectorD fWeightTest
Definition RMethodBase.h:74
std::vector< std::string > fFactorTest
Definition RMethodBase.h:76
ROOT::R::TRDataFrame fDfSpectators
Definition RMethodBase.h:77
@ kSignal
Never change this number - it is elsewhere assumed to be zero !
Definition Types.h:135
@ kTraining
Definition Types.h:143
const TString & GetLabel() const
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
create variable transformations