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