SVKernelMatrix.cxx

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: SVKernelMatrix.cxx 37399 2010-12-08 15:22:07Z evt $
00002 // Author: Andrzej Zemla
00003 
00004 /**********************************************************************************
00005 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006 * Package: TMVA                                                                  *
00007 * Class  : SVKernelMatrix                                                        *
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/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    // constructor
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    // constructor
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    // destructor
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    // returns a row of the kernel matrix
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    // returns an element of the kernel matrix
00101 
00102    if (i > j) return fSVKernelMatrix[i][j]; 
00103    else       return fSVKernelMatrix[j][i]; // it's symmetric, ;)
00104 }

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