Logo ROOT   6.12/07
Reference Guide
DataSet.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : DataSet *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Contains all the data information *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16  * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
17  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18  * *
19  * Copyright (c) 2006: *
20  * CERN, Switzerland *
21  * U. of Victoria, Canada *
22  * MPI-K Heidelberg, Germany *
23  * *
24  * Redistribution and use in source and binary forms, with or without *
25  * modification, are permitted according to the terms listed in LICENSE *
26  * (http://tmva.sourceforge.net/LICENSE) *
27  **********************************************************************************/
28 
29 #ifndef ROOT_TMVA_DataSet
30 #define ROOT_TMVA_DataSet
31 
32 //////////////////////////////////////////////////////////////////////////
33 // //
34 // DataSet //
35 // //
36 // Class that contains all the data information //
37 // //
38 //////////////////////////////////////////////////////////////////////////
39 
40 #include <vector>
41 #include <map>
42 #include <string>
43 
44 #include "TObject.h"
45 #include "TNamed.h"
46 #include "TString.h"
47 #include "TTree.h"
48 //#ifndef ROOT_TCut
49 //#include "TCut.h"
50 //#endif
51 //#ifndef ROOT_TMatrixDfwd
52 //#include "TMatrixDfwd.h"
53 //#endif
54 //#ifndef ROOT_TPrincipal
55 //#include "TPrincipal.h"
56 //#endif
57 #include "TRandom3.h"
58 
59 #include "TMVA/Types.h"
60 #include "TMVA/VariableInfo.h"
61 
62 namespace TMVA {
63 
64  class Event;
65  class DataSetInfo;
66  class MsgLogger;
67  class Results;
68 
69  class DataSet :public TNamed {
70 
71  public:
72  DataSet();
73  DataSet(const DataSetInfo&);
74  virtual ~DataSet();
75 
76  void AddEvent( Event *, Types::ETreeType );
77 
81 
82  // const getters
83  const Event* GetEvent() const; // returns event without transformations
84  const Event* GetEvent ( Long64_t ievt ) const { fCurrentEventIdx = ievt; return GetEvent(); } // returns event without transformations
85  const Event* GetTrainingEvent( Long64_t ievt ) const { return GetEvent(ievt, Types::kTraining); }
86  const Event* GetTestEvent ( Long64_t ievt ) const { return GetEvent(ievt, Types::kTesting); }
87  const Event* GetEvent ( Long64_t ievt, Types::ETreeType type ) const
88  {
89  fCurrentTreeIdx = TreeIndex(type); fCurrentEventIdx = ievt; return GetEvent();
90  }
91 
92 
93 
94 
95  UInt_t GetNVariables() const;
96  UInt_t GetNTargets() const;
97  UInt_t GetNSpectators() const;
98 
99  void SetCurrentEvent( Long64_t ievt ) const { fCurrentEventIdx = ievt; }
102 
103  void SetEventCollection( std::vector<Event*>*, Types::ETreeType, Bool_t deleteEvents = true );
104  const std::vector<Event*>& GetEventCollection( Types::ETreeType type = Types::kMaxTreeType ) const;
106 
111 
113 
114  Results* GetResults ( const TString &,
116  Types::EAnalysisType analysistype );
117  void DeleteResults ( const TString &,
118  Types::ETreeType type,
119  Types::EAnalysisType analysistype );
120 
121  void SetVerbose( Bool_t ) {}
122 
123  // sets the number of blocks to which the training set is divided,
124  // some of which are given to the Validation sample. As default they belong all to Training set.
125  void DivideTrainingSet( UInt_t blockNum );
126 
127  // sets a certrain block from the origin training set to belong to either Training or Validation set
128  void MoveTrainingBlock( Int_t blockInd,Types::ETreeType dest, Bool_t applyChanges = kTRUE );
129 
130  void IncrementNClassEvents( Int_t type, UInt_t classNumber );
131  Long64_t GetNClassEvents ( Int_t type, UInt_t classNumber );
132  void ClearNClassEvents ( Int_t type );
133 
134  TTree* GetTree( Types::ETreeType type );
135 
136  // accessors for random and importance sampling
137  void InitSampling( Float_t fraction, Float_t weight, UInt_t seed = 0 );
138  void EventResult( Bool_t successful, Long64_t evtNumber = -1 );
139  void CreateSampling() const;
140 
141  UInt_t TreeIndex(Types::ETreeType type) const;
142 
143  private:
144 
145  // data members
146  void DestroyCollection( Types::ETreeType type, Bool_t deleteEvents );
147 
148  const DataSetInfo *fdsi; //-> datasetinfo that created this dataset
149 
150  std::vector< std::vector<Event*> > fEventCollection; // list of events for training/testing/...
151 
152  std::vector< std::map< TString, Results* > > fResults; //! [train/test/...][method-identifier]
153 
156 
157  // event sampling
158  std::vector<Char_t> fSampling; // random or importance sampling (not all events are taken) !! Bool_t are stored ( no std::vector<bool> taken for speed (performance) issues )
159  std::vector<Int_t> fSamplingNEvents; // number of events which should be sampled
160  std::vector<Float_t> fSamplingWeight; // weight change factor [weight is indicating if sampling is random (1.0) or importance (<1.0)]
161  mutable std::vector< std::vector< std::pair< Float_t, Long64_t > > > fSamplingEventList; // weights and indices for sampling
162  mutable std::vector< std::vector< std::pair< Float_t, Long64_t > > > fSamplingSelected; // selected events
163  TRandom3 *fSamplingRandom; //-> random generator for sampling
164 
165 
166  // further things
167  std::vector< std::vector<Long64_t> > fClassEvents; // number of events of class 0,1,2,... in training[0]
168  // and testing[1] (+validation, trainingoriginal)
169 
170  Bool_t fHasNegativeEventWeights; // true if at least one signal or bkg event has negative weight
171 
172  mutable MsgLogger* fLogger; //! message logger
173  MsgLogger& Log() const { return *fLogger; }
174  std::vector<Char_t> fBlockBelongToTraining; // when dividing the dataset to blocks, sets whether
175  // the certain block is in the Training set or else
176  // in the validation set
177  // boolean are stored, taken std::vector<Char_t> for performance reasons (instead of std::vector<Bool_t>)
178  Long64_t fTrainingBlockSize; // block size into which the training dataset is divided
179 
182  public:
183 
184  ClassDef(DataSet,1);
185  };
186 }
187 
188 
189 //_______________________________________________________________________
191 {
192  switch (type) {
193  case Types::kMaxTreeType : return fCurrentTreeIdx;
194  case Types::kTraining : return 0;
195  case Types::kTesting : return 1;
196  case Types::kValidation : return 2;
197  case Types::kTrainingOriginal : return 3;
198  default : return fCurrentTreeIdx;
199  }
200 }
201 
202 //_______________________________________________________________________
204 {
205  switch (fCurrentTreeIdx) {
206  case 0: return Types::kTraining;
207  case 1: return Types::kTesting;
208  case 2: return Types::kValidation;
209  case 3: return Types::kTrainingOriginal;
210  }
211  return Types::kMaxTreeType;
212 }
213 
214 //_______________________________________________________________________
216 {
217  Int_t treeIdx = TreeIndex(type);
218  if (fSampling.size() > UInt_t(treeIdx) && fSampling.at(treeIdx)) {
219  return fSamplingSelected.at(treeIdx).size();
220  }
221  return GetEventCollection(type).size();
222 }
223 
224 //_______________________________________________________________________
225 inline const std::vector<TMVA::Event*>& TMVA::DataSet::GetEventCollection( TMVA::Types::ETreeType type ) const
226 {
227  return fEventCollection.at(TreeIndex(type));
228 }
229 
230 
231 #endif
Random number generator class based on M.
Definition: TRandom3.h:27
const Event * GetTestEvent(Long64_t ievt) const
Definition: DataSet.h:86
void SetCurrentEvent(Long64_t ievt) const
Definition: DataSet.h:99
long long Long64_t
Definition: RtypesCore.h:69
Long64_t fTrainingBlockSize
Definition: DataSet.h:178
std::vector< std::vector< std::pair< Float_t, Long64_t > > > fSamplingSelected
Definition: DataSet.h:162
void AddEvent(Event *, Types::ETreeType)
add event to event list after which the event is owned by the dataset
Definition: DataSet.cxx:241
float Float_t
Definition: RtypesCore.h:53
std::vector< std::vector< std::pair< Float_t, Long64_t > > > fSamplingEventList
Definition: DataSet.h:161
DataSet()
constructor
Definition: DataSet.cxx:91
std::vector< std::vector< Event * > > fEventCollection
Definition: DataSet.h:150
void CreateSampling() const
create an event sampling (random or importance sampling)
Definition: DataSet.cxx:479
TRandom3 * fSamplingRandom
Definition: DataSet.h:163
EAnalysisType
Definition: Types.h:125
UInt_t GetNVariables() const
access the number of variables through the datasetinfo
Definition: DataSet.cxx:216
Basic string class.
Definition: TString.h:125
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
std::vector< Char_t > fBlockBelongToTraining
Definition: DataSet.h:174
void ClearNClassEvents(Int_t type)
Definition: DataSet.cxx:160
const std::vector< Event * > & GetEventCollection(Types::ETreeType type=Types::kMaxTreeType) const
Definition: DataSet.h:225
Long64_t GetNEvtBkgdTrain()
return number of background training events in dataset
Definition: DataSet.cxx:422
UInt_t TreeIndex(Types::ETreeType type) const
Definition: DataSet.h:190
#define ClassDef(name, id)
Definition: Rtypes.h:320
UInt_t GetNSpectators() const
access the number of targets through the datasetinfo
Definition: DataSet.cxx:232
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual ~DataSet()
destructor
Definition: DataSet.cxx:123
TTree * GetTree(Types::ETreeType type)
create the test/trainings tree with all the variables, the weights, the classes, the targets...
Definition: DataSet.cxx:580
Types::ETreeType GetCurrentType() const
Definition: DataSet.h:203
const Event * GetEvent(Long64_t ievt, Types::ETreeType type) const
Definition: DataSet.h:87
Class that contains all the data information.
Definition: DataSetInfo.h:60
Long64_t GetNTrainingEvents() const
Definition: DataSet.h:79
Bool_t fHasNegativeEventWeights
Definition: DataSet.h:170
void MoveTrainingBlock(Int_t blockInd, Types::ETreeType dest, Bool_t applyChanges=kTRUE)
move training block
Definition: DataSet.cxx:386
const Event * GetTrainingEvent(Long64_t ievt) const
Definition: DataSet.h:85
Class that contains all the data information.
Definition: DataSet.h:69
void ApplyTrainingSetDivision()
apply division of data set
Definition: DataSet.cxx:366
Bool_t HasNegativeEventWeights() const
Definition: DataSet.h:112
Results * GetResults(const TString &, Types::ETreeType type, Types::EAnalysisType analysistype)
Definition: DataSet.cxx:265
std::vector< std::vector< Long64_t > > fClassEvents
Definition: DataSet.h:167
Long64_t GetNEvtSigTest()
return number of signal test events in dataset
Definition: DataSet.cxx:398
void DeleteResults(const TString &, Types::ETreeType type, Types::EAnalysisType analysistype)
delete the results stored for this particular Method instance.
Definition: DataSet.cxx:316
unsigned int UInt_t
Definition: RtypesCore.h:42
void DivideTrainingSet(UInt_t blockNum)
divide training set
Definition: DataSet.cxx:342
void DestroyCollection(Types::ETreeType type, Bool_t deleteEvents)
destroys the event collection (events + vector)
Definition: DataSet.cxx:189
const Event * GetEvent(Long64_t ievt) const
Definition: DataSet.h:84
const DataSetInfo * fdsi
Definition: DataSet.h:148
Long64_t GetNEvtBkgdTest()
return number of background test events in dataset
Definition: DataSet.cxx:406
Long64_t GetNTestEvents() const
Definition: DataSet.h:80
void IncrementNClassEvents(Int_t type, UInt_t classNumber)
Definition: DataSet.cxx:151
std::vector< Char_t > fSampling
Definition: DataSet.h:158
void EventResult(Bool_t successful, Long64_t evtNumber=-1)
increase the importance sampling weight of the event when not successful and decrease it when success...
Definition: DataSet.cxx:543
std::vector< Float_t > fSamplingWeight
Definition: DataSet.h:160
Long64_t fCurrentEventIdx
Definition: DataSet.h:155
UInt_t fCurrentTreeIdx
[train/test/...][method-identifier]
Definition: DataSet.h:154
Long64_t GetNEvtSigTrain()
return number of signal training events in dataset
Definition: DataSet.cxx:414
MsgLogger & Log() const
message logger
Definition: DataSet.h:173
int type
Definition: TGX11.cxx:120
void SetVerbose(Bool_t)
Definition: DataSet.h:121
void SetCurrentType(Types::ETreeType type) const
Definition: DataSet.h:100
void SetEventCollection(std::vector< Event *> *, Types::ETreeType, Bool_t deleteEvents=true)
Sets the event collection (by DataSetFactory)
Definition: DataSet.cxx:250
void ApplyTrainingBlockDivision()
std::vector< Int_t > fSamplingNEvents
Definition: DataSet.h:159
Long64_t GetNClassEvents(Int_t type, UInt_t classNumber)
Definition: DataSet.cxx:168
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
MsgLogger * fLogger
Definition: DataSet.h:172
Abstract ClassifierFactory template that handles arbitrary types.
#define dest(otri, vertexptr)
Definition: triangle.c:1040
Class that is the base-class for a vector of result.
Definition: Results.h:57
Long64_t GetNEvents(Types::ETreeType type=Types::kMaxTreeType) const
Definition: DataSet.h:215
A TTree object has a header with a name and a title.
Definition: TTree.h:70
const TTree * GetEventCollectionAsTree()
UInt_t GetNTargets() const
access the number of targets through the datasetinfo
Definition: DataSet.cxx:224
const Bool_t kTRUE
Definition: RtypesCore.h:87
void InitSampling(Float_t fraction, Float_t weight, UInt_t seed=0)
initialize random or importance sampling
Definition: DataSet.cxx:430
const Event * GetEvent() const
Definition: DataSet.cxx:202
std::vector< std::map< TString, Results *> > fResults
Definition: DataSet.h:152