00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "TMVA/SVKernelMatrix.h"
00029 #include "TMVA/SVKernelFunction.h"
00030 #include "TMVA/SVEvent.h"
00031 #include <iostream>
00032 #include <stdexcept>
00033 #include "TMVA/MsgLogger.h"
00034
00035
00036 TMVA::SVKernelMatrix::SVKernelMatrix()
00037 : fSize(0),
00038 fKernelFunction(0),
00039 fSVKernelMatrix(0),
00040 fLogger( new MsgLogger("ResultsRegression", kINFO) )
00041 {
00042
00043 }
00044
00045
00046 TMVA::SVKernelMatrix::SVKernelMatrix( std::vector<TMVA::SVEvent*>* inputVectors, SVKernelFunction* kernelFunction )
00047 : fSize(inputVectors->size()),
00048 fKernelFunction(kernelFunction),
00049 fLogger( new MsgLogger("SVKernelMatrix", kINFO) )
00050 {
00051
00052 fSVKernelMatrix = new Float_t*[fSize];
00053 try{
00054 for (UInt_t i = 0; i < fSize; i++) fSVKernelMatrix[i] = new Float_t[i+1];
00055 }catch(...){
00056 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;
00057 }
00058 for (UInt_t i = 0; i < fSize; i++) {
00059 fSVKernelMatrix[i][i] = 2*fKernelFunction->Evaluate((*inputVectors)[i], (*inputVectors)[i]);
00060 for (UInt_t j = 0; j <=i; j++) {
00061 fSVKernelMatrix[i][j] = fKernelFunction->Evaluate((*inputVectors)[i], (*inputVectors)[j]);
00062 }
00063 }
00064 }
00065
00066
00067 TMVA::SVKernelMatrix::~SVKernelMatrix()
00068 {
00069
00070 for (UInt_t i = fSize -1; i > 0; i--) {
00071 delete[] fSVKernelMatrix[i];
00072 fSVKernelMatrix[i] = 0;
00073 }
00074 delete[] fSVKernelMatrix;
00075 fSVKernelMatrix = 0;
00076 }
00077
00078
00079 Float_t* TMVA::SVKernelMatrix::GetLine( UInt_t line )
00080 {
00081
00082
00083 Float_t* fLine = NULL;
00084 if (line >= fSize) {
00085 return NULL;
00086 }
00087 else {
00088 fLine = new Float_t[fSize];
00089 for( UInt_t i = 0; i <line; i++)
00090 fLine[i] = fSVKernelMatrix[line][i];
00091 for( UInt_t i = line; i < fSize; i++)
00092 fLine[i] = fSVKernelMatrix[i][line];
00093 return fLine;
00094 }
00095 }
00096
00097
00098 Float_t TMVA::SVKernelMatrix::GetElement(UInt_t i, UInt_t j)
00099 {
00100
00101
00102 if (i > j) return fSVKernelMatrix[i][j];
00103 else return fSVKernelMatrix[j][i];
00104 }