ROOT  6.06/09
Reference Guide
SVKernelMatrix.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 : SVKernelMatrix *
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/SVKernelMatrix.h"
29 #include "TMVA/SVKernelFunction.h"
30 #include "TMVA/SVEvent.h"
31 #include <iostream>
32 #include <stdexcept>
33 #include "TMVA/MsgLogger.h"
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// constructor
37 
39  : fSize(0),
40  fKernelFunction(0),
41  fSVKernelMatrix(0),
42  fLogger( new MsgLogger("ResultsRegression", kINFO) )
43 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// constructor
48 
49 TMVA::SVKernelMatrix::SVKernelMatrix( std::vector<TMVA::SVEvent*>* inputVectors, SVKernelFunction* kernelFunction )
50  : fSize(inputVectors->size()),
51  fKernelFunction(kernelFunction),
52  fLogger( new MsgLogger("SVKernelMatrix", kINFO) )
53 {
55  try{
56  for (UInt_t i = 0; i < fSize; i++) fSVKernelMatrix[i] = new Float_t[i+1];
57  }catch(...){
58  Log() << kFATAL << "Input data too large. Not enough memory to allocate memory for Support Vector Kernel Matrix. Please reduce the number of input events or use a different method."<<Endl;
59  }
60  for (UInt_t i = 0; i < fSize; i++) {
61  fSVKernelMatrix[i][i] = 2*fKernelFunction->Evaluate((*inputVectors)[i], (*inputVectors)[i]);
62  for (UInt_t j = 0; j <=i; j++) {
63  fSVKernelMatrix[i][j] = fKernelFunction->Evaluate((*inputVectors)[i], (*inputVectors)[j]);
64  }
65  }
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// destructor
70 
72 {
73  for (UInt_t i = fSize -1; i > 0; i--) {
74  delete[] fSVKernelMatrix[i];
75  fSVKernelMatrix[i] = 0;
76  }
77  delete[] fSVKernelMatrix;
78  fSVKernelMatrix = 0;
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// returns a row of the kernel matrix
83 
85 {
86  Float_t* fLine = NULL;
87  if (line >= fSize) {
88  return NULL;
89  }
90  else {
91  fLine = new Float_t[fSize];
92  for( UInt_t i = 0; i <line; i++)
93  fLine[i] = fSVKernelMatrix[line][i];
94  for( UInt_t i = line; i < fSize; i++)
95  fLine[i] = fSVKernelMatrix[i][line];
96  return fLine;
97  }
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// returns an element of the kernel matrix
102 
104 {
105  if (i > j) return fSVKernelMatrix[i][j];
106  else return fSVKernelMatrix[j][i]; // it's symmetric, ;)
107 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
Float_t * GetLine(UInt_t)
returns a row of the kernel matrix
TLine * line
float Float_t
Definition: RtypesCore.h:53
SVKernelFunction * fKernelFunction
Float_t ** fSVKernelMatrix
MsgLogger & Log() const
message logger
Float_t GetElement(UInt_t i, UInt_t j)
returns an element of the kernel matrix
~SVKernelMatrix()
destructor
unsigned int UInt_t
Definition: RtypesCore.h:42
SVKernelMatrix()
constructor
#define NULL
Definition: Rtypes.h:82
Float_t Evaluate(SVEvent *ev1, SVEvent *ev2)