SVKernelFunction.cxx

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: SVKernelFunction.cxx 31569 2009-12-05 13:12:39Z stelzer $
00002 // Author: Andrzej Zemla
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : SVKernelFunction                                                      *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Implementation                                                            *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Marcin Wolter  <Marcin.Wolter@cern.ch> - IFJ PAN, Krakow, Poland          *
00015  *      Andrzej Zemla  <azemla@cern.ch>        - IFJ PAN, Krakow, Poland          *
00016  *      (IFJ PAN: Henryk Niewodniczanski Inst. Nucl. Physics, Krakow, Poland)     *
00017  *                                                                                *
00018  * Copyright (c) 2005:                                                            *
00019  *      CERN, Switzerland                                                         *
00020  *      MPI-K Heidelberg, Germany                                                 *
00021  *      PAN, Krakow, Poland                                                       *
00022  *                                                                                *
00023  * Redistribution and use in source and binary forms, with or without             *
00024  * modification, are permitted according to the terms listed in LICENSE           *
00025  * (http://tmva.sourceforge.net/LICENSE)                                          *
00026  **********************************************************************************/
00027 
00028 #include "TMVA/SVKernelFunction.h"
00029 #include "TMVA/SVEvent.h"
00030 #include "TMath.h"
00031 #include <vector>
00032 
00033 //_______________________________________________________________________
00034 TMVA::SVKernelFunction::SVKernelFunction()
00035    : fGamma(0.),
00036      fKernel(kRBF),  // kernel, order, theta, and kappa are for backward compatibility
00037      fOrder(0),
00038      fTheta(0),
00039      fKappa(0)
00040 {
00041    // constructor
00042 }
00043 
00044 //_______________________________________________________________________
00045 TMVA::SVKernelFunction::SVKernelFunction( Float_t gamma )
00046    : fGamma(gamma),
00047      fKernel(kRBF),  // kernel, order, theta, and kappa are for backward compatibility
00048      fOrder(0),
00049      fTheta(0),
00050      fKappa(0)
00051 {
00052    // constructor
00053 }
00054 
00055 //_______________________________________________________________________
00056 TMVA::SVKernelFunction::~SVKernelFunction() 
00057 {
00058    // destructor
00059 }
00060 
00061 //_______________________________________________________________________
00062 void TMVA::SVKernelFunction::setCompatibilityParams(EKernelType k, UInt_t order, Float_t theta, Float_t kappa) {
00063    // set old options for compatibility mode
00064    fKernel = k;
00065    fOrder = order;
00066    fTheta = theta;
00067    fKappa = kappa;
00068 }
00069 
00070 //_______________________________________________________________________
00071 Float_t TMVA::SVKernelFunction::Evaluate( SVEvent* ev1, SVEvent* ev2 )
00072 {
00073 
00074    switch(fKernel) {
00075    case kRBF:
00076       {
00077          std::vector<Float_t> *v1 = ev1->GetDataVector();
00078          std::vector<Float_t> *v2 = ev2->GetDataVector();
00079 
00080          Float_t norm = 0;
00081          for (UInt_t i = 0; i < v1->size(); i++) norm += ((*v1)[i] -(*v2)[i]) *((*v1)[i] -(*v2)[i]) ;
00082 
00083          return TMath::Exp(-norm*fGamma);
00084       }
00085    case kPolynomial:
00086       {
00087          std::vector<Float_t> *v1 = ev1->GetDataVector();
00088          std::vector<Float_t> *v2 = ev2->GetDataVector();
00089          Float_t prod = fTheta;
00090          for (UInt_t idx = 0; idx < v1->size(); idx++) prod += (*v1)[idx] * (*v2)[idx];
00091 
00092          Float_t result = 1.;
00093          Int_t i = fOrder;
00094          for (; i > 0; i /= 2) {
00095             if (i%2) result = prod;
00096             prod *= prod;
00097          }
00098          return result;
00099       }
00100    case kLinear:
00101       {
00102          std::vector<Float_t> *v1 = ev1->GetDataVector();
00103          std::vector<Float_t> *v2 = ev2->GetDataVector();
00104          Float_t prod = 0;
00105          for (UInt_t i = 0; i < v1->size(); i++) prod += (*v1)[i] * (*v2)[i];
00106          return prod;
00107       }
00108    case kSigmoidal:
00109       {
00110          std::vector<Float_t> *v1 = ev1->GetDataVector();
00111          std::vector<Float_t> *v2 = ev2->GetDataVector();
00112          Float_t prod = 0;
00113          for (UInt_t i = 0; i < v1->size(); i++) prod += ((*v1)[i] -(*v2)[i]) *((*v1)[i] -(*v2)[i]) ;
00114          prod *= fKappa;
00115          prod += fTheta;
00116          return TMath::TanH( prod );
00117       }
00118    }
00119    return 0;
00120 }
00121 

Generated on Tue Jul 5 15:25:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1