Logo ROOT  
Reference Guide
MethodCrossValidation.h
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Kim Albertsson
3
4/*************************************************************************
5 * Copyright (C) 2018, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TMVA_MethodCrossValidation
13#define ROOT_TMVA_MethodCrossValidation
14
15//////////////////////////////////////////////////////////////////////////
16// //
17// MethodCrossValidation //
18// //
19//////////////////////////////////////////////////////////////////////////
20
21#include "TMVA/CvSplit.h"
22#include "TMVA/DataSetInfo.h"
23#include "TMVA/MethodBase.h"
24
25#include "TString.h"
26
27#include <iostream>
28#include <memory>
29#include <vector>
30#include <map>
31
32namespace TMVA {
33
34class CrossValidation;
35class Ranking;
36
37// Looks for serialised methods of the form methodTitle + "_fold" + iFold;
39
41
42public:
43 // constructor for training and reading
44 MethodCrossValidation(const TString &jobName, const TString &methodTitle, DataSetInfo &theData,
45 const TString &theOption = "");
46
47 // constructor for calculating BDT-MVA using previously generated decision trees
48 MethodCrossValidation(DataSetInfo &theData, const TString &theWeightFile);
49
50 virtual ~MethodCrossValidation(void);
51
52 // optimize tuning parameters
53 // virtual std::map<TString,Double_t> OptimizeTuningParameters(TString fomType="ROCIntegral", TString
54 // fitType="FitGA"); virtual void SetTuneParameters(std::map<TString,Double_t> tuneParameters);
55
56 // training method
57 void Train(void);
58
59 // revoke training
60 void Reset(void);
61
63
64 // write weights to file
65 void AddWeightsXMLTo(void *parent) const;
66
67 // read weights from file
68 void ReadWeightsFromStream(std::istream &istr);
69 void ReadWeightsFromXML(void *parent);
70
71 // write method specific histos to target file
72 void WriteMonitoringHistosToFile(void) const;
73
74 // calculate the MVA value
75 Double_t GetMvaValue(Double_t *err = 0, Double_t *errUpper = 0);
76 const std::vector<Float_t> &GetMulticlassValues();
77 const std::vector<Float_t> &GetRegressionValues();
78
79 // the option handling methods
80 void DeclareOptions();
81 void ProcessOptions();
82
83 // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
84 void MakeClassSpecific(std::ostream &, const TString &) const;
85 void MakeClassSpecificHeader(std::ostream &, const TString &) const;
86
87 void GetHelpMessage() const;
88
89 const Ranking *CreateRanking();
90 Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets);
91
92protected:
93 void Init(void);
95
96private:
98 MethodBase *InstantiateMethodFromXML(TString methodTypeName, TString weightfile) const;
99
100private:
105
107 std::unique_ptr<CvSplitKFoldsExpr> fSplitExpr;
108
109 std::vector<Float_t> fMulticlassValues;
110 std::vector<Float_t> fRegressionValues;
111
112 std::vector<MethodBase *> fEncapsulatedMethods;
113
114 // Used for CrossValidation with random splits (not using the
115 // CVSplitCrossValisationExpr functionality) to communicate Event to fold
116 // mapping.
117 std::map<const TMVA::Event *, UInt_t> fEventToFoldMapping;
118
119 // for backward compatibility
121};
122
123} // namespace TMVA
124
125#endif
#define ClassDef(name, id)
Definition: Rtypes.h:335
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Class that contains all the data information.
Definition: DataSetInfo.h:62
Virtual base Class for all MVA method.
Definition: MethodBase.h:111
virtual void ReadWeightsFromStream(std::istream &)=0
friend class MethodCrossValidation
Definition: MethodBase.h:117
std::vector< Float_t > fRegressionValues
std::vector< Float_t > fMulticlassValues
std::unique_ptr< CvSplitKFoldsExpr > fSplitExpr
void MakeClassSpecific(std::ostream &, const TString &) const
Make ROOT-independent C++ class for classifier response (classifier-specific implementation).
void AddWeightsXMLTo(void *parent) const
Write weights to XML.
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
void Init(void)
Common initialisation with defaults for the Method.
std::vector< MethodBase * > fEncapsulatedMethods
void MakeClassSpecificHeader(std::ostream &, const TString &) const
Specific class header.
void Reset(void)
Reset the method, as if it had just been instantiated (forget all training etc.).
TString GetWeightFileNameForFold(UInt_t iFold) const
Returns filename of weight file for a given fold.
const std::vector< Float_t > & GetRegressionValues()
Get the regression value generated by the containing methods.
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
MethodBase * InstantiateMethodFromXML(TString methodTypeName, TString weightfile) const
Reads in a weight file an instantiates the corresponding method.
void Train(void)
Call the Optimizer with the set of parameters and ranges that are meant to be tuned.
const std::vector< Float_t > & GetMulticlassValues()
Get the multiclass MVA response.
std::map< const TMVA::Event *, UInt_t > fEventToFoldMapping
void ReadWeightsFromXML(void *parent)
Reads from the xml file.
void DeclareCompatibilityOptions()
Options that are used ONLY for the READER to ensure backward compatibility.
void WriteMonitoringHistosToFile(void) const
write special monitoring histograms to file dummy implementation here --------------—
virtual ~MethodCrossValidation(void)
Destructor.
void ReadWeightsFromStream(std::istream &istr)
Read the weights.
void ProcessOptions()
The option string is decoded, for available options see "DeclareOptions".
Ranking for variables in method (implementation)
Definition: Ranking.h:48
EAnalysisType
Definition: Types.h:126
Basic string class.
Definition: TString.h:136
create variable transformations