iRoCS Toolbox  1.1.0
Kernel.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2004-2015 Olaf Ronneberger, Florian Pigorsch, Jörg Mechnich,
4  * Thorsten Falk
5  *
6  * Image Analysis Lab, University of Freiburg, Germany
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  **************************************************************************/
23 
24 /**************************************************************************
25 ** Title:
26 ** $RCSfile$
27 ** $Revision: 509 $$Name$
28 ** $Date: 2004-09-03 13:35:04 +0200 (Fri, 03 Sep 2004) $
29 ** Copyright: LGPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.2 2004/09/03 11:35:04 ronneber
38 ** - replaced Chi-Jen Lin's own min,max,swap with std::min,
39 ** std::max. std::swap to compile with programs, that "#include
40 ** <algorithm>" and do a "using namespace std;"
41 **
42 ** Revision 1.1 2004/08/26 08:36:58 ronneber
43 ** initital import
44 **
45 **
46 **
47 **************************************************************************/
48 
49 #ifndef KERNEL_HH
50 #define KERNEL_HH
51 
52 #ifdef HAVE_CONFIG_H
53 #include <config.hh>
54 #endif
55 
56 //
57 // Kernel evaluation
58 //
59 // the static method k_function is for doing single kernel evaluation
60 // the constructor of Kernel prepares to calculate the l*l kernel matrix
61 // the member function get_Q is for getting one column from the Q Matrix
62 //
63 // libsvm -> libsvmtl:
64 // - svm_node is replaced by FV template class
65 // - kernel evaluation is done in given KF template class
66 // - caching of square_x for RBF-kernels is done in BasicFV class
67 //
68 namespace svt
69 {
70  template< typename FV, typename KF>
71  class Kernel {
72  public:
73  Kernel( const KF& kernel, int l, FV * const * x);
74  virtual ~Kernel();
75 
76  private:
77  // forbid copying
78  Kernel( const Kernel<FV,KF>& orig) {}
79  void operator=( const Kernel<FV,KF>& orig) {}
80  public:
81 
82 
83 // static double k_function(const svm_node *x, const svm_node *y,
84 // const svm_parameter& param);
85  virtual Qfloat *get_Q(int column, int len) const = 0;
86  virtual void swap_index(int i, int j) const // no so const...
87  {
88  std::swap(x[i],x[j]);
89  }
90  protected:
91 
92  double kernel_function(int i, int j) const
93  {
94  return _kernel.k_function( *(x[i]), *(x[j]));
95  }
96 
97 
98  private:
99  const FV** x; // array of pointers to feature vectors
100  const KF& _kernel;
101 
102 
103  };
104 }
105 
106 #include "Kernel.icc"
107 #endif
Kernel(const KF &kernel, int l, FV *const *x)
double kernel_function(int i, int j) const
Definition: Kernel.hh:92
virtual Qfloat * get_Q(int column, int len) const =0
float Qfloat
Definition: svm_defines.hh:66
virtual ~Kernel()
virtual void swap_index(int i, int j) const
Definition: Kernel.hh:86