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
69
70 virtual ~MethodSVM( void );
71
73
74 // optimise tuning parameters
75 std::map<TString,Double_t> OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="Minuit") override;
76 void SetTuneParameters(std::map<TString,Double_t> tuneParameters) override;
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 ) override;
82
83 // revoke training (required for optimise tuning parameters)
84 void Reset( void ) override;
85
87
88 // write weights to file
89 void WriteWeightsToStream( TFile& fout ) const;
90 void AddWeightsXMLTo ( void* parent ) const override;
91
92 // read weights from file
93 void ReadWeightsFromStream( std::istream& istr ) override;
94 void ReadWeightsFromStream( TFile& fFin ) override;
95 void ReadWeightsFromXML ( void* wghtnode ) override;
96 // calculate the MVA value
97
98 Double_t GetMvaValue( Double_t* err = nullptr, Double_t* errUpper = nullptr ) override;
99 const std::vector<Float_t>& GetRegressionValues() override;
100
101 void Init( void ) override;
102
103 // ranking of input variables
104 const Ranking* CreateRanking() override { 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 override;
121
122 // get help message text
123 void GetHelpMessage() const override;
124
125 private:
126
127 // the option handling methods
128 void DeclareOptions() override;
129 void DeclareCompatibilityOptions() override;
130 void ProcessOptions() override;
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 ClassDefOverride(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
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
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:131
Class that contains all the data information.
Definition DataSetInfo.h:62
Virtual base Class for all MVA method.
Definition MethodBase.h:111
void ReadWeightsFromStream(std::istream &) override=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
TVectorD * fMaxVars
for normalization //is it still needed??
Definition MethodSVM.h:145
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets) override
SVM can handle classification with 2 classes and regression with one regression-target.
void Init(void) override
default initialisation
void Reset(void) override
void SetKappa(Double_t k)
Definition MethodSVM.h:112
void ReadWeightsFromXML(void *wghtnode) override
TVectorD * fMinVars
for normalization //is it still needed??
Definition MethodSVM.h:144
void Train(void) override
Train SVM.
std::vector< TString > fVarNames
Definition MethodSVM.h:156
void MakeClassSpecific(std::ostream &, const TString &) const override
write specific classifier response
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
SVKernelFunction * fSVKernelFunction
kernel function
Definition MethodSVM.h:142
Float_t fBparm
free plane coefficient
Definition MethodSVM.h:137
void GetHelpMessage() const override
get help message text
Float_t fDoubleSigmaSquared
for RBF Kernel
Definition MethodSVM.h:149
void SetTuneParameters(std::map< TString, Double_t > tuneParameters) override
Set the tuning parameters according to the argument.
void GetMGamma(const std::vector< float > &gammas)
Produces GammaList string for multigaussian kernel to be written to xml file.
const Ranking * CreateRanking() override
Definition MethodSVM.h:104
Float_t fNumVars
number of input variables for multi-gaussian
Definition MethodSVM.h:155
void AddWeightsXMLTo(void *parent) const override
write configuration to xml file
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
std::map< TString, Double_t > OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="Minuit") override
Optimize Tuning Parameters This is used to optimise the kernel function parameters and cost.
Float_t fGamma
RBF Kernel parameter.
Definition MethodSVM.h:138
void SetOrder(Double_t o)
Definition MethodSVM.h:110
void ProcessOptions() override
option post processing (if necessary)
UShort_t fNSubSets
nr of subsets, default 1
Definition MethodSVM.h:136
void DeclareOptions() override
declare options available for this method
std::map< TString, std::vector< Double_t > > GetTuningOptions()
GetTuningOptions Function to allow for ranges and number of steps (for scan) when optimising kernel f...
std::string fGammas
Definition MethodSVM.h:157
std::vector< Float_t > fmGamma
vector of gammas for multi-gaussian kernel
Definition MethodSVM.h:154
Float_t fCost
cost value
Definition MethodSVM.h:133
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr) override
returns MVA value for given event
void ReadWeightsFromStream(std::istream &istr) override
std::vector< TMVA::SVEvent * > * fInputData
vector of training data in SVM format
Definition MethodSVM.h:140
const std::vector< Float_t > & GetRegressionValues() override
virtual ~MethodSVM(void)
destructor
void DeclareCompatibilityOptions() override
options that are used ONLY for the READER to ensure backward compatibility
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
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
Specify parameters to be tuned.
Definition MethodSVM.h:159
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...
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:138
create variable transformations
TMarker m
Definition textangle.C:8