ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SVKernelFunction.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andrzej Zemla
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : SVKernelFunction *
8  * Web : http://tmva.sourceforge.net *
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  * Copyright (c) 2005: *
19  * CERN, Switzerland *
20  * MPI-K Heidelberg, Germany *
21  * PAN, Krakow, Poland *
22  * *
23  * Redistribution and use in source and binary forms, with or without *
24  * modification, are permitted according to the terms listed in LICENSE *
25  * (http://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 #include "TMVA/SVKernelFunction.h"
29 #include "TMVA/SVEvent.h"
30 #include "TMath.h"
31 #include <vector>
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// constructor
35 
37  : fGamma(0.),
38  fKernel(kRBF), // kernel, order, theta, and kappa are for backward compatibility
39  fOrder(0),
40  fTheta(0),
41  fKappa(0)
42 {
43 }
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// constructor
47 
49  : fGamma(gamma),
50  fKernel(kRBF), // kernel, order, theta, and kappa are for backward compatibility
51  fOrder(0),
52  fTheta(0),
53  fKappa(0)
54 {
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// destructor
59 
61 {
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// set old options for compatibility mode
66 
68  fKernel = k;
69  fOrder = order;
70  fTheta = theta;
71  fKappa = kappa;
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 
77 {
78  switch(fKernel) {
79  case kRBF:
80  {
81  std::vector<Float_t> *v1 = ev1->GetDataVector();
82  std::vector<Float_t> *v2 = ev2->GetDataVector();
83 
84  Float_t norm = 0;
85  for (UInt_t i = 0; i < v1->size(); i++) norm += ((*v1)[i] -(*v2)[i]) *((*v1)[i] -(*v2)[i]) ;
86 
87  return TMath::Exp(-norm*fGamma);
88  }
89  case kPolynomial:
90  {
91  std::vector<Float_t> *v1 = ev1->GetDataVector();
92  std::vector<Float_t> *v2 = ev2->GetDataVector();
93  Float_t prod = fTheta;
94  for (UInt_t idx = 0; idx < v1->size(); idx++) prod += (*v1)[idx] * (*v2)[idx];
95 
96  Float_t result = 1.;
97  Int_t i = fOrder;
98  for (; i > 0; i /= 2) {
99  if (i%2) result = prod;
100  prod *= prod;
101  }
102  return result;
103  }
104  case kLinear:
105  {
106  std::vector<Float_t> *v1 = ev1->GetDataVector();
107  std::vector<Float_t> *v2 = ev2->GetDataVector();
108  Float_t prod = 0;
109  for (UInt_t i = 0; i < v1->size(); i++) prod += (*v1)[i] * (*v2)[i];
110  return prod;
111  }
112  case kSigmoidal:
113  {
114  std::vector<Float_t> *v1 = ev1->GetDataVector();
115  std::vector<Float_t> *v2 = ev2->GetDataVector();
116  Float_t prod = 0;
117  for (UInt_t i = 0; i < v1->size(); i++) prod += ((*v1)[i] -(*v2)[i]) *((*v1)[i] -(*v2)[i]) ;
118  prod *= fKappa;
119  prod += fTheta;
120  return TMath::TanH( prod );
121  }
122  }
123  return 0;
124 }
125 
Double_t TanH(Double_t)
Definition: TMath.h:436
const Double_t * v1
Definition: TArcBall.cxx:33
float Float_t
Definition: RtypesCore.h:53
Float_t theta
Definition: shapesAnim.C:5
int Int_t
Definition: RtypesCore.h:41
void setCompatibilityParams(EKernelType k, UInt_t order, Float_t theta, Float_t kappa)
set old options for compatibility mode
double gamma(double x)
unsigned int UInt_t
Definition: RtypesCore.h:42
Double_t Exp(Double_t x)
Definition: TMath.h:495
double result[121]
std::vector< Float_t > * GetDataVector()
Definition: SVEvent.h:62
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
Float_t Evaluate(SVEvent *ev1, SVEvent *ev2)
SVKernelFunction()
constructor