33 #ifndef ROOT_TMVA_DataSetInfo 36 #ifndef ROOT_TMVA_DataSet 39 #ifndef ROOT_TMVA_Event 42 #ifndef ROOT_TMVA_MsgLogger 45 #ifndef ROOT_TMVA_ResultsRegression 48 #ifndef ROOT_TMVA_ResultsClassification 51 #ifndef ROOT_TMVA_ResultsMulticlass 54 #ifndef ROOT_TMVA_Configurable 63 fEventCollection(4,(
std::vector<
Event*>*)0),
66 fHasNegativeEventWeights(
kFALSE),
70 for (
UInt_t i=0; i<4; i++) fEventCollection[i] = new std::vector<Event*>;
84 for (
Int_t treeIdx = 0; treeIdx < treeNum; treeIdx++) {
103 for (std::vector< std::map< TString, Results* > >::iterator it =
fResults.begin(); it !=
fResults.end(); it++) {
104 for (std::map< TString, Results* >::iterator itMap = (*it).begin(); itMap != (*it).end(); itMap++) {
105 delete itMap->second;
112 std::vector< std::pair< Float_t, Long64_t >* >::iterator itEv;
113 std::vector< std::vector<std::pair< Float_t, Long64_t >* > >::iterator treeIt;
115 for (itEv = (*treeIt).begin(); itEv != (*treeIt).end(); itEv++) {
151 catch (std::out_of_range excpt) {
153 Log() <<
kFATAL <<
"No " << (type==0?
"training":(type==1?
"testing":
"_unknown_type_"))
154 <<
" events for class " << (ci==
NULL?
"_no_name_known_":ci->
GetName().
Data()) <<
" (index # "<<classNumber<<
")" 155 <<
" available. Check if all class names are spelled correctly and if events are" 156 <<
" passing the selection cuts." <<
Endl;
159 Log() <<
kFATAL <<
"ERROR/CAUGHT : DataSet/GetNClassEvents, .. unknown error" <<
Endl;
231 Bool_t deleteEvents =
true;
263 const std::map< TString, Results* >& resultsForType =
fResults[t];
264 std::map< TString, Results* >::const_iterator it = resultsForType.find(resultsName);
265 if (it!=resultsForType.end()) {
277 switch(analysistype) {
297 fResults[t][resultsName] = newresults;
315 Log()<<
kFATAL<<
"you asked for an Treetype (training/testing/...)" 316 <<
" whose index " << type <<
" does not exist " <<
Endl;
318 std::map< TString, Results* >& resultsForType =
fResults[
UInt_t(type)];
319 std::map< TString, Results* >::iterator it = resultsForType.find(resultsName);
320 if (it!=resultsForType.end()) {
321 Log() <<
kDEBUG <<
" Delete Results previous existing result:" << resultsName
322 <<
" of type " << type <<
Endl;
324 resultsForType.erase(it->first);
327 Log() <<
kINFO <<
"could not fine Result class of " << resultsName
328 <<
" of type " << type <<
" which I should have deleted" <<
Endl;
428 std::vector< std::pair< Float_t, Long64_t >* > evtList;
429 std::vector< std::pair< Float_t, Long64_t >* >::iterator it;
443 if (fraction > 0.999999 || fraction < 0.0000001) {
459 for (
Long64_t ievt=0; ievt<nEvts; ievt++) {
460 std::pair<Float_t,Long64_t> *p =
new std::pair<Float_t,Long64_t>(1.0,ievt);
480 <<
"no random generator present for creating a random/importance sampling (initialized?)" <<
Endl;
486 std::vector< std::pair< Float_t, Long64_t >* > evtList;
487 std::vector< std::pair< Float_t, Long64_t >* >::iterator evtListIt;
496 for (evtListIt = evtList.begin(); evtListIt != evtList.end(); evtListIt++) {
497 sumWeights += (*evtListIt)->first;
499 evtListIt = evtList.begin();
502 std::vector< Float_t > rnds;
508 rnds.push_back( pos );
512 std::sort(rnds.begin(),rnds.end());
515 std::vector< Float_t >::iterator rndsIt = rnds.begin();
516 Float_t runningSum = 0.000000001;
517 for (evtListIt = evtList.begin(); evtListIt != evtList.end();) {
518 runningSum += (*evtListIt)->first;
519 if (runningSum >= (*rndsIt)) {
521 evtListIt = evtList.erase( evtListIt );
524 if (rndsIt == rnds.end() )
break;
544 if (evtNumber >= 0) {
548 for (
Long64_t iEvt = start; iEvt <= stop; iEvt++ ){
551 <<
") larger than number of sampled events (" 559 if (weight > 1.0 ) weight = 1.0;
601 char *className =
new char[40];
611 tree->
Branch(
"classID", &cls,
"classID/I" );
612 tree->
Branch(
"className",(
void*)className,
"className/C" );
620 tree->
Branch( (*itVars).GetInternalName(), &varVals[
n], (*itVars).GetInternalName()+
TString(
"/F") );
625 for (std::vector<VariableInfo>::const_iterator itTgts =
fdsi.
GetTargetInfos().begin();
628 tree->
Branch( (*itTgts).GetInternalName(), &tgtVals[
n], (*itTgts).GetInternalName()+
TString(
"/F") );
636 tree->
Branch( (*itVis).GetInternalName(), &visVals[
n], (*itVis).GetInternalName()+
TString(
"/F") );
640 tree->
Branch(
"weight", &weight,
"weight/F" );
644 for (std::map< TString, Results* >::iterator itMethod =
fResults.at(t).begin();
645 itMethod !=
fResults.at(t).end(); itMethod++) {
653 tree->
Branch( itMethod->first, &(metVals[n][0]), itMethod->first +
"/F" );
659 if (iCls > 0) leafList.
Append(
":" );
663 Log() <<
kDEBUG <<
"itMethod->first " << itMethod->first <<
" LEAFLIST: " 664 << leafList <<
" itMethod->second " << itMethod->second <<
Endl;
665 tree->
Branch( itMethod->first, (metVals[n]), leafList );
671 if (iTgt > 0) leafList.
Append(
":" );
676 Log() <<
kDEBUG <<
"itMethod->first " << itMethod->first <<
" LEAFLIST: " 677 << leafList <<
" itMethod->second " << itMethod->second <<
Endl;
678 tree->
Branch( itMethod->first, (metVals[n]), leafList );
681 Log() <<
kWARNING <<
"Unknown analysis type for result found when writing TestTree." <<
Endl;
695 for (
Int_t itmp = 0; itmp < tmp.
Sizeof(); itmp++) {
696 className[itmp] = tmp(itmp);
697 className[itmp+1] = 0;
708 for (std::map<TString, Results*>::iterator itMethod =
fResults.at(t).begin();
709 itMethod !=
fResults.at(t).end(); itMethod++) {
710 Results* results = itMethod->second;
712 const std::vector< Float_t >& vals = results->operator[](iEvt);
716 metVals[
n][0] = vals[0];
722 metVals[
n][nCls] = val;
729 metVals[
n][nTgts] = val;
virtual const char * GetName() const
Returns name of object.
UInt_t GetNVariables() const
Random number generator class based on M.
MsgLogger & Endl(MsgLogger &ml)
const TString & GetInternalName() const
void AddEvent(Event *, Types::ETreeType)
add event to event list after which the event is owned by the dataset
std::vector< VariableInfo > & GetSpectatorInfos()
void CreateSampling() const
create an event sampling (random or importance sampling)
virtual Int_t Fill()
Fill all branches.
TRandom3 * fSamplingRandom
UInt_t GetNVariables() const
access the number of variables through the datasetinfo
void SetTreeType(Types::ETreeType type)
std::vector< Char_t > fBlockBelongToTraining
void ClearNClassEvents(Int_t type)
UInt_t GetNClasses() const
std::vector< std::vector< std::pair< Float_t, Long64_t > *> > fSamplingEventList
Long64_t GetNEvtBkgdTrain()
return number of background training events in dataset
UInt_t TreeIndex(Types::ETreeType type) const
const TString & GetName() const
UInt_t GetNSpectators() const
access the number of targets through the datasetinfo
virtual ~DataSet()
destructor
TTree * GetTree(Types::ETreeType type)
create the test/trainings tree with all the variables, the weights, the classes, the targets...
Types::ETreeType GetCurrentType() const
TString & Append(const char *cs)
std::vector< std::vector< double > > Data
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
std::vector< VariableInfo > & GetTargetInfos()
Bool_t fHasNegativeEventWeights
number of events of class 0,1,2,... in training[0]
UInt_t GetNTargets() const
accessor to the number of targets
void MoveTrainingBlock(Int_t blockInd, Types::ETreeType dest, Bool_t applyChanges=kTRUE)
move training block
void ApplyTrainingSetDivision()
apply division of data set
void SetEventCollection(std::vector< Event *> *, Types::ETreeType)
Sets the event collection (by DataSetFactory)
Float_t GetTarget(UInt_t itgt) const
UInt_t GetNTargets() const
Results * GetResults(const TString &, Types::ETreeType type, Types::EAnalysisType analysistype)
TString info(resultsName+"/"); switch(type) { case Types::kTraining: info += "kTraining/"; break; cas...
std::vector< std::vector< Long64_t > > fClassEvents
Long64_t GetNEvtSigTest()
return number of signal test events in dataset
ClassInfo * GetClassInfo(Int_t clNum) const
std::vector< std::vector< std::pair< Float_t, Long64_t > *> > fSamplingSelected
VariableInfo & GetTargetInfo(Int_t i)
void DeleteResults(const TString &, Types::ETreeType type, Types::EAnalysisType analysistype)
delete the results stored for this particulary Method instance (here appareantly called resultsName i...
UInt_t GetNSpectators() const
accessor to the number of spectators
void DivideTrainingSet(UInt_t blockNum)
divide training set
void DestroyCollection(Types::ETreeType type, Bool_t deleteEvents)
destroys the event collection (events + vector)
UInt_t GetNSpectators(bool all=kTRUE) const
Long64_t GetNEvtBkgdTest()
return number of background test events in dataset
UInt_t GetNVariables() const
accessor to the number of variables
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
std::vector< Event * >::iterator fEvtCollIt
datasetinfo that created this dataset
void IncrementNClassEvents(Int_t type, UInt_t classNumber)
std::vector< Char_t > fSampling
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...
std::vector< Float_t > fSamplingWeight
Long64_t fCurrentEventIdx
UInt_t fCurrentTreeIdx
[train/test/...][method-identifier]
Long64_t GetNEvtSigTrain()
return number of signal training events in dataset
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
void SetCurrentType(Types::ETreeType type) const
std::vector< std::vector< Event * > *> fEventCollection
std::vector< Int_t > fSamplingNEvents
virtual Long64_t GetEntries() const
Long64_t GetNClassEvents(Int_t type, UInt_t classNumber)
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Create one branch for each element in the collection.
#define dest(otri, vertexptr)
Long64_t GetNEvents(Types::ETreeType type=Types::kMaxTreeType) const
A TTree object has a header with a name and a title.
UInt_t GetNTargets() const
access the number of targets through the datasetinfo
Float_t GetSpectator(UInt_t ivar) const
return spectator content
void InitSampling(Float_t fraction, Float_t weight, UInt_t seed=0)
initialize random or importance sampling
const Event * GetEvent() const
std::vector< VariableInfo > & GetVariableInfos()
const char * Data() const
std::vector< std::map< TString, Results *> > fResults
list of events for training/testing/...