ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #endif
57 
58 namespace TMVA
59 {
60  class SVWorkingSet;
61  class SVEvent;
62  class SVKernelFunction;
63 
64  class MethodSVM : public MethodBase {
65 
66  public:
67 
68  MethodSVM( const TString& jobName, const TString& methodTitle, DataSetInfo& theData,
69  const TString& theOption = "", TDirectory* theTargetDir = 0 );
70 
71  MethodSVM( DataSetInfo& theData, const TString& theWeightFile, TDirectory* theTargetDir = NULL );
72 
73  virtual ~MethodSVM( void );
74 
75  virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
76 
77  // training method
78  void Train( void );
79 
81 
82  // write weights to file
83  void WriteWeightsToStream( TFile& fout ) const;
84  void AddWeightsXMLTo ( void* parent ) const;
85 
86  // read weights from file
87  void ReadWeightsFromStream( std::istream& istr );
88  void ReadWeightsFromStream( TFile& fFin );
89  void ReadWeightsFromXML ( void* wghtnode );
90  // calculate the MVA value
91 
92  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
93  const std::vector<Float_t>& GetRegressionValues();
94 
95  void Init( void );
96 
97  // ranking of input variables
98  const Ranking* CreateRanking() { return 0; }
99 
100  protected:
101 
102  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
103  void MakeClassSpecific( std::ostream&, const TString& ) const;
104 
105  // get help message text
106  void GetHelpMessage() const;
107 
108  private:
109 
110  // the option handling methods
111  void DeclareOptions();
113  void ProcessOptions();
114 
115  Float_t fCost; // cost value
116  Float_t fTolerance; // tolerance parameter
117  UInt_t fMaxIter; // max number of iteration
118  UShort_t fNSubSets; // nr of subsets, default 1
119  Float_t fBparm; // free plane coefficient
120  Float_t fGamma; // RBF Kernel parameter
121  SVWorkingSet* fWgSet; // svm working set
122  std::vector<TMVA::SVEvent*>* fInputData; // vector of training data in SVM format
123  std::vector<TMVA::SVEvent*>* fSupportVectors; // contains support vectors
124  SVKernelFunction* fSVKernelFunction; // kernel function
125 
126  TVectorD* fMinVars; // for normalization //is it still needed??
127  TVectorD* fMaxVars; // for normalization //is it still needed??
128 
129  // for backward compatibility
130  TString fTheKernel; // kernel name
131  Float_t fDoubleSigmaSquared; // for RBF Kernel
132  Int_t fOrder; // for Polynomial Kernel ( polynomial order )
133  Float_t fTheta; // for Sigmoidal Kernel
134  Float_t fKappa; // for Sigmoidal Kernel
135 
136  ClassDef(MethodSVM,0) // Support Vector Machine
137  };
138 
139 } // namespace TMVA
140 
141 #endif // MethodSVM_H
void Train(void)
Train SVM.
Definition: MethodSVM.cxx:220
Float_t fTolerance
Definition: MethodSVM.h:116
TString fTheKernel
Definition: MethodSVM.h:130
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
Definition: MethodSVM.cxx:190
Float_t fDoubleSigmaSquared
Definition: MethodSVM.h:131
float Float_t
Definition: RtypesCore.h:53
UShort_t fNSubSets
Definition: MethodSVM.h:118
unsigned short UShort_t
Definition: RtypesCore.h:36
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
EAnalysisType
Definition: Types.h:124
std::vector< TMVA::SVEvent * > * fInputData
Definition: MethodSVM.h:122
Basic string class.
Definition: TString.h:137
void MakeClassSpecific(std::ostream &, const TString &) const
write specific classifier response
Definition: MethodSVM.cxx:471
Float_t fTheta
Definition: MethodSVM.h:133
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void ProcessOptions()
option post processing (if necessary)
Definition: MethodSVM.cxx:207
TVectorD * fMinVars
Definition: MethodSVM.h:126
Float_t fCost
Definition: MethodSVM.h:115
Float_t fKappa
Definition: MethodSVM.h:134
#define ClassDef(name, id)
Definition: Rtypes.h:254
TVectorD * fMaxVars
Definition: MethodSVM.h:127
Float_t fBparm
Definition: MethodSVM.h:119
void DeclareOptions()
declare options available for this method
Definition: MethodSVM.cxx:171
void AddWeightsXMLTo(void *parent) const
write configuration to xml file
Definition: MethodSVM.cxx:261
void ReadWeightsFromXML(void *wghtnode)
Definition: MethodSVM.cxx:290
void ReadWeightsFromStream(std::istream &istr)
Definition: MethodSVM.cxx:349
void Init(void)
default initialisation
Definition: MethodSVM.cxx:156
SVKernelFunction * fSVKernelFunction
Definition: MethodSVM.h:124
unsigned int UInt_t
Definition: RtypesCore.h:42
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:146
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns MVA value for given event
Definition: MethodSVM.cxx:413
std::vector< TMVA::SVEvent * > * fSupportVectors
Definition: MethodSVM.h:123
MethodSVM(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="", TDirectory *theTargetDir=0)
double Double_t
Definition: RtypesCore.h:55
Describe directory structure in memory.
Definition: TDirectory.h:44
int type
Definition: TGX11.cxx:120
const Ranking * CreateRanking()
Definition: MethodSVM.h:98
virtual ~MethodSVM(void)
destructor
Definition: MethodSVM.cxx:135
#define NULL
Definition: Rtypes.h:82
Float_t fGamma
Definition: MethodSVM.h:120
void WriteWeightsToStream(TFile &fout) const
TODO write IT write training sample (TTree) to file.
Definition: MethodSVM.cxx:343
virtual void ReadWeightsFromStream(std::istream &)=0
UInt_t fMaxIter
Definition: MethodSVM.h:117
void GetHelpMessage() const
get help message text
Definition: MethodSVM.cxx:551
SVWorkingSet * fWgSet
Definition: MethodSVM.h:121
const std::vector< Float_t > & GetRegressionValues()
Definition: MethodSVM.cxx:438