Logo ROOT   6.08/07
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 #ifndef ROOT_TMVA_MethodBase
45 #include "TMVA/MethodBase.h"
46 #endif
47 #ifndef ROOT_TMVA_TMatrixD
48 #ifndef ROOT_TMatrixDfwd
49 #include "TMatrixDfwd.h"
50 #endif
51 #endif
52 #ifndef ROOT_TMVA_TVectorD
53 #ifndef ROOT_TVectorD
54 #include "TVectorD.h"
55 #endif
56 #ifndef ROOT_TMVA_SVKernelFunction
57 #include "TMVA/SVKernelFunction.h"
58 #endif
59 #endif
60 
61 namespace TMVA
62 {
63  class SVWorkingSet;
64  class SVEvent;
65  class SVKernelFunction;
66 
67  class MethodSVM : public MethodBase {
68 
69  public:
70 
71  MethodSVM( const TString& jobName, const TString& methodTitle, DataSetInfo& theData,
72  const TString& theOption = "" );
73 
74  MethodSVM( DataSetInfo& theData, const TString& theWeightFile);
75 
76  virtual ~MethodSVM( void );
77 
78  virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
79 
80  // optimise tuning parameters
81  virtual std::map<TString,Double_t> OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="Minuit");
82  virtual void SetTuneParameters(std::map<TString,Double_t> tuneParameters);
83  std::vector<TMVA::SVKernelFunction::EKernelType> MakeKernelList(std::string multiKernels, TString kernel);
84  std::map< TString,std::vector<Double_t> > GetTuningOptions();
85 
86  // training method
87  void Train( void );
88 
89  // revoke training (required for optimise tuning parameters)
90  void Reset( void );
91 
93 
94  // write weights to file
95  void WriteWeightsToStream( TFile& fout ) const;
96  void AddWeightsXMLTo ( void* parent ) const;
97 
98  // read weights from file
99  void ReadWeightsFromStream( std::istream& istr );
100  void ReadWeightsFromStream( TFile& fFin );
101  void ReadWeightsFromXML ( void* wghtnode );
102  // calculate the MVA value
103 
104  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
105  const std::vector<Float_t>& GetRegressionValues();
106 
107  void Init( void );
108 
109  // ranking of input variables
110  const Ranking* CreateRanking() { return 0; }
111 
112  // for SVM optimisation
113  void SetGamma(Double_t g){fGamma = g;}
115  void SetMGamma(std::string & mg);
116  void SetOrder(Double_t o){fOrder = o;}
117  void SetTheta(Double_t t){fTheta = t;}
118  void SetKappa(Double_t k){fKappa = k;}
120 
121  void GetMGamma(const std::vector<float> & gammas);
122 
123  protected:
124 
125  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
126  void MakeClassSpecific( std::ostream&, const TString& ) const;
127 
128  // get help message text
129  void GetHelpMessage() const;
130 
131  private:
132 
133  // the option handling methods
134  void DeclareOptions();
136  void ProcessOptions();
137  Double_t getLoss( TString lossFunction );
138 
139  Float_t fCost; // cost value
140  Float_t fTolerance; // tolerance parameter
141  UInt_t fMaxIter; // max number of iteration
142  UShort_t fNSubSets; // nr of subsets, default 1
143  Float_t fBparm; // free plane coefficient
144  Float_t fGamma; // RBF Kernel parameter
145  SVWorkingSet* fWgSet; // svm working set
146  std::vector<TMVA::SVEvent*>* fInputData; // vector of training data in SVM format
147  std::vector<TMVA::SVEvent*>* fSupportVectors; // contains support vectors
148  SVKernelFunction* fSVKernelFunction; // kernel function
149 
150  TVectorD* fMinVars; // for normalization //is it still needed??
151  TVectorD* fMaxVars; // for normalization //is it still needed??
152 
153  // for kernel functions
154  TString fTheKernel; // kernel name
155  Float_t fDoubleSigmaSquared; // for RBF Kernel
156  Int_t fOrder; // for Polynomial Kernel ( polynomial order )
157  Float_t fTheta; // for Sigmoidal Kernel
158  Float_t fKappa; // for Sigmoidal Kernel
160  std::vector<Float_t> fmGamma; // vector of gammas for multi-gaussian kernel
161  Float_t fNumVars; // number of input variables for multi-gaussian
162  std::vector<TString> fVarNames;
163  std::string fGammas;
164  std::string fGammaList;
165  std::string fTune; // Specify parameters to be tuned
166  std::string fMultiKernels;
167 
170 
171  ClassDef(MethodSVM,0); // Support Vector Machine
172  };
173 
174 } // namespace TMVA
175 
176 #endif // MethodSVM_H
void Train(void)
Train SVM.
Definition: MethodSVM.cxx:291
void MakeClassSpecific(std::ostream &, const TString &) const
write specific classifier response
Definition: MethodSVM.cxx:645
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:1056
Float_t fTolerance
Definition: MethodSVM.h:140
TString fTheKernel
Definition: MethodSVM.h:154
void SetMult(Double_t m)
Definition: MethodSVM.h:119
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
Definition: MethodSVM.cxx:261
Float_t fNumVars
Definition: MethodSVM.h:161
Float_t fDoubleSigmaSquared
Definition: MethodSVM.h:155
float Float_t
Definition: RtypesCore.h:53
return c
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:1108
UShort_t fNSubSets
Definition: MethodSVM.h:142
unsigned short UShort_t
Definition: RtypesCore.h:36
std::string fTune
Definition: MethodSVM.h:165
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
EAnalysisType
Definition: Types.h:129
std::string fMultiKernels
Definition: MethodSVM.h:166
std::vector< TMVA::SVEvent * > * fInputData
Definition: MethodSVM.h:146
Basic string class.
Definition: TString.h:137
Float_t fTheta
Definition: MethodSVM.h:157
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
std::string fGammas
Definition: MethodSVM.h:163
void AddWeightsXMLTo(void *parent) const
write configuration to xml file
Definition: MethodSVM.cxx:408
void ProcessOptions()
option post processing (if necessary)
Definition: MethodSVM.cxx:278
std::vector< TString > fVarNames
Definition: MethodSVM.h:162
Float_t fMult
Definition: MethodSVM.h:159
TVectorD * fMinVars
Definition: MethodSVM.h:150
virtual void SetTuneParameters(std::map< TString, Double_t > tuneParameters)
Set the tuning parameters according to the arguement.
Definition: MethodSVM.cxx:923
Float_t fCost
Definition: MethodSVM.h:139
Float_t fKappa
Definition: MethodSVM.h:158
std::vector< Float_t > fmGamma
Definition: MethodSVM.h:160
#define ClassDef(name, id)
Definition: Rtypes.h:254
void SetOrder(Double_t o)
Definition: MethodSVM.h:116
void GetMGamma(const std::vector< float > &gammas)
Produces GammaList string for multigaussian kernel to be written to xml file.
Definition: MethodSVM.cxx:1038
TVectorD * fMaxVars
Definition: MethodSVM.h:151
Float_t fBparm
Definition: MethodSVM.h:143
void DeclareOptions()
declare options available for this method
Definition: MethodSVM.cxx:230
void SetGamma(Double_t g)
Definition: MethodSVM.h:113
void ReadWeightsFromXML(void *wghtnode)
Definition: MethodSVM.cxx:440
void ReadWeightsFromStream(std::istream &istr)
Definition: MethodSVM.cxx:523
MethodSVM(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
standard constructor
Definition: MethodSVM.cxx:100
void Init(void)
default initialisation
Definition: MethodSVM.cxx:215
SVKernelFunction * fSVKernelFunction
Definition: MethodSVM.h:148
void SetTheta(Double_t t)
Definition: MethodSVM.h:117
unsigned int UInt_t
Definition: RtypesCore.h:42
TMarker * m
Definition: textangle.C:8
TString fLoss
Definition: MethodSVM.h:169
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:766
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:205
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns MVA value for given event
Definition: MethodSVM.cxx:587
std::vector< TMVA::SVEvent * > * fSupportVectors
Definition: MethodSVM.h:147
void WriteWeightsToStream(TFile &fout) const
TODO write IT write training sample (TTree) to file.
Definition: MethodSVM.cxx:517
double Double_t
Definition: RtypesCore.h:55
Double_t getLoss(TString lossFunction)
getLoss Calculates loss for testing dataset.
Definition: MethodSVM.cxx:1164
int type
Definition: TGX11.cxx:120
void SetCost(Double_t c)
Definition: MethodSVM.h:114
const Ranking * CreateRanking()
Definition: MethodSVM.h:110
void GetHelpMessage() const
get help message text
Definition: MethodSVM.cxx:725
Abstract ClassifierFactory template that handles arbitrary types.
virtual ~MethodSVM(void)
destructor
Definition: MethodSVM.cxx:171
std::string fGammaList
Definition: MethodSVM.h:164
Float_t fGamma
Definition: MethodSVM.h:144
virtual void ReadWeightsFromStream(std::istream &)=0
UInt_t fMaxIter
Definition: MethodSVM.h:141
void Reset(void)
Definition: MethodSVM.cxx:184
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:1024
void SetKappa(Double_t k)
Definition: MethodSVM.h:118
SVWorkingSet * fWgSet
Definition: MethodSVM.h:145
const std::vector< Float_t > & GetRegressionValues()
Definition: MethodSVM.cxx:612