Logo ROOT   6.10/09
Reference Guide
MethodSVM.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Marcin Wolter, Andrzej Zemla
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : MethodSVM *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Support Vector Machine *
12  * *
13  * Authors (alphabetical): *
14  * Marcin Wolter <Marcin.Wolter@cern.ch> - IFJ PAN, Krakow, Poland *
15  * Andrzej Zemla <azemla@cern.ch> - IFJ PAN, Krakow, Poland *
16  * (IFJ PAN: Henryk Niewodniczanski Inst. Nucl. Physics, Krakow, Poland) *
17  * *
18  * Introduction of regression by: *
19  * Krzysztof Danielowski <danielow@cern.ch> - IFJ PAN & AGH, Krakow, Poland *
20  * Kamil Kraszewski <kalq@cern.ch> - IFJ PAN & UJ, Krakow, Poland *
21  * Maciej Kruk <mkruk@cern.ch> - IFJ PAN & AGH, Krakow, Poland *
22  * *
23  * Copyright (c) 2005: *
24  * CERN, Switzerland *
25  * MPI-K Heidelberg, Germany *
26  * PAN, Krakow, Poland *
27  * *
28  * Redistribution and use in source and binary forms, with or without *
29  * modification, are permitted according to the terms listed in LICENSE *
30  * (http://tmva.sourceforge.net/LICENSE) *
31  **********************************************************************************/
32 
33 #ifndef ROOT_TMVA_MethodSVM
34 #define ROOT_TMVA_MethodSVM
35 
36 //////////////////////////////////////////////////////////////////////////
37 // //
38 // MethodSVM //
39 // //
40 // SMO Platt's SVM classifier with Keerthi & Shavade improvements //
41 // //
42 //////////////////////////////////////////////////////////////////////////
43 
44 #include "TMVA/MethodBase.h"
45 #include "TMatrixDfwd.h"
46 #ifndef ROOT_TMVA_TVectorD
47 #include "TVectorD.h"
48 #include "TMVA/SVKernelFunction.h"
49 #endif
50 
51 namespace TMVA
52 {
53  class SVWorkingSet;
54  class SVEvent;
55  class SVKernelFunction;
56 
57  class MethodSVM : public MethodBase {
58 
59  public:
60 
61  MethodSVM( const TString& jobName, const TString& methodTitle, DataSetInfo& theData,
62  const TString& theOption = "" );
63 
64  MethodSVM( DataSetInfo& theData, const TString& theWeightFile);
65 
66  virtual ~MethodSVM( void );
67 
68  virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
69 
70  // optimise tuning parameters
71  virtual std::map<TString,Double_t> OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="Minuit");
72  virtual void SetTuneParameters(std::map<TString,Double_t> tuneParameters);
73  std::vector<TMVA::SVKernelFunction::EKernelType> MakeKernelList(std::string multiKernels, TString kernel);
74  std::map< TString,std::vector<Double_t> > GetTuningOptions();
75 
76  // training method
77  void Train( void );
78 
79  // revoke training (required for optimise tuning parameters)
80  void Reset( void );
81 
83 
84  // write weights to file
85  void WriteWeightsToStream( TFile& fout ) const;
86  void AddWeightsXMLTo ( void* parent ) const;
87 
88  // read weights from file
89  void ReadWeightsFromStream( std::istream& istr );
90  void ReadWeightsFromStream( TFile& fFin );
91  void ReadWeightsFromXML ( void* wghtnode );
92  // calculate the MVA value
93 
94  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
95  const std::vector<Float_t>& GetRegressionValues();
96 
97  void Init( void );
98 
99  // ranking of input variables
100  const Ranking* CreateRanking() { return 0; }
101 
102  // for SVM optimisation
103  void SetGamma(Double_t g){fGamma = g;}
104  void SetCost(Double_t c){fCost = c;}
105  void SetMGamma(std::string & mg);
106  void SetOrder(Double_t o){fOrder = o;}
107  void SetTheta(Double_t t){fTheta = t;}
108  void SetKappa(Double_t k){fKappa = k;}
110 
111  void GetMGamma(const std::vector<float> & gammas);
112 
113  protected:
114 
115  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
116  void MakeClassSpecific( std::ostream&, const TString& ) const;
117 
118  // get help message text
119  void GetHelpMessage() const;
120 
121  private:
122 
123  // the option handling methods
124  void DeclareOptions();
126  void ProcessOptions();
127  Double_t getLoss( TString lossFunction );
128 
129  Float_t fCost; // cost value
130  Float_t fTolerance; // tolerance parameter
131  UInt_t fMaxIter; // max number of iteration
132  UShort_t fNSubSets; // nr of subsets, default 1
133  Float_t fBparm; // free plane coefficient
134  Float_t fGamma; // RBF Kernel parameter
135  SVWorkingSet* fWgSet; // svm working set
136  std::vector<TMVA::SVEvent*>* fInputData; // vector of training data in SVM format
137  std::vector<TMVA::SVEvent*>* fSupportVectors; // contains support vectors
138  SVKernelFunction* fSVKernelFunction; // kernel function
139 
140  TVectorD* fMinVars; // for normalization //is it still needed??
141  TVectorD* fMaxVars; // for normalization //is it still needed??
142 
143  // for kernel functions
144  TString fTheKernel; // kernel name
145  Float_t fDoubleSigmaSquared; // for RBF Kernel
146  Int_t fOrder; // for Polynomial Kernel ( polynomial order )
147  Float_t fTheta; // for Sigmoidal Kernel
148  Float_t fKappa; // for Sigmoidal Kernel
150  std::vector<Float_t> fmGamma; // vector of gammas for multi-gaussian kernel
151  Float_t fNumVars; // number of input variables for multi-gaussian
152  std::vector<TString> fVarNames;
153  std::string fGammas;
154  std::string fGammaList;
155  std::string fTune; // Specify parameters to be tuned
156  std::string fMultiKernels;
157 
160 
161  ClassDef(MethodSVM,0); // Support Vector Machine
162  };
163 
164 } // namespace TMVA
165 
166 #endif // MethodSVM_H
void Train(void)
Train SVM.
Definition: MethodSVM.cxx:281
void MakeClassSpecific(std::ostream &, const TString &) const
write specific classifier response
Definition: MethodSVM.cxx:635
std::vector< TMVA::SVKernelFunction::EKernelType > MakeKernelList(std::string multiKernels, TString kernel)
MakeKernelList Function providing string manipulation for product or sum of kernels functions to take...
Definition: MethodSVM.cxx:1054
Float_t fTolerance
Definition: MethodSVM.h:130
TString fTheKernel
Definition: MethodSVM.h:144
void SetMult(Double_t m)
Definition: MethodSVM.h:109
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
Definition: MethodSVM.cxx:251
Kernel for Support Vector Machine.
Float_t fNumVars
Definition: MethodSVM.h:151
Float_t fDoubleSigmaSquared
Definition: MethodSVM.h:145
float Float_t
Definition: RtypesCore.h:53
std::map< TString, std::vector< Double_t > > GetTuningOptions()
GetTuningOptions Function to allow for ranges and number of steps (for scan) when optimising kernel f...
Definition: MethodSVM.cxx:1106
UShort_t fNSubSets
Definition: MethodSVM.h:132
unsigned short UShort_t
Definition: RtypesCore.h:36
std::string fTune
Definition: MethodSVM.h:155
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
EAnalysisType
Definition: Types.h:125
Virtual base Class for all MVA method.
Definition: MethodBase.h:106
std::string fMultiKernels
Definition: MethodSVM.h:156
std::vector< TMVA::SVEvent * > * fInputData
Definition: MethodSVM.h:136
Basic string class.
Definition: TString.h:129
Ranking for variables in method (implementation)
Definition: Ranking.h:48
Float_t fTheta
Definition: MethodSVM.h:147
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
std::string fGammas
Definition: MethodSVM.h:153
void AddWeightsXMLTo(void *parent) const
write configuration to xml file
Definition: MethodSVM.cxx:398
void ProcessOptions()
option post processing (if necessary)
Definition: MethodSVM.cxx:268
std::vector< TString > fVarNames
Definition: MethodSVM.h:152
Float_t fMult
Definition: MethodSVM.h:149
TVectorD * fMinVars
Definition: MethodSVM.h:140
virtual void SetTuneParameters(std::map< TString, Double_t > tuneParameters)
Set the tuning parameters according to the argument.
Definition: MethodSVM.cxx:917
Float_t fCost
Definition: MethodSVM.h:129
SMO Platt&#39;s SVM classifier with Keerthi & Shavade improvements.
Definition: MethodSVM.h:57
Float_t fKappa
Definition: MethodSVM.h:148
std::vector< Float_t > fmGamma
Definition: MethodSVM.h:150
#define ClassDef(name, id)
Definition: Rtypes.h:297
void SetOrder(Double_t o)
Definition: MethodSVM.h:106
void GetMGamma(const std::vector< float > &gammas)
Produces GammaList string for multigaussian kernel to be written to xml file.
Definition: MethodSVM.cxx:1032
TVectorD * fMaxVars
Definition: MethodSVM.h:141
Class that contains all the data information.
Definition: DataSetInfo.h:60
Float_t fBparm
Definition: MethodSVM.h:133
void DeclareOptions()
declare options available for this method
Definition: MethodSVM.cxx:220
void SetGamma(Double_t g)
Definition: MethodSVM.h:103
void ReadWeightsFromXML(void *wghtnode)
Definition: MethodSVM.cxx:430
void ReadWeightsFromStream(std::istream &istr)
Definition: MethodSVM.cxx:513
MethodSVM(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
standard constructor
Definition: MethodSVM.cxx:90
void Init(void)
default initialisation
Definition: MethodSVM.cxx:205
SVKernelFunction * fSVKernelFunction
Definition: MethodSVM.h:138
void SetTheta(Double_t t)
Definition: MethodSVM.h:107
unsigned int UInt_t
Definition: RtypesCore.h:42
TMarker * m
Definition: textangle.C:8
TString fLoss
Definition: MethodSVM.h:159
virtual std::map< TString, Double_t > OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="Minuit")
Optimize Tuning Parameters This is used to optimise the kernel function parameters and cost...
Definition: MethodSVM.cxx:760
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
SVM can handle classification with 2 classes and regression with one regression-target.
Definition: MethodSVM.cxx:195
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns MVA value for given event
Definition: MethodSVM.cxx:577
std::vector< TMVA::SVEvent * > * fSupportVectors
Definition: MethodSVM.h:137
void WriteWeightsToStream(TFile &fout) const
TODO write IT write training sample (TTree) to file.
Definition: MethodSVM.cxx:507
double Double_t
Definition: RtypesCore.h:55
Double_t getLoss(TString lossFunction)
getLoss Calculates loss for testing dataset.
Definition: MethodSVM.cxx:1163
int type
Definition: TGX11.cxx:120
void SetCost(Double_t c)
Definition: MethodSVM.h:104
const Ranking * CreateRanking()
Definition: MethodSVM.h:100
void GetHelpMessage() const
get help message text
Definition: MethodSVM.cxx:715
Working class for Support Vector Machine.
Definition: SVWorkingSet.h:42
Abstract ClassifierFactory template that handles arbitrary types.
virtual ~MethodSVM(void)
destructor
Definition: MethodSVM.cxx:161
std::string fGammaList
Definition: MethodSVM.h:154
Float_t fGamma
Definition: MethodSVM.h:134
virtual void ReadWeightsFromStream(std::istream &)=0
UInt_t fMaxIter
Definition: MethodSVM.h:131
void Reset(void)
Definition: MethodSVM.cxx:174
void SetMGamma(std::string &mg)
Takes as input a string of values for multigaussian gammas and splits it, filling the gamma vector re...
Definition: MethodSVM.cxx:1018
void SetKappa(Double_t k)
Definition: MethodSVM.h:108
SVWorkingSet * fWgSet
Definition: MethodSVM.h:135
const std::vector< Float_t > & GetRegressionValues()
Definition: MethodSVM.cxx:602