44 #ifndef ROOT_TMVA_MethodSVM 47 #ifndef ROOT_TMVA_Tools 50 #ifndef ROOT_TMVA_Timer 54 #ifndef ROOT_TMVA_SVWorkingSet 58 #ifndef ROOT_TMVA_SVEvent 62 #ifndef ROOT_TMVA_SVKernelFunction 80 :
MethodBase( jobName,
Types::kSVM, methodTitle, theData, theOption, theTargetDir )
90 , fSVKernelFunction(0)
93 , fDoubleSigmaSquared(0)
114 , fSVKernelFunction(0)
117 , fDoubleSigmaSquared(0)
156 fInputData =
new std::vector<TMVA::SVEvent*>(0);
202 Log() <<
kFATAL <<
"Mechanism to ignore events with negative weights in training not yet available for method: " 204 <<
" --> please remove \"IgnoreNegWeightsInTraining\" option from booking string." 231 Log() <<
kINFO <<
"Sorry, no computing time forecast available for SVM, please wait ..." <<
Endl;
260 for (std::vector<TMVA::SVEvent*>::iterator veciter=
fSupportVectors->begin();
263 temp[0] = (*veciter)->GetNs();
264 temp[1] = (*veciter)->GetTypeFlag();
265 temp[2] = (*veciter)->GetAlpha();
266 temp[3] = (*veciter)->GetAlpha_p();
268 temp[ivar+4] = (*(*veciter)->GetDataVector())[ivar];
294 std::vector<Float_t>* svector =
new std::vector<Float_t>(
GetNvar());
307 for (
UInt_t ievt = 0; ievt < fNsupv; ievt++) {
311 typeFlag=(int)temp[1];
314 for (
UInt_t ivar = 0; ivar <
GetNvar(); ivar++) (*svector)[ivar]=temp[ivar+4];
320 void* maxminnode = supportvectornode;
358 std::vector<Float_t>* svector =
new std::vector<Float_t>(
GetNvar());
363 for (
UInt_t ievt = 0; ievt < fNsupv; ievt++) {
366 typeFlag = typeTalpha<0?-1:1;
367 alpha = typeTalpha<0?-typeTalpha:typeTalpha;
368 for (
UInt_t ivar = 0; ivar < GetNvar(); ivar++) istr >> svector->at(ivar);
373 for (
UInt_t ivar = 0; ivar < GetNvar(); ivar++) istr >> (*fMaxVars)[ivar];
375 for (
UInt_t ivar = 0; ivar < GetNvar(); ivar++) istr >> (*fMinVars)[ivar];
387 Log() <<
kFATAL <<
"Unknown kernel function found in weight file!" <<
Endl;
466 fout <<
" // not implemented for class: \"" << className <<
"\"" << std::endl;
467 fout <<
" float fBparameter;" << std::endl;
468 fout <<
" int fNOfSuppVec;" << std::endl;
469 fout <<
" static float fAllSuppVectors[][" << fNsupv <<
"];" << std::endl;
470 fout <<
" static float fAlphaTypeCoef[" << fNsupv <<
"];" << std::endl;
472 fout <<
" // Kernel parameter(s) " << std::endl;
473 fout <<
" float fGamma;" << std::endl;
474 fout <<
"};" << std::endl;
475 fout <<
"" << std::endl;
478 fout <<
"inline void " << className <<
"::Initialize() " << std::endl;
479 fout <<
"{" << std::endl;
480 fout <<
" fBparameter = " <<
fBparm <<
";" << std::endl;
481 fout <<
" fNOfSuppVec = " << fNsupv <<
";" << std::endl;
482 fout <<
" fGamma = " <<
fGamma <<
";" <<std::endl;
483 fout <<
"}" << std::endl;
487 fout <<
"inline double " << className <<
"::GetMvaValue__(const std::vector<double>& inputValues ) const" << std::endl;
488 fout <<
"{" << std::endl;
489 fout <<
" double mvaval = 0; " << std::endl;
490 fout <<
" double temp = 0; " << std::endl;
492 fout <<
" for (int ievt = 0; ievt < fNOfSuppVec; ievt++ ){" << std::endl;
493 fout <<
" temp = 0;" << std::endl;
494 fout <<
" for ( unsigned int ivar = 0; ivar < GetNvar(); ivar++ ) {" << std::endl;
496 fout <<
" temp += (fAllSuppVectors[ivar][ievt] - inputValues[ivar]) " << std::endl;
497 fout <<
" * (fAllSuppVectors[ivar][ievt] - inputValues[ivar]); " << std::endl;
498 fout <<
" }" << std::endl;
499 fout <<
" mvaval += fAlphaTypeCoef[ievt] * exp( -fGamma * temp ); " << std::endl;
501 fout <<
" }" << std::endl;
502 fout <<
" mvaval -= fBparameter;" << std::endl;
503 fout <<
" return 1./(1. + exp(mvaval));" << std::endl;
504 fout <<
"}" << std::endl;
505 fout <<
"// Clean up" << std::endl;
506 fout <<
"inline void " << className <<
"::Clear() " << std::endl;
507 fout <<
"{" << std::endl;
508 fout <<
" // nothing to clear " << std::endl;
509 fout <<
"}" << std::endl;
510 fout <<
"" << std::endl;
513 fout <<
"float " << className <<
"::fAlphaTypeCoef[] =" << std::endl;
515 for (
Int_t isv = 0; isv < fNsupv; isv++) {
517 if (isv < fNsupv-1) fout <<
", ";
519 fout <<
" };" << std::endl << std::endl;
521 fout <<
"float " << className <<
"::fAllSuppVectors[][" << fNsupv <<
"] =" << std::endl;
526 for (
Int_t isv = 0; isv < fNsupv; isv++){
528 if (isv < fNsupv-1) fout <<
", ";
531 if (ivar <
GetNvar()-1) fout <<
", " << std::endl;
532 else fout << std::endl;
534 fout <<
"};" << std::endl<< std::endl;
548 Log() <<
"The Support Vector Machine (SVM) builds a hyperplance separating" <<
Endl;
549 Log() <<
"signal and background events (vectors) using the minimal subset of " <<
Endl;
550 Log() <<
"all vectors used for training (support vectors). The extension to" <<
Endl;
551 Log() <<
"the non-linear case is performed by mapping input vectors into a " <<
Endl;
552 Log() <<
"higher-dimensional feature space in which linear separation is " <<
Endl;
553 Log() <<
"possible. The use of the kernel functions thereby eliminates the " <<
Endl;
554 Log() <<
"explicit transformation to the feature space. The implemented SVM " <<
Endl;
555 Log() <<
"algorithm performs the classification tasks using linear, polynomial, " <<
Endl;
556 Log() <<
"Gaussian and sigmoidal kernel functions. The Gaussian kernel allows " <<
Endl;
557 Log() <<
"to apply any discriminant shape in the input space." <<
Endl;
561 Log() <<
"SVM is a general purpose non-linear classification method, which " <<
Endl;
562 Log() <<
"does not require data preprocessing like decorrelation or Principal " <<
Endl;
563 Log() <<
"Component Analysis. It generalises quite well and can handle analyses " <<
Endl;
564 Log() <<
"with large numbers of input variables." <<
Endl;
568 Log() <<
"Optimal performance requires primarily a proper choice of the kernel " <<
Endl;
569 Log() <<
"parameters (the width \"Sigma\" in case of Gaussian kernel) and the" <<
Endl;
570 Log() <<
"cost parameter \"C\". The user must optimise them empirically by running" <<
Endl;
571 Log() <<
"SVM several times with different parameter sets. The time needed for " <<
Endl;
572 Log() <<
"each evaluation scales like the square of the number of training " <<
Endl;
573 Log() <<
"events so that a coarse preliminary tuning should be performed on " <<
Endl;
574 Log() <<
"reduced data sets." <<
Endl;
void Train(void)
Train SVM.
void MakeClassSpecific(std::ostream &, const TString &) const
write specific classifier response
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
MsgLogger & Endl(MsgLogger &ml)
Float_t fDoubleSigmaSquared
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
void Train(UInt_t nIter=1000)
train the SVM
std::vector< TMVA::SVEvent * > * fInputData
TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true)
void AddWeightsXMLTo(void *parent) const
write configuration to xml file
void ProcessOptions()
option post processing (if necessary)
void setCompatibilityParams(EKernelType k, UInt_t order, Float_t theta, Float_t kappa)
set old options for compatibility mode
const Event * GetEvent() const
Double_t GetXmin(Int_t ivar) const
DataSetInfo & DataInfo() const
Bool_t DoRegression() const
void DeclareOptions()
declare options available for this method
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
TVectorT< Double_t > TVectorD
TString GetElapsedTime(Bool_t Scientific=kTRUE)
Double_t GetXmax(Int_t ivar) const
Float_t GetTarget(UInt_t itgt) const
void ReadWeightsFromXML(void *wghtnode)
void ReadWeightsFromStream(std::istream &istr)
const char * GetName() const
Returns name of object.
void Init(void)
default initialisation
SVKernelFunction * fSVKernelFunction
void SetTarget(UInt_t itgt, Float_t value)
set the target value (dimension itgt) to value
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.
void SetNormalised(Bool_t norm)
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns MVA value for given event
std::vector< TMVA::SVEvent * > * fSupportVectors
void WriteWeightsToStream(TFile &fout) const
TODO write IT write training sample (TTree) to file.
MethodSVM(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="", TDirectory *theTargetDir=0)
standard constructor
Bool_t IgnoreEventsWithNegWeightsInTraining() const
std::vector< TMVA::SVEvent * > * GetSupportVectors()
Describe directory structure in memory.
void SetCurrentType(Types::ETreeType type) const
void GetHelpMessage() const
get help message text
#define REGISTER_METHOD(CLASS)
for example
Abstract ClassifierFactory template that handles arbitrary types.
virtual ~MethodSVM(void)
destructor
TString GetMethodTypeName() const
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
Long64_t GetNEvents(Types::ETreeType type=Types::kMaxTreeType) const
std::vector< Float_t > * fRegressionReturnVal
Float_t Evaluate(SVEvent *ev1, SVEvent *ev2)
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
const std::vector< Float_t > & GetRegressionValues()