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 74 fHasNegativeEventWeights(
kFALSE),
91 for (
Int_t treeIdx = 0; treeIdx < treeNum; treeIdx++) {
120 for (
Int_t treeIdx = 0; treeIdx < treeNum; treeIdx++) {
141 for (std::vector< std::map< TString, Results* > >::iterator it =
fResults.begin(); it !=
fResults.end(); it++) {
142 for (std::map< TString, Results* >::iterator itMap = (*it).begin(); itMap != (*it).end(); itMap++) {
143 delete itMap->second;
182 catch (std::out_of_range excpt) {
184 Log() <<
kFATAL <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"No " << (type==0?
"training":(type==1?
"testing":
"_unknown_type_"))
185 <<
" events for class " << (ci==
NULL?
"_no_name_known_":ci->
GetName()) <<
" (index # "<<classNumber<<
")" 186 <<
" available. Check if all class names are spelled correctly and if events are" 187 <<
" passing the selection cuts." <<
Endl;
292 const std::map< TString, Results* >& resultsForType =
fResults[t];
293 std::map< TString, Results* >::const_iterator it = resultsForType.find(resultsName);
294 if (it!=resultsForType.end()) {
306 switch(analysistype) {
326 fResults[t][resultsName] = newresults;
345 <<
" whose index " << type <<
" does not exist " <<
Endl;
347 std::map< TString, Results* >& resultsForType =
fResults[
UInt_t(type)];
348 std::map< TString, Results* >::iterator it = resultsForType.find(resultsName);
349 if (it!=resultsForType.end()) {
350 Log() <<
kDEBUG <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
" Delete Results previous existing result:" << resultsName
351 <<
" of type " << type <<
Endl;
353 resultsForType.erase(it->first);
357 <<
" of type " << type <<
" which I should have deleted" <<
Endl;
457 std::vector< std::pair< Float_t, Long64_t >* > evtList;
458 std::vector< std::pair< Float_t, Long64_t >* >::iterator it;
472 if (fraction > 0.999999 || fraction < 0.0000001) {
488 for (
Long64_t ievt=0; ievt<nEvts; ievt++) {
489 std::pair<Float_t,Long64_t> p(1.0,ievt);
509 <<
"no random generator present for creating a random/importance sampling (initialized?)" <<
Endl;
515 std::vector< std::pair< Float_t, Long64_t > > evtList;
516 std::vector< std::pair< Float_t, Long64_t > >::iterator evtListIt;
525 for (evtListIt = evtList.begin(); evtListIt != evtList.end(); evtListIt++) {
526 sumWeights += (*evtListIt).first;
528 evtListIt = evtList.begin();
531 std::vector< Float_t > rnds;
537 rnds.push_back( pos );
541 std::sort(rnds.begin(),rnds.end());
544 std::vector< Float_t >::iterator rndsIt = rnds.begin();
545 Float_t runningSum = 0.000000001;
546 for (evtListIt = evtList.begin(); evtListIt != evtList.end();) {
547 runningSum += (*evtListIt).first;
548 if (runningSum >= (*rndsIt)) {
550 evtListIt = evtList.erase( evtListIt );
553 if (rndsIt == rnds.end() )
break;
573 if (evtNumber >= 0) {
577 for (
Long64_t iEvt = start; iEvt <= stop; iEvt++ ){
580 <<
") larger than number of sampled events (" 588 if (weight > 1.0 ) weight = 1.0;
630 char *className =
new char[40];
640 tree->
Branch(
"classID", &cls,
"classID/I" );
641 tree->
Branch(
"className",(
void*)className,
"className/C" );
649 tree->
Branch( (*itVars).GetInternalName(), &varVals[
n], (*itVars).GetInternalName()+
TString(
"/F") );
654 for (std::vector<VariableInfo>::const_iterator itTgts =
fdsi->
GetTargetInfos().begin();
657 tree->
Branch( (*itTgts).GetInternalName(), &tgtVals[
n], (*itTgts).GetInternalName()+
TString(
"/F") );
665 tree->
Branch( (*itVis).GetInternalName(), &visVals[
n], (*itVis).GetInternalName()+
TString(
"/F") );
669 tree->
Branch(
"weight", &weight,
"weight/F" );
673 for (std::map< TString, Results* >::iterator itMethod =
fResults.at(t).begin();
674 itMethod !=
fResults.at(t).end(); itMethod++) {
682 tree->
Branch( itMethod->first, &(metVals[n][0]), itMethod->first +
"/F" );
688 if (iCls > 0) leafList.
Append(
":" );
693 << leafList <<
" itMethod->second " << itMethod->second << Endl;
694 tree->
Branch( itMethod->first, (metVals[n]), leafList );
700 if (iTgt > 0) leafList.
Append(
":" );
706 << leafList <<
" itMethod->second " << itMethod->second << Endl;
707 tree->
Branch( itMethod->first, (metVals[n]), leafList );
710 Log() <<
kWARNING <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"Unknown analysis type for result found when writing TestTree." << Endl;
724 for (
Int_t itmp = 0; itmp < tmp.
Sizeof(); itmp++) {
725 className[itmp] = tmp(itmp);
726 className[itmp+1] = 0;
737 for (std::map<TString, Results*>::iterator itMethod =
fResults.at(t).begin();
738 itMethod !=
fResults.at(t).end(); itMethod++) {
739 Results* results = itMethod->second;
741 const std::vector< Float_t >& vals = results->operator[](iEvt);
745 metVals[
n][0] = vals[0];
751 metVals[
n][nCls] = val;
758 metVals[
n][nTgts] = val;
768 <<
"Created tree '" << tree->
GetName() <<
"' with " << tree->
GetEntries() <<
" events" << Endl <<
Endl;
virtual const char * GetName() const
Returns name of object.
std::string GetName(const std::string &scope_name)
UInt_t GetNVariables() const
Random number generator class based on M.
MsgLogger & Endl(MsgLogger &ml)
Long64_t fTrainingBlockSize
std::vector< std::vector< std::pair< Float_t, Long64_t > > > fSamplingSelected
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()
virtual Double_t Rndm()
Machine independent random number generator.
std::vector< std::vector< std::pair< Float_t, Long64_t > > > fSamplingEventList
std::vector< std::vector< Event * > > fEventCollection
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
Long64_t GetNEvtBkgdTrain()
return number of background training events in dataset
UInt_t TreeIndex(Types::ETreeType type) const
UInt_t GetNSpectators() const
access the number of targets through the datasetinfo
The TNamed class is the base class for all named ROOT classes.
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
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
std::vector< VariableInfo > & GetTargetInfos()
Bool_t fHasNegativeEventWeights
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
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
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
char * Form(const char *fmt,...)
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
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
MsgLogger & Log() const
message logger
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
void SetCurrentType(Types::ETreeType type) const
void SetEventCollection(std::vector< Event *> *, Types::ETreeType, Bool_t deleteEvents=true)
Sets the event collection (by DataSetFactory)
std::vector< Int_t > fSamplingNEvents
virtual const char * GetName() const
Returns name of object.
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()
std::vector< std::map< TString, Results *> > fResults