Logo ROOT   6.18/05
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"
49#endif
50
51namespace 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
105 void SetMGamma(std::string & mg);
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
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
#define c(i)
Definition: RSha256.hxx:101
#define g(i)
Definition: RSha256.hxx:105
unsigned short UShort_t
Definition: RtypesCore.h:36
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
#define ClassDef(name, id)
Definition: Rtypes.h:326
int type
Definition: TGX11.cxx:120
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
Class that contains all the data information.
Definition: DataSetInfo.h:60
Virtual base Class for all MVA method.
Definition: MethodBase.h:109
virtual void ReadWeightsFromStream(std::istream &)=0
SMO Platt's SVM classifier with Keerthi & Shavade improvements.
Definition: MethodSVM.h:57
Double_t getLoss(TString lossFunction)
getLoss Calculates loss for testing dataset.
Definition: MethodSVM.cxx:1163
Float_t fTolerance
Definition: MethodSVM.h:130
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:141
void SetKappa(Double_t k)
Definition: MethodSVM.h:108
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:140
void DeclareOptions()
declare options available for this method
Definition: MethodSVM.cxx:220
std::vector< TString > fVarNames
Definition: MethodSVM.h:152
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:104
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:138
Float_t fBparm
Definition: MethodSVM.h:133
void ReadWeightsFromStream(std::istream &istr)
Definition: MethodSVM.cxx:513
Float_t fMult
Definition: MethodSVM.h:149
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:159
Float_t fDoubleSigmaSquared
Definition: MethodSVM.h:145
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:151
void SetTheta(Double_t t)
Definition: MethodSVM.h:107
void SetGamma(Double_t g)
Definition: MethodSVM.h:103
std::vector< TMVA::SVEvent * > * fSupportVectors
Definition: MethodSVM.h:137
Float_t fKappa
Definition: MethodSVM.h:148
Float_t fGamma
Definition: MethodSVM.h:134
void SetOrder(Double_t o)
Definition: MethodSVM.h:106
void Reset(void)
Definition: MethodSVM.cxx:174
UShort_t fNSubSets
Definition: MethodSVM.h:132
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:153
std::vector< Float_t > fmGamma
Definition: MethodSVM.h:150
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:129
const Ranking * CreateRanking()
Definition: MethodSVM.h:100
std::vector< TMVA::SVEvent * > * fInputData
Definition: MethodSVM.h:136
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:144
std::string fMultiKernels
Definition: MethodSVM.h:156
Float_t fTheta
Definition: MethodSVM.h:147
const std::vector< Float_t > & GetRegressionValues()
Definition: MethodSVM.cxx:602
void SetMult(Double_t m)
Definition: MethodSVM.h:109
MethodSVM(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
standard constructor
Definition: MethodSVM.cxx:90
std::string fTune
Definition: MethodSVM.h:155
void GetHelpMessage() const
get help message text
Definition: MethodSVM.cxx:715
UInt_t fMaxIter
Definition: MethodSVM.h:131
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:154
SVWorkingSet * fWgSet
Definition: MethodSVM.h:135
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:127
Basic string class.
Definition: TString.h:131
static constexpr double mg
create variable transformations
auto * m
Definition: textangle.C:8