Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MethodSVM.cxx
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 * Implementation *
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 * Introduction of kernel parameter optimisation *
24 * and additional kernel functions by: *
25 * Adrian Bevan <adrian.bevan@cern.ch> - Queen Mary *
26 * University of London, UK *
27 * Tom Stevenson <thomas.james.stevenson@cern.ch> - Queen Mary *
28 * University of London, UK *
29 * *
30 * Copyright (c) 2005: *
31 * CERN, Switzerland *
32 * MPI-K Heidelberg, Germany *
33 * PAN, Krakow, Poland *
34 * *
35 * Redistribution and use in source and binary forms, with or without *
36 * modification, are permitted according to the terms listed in LICENSE *
37 * (see tmva/doc/LICENSE) *
38 **********************************************************************************/
39
40/*! \class TMVA::MethodSVM
41\ingroup TMVA
42SMO Platt's SVM classifier with Keerthi & Shavade improvements
43*/
44
45#include "TMVA/MethodSVM.h"
46
47#include "TMVA/Tools.h"
48#include "TMVA/Timer.h"
49
50#include "TMVA/SVWorkingSet.h"
51
52#include "TMVA/SVEvent.h"
53
55
57#include "TMVA/Configurable.h"
58#include "TMVA/DataSet.h"
59#include "TMVA/DataSetInfo.h"
60#include "TMVA/Event.h"
61#include "TMVA/IMethod.h"
62#include "TMVA/MethodBase.h"
63#include "TMVA/MsgLogger.h"
64#include "TMVA/Types.h"
65#include "TMVA/Interval.h"
67#include "TMVA/Results.h"
69#include "TMVA/VariableInfo.h"
70
71#include "TFile.h"
72#include "TVectorD.h"
73#include "TMath.h"
74
75#include <iostream>
76#include <string>
77
78using std::vector;
79using std::string;
80using std::stringstream;
81
82//const Int_t basketsize__ = 1280000;
84
85
86////////////////////////////////////////////////////////////////////////////////
87/// standard constructor
88
91 : MethodBase( jobName, Types::kSVM, methodTitle, theData, theOption)
92 , fCost(0)
93 , fTolerance(0)
94 , fMaxIter(0)
95 , fNSubSets(0)
96 , fBparm(0)
97 , fGamma(0)
98 , fWgSet(0)
99 , fInputData(0)
100 , fSupportVectors(0)
101 , fSVKernelFunction(0)
102 , fMinVars(0)
103 , fMaxVars(0)
104 , fDoubleSigmaSquared(0)
105 , fOrder(0)
106 , fTheta(0)
107 , fKappa(0)
108 , fMult(0)
109 ,fNumVars(0)
110 , fGammas("")
111 , fGammaList("")
112 , fDataSize(0)
113 , fLoss(0)
114{
115 fVarNames.clear();
116 fNumVars = theData.GetVariableInfos().size();
117 for( int i=0; i<fNumVars; i++){
118 fVarNames.push_back(theData.GetVariableInfos().at(i).GetTitle());
119 }
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// constructor from weight file
124
127 , fCost(0)
128 , fTolerance(0)
129 , fMaxIter(0)
130 , fNSubSets(0)
131 , fBparm(0)
132 , fGamma(0)
133 , fWgSet(0)
134 , fInputData(0)
135 , fSupportVectors(0)
136 , fSVKernelFunction(0)
137 , fMinVars(0)
138 , fMaxVars(0)
139 , fDoubleSigmaSquared(0)
140 , fOrder(0)
141 , fTheta(0)
142 , fKappa(0)
143 , fMult(0)
144 , fNumVars(0)
145 , fGammas("")
146 , fGammaList("")
147 , fDataSize(0)
148 , fLoss(0)
149{
150 fVarNames.clear();
151 fNumVars = theData.GetVariableInfos().size();
152 for( int i=0;i<fNumVars; i++){
153 fVarNames.push_back(theData.GetVariableInfos().at(i).GetTitle());
154 }
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// destructor
159
161{
162 fSupportVectors->clear();
163 for (UInt_t i=0; i<fInputData->size(); i++) {
164 delete fInputData->at(i);
165 }
166 if (fWgSet !=0) { delete fWgSet; fWgSet=0; }
167 if (fSVKernelFunction !=0 ) { delete fSVKernelFunction; fSVKernelFunction = 0; }
168}
169
170////////////////////////////////////////////////////////////////////////////////
171// reset the method, as if it had just been instantiated (forget all training etc.)
172
174{
175 // reset the method, as if it had just been instantiated (forget all training etc.)
176 fSupportVectors->clear();
177 for (UInt_t i=0; i<fInputData->size(); i++){
178 delete fInputData->at(i);
179 fInputData->at(i)=0;
180 }
181 fInputData->clear();
182 if (fWgSet !=0) { fWgSet=0; }
183 if (fSVKernelFunction !=0 ) { fSVKernelFunction = 0; }
184 if (Data()){
185 Data()->DeleteResults(GetMethodName(), Types::kTraining, GetAnalysisType());
186 }
187
188 Log() << kDEBUG << " successfully(?) reset the method " << Endl;
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// SVM can handle classification with 2 classes and regression with one regression-target
193
200
201////////////////////////////////////////////////////////////////////////////////
202/// default initialisation
203
205{
206 // SVM always uses normalised input variables
207 SetNormalised( kTRUE );
208
209 // Helge: do not book a event vector of given size but rather fill the vector
210 // later with pus_back. Anyway, this is NOT what is time consuming in
211 // SVM and it allows to skip totally events with weights == 0 ;)
212 fInputData = new std::vector<TMVA::SVEvent*>(0);
213 fSupportVectors = new std::vector<TMVA::SVEvent*>(0);
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// declare options available for this method
218
220{
221 DeclareOptionRef( fTheKernel = "RBF", "Kernel", "Pick which kernel ( RBF or MultiGauss )");
222 // for gaussian kernel parameter(s)
223 DeclareOptionRef( fGamma = 1., "Gamma", "RBF kernel parameter: Gamma (size of the Kernel)");
224 // for polynomial kernel parameter(s)
225 DeclareOptionRef( fOrder = 3, "Order", "Polynomial Kernel parameter: polynomial order");
226 DeclareOptionRef( fTheta = 1., "Theta", "Polynomial Kernel parameter: polynomial theta");
227 // for multi-gaussian kernel parameter(s)
228 DeclareOptionRef( fGammas = "", "GammaList", "MultiGauss parameters" );
229
230 // for range and step number for kernel parameter optimisation
231 DeclareOptionRef( fTune = "All", "Tune", "Tune Parameters");
232 // for list of kernels to be used with product or sum kernel
233 DeclareOptionRef( fMultiKernels = "None", "KernelList", "Sum or product of kernels");
234 DeclareOptionRef( fLoss = "hinge", "Loss", "Loss function");
235
236 DeclareOptionRef( fCost, "C", "Cost parameter" );
237 if (DoRegression()) {
238 fCost = 0.002;
239 }else{
240 fCost = 1.;
241 }
242 DeclareOptionRef( fTolerance = 0.01, "Tol", "Tolerance parameter" ); //should be fixed
243 DeclareOptionRef( fMaxIter = 1000, "MaxIter", "Maximum number of training loops" );
244
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// options that are used ONLY for the READER to ensure backward compatibility
249
251{
253 DeclareOptionRef( fNSubSets = 1, "NSubSets", "Number of training subsets" );
254 DeclareOptionRef( fTheKernel = "Gauss", "Kernel", "Uses kernel function");
255 // for gaussian kernel parameter(s)
256 DeclareOptionRef( fDoubleSigmaSquared = 2., "Sigma", "Kernel parameter: sigma");
257 // for polynomial kernel parameter(s)
258 DeclareOptionRef( fOrder = 3, "Order", "Polynomial Kernel parameter: polynomial order");
259 // for sigmoid kernel parameters
260 DeclareOptionRef( fTheta = 1., "Theta", "Sigmoid Kernel parameter: theta");
261 DeclareOptionRef( fKappa = 1., "Kappa", "Sigmoid Kernel parameter: kappa");
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// option post processing (if necessary)
266
268{
269 if (IgnoreEventsWithNegWeightsInTraining()) {
270 Log() << kFATAL << "Mechanism to ignore events with negative weights in training not yet available for method: "
271 << GetMethodTypeName()
272 << " --> please remove \"IgnoreNegWeightsInTraining\" option from booking string."
273 << Endl;
274 }
275}
276
277////////////////////////////////////////////////////////////////////////////////
278/// Train SVM
279
281{
282 Data()->SetCurrentType(Types::kTraining);
283
284 Log() << kDEBUG << "Create event vector"<< Endl;
285
286 fDataSize = Data()->GetNEvents();
287 Int_t nSignal = Data()->GetNEvtSigTrain();
288 Int_t nBackground = Data()->GetNEvtBkgdTrain();
291
292 // Use number of signal and background from above to weight the cost parameter
293 // so that the training is not biased towards the larger dataset when the signal
294 // and background samples are significantly different sizes.
295 if(nSignal < nBackground){
296 CSig = fCost;
298 }
299 else{
300 CBkg = fCost;
302 }
303
304 // Loop over events and assign the correct cost parameter.
305 for (Int_t ievnt=0; ievnt<Data()->GetNEvents(); ievnt++){
306 if (GetEvent(ievnt)->GetWeight() != 0){
307 if(DataInfo().IsSignal(GetEvent(ievnt))){
308 fInputData->push_back(new SVEvent(GetEvent(ievnt), CSig, DataInfo().IsSignal\
309 (GetEvent(ievnt))));
310 }
311 else{
312 fInputData->push_back(new SVEvent(GetEvent(ievnt), CBkg, DataInfo().IsSignal\
313 (GetEvent(ievnt))));
314 }
315 }
316 }
317
318 // Set the correct kernel function.
319 // Here we only use valid Mercer kernels. In the literature some people have reported reasonable
320 // results using Sigmoid kernel function however that is not a valid Mercer kernel and is not used here.
321 if( fTheKernel == "RBF"){
322 fSVKernelFunction = new SVKernelFunction( SVKernelFunction::kRBF, fGamma);
323 }
324 else if( fTheKernel == "MultiGauss" ){
325 if(fGammas!=""){
326 SetMGamma(fGammas);
327 fGammaList=fGammas;
328 }
329 else{
330 if(fmGamma.size()!=0){ GetMGamma(fmGamma); } // Set fGammas if empty to write to XML file
331 else{
332 for(Int_t ngammas=0; ngammas<fNumVars; ++ngammas){
333 fmGamma.push_back(1.0);
334 }
335 GetMGamma(fmGamma);
336 }
337 }
338 fSVKernelFunction = new SVKernelFunction(fmGamma);
339 }
340 else if( fTheKernel == "Polynomial" ){
341 fSVKernelFunction = new SVKernelFunction( SVKernelFunction::kPolynomial, fOrder,fTheta);
342 }
343 else if( fTheKernel == "Prod" ){
344 if(fGammas!=""){
345 SetMGamma(fGammas);
346 fGammaList=fGammas;
347 }
348 else{
349 if(fmGamma.size()!=0){ GetMGamma(fmGamma); } // Set fGammas if empty to write to XML file
350 }
351 fSVKernelFunction = new SVKernelFunction( SVKernelFunction::kProd, MakeKernelList(fMultiKernels,fTheKernel), fmGamma, fGamma, fOrder, fTheta );
352 }
353 else if( fTheKernel == "Sum" ){
354 if(fGammas!=""){
355 SetMGamma(fGammas);
356 fGammaList=fGammas;
357 }
358 else{
359 if(fmGamma.size()!=0){ GetMGamma(fmGamma); } // Set fGammas if empty to write to XML file
360 }
361 fSVKernelFunction = new SVKernelFunction( SVKernelFunction::kSum, MakeKernelList(fMultiKernels,fTheKernel), fmGamma, fGamma, fOrder, fTheta );
362 }
363 else {
364 Log() << kWARNING << fTheKernel << " is not a recognised kernel function." << Endl;
365 exit(1);
366 }
367
368 Log()<< kINFO << "Building SVM Working Set...with "<<fInputData->size()<<" event instances"<< Endl;
369 Timer bldwstime( GetName());
370 fWgSet = new SVWorkingSet( fInputData, fSVKernelFunction,fTolerance, DoRegression() );
371 Log() << kINFO <<"Elapsed time for Working Set build: "<< bldwstime.GetElapsedTime()<<Endl;
372
373 // timing
374 Timer timer( GetName() );
375 Log() << kINFO << "Sorry, no computing time forecast available for SVM, please wait ..." << Endl;
376
377 fWgSet->Train(fMaxIter);
378
379 Log() << kINFO << "Elapsed time: " << timer.GetElapsedTime()
380 << " " << Endl;
381
382 fBparm = fWgSet->GetBpar();
383 fSupportVectors = fWgSet->GetSupportVectors();
384 delete fWgSet;
385 fWgSet=0;
386
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// write configuration to xml file
391
392void TMVA::MethodSVM::AddWeightsXMLTo( void* parent ) const
393{
394 void* wght = gTools().AddChild(parent, "Weights");
395 gTools().AddAttr(wght,"fBparm",fBparm);
396 gTools().AddAttr(wght,"fGamma",fGamma);
397 gTools().AddAttr(wght,"fGammaList",fGammaList);
398 gTools().AddAttr(wght,"fTheta",fTheta);
399 gTools().AddAttr(wght,"fOrder",fOrder);
400 gTools().AddAttr(wght,"NSupVec",fSupportVectors->size());
401
402 for (std::vector<TMVA::SVEvent*>::iterator veciter=fSupportVectors->begin();
403 veciter!=fSupportVectors->end() ; ++veciter ) {
404 TVectorD temp(GetNvar()+4);
405 temp[0] = (*veciter)->GetNs();
406 temp[1] = (*veciter)->GetTypeFlag();
407 temp[2] = (*veciter)->GetAlpha();
408 temp[3] = (*veciter)->GetAlpha_p();
409 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++)
410 temp[ivar+4] = (*(*veciter)->GetDataVector())[ivar];
411 gTools().WriteTVectorDToXML(wght,"SupportVector",&temp);
412 }
413 // write max/min data values
414 void* maxnode = gTools().AddChild(wght, "Maxima");
415 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++)
416 gTools().AddAttr(maxnode, "Var"+gTools().StringFromInt(ivar), GetXmax(ivar));
417 void* minnode = gTools().AddChild(wght, "Minima");
418 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++)
419 gTools().AddAttr(minnode, "Var"+gTools().StringFromInt(ivar), GetXmin(ivar));
420}
421
422////////////////////////////////////////////////////////////////////////////////
423
425{
426 gTools().ReadAttr( wghtnode, "fBparm",fBparm );
427 gTools().ReadAttr( wghtnode, "fGamma",fGamma);
428 gTools().ReadAttr( wghtnode, "fGammaList",fGammaList);
429 gTools().ReadAttr( wghtnode, "fOrder",fOrder);
430 gTools().ReadAttr( wghtnode, "fTheta",fTheta);
431 UInt_t fNsupv=0;
432 gTools().ReadAttr( wghtnode, "NSupVec",fNsupv );
433
434 Float_t alpha=0.;
435 Float_t alpha_p = 0.;
436
437 Int_t typeFlag=-1;
438 // UInt_t ns = 0;
439 std::vector<Float_t>* svector = new std::vector<Float_t>(GetNvar());
440
441 if (fMaxVars!=0) delete fMaxVars;
442 fMaxVars = new TVectorD( GetNvar() );
443 if (fMinVars!=0) delete fMinVars;
444 fMinVars = new TVectorD( GetNvar() );
445 if (fSupportVectors!=0) {
446 for (vector< SVEvent* >::iterator it = fSupportVectors->begin(); it!=fSupportVectors->end(); ++it)
447 delete *it;
448 delete fSupportVectors;
449 }
450 fSupportVectors = new std::vector<TMVA::SVEvent*>(0);
452 for (UInt_t ievt = 0; ievt < fNsupv; ievt++) {
453 TVectorD temp(GetNvar()+4);
454 gTools().ReadTVectorDFromXML(supportvectornode,"SupportVector",&temp);
455 // ns=(UInt_t)temp[0];
456 typeFlag=(int)temp[1];
457 alpha=temp[2];
458 alpha_p=temp[3];
459 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++) (*svector)[ivar]=temp[ivar+4];
460
461 fSupportVectors->push_back(new SVEvent(svector,alpha,alpha_p,typeFlag));
463 }
464
466 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++)
467 gTools().ReadAttr( maxminnode,"Var"+gTools().StringFromInt(ivar),(*fMaxVars)[ivar]);
469 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++)
470 gTools().ReadAttr( maxminnode,"Var"+gTools().StringFromInt(ivar),(*fMinVars)[ivar]);
471 if (fSVKernelFunction!=0) delete fSVKernelFunction;
472 if( fTheKernel == "RBF" ){
473 fSVKernelFunction = new SVKernelFunction(SVKernelFunction::kRBF, fGamma);
474 }
475 else if( fTheKernel == "MultiGauss" ){
476 SetMGamma(fGammaList);
477 fSVKernelFunction = new SVKernelFunction(fmGamma);
478 }
479 else if( fTheKernel == "Polynomial" ){
480 fSVKernelFunction = new SVKernelFunction(SVKernelFunction::kPolynomial, fOrder, fTheta);
481 }
482 else if( fTheKernel == "Prod" ){
483 SetMGamma(fGammaList);
484 fSVKernelFunction = new SVKernelFunction(SVKernelFunction::kSum, MakeKernelList(fMultiKernels,fTheKernel), fmGamma, fGamma, fOrder, fTheta);
485 }
486 else if( fTheKernel == "Sum" ){
487 SetMGamma(fGammaList);
488 fSVKernelFunction = new SVKernelFunction(SVKernelFunction::kSum, MakeKernelList(fMultiKernels,fTheKernel), fmGamma, fGamma, fOrder, fTheta);
489 }
490 else {
491 Log() << kWARNING << fTheKernel << " is not a recognised kernel function." << Endl;
492 exit(1);
493 }
494 delete svector;
495}
496
497////////////////////////////////////////////////////////////////////////////////
498///TODO write IT
499/// write training sample (TTree) to file
500
504
505////////////////////////////////////////////////////////////////////////////////
506
508{
509 if (fSupportVectors !=0) { delete fSupportVectors; fSupportVectors = 0;}
510 fSupportVectors = new std::vector<TMVA::SVEvent*>(0);
511
512 // read configuration from input stream
513 istr >> fBparm;
514
516 // coverity[tainted_data_argument]
517 istr >> fNsupv;
518 fSupportVectors->reserve(fNsupv);
519
521 Float_t alpha=0.;
522 Int_t typeFlag=-1;
523 UInt_t ns = 0;
524 std::vector<Float_t>* svector = new std::vector<Float_t>(GetNvar());
525
526 fMaxVars = new TVectorD( GetNvar() );
527 fMinVars = new TVectorD( GetNvar() );
528
529 for (UInt_t ievt = 0; ievt < fNsupv; ievt++) {
530 istr>>ns;
532 typeFlag = typeTalpha<0?-1:1;
534 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++) istr >> svector->at(ivar);
535
536 fSupportVectors->push_back(new SVEvent(svector,alpha,typeFlag,ns));
537 }
538
539 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++) istr >> (*fMaxVars)[ivar];
540
541 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++) istr >> (*fMinVars)[ivar];
542
543 delete fSVKernelFunction;
544 if (fTheKernel == "Gauss" ) {
545 fSVKernelFunction = new SVKernelFunction(1/fDoubleSigmaSquared);
546 }
547 else {
549 if(fTheKernel == "Linear") k = SVKernelFunction::kLinear;
550 else if (fTheKernel == "Polynomial") k = SVKernelFunction::kPolynomial;
551 else if (fTheKernel == "Sigmoid" ) k = SVKernelFunction::kSigmoidal;
552 else {
553 Log() << kFATAL <<"Unknown kernel function found in weight file!" << Endl;
554 }
555 fSVKernelFunction = new SVKernelFunction();
556 fSVKernelFunction->setCompatibilityParams(k, fOrder, fTheta, fKappa);
557 }
558 delete svector;
559}
560
561////////////////////////////////////////////////////////////////////////////////
562/// TODO write IT
563
565{
566}
567
568////////////////////////////////////////////////////////////////////////////////
569/// returns MVA value for given event
570
572{
573 Double_t myMVA = 0;
574
575 // TODO: avoid creation of a new SVEvent every time (Joerg)
576 SVEvent* ev = new SVEvent( GetEvent(), 0. ); // check for specificators
577
578 for (UInt_t ievt = 0; ievt < fSupportVectors->size() ; ievt++) {
579 myMVA += ( fSupportVectors->at(ievt)->GetAlpha()
580 * fSupportVectors->at(ievt)->GetTypeFlag()
581 * fSVKernelFunction->Evaluate( fSupportVectors->at(ievt), ev ) );
582 }
583
584 delete ev;
585
586 myMVA -= fBparm;
587
588 // cannot determine error
589 NoErrorCalc(err, errUpper);
590
591 // 08/12/09: changed sign here to make results agree with convention signal=1
592 return 1.0/(1.0 + TMath::Exp(myMVA));
593}
594////////////////////////////////////////////////////////////////////////////////
595
596const std::vector<Float_t>& TMVA::MethodSVM::GetRegressionValues()
597{
598 if( fRegressionReturnVal == NULL )
599 fRegressionReturnVal = new std::vector<Float_t>();
600 fRegressionReturnVal->clear();
601
602 Double_t myMVA = 0;
603
604 const Event *baseev = GetEvent();
605 SVEvent* ev = new SVEvent( baseev,0. ); //check for specificators
606
607 for (UInt_t ievt = 0; ievt < fSupportVectors->size() ; ievt++) {
608 myMVA += ( fSupportVectors->at(ievt)->GetDeltaAlpha()
609 *fSVKernelFunction->Evaluate( fSupportVectors->at(ievt), ev ) );
610 }
611 myMVA += fBparm;
612 Event * evT = new Event(*baseev);
613 evT->SetTarget(0,myMVA);
614
615 const Event* evT2 = GetTransformationHandler().InverseTransform( evT );
616
617 fRegressionReturnVal->push_back(evT2->GetTarget(0));
618
619 delete evT;
620
621 delete ev;
622
623 return *fRegressionReturnVal;
624}
625
626////////////////////////////////////////////////////////////////////////////////
627/// write specific classifier response
628
629void TMVA::MethodSVM::MakeClassSpecific( std::ostream& fout, const TString& className ) const
630{
631 const int fNsupv = fSupportVectors->size();
632 fout << " // not implemented for class: \"" << className << "\"" << std::endl;
633 fout << " float fBparameter;" << std::endl;
634 fout << " int fNOfSuppVec;" << std::endl;
635 fout << " static float fAllSuppVectors[][" << fNsupv << "];" << std::endl;
636 fout << " static float fAlphaTypeCoef[" << fNsupv << "];" << std::endl;
637 fout << std::endl;
638 fout << " // Kernel parameter(s) " << std::endl;
639 fout << " float fGamma;" << std::endl;
640 fout << "};" << std::endl;
641 fout << "" << std::endl;
642
643 //Initialize function definition
644 fout << "inline void " << className << "::Initialize() " << std::endl;
645 fout << "{" << std::endl;
646 fout << " fBparameter = " << fBparm << ";" << std::endl;
647 fout << " fNOfSuppVec = " << fNsupv << ";" << std::endl;
648 fout << " fGamma = " << fGamma << ";" <<std::endl;
649 fout << "}" << std::endl;
650 fout << std::endl;
651
652 // GetMvaValue__ function definition
653 fout << "inline double " << className << "::GetMvaValue__(const std::vector<double>& inputValues ) const" << std::endl;
654 fout << "{" << std::endl;
655 fout << " double mvaval = 0; " << std::endl;
656 fout << " double temp = 0; " << std::endl;
657 fout << std::endl;
658 fout << " for (int ievt = 0; ievt < fNOfSuppVec; ievt++ ){" << std::endl;
659 fout << " temp = 0;" << std::endl;
660 fout << " for ( unsigned int ivar = 0; ivar < GetNvar(); ivar++ ) {" << std::endl;
661
662 fout << " temp += (fAllSuppVectors[ivar][ievt] - inputValues[ivar]) " << std::endl;
663 fout << " * (fAllSuppVectors[ivar][ievt] - inputValues[ivar]); " << std::endl;
664 fout << " }" << std::endl;
665 fout << " mvaval += fAlphaTypeCoef[ievt] * exp( -fGamma * temp ); " << std::endl;
666
667 fout << " }" << std::endl;
668 fout << " mvaval -= fBparameter;" << std::endl;
669 fout << " return 1./(1. + exp(mvaval));" << std::endl;
670 fout << "}" << std::endl;
671 fout << "// Clean up" << std::endl;
672 fout << "inline void " << className << "::Clear() " << std::endl;
673 fout << "{" << std::endl;
674 fout << " // nothing to clear " << std::endl;
675 fout << "}" << std::endl;
676 fout << "" << std::endl;
677
678 // define support vectors
679 fout << "float " << className << "::fAlphaTypeCoef[] =" << std::endl;
680 fout << "{ ";
681 for (Int_t isv = 0; isv < fNsupv; isv++) {
682 fout << fSupportVectors->at(isv)->GetDeltaAlpha() * fSupportVectors->at(isv)->GetTypeFlag();
683 if (isv < fNsupv-1) fout << ", ";
684 }
685 fout << " };" << std::endl << std::endl;
686
687 fout << "float " << className << "::fAllSuppVectors[][" << fNsupv << "] =" << std::endl;
688 fout << "{";
689 for (UInt_t ivar = 0; ivar < GetNvar(); ivar++) {
690 fout << std::endl;
691 fout << " { ";
692 for (Int_t isv = 0; isv < fNsupv; isv++){
693 fout << fSupportVectors->at(isv)->GetDataVector()->at(ivar);
694 if (isv < fNsupv-1) fout << ", ";
695 }
696 fout << " }";
697 if (ivar < GetNvar()-1) fout << ", " << std::endl;
698 else fout << std::endl;
699 }
700 fout << "};" << std::endl<< std::endl;
701}
702
703////////////////////////////////////////////////////////////////////////////////
704/// get help message text
705///
706/// typical length of text line:
707/// "|--------------------------------------------------------------|"
708
710{
711 Log() << Endl;
712 Log() << gTools().Color("bold") << "--- Short description:" << gTools().Color("reset") << Endl;
713 Log() << Endl;
714 Log() << "The Support Vector Machine (SVM) builds a hyperplane separating" << Endl;
715 Log() << "signal and background events (vectors) using the minimal subset of " << Endl;
716 Log() << "all vectors used for training (support vectors). The extension to" << Endl;
717 Log() << "the non-linear case is performed by mapping input vectors into a " << Endl;
718 Log() << "higher-dimensional feature space in which linear separation is " << Endl;
719 Log() << "possible. The use of the kernel functions thereby eliminates the " << Endl;
720 Log() << "explicit transformation to the feature space. The implemented SVM " << Endl;
721 Log() << "algorithm performs the classification tasks using linear, polynomial, " << Endl;
722 Log() << "Gaussian and sigmoidal kernel functions. The Gaussian kernel allows " << Endl;
723 Log() << "to apply any discriminant shape in the input space." << Endl;
724 Log() << Endl;
725 Log() << gTools().Color("bold") << "--- Performance optimisation:" << gTools().Color("reset") << Endl;
726 Log() << Endl;
727 Log() << "SVM is a general purpose non-linear classification method, which " << Endl;
728 Log() << "does not require data preprocessing like decorrelation or Principal " << Endl;
729 Log() << "Component Analysis. It generalises quite well and can handle analyses " << Endl;
730 Log() << "with large numbers of input variables." << Endl;
731 Log() << Endl;
732 Log() << gTools().Color("bold") << "--- Performance tuning via configuration options:" << gTools().Color("reset") << Endl;
733 Log() << Endl;
734 Log() << "Optimal performance requires primarily a proper choice of the kernel " << Endl;
735 Log() << "parameters (the width \"Sigma\" in case of Gaussian kernel) and the" << Endl;
736 Log() << "cost parameter \"C\". The user must optimise them empirically by running" << Endl;
737 Log() << "SVM several times with different parameter sets. The time needed for " << Endl;
738 Log() << "each evaluation scales like the square of the number of training " << Endl;
739 Log() << "events so that a coarse preliminary tuning should be performed on " << Endl;
740 Log() << "reduced data sets." << Endl;
741}
742
743////////////////////////////////////////////////////////////////////////////////
744/// Optimize Tuning Parameters
745/// This is used to optimise the kernel function parameters and cost. All kernel parameters
746/// are optimised by default with default ranges, however the parameters to be optimised can
747/// be set when booking the method with the option Tune.
748///
749/// Example:
750///
751/// "Tune=Gamma[0.01;1.0;100]" would only tune the RBF Gamma between 0.01 and 1.0
752/// with 100 steps.
753
755{
756 // Call the Optimizer with the set of kernel parameters and ranges that are meant to be tuned.
757 std::map< TString,std::vector<Double_t> > optVars;
758 // Get parameters and options specified in booking of method.
759 if(fTune != "All"){
760 optVars= GetTuningOptions();
761 }
762 std::map< TString,std::vector<Double_t> >::iterator iter;
763 // Fill all the tuning parameters that should be optimized into a map
764 std::map<TString,TMVA::Interval*> tuneParameters;
765 std::map<TString,Double_t> tunedParameters;
766 // Note: the 3rd parameter in the interval is the "number of bins", NOT the stepsize!!
767 // The actual values are always read from the middle of the bins.
768 Log() << kINFO << "Using the " << fTheKernel << " kernel." << Endl;
769 // Setup map of parameters based on the specified options or defaults.
770 if( fTheKernel == "RBF" ){
771 if(fTune == "All"){
772 tuneParameters.insert(std::pair<TString,Interval*>("Gamma",new Interval(0.01,1.,100)));
773 tuneParameters.insert(std::pair<TString,Interval*>("C",new Interval(0.01,1.,100)));
774 }
775 else{
776 for(iter=optVars.begin(); iter!=optVars.end(); ++iter){
777 if( iter->first == "Gamma" || iter->first == "C"){
778 tuneParameters.insert(std::pair<TString,Interval*>(iter->first, new Interval(iter->second.at(0),iter->second.at(1),iter->second.at(2))));
779 }
780 else{
781 Log() << kWARNING << iter->first << " is not a recognised tuneable parameter." << Endl;
782 exit(1);
783 }
784 }
785 }
786 }
787 else if( fTheKernel == "Polynomial" ){
788 if (fTune == "All"){
789 tuneParameters.insert(std::pair<TString,Interval*>("Order", new Interval(1,10,10)));
790 tuneParameters.insert(std::pair<TString,Interval*>("Theta", new Interval(0.01,1.,100)));
791 tuneParameters.insert(std::pair<TString,Interval*>("C", new Interval(0.01,1.,100)));
792 }
793 else{
794 for(iter=optVars.begin(); iter!=optVars.end(); ++iter){
795 if( iter->first == "Theta" || iter->first == "C"){
796 tuneParameters.insert(std::pair<TString,Interval*>(iter->first, new Interval(iter->second.at(0),iter->second.at(1),iter->second.at(2))));
797 }
798 else if( iter->first == "Order"){
799 tuneParameters.insert(std::pair<TString,Interval*>(iter->first, new Interval(iter->second.at(0),iter->second.at(1),iter->second.at(2))));
800 }
801 else{
802 Log() << kWARNING << iter->first << " is not a recognised tuneable parameter." << Endl;
803 exit(1);
804 }
805 }
806 }
807 }
808 else if( fTheKernel == "MultiGauss" ){
809 if (fTune == "All"){
810 for(int i=0; i<fNumVars; i++){
811 stringstream s;
812 s << fVarNames.at(i);
813 string str = "Gamma_" + s.str();
814 tuneParameters.insert(std::pair<TString,Interval*>(str,new Interval(0.01,1.,100)));
815 }
816 tuneParameters.insert(std::pair<TString,Interval*>("C",new Interval(0.01,1.,100)));
817 } else {
818 for(iter=optVars.begin(); iter!=optVars.end(); ++iter){
819 if( iter->first == "GammaList"){
820 for(int j=0; j<fNumVars; j++){
821 stringstream s;
822 s << fVarNames.at(j);
823 string str = "Gamma_" + s.str();
824 tuneParameters.insert(std::pair<TString,Interval*>(str, new Interval(iter->second.at(0),iter->second.at(1),iter->second.at(2))));
825 }
826 }
827 else if( iter->first == "C"){
828 tuneParameters.insert(std::pair<TString,Interval*>(iter->first, new Interval(iter->second.at(0),iter->second.at(1),iter->second.at(2))));
829 }
830 else{
831 Log() << kWARNING << iter->first << " is not a recognised tuneable parameter." << Endl;
832 exit(1);
833 }
834 }
835 }
836 }
837 else if( fTheKernel == "Prod" ){
838 std::stringstream tempstring(fMultiKernels);
839 std::string value;
840 while (std::getline(tempstring,value,'*')){
841 if(value == "RBF"){
842 tuneParameters.insert(std::pair<TString,Interval*>("Gamma",new Interval(0.01,1.,100)));
843 }
844 else if(value == "MultiGauss"){
845 for(int i=0; i<fNumVars; i++){
846 stringstream s;
847 s << fVarNames.at(i);
848 string str = "Gamma_" + s.str();
849 tuneParameters.insert(std::pair<TString,Interval*>(str,new Interval(0.01,1.,100)));
850 }
851 }
852 else if(value == "Polynomial"){
853 tuneParameters.insert(std::pair<TString,Interval*>("Order",new Interval(1,10,10)));
854 tuneParameters.insert(std::pair<TString,Interval*>("Theta",new Interval(0.0,1.0,101)));
855 }
856 else {
857 Log() << kWARNING << value << " is not a recognised kernel function." << Endl;
858 exit(1);
859 }
860 }
861 tuneParameters.insert(std::pair<TString,Interval*>("C",new Interval(0.01,1.,100)));
862 }
863 else if( fTheKernel == "Sum" ){
864 std::stringstream tempstring(fMultiKernels);
865 std::string value;
866 while (std::getline(tempstring,value,'+')){
867 if(value == "RBF"){
868 tuneParameters.insert(std::pair<TString,Interval*>("Gamma",new Interval(0.01,1.,100)));
869 }
870 else if(value == "MultiGauss"){
871 for(int i=0; i<fNumVars; i++){
872 stringstream s;
873 s << fVarNames.at(i);
874 string str = "Gamma_" + s.str();
875 tuneParameters.insert(std::pair<TString,Interval*>(str,new Interval(0.01,1.,100)));
876 }
877 }
878 else if(value == "Polynomial"){
879 tuneParameters.insert(std::pair<TString,Interval*>("Order",new Interval(1,10,10)));
880 tuneParameters.insert(std::pair<TString,Interval*>("Theta",new Interval(0.0,1.0,101)));
881 }
882 else {
883 Log() << kWARNING << value << " is not a recognised kernel function." << Endl;
884 exit(1);
885 }
886 }
887 tuneParameters.insert(std::pair<TString,Interval*>("C",new Interval(0.01,1.,100)));
888 }
889 else {
890 Log() << kWARNING << fTheKernel << " is not a recognised kernel function." << Endl;
891 exit(1);
892 }
893 Log() << kINFO << " the following SVM parameters will be tuned on the respective *grid*\n" << Endl;
894 std::map<TString,TMVA::Interval*>::iterator it;
895 for(it=tuneParameters.begin(); it!=tuneParameters.end(); ++it){
896 Log() << kWARNING << it->first <<Endl;
897 std::ostringstream oss;
898 (it->second)->Print(oss);
899 Log()<<oss.str();
900 Log()<<Endl;
901 }
903 tunedParameters=optimize.optimize();
904
905 return tunedParameters;
906
907}
908
909////////////////////////////////////////////////////////////////////////////////
910/// Set the tuning parameters according to the argument
912{
913 std::map<TString,Double_t>::iterator it;
914 if( fTheKernel == "RBF" ){
915 for(it=tuneParameters.begin(); it!=tuneParameters.end(); ++it){
916 Log() << kWARNING << it->first << " = " << it->second << Endl;
917 if (it->first == "Gamma"){
918 SetGamma (it->second);
919 }
920 else if(it->first == "C"){
921 SetCost (it->second);
922 }
923 else {
924 Log() << kFATAL << " SetParameter for " << it->first << " not implemented " << Endl;
925 }
926 }
927 }
928 else if( fTheKernel == "MultiGauss" ){
929 fmGamma.clear();
930 for(int i=0; i<fNumVars; i++){
931 stringstream s;
932 s << fVarNames.at(i);
933 string str = "Gamma_" + s.str();
934 Log() << kWARNING << tuneParameters.find(str)->first << " = " << tuneParameters.find(str)->second << Endl;
935 fmGamma.push_back(tuneParameters.find(str)->second);
936 }
937 for(it=tuneParameters.begin(); it!=tuneParameters.end(); ++it){
938 if (it->first == "C"){
939 Log() << kWARNING << it->first << " = " << it->second << Endl;
940 SetCost(it->second);
941 break;
942 }
943 }
944 }
945 else if( fTheKernel == "Polynomial" ){
946 for(it=tuneParameters.begin(); it!=tuneParameters.end(); ++it){
947 Log() << kWARNING << it->first << " = " << it->second << Endl;
948 if (it->first == "Order"){
949 SetOrder(it->second);
950 }
951 else if (it->first == "Theta"){
952 SetTheta(it->second);
953 }
954 else if(it->first == "C"){ SetCost (it->second);
955 }
956 else if(it->first == "Mult"){
957 SetMult(it->second);
958 }
959 else{
960 Log() << kFATAL << " SetParameter for " << it->first << " not implemented " << Endl;
961 }
962 }
963 }
964 else if( fTheKernel == "Prod" || fTheKernel == "Sum"){
965 fmGamma.clear();
966 for(it=tuneParameters.begin(); it!=tuneParameters.end(); ++it){
967 bool foundParam = false;
968 Log() << kWARNING << it->first << " = " << it->second << Endl;
969 for(int i=0; i<fNumVars; i++){
970 stringstream s;
971 s << fVarNames.at(i);
972 string str = "Gamma_" + s.str();
973 if(it->first == str){
974 fmGamma.push_back(it->second);
975 foundParam = true;
976 }
977 }
978 if (it->first == "Gamma"){
979 SetGamma (it->second);
980 foundParam = true;
981 }
982 else if (it->first == "Order"){
983 SetOrder (it->second);
984 foundParam = true;
985 }
986 else if (it->first == "Theta"){
987 SetTheta (it->second);
988 foundParam = true;
989 }
990 else if (it->first == "C"){ SetCost (it->second);
991 SetCost (it->second);
992 foundParam = true;
993 }
994 else{
995 if(!foundParam){
996 Log() << kFATAL << " SetParameter for " << it->first << " not implemented " << Endl;
997 }
998 }
999 }
1000 }
1001 else {
1002 Log() << kWARNING << fTheKernel << " is not a recognised kernel function." << Endl;
1003 exit(1);
1004 }
1005}
1006
1007////////////////////////////////////////////////////////////////////////////////
1008/// Takes as input a string of values for multigaussian gammas and splits it, filling the
1009/// gamma vector required by the SVKernelFunction. Example: "GammaList=0.1,0.2,0.3" would
1010/// make a vector with Gammas of 0.1,0.2 & 0.3 corresponding to input variables 1,2 & 3
1011/// respectively.
1012void TMVA::MethodSVM::SetMGamma(std::string & mg){
1013 std::stringstream tempstring(mg);
1014 Float_t value;
1015 while (tempstring >> value){
1016 fmGamma.push_back(value);
1017
1018 if (tempstring.peek() == ','){
1019 tempstring.ignore();
1020 }
1021 }
1022}
1023
1024////////////////////////////////////////////////////////////////////////////////
1025/// Produces GammaList string for multigaussian kernel to be written to xml file
1026void TMVA::MethodSVM::GetMGamma(const std::vector<float> & gammas){
1027 std::ostringstream tempstring;
1028 for(UInt_t i = 0; i<gammas.size(); ++i){
1029 tempstring << gammas.at(i);
1030 if(i!=(gammas.size()-1)){
1031 tempstring << ",";
1032 }
1033 }
1034 fGammaList= tempstring.str();
1035}
1036
1037////////////////////////////////////////////////////////////////////////////////
1038/// MakeKernelList
1039/// Function providing string manipulation for product or sum of kernels functions
1040/// to take list of kernels specified in the booking of the method and provide a vector
1041/// of SV kernels to iterate over in SVKernelFunction.
1042///
1043/// Example:
1044///
1045/// "KernelList=RBF*Polynomial" would use a product of the RBF and Polynomial
1046/// kernels.
1047
1048std::vector<TMVA::SVKernelFunction::EKernelType> TMVA::MethodSVM::MakeKernelList(std::string multiKernels, TString kernel)
1049{
1050 std::vector<TMVA::SVKernelFunction::EKernelType> kernelsList;
1051 std::stringstream tempstring(multiKernels);
1052 std::string value;
1053 if(kernel=="Prod"){
1054 while (std::getline(tempstring,value,'*')){
1055 if(value == "RBF"){ kernelsList.push_back(SVKernelFunction::kRBF);}
1056 else if(value == "MultiGauss"){
1058 if(fGammas!=""){
1059 SetMGamma(fGammas);
1060 }
1061 }
1062 else if(value == "Polynomial"){ kernelsList.push_back(SVKernelFunction::kPolynomial);}
1063 else {
1064 Log() << kWARNING << value << " is not a recognised kernel function." << Endl;
1065 exit(1);
1066 }
1067 }
1068 }
1069 else if(kernel=="Sum"){
1070 while (std::getline(tempstring,value,'+')){
1071 if(value == "RBF"){ kernelsList.push_back(SVKernelFunction::kRBF);}
1072 else if(value == "MultiGauss"){
1074 if(fGammas!=""){
1075 SetMGamma(fGammas);
1076 }
1077 }
1078 else if(value == "Polynomial"){ kernelsList.push_back(SVKernelFunction::kPolynomial);}
1079 else {
1080 Log() << kWARNING << value << " is not a recognised kernel function." << Endl;
1081 exit(1);
1082 }
1083 }
1084 }
1085 else {
1086 Log() << kWARNING << "Unable to split MultiKernels. Delimiters */+ required." << Endl;
1087 exit(1);
1088 }
1089 return kernelsList;
1090}
1091
1092////////////////////////////////////////////////////////////////////////////////
1093/// GetTuningOptions
1094/// Function to allow for ranges and number of steps (for scan) when optimising kernel
1095/// function parameters. Specified when booking the method after the parameter to be
1096/// optimised between square brackets with each value separated by ;, the first value
1097/// is the lower limit, the second the upper limit and the third is the number of steps.
1098/// Example: "Tune=Gamma[0.01;1.0;100]" would only tune the RBF Gamma between 0.01 and
1099/// 100 steps.
1100std::map< TString,std::vector<Double_t> > TMVA::MethodSVM::GetTuningOptions()
1101{
1102 std::map< TString,std::vector<Double_t> > optVars;
1103 std::stringstream tempstring(fTune);
1104 std::string value;
1105 while (std::getline(tempstring,value,',')){
1106 unsigned first = value.find('[')+1;
1107 unsigned last = value.find_last_of(']');
1108 std::string optParam = value.substr(0,first-1);
1109 std::stringstream strNew (value.substr(first,last-first));
1111 std::vector<Double_t> tempVec;
1112 UInt_t i = 0;
1113 while (strNew >> optInterval){
1114 tempVec.push_back(optInterval);
1115 if (strNew.peek() == ';'){
1116 strNew.ignore();
1117 }
1118 ++i;
1119 }
1120 if(i != 3 && i == tempVec.size()){
1121 if(optParam == "C" || optParam == "Gamma" || optParam == "GammaList" || optParam == "Theta"){
1122 switch(i){
1123 case 0:
1124 tempVec.push_back(0.01);
1125 case 1:
1126 tempVec.push_back(1.);
1127 case 2:
1128 tempVec.push_back(100);
1129 }
1130 }
1131 else if(optParam == "Order"){
1132 switch(i){
1133 case 0:
1134 tempVec.push_back(1);
1135 case 1:
1136 tempVec.push_back(10);
1137 case 2:
1138 tempVec.push_back(10);
1139 }
1140 }
1141 else{
1142 Log() << kWARNING << optParam << " is not a recognised tuneable parameter." << Endl;
1143 exit(1);
1144 }
1145 }
1146 optVars.insert(std::pair<TString,std::vector<Double_t> >(optParam,tempVec));
1147 }
1148 return optVars;
1149}
1150
1151////////////////////////////////////////////////////////////////////////////////
1152/// getLoss
1153/// Calculates loss for testing dataset. The loss function can be specified when
1154/// booking the method, otherwise defaults to hinge loss. Currently not used however
1155/// is accesible if required.
1156
1158 Double_t loss = 0.0;
1159 Double_t sumW = 0.0;
1160 Double_t temp = 0.0;
1161 Data()->SetCurrentType(Types::kTesting);
1162 ResultsClassification* mvaRes = dynamic_cast<ResultsClassification*> ( Data()->GetResults(GetMethodName(),Types::kTesting, Types::kClassification) );
1163 for (Long64_t ievt=0; ievt<GetNEvents(); ievt++) {
1164 const Event* ev = GetEvent(ievt);
1165 Float_t v = (*mvaRes)[ievt][0];
1166 Float_t w = ev->GetWeight();
1167 if(DataInfo().IsSignal(ev)){
1168 if(lossFunction == "hinge"){
1169 temp += w*(1-v);
1170 }
1171 else if(lossFunction == "exp"){
1172 temp += w*TMath::Exp(-v);
1173 }
1174 else if(lossFunction == "binomial"){
1175 temp += w*TMath::Log(1+TMath::Exp(-2*v));
1176 }
1177 else{
1178 Log() << kWARNING << lossFunction << " is not a recognised loss function." << Endl;
1179 exit(1);
1180 }
1181 }
1182 else{
1183 if(lossFunction == "hinge"){
1184 temp += w*v;
1185 }
1186 else if(lossFunction == "exp"){
1187 temp += w*TMath::Exp(-(1-v));
1188 }
1189 else if(lossFunction == "binomial"){
1190 temp += w*TMath::Log(1+TMath::Exp(-2*(1-v)));
1191 }
1192 else{
1193 Log() << kWARNING << lossFunction << " is not a recognised loss function." << Endl;
1194 exit(1);
1195 }
1196 }
1197 sumW += w;
1198 }
1199 loss = temp/sumW;
1200
1201 return loss;
1202}
#define REGISTER_METHOD(CLASS)
for example
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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
TVectorT< Double_t > TVectorD
Definition TVectorDfwd.h:23
const_iterator begin() const
const_iterator end() const
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
Class that contains all the data information.
Definition DataSetInfo.h:62
The TMVA::Interval Class.
Definition Interval.h:61
Virtual base Class for all MVA method.
Definition MethodBase.h:82
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
SMO Platt's SVM classifier with Keerthi & Shavade improvements.
Definition MethodSVM.h:61
Double_t getLoss(TString lossFunction)
getLoss Calculates loss for testing dataset.
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 ReadWeightsFromXML(void *wghtnode) override
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 GetHelpMessage() const override
get help message text
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.
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
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.
void ProcessOptions() override
option post processing (if necessary)
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...
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr) override
returns MVA value for given event
void ReadWeightsFromStream(std::istream &istr) override
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
MethodSVM(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
standard constructor
Definition MethodSVM.cxx:89
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::map< TString, Double_t > optimize()
Class that is the base-class for a vector of result.
Event class for Support Vector Machine.
Definition SVEvent.h:40
Kernel for Support Vector Machine.
Working class for Support Vector Machine.
Timing information for training and evaluation of MVA methods.
Definition Timer.h:58
void ReadTVectorDFromXML(void *node, const char *name, TVectorD *vec)
Definition Tools.cxx:1242
const TString & Color(const TString &)
human readable color strings
Definition Tools.cxx:803
void WriteTVectorDToXML(void *node, const char *name, TVectorD *vec)
Definition Tools.cxx:1234
void ReadAttr(void *node, const char *, T &value)
read attribute from xml
Definition Tools.h:329
void * GetChild(void *parent, const char *childname=nullptr)
get child node
Definition Tools.cxx:1125
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
add attribute to xml
Definition Tools.h:347
TString StringFromInt(Long_t i)
string tools
Definition Tools.cxx:1198
void * AddChild(void *parent, const char *childname, const char *content=nullptr, bool isRootNode=false)
add child node
Definition Tools.cxx:1099
void * GetNextChild(void *prevchild, const char *childname=nullptr)
XML helpers.
Definition Tools.cxx:1137
Singleton class for Global types used by TMVA.
Definition Types.h:71
@ kClassification
Definition Types.h:127
@ kRegression
Definition Types.h:128
@ kTraining
Definition Types.h:143
Basic string class.
Definition TString.h:138
create variable transformations
Tools & gTools()
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Definition TMath.h:722
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:769