Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 #include "TMVA/MethodBase.h"
45 #include "TMatrixDfwd.h"
46 #ifndef ROOT_TMVA_TVectorD
47 #include "TVectorD.h"
48 #include "TMVA/SVKernelFunction.h"
49 #endif
50 
51 namespace 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 
82  using MethodBase::ReadWeightsFromStream;
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
103  void SetGamma(Double_t g){fGamma = g;}
104  void SetCost(Double_t c){fCost = c;}
105  void SetMGamma(std::string & mg);
106  void SetOrder(Double_t o){fOrder = o;}
107  void SetTheta(Double_t t){fTheta = t;}
108  void SetKappa(Double_t k){fKappa = k;}
109  void SetMult(Double_t m){fMult = m;}
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();
125  void DeclareCompatibilityOptions();
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
138  SVKernelFunction* fSVKernelFunction; // kernel function
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
149  Float_t fMult;
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 
158  Int_t fDataSize;
159  TString fLoss;
160 
161  ClassDef(MethodSVM,0); // Support Vector Machine
162  };
163 
164 } // namespace TMVA
165 
166 #endif // MethodSVM_H