Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/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 = nullptr, Double_t* errUpper = nullptr );
99 const std::vector<Float_t>& GetRegressionValues();
100
101 void Init( void );
102
103 // ranking of input variables
104 const Ranking* CreateRanking() { return nullptr; }
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
142 SVKernelFunction* fSVKernelFunction; ///< kernel function
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
float Float_t
Definition RtypesCore.h:57
double Double_t
Definition RtypesCore.h:59
#define ClassDef(name, id)
Definition Rtypes.h:342
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
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
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.
Float_t fTolerance
tolerance parameter
Definition MethodSVM.h:134
virtual void SetTuneParameters(std::map< TString, Double_t > tuneParameters)
Set the tuning parameters according to the argument.
TVectorD * fMaxVars
for normalization //is it still needed??
Definition MethodSVM.h:145
void SetKappa(Double_t k)
Definition MethodSVM.h:112
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr)
returns MVA value for given event
TVectorD * fMinVars
for normalization //is it still needed??
Definition MethodSVM.h:144
void DeclareOptions()
declare options available for this method
std::vector< TString > fVarNames
Definition MethodSVM.h:156
void WriteWeightsToStream(TFile &fout) const
TODO write IT write training sample (TTree) to file.
void SetMGamma(std::string &mg)
Takes as input a string of values for multigaussian gammas and splits it, filling the gamma vector re...
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.
SVKernelFunction * fSVKernelFunction
kernel function
Definition MethodSVM.h:142
Float_t fBparm
free plane coefficient
Definition MethodSVM.h:137
void ReadWeightsFromStream(std::istream &istr)
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.
Float_t fDoubleSigmaSquared
for RBF Kernel
Definition MethodSVM.h:149
void GetMGamma(const std::vector< float > &gammas)
Produces GammaList string for multigaussian kernel to be written to xml file.
void AddWeightsXMLTo(void *parent) const
write configuration to xml file
Float_t fNumVars
number of input variables for multi-gaussian
Definition MethodSVM.h:155
Int_t fOrder
for Polynomial Kernel ( polynomial order )
Definition MethodSVM.h:150
void SetTheta(Double_t t)
Definition MethodSVM.h:111
void SetGamma(Double_t g)
Definition MethodSVM.h:107
std::vector< TMVA::SVEvent * > * fSupportVectors
contains support vectors
Definition MethodSVM.h:141
Float_t fKappa
for Sigmoidal Kernel
Definition MethodSVM.h:152
Float_t fGamma
RBF Kernel parameter.
Definition MethodSVM.h:138
void SetOrder(Double_t o)
Definition MethodSVM.h:110
void Reset(void)
UShort_t fNSubSets
nr of subsets, default 1
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...
void ReadWeightsFromXML(void *wghtnode)
std::string fGammas
Definition MethodSVM.h:157
std::vector< Float_t > fmGamma
vector of gammas for multi-gaussian kernel
Definition MethodSVM.h:154
void ProcessOptions()
option post processing (if necessary)
void Train(void)
Train SVM.
Float_t fCost
cost value
Definition MethodSVM.h:133
const Ranking * CreateRanking()
Definition MethodSVM.h:104
std::vector< TMVA::SVEvent * > * fInputData
vector of training data in SVM format
Definition MethodSVM.h:140
void Init(void)
default initialisation
void MakeClassSpecific(std::ostream &, const TString &) const
write specific classifier response
virtual ~MethodSVM(void)
destructor
TString fTheKernel
kernel name
Definition MethodSVM.h:148
std::string fMultiKernels
Definition MethodSVM.h:160
Float_t fTheta
for Sigmoidal Kernel
Definition MethodSVM.h:151
const std::vector< Float_t > & GetRegressionValues()
void SetMult(Double_t m)
Definition MethodSVM.h:113
std::string fTune
Specify parameters to be tuned.
Definition MethodSVM.h:159
void GetHelpMessage() const
get help message text
UInt_t fMaxIter
max number of iteration
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...
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
std::string fGammaList
Definition MethodSVM.h:158
SVWorkingSet * fWgSet
svm working set
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.
Basic string class.
Definition TString.h:139
create variable transformations
TMarker m
Definition textangle.C:8