iRoCS Toolbox  1.1.0
Kernel_LINEAR.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: LINEAR kernel functor
26 ** $RCSfile$
27 ** $Revision: 2825 $$Name$
28 ** $Date: 2009-09-15 17:04:15 +0200 (Tue, 15 Sep 2009) $
29 ** Copyright: LGPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.7 2005/10/26 07:05:16 ronneber
38 ** - added gradient_of_k_function()
39 **
40 ** Revision 1.6 2005/06/06 21:23:31 haasdonk
41 ** added updateCache() with two FV-lists, required for classification with precomputed kernel-matrices
42 **
43 ** Revision 1.5 2005/03/29 17:53:19 ronneber
44 ** - added clearCache()
45 **
46 ** Revision 1.4 2004/09/13 10:03:24 ronneber
47 ** - documentation update
48 **
49 ** Revision 1.3 2004/09/08 14:28:45 ronneber
50 ** - adapted to new ParamInfo class
51 **
52 ** Revision 1.2 2004/09/03 07:09:12 ronneber
53 ** - updateCache now takes an Accessor
54 **
55 ** Revision 1.1 2004/08/26 08:36:58 ronneber
56 ** initital import
57 **
58 ** Revision 1.4 2003/05/19 10:52:34 ronneber
59 ** - converted from MapTools to ParamMapWrapper
60 ** - added name()
61 **
62 ** Revision 1.3 2002/09/05 13:05:39 pigorsch
63 ** - modfified to use new MapTools
64 **
65 ** Revision 1.2 2002/05/10 11:07:03 ronneber
66 ** - removed FV template for all public classes, because Feature Vector type
67 ** can be extracted automatically from passed iterators or other
68 ** parameters -- this makes the public interface much more intuitive
69 **
70 ** Revision 1.1 2002/03/26 12:44:02 ronneber
71 ** restructured for autoconf
72 **
73 ** Revision 1.2 2002/01/14 13:52:25 pigorsch
74 ** * use FV.dotProduct(...)
75 **
76 ** Revision 1.1 2001/12/11 11:03:00 pigorsch
77 ** Initial Revision
78 **
79 **
80 **
81 **************************************************************************/
82 
83 #ifndef KERNEL_LINEAR_HH
84 #define KERNEL_LINEAR_HH
85 
86 #ifdef HAVE_CONFIG_H
87 #include <config.hh>
88 #endif
89 
90 // std includes
91 #include <map>
92 #include <set>
93 #include <string>
94 
95 // libsvmtl includes
96 #include "ProgressReporter.hh"
97 
98 // requirements of template parameters
100 
101 namespace svt
102 {
103  /*======================================================================*/
109  /*======================================================================*/
111  {
112  public:
114  {};
115 
117  {};
118 
119  template< typename ForwardIter, typename Accessor>
120  void updateCache( const ForwardIter&,
121  const ForwardIter&,
122  Accessor,
123  ProgressReporter*) const
124  {
125  // nothing to do here
126  }
127 
128  // new updateCache-Syntax:
129  template< typename ForwardIter1, typename Accessor1,
130  typename ForwardIter2, typename Accessor2 >
131  void updateCache( const ForwardIter1&,
132  const ForwardIter1&,
133  Accessor1,
134  const ForwardIter2&,
135  const ForwardIter2&,
136  Accessor2,
137  ProgressReporter* = 0) const
138  {
139  // nothing to do here
140  }
141 
142  void clearCache() const
143  {
144  // nothing to do here
145  }
146 
147  template< typename FV>
148  double k_function( const FV& x, const FV& y) const
149  {
150  return x.dotProduct(y);
151  }
152 
153  template< typename FV, typename FVGradient>
154  void gradient_of_k_function( const FV& x, const FV& y,
155  FVGradient& gradient) const
156  {
157  gradient = y;
158  }
159 
160  template<typename STDATA>
161  void loadParameters( STDATA&)
162  {}
163 
164  template<typename STDATA>
165  void saveParameters( STDATA& stData) const
166  {
168  stData.setValue( "kernel_type", name());
169  }
170 
171  static const char* name()
172  {
173  return "linear";
174  }
175 
176  static const char* description()
177  {
178  return "linear kernel: u'*v";
179  }
180 
181  /*======================================================================*/
190  /*======================================================================*/
191  static void getParamInfos( std::vector<ParamInfo>&)
192  {}
193 
194 
195 
196  };
197 }
198 
199 #endif
#define CHECK_MEMBER_TEMPLATE(c)
double k_function(const FV &x, const FV &y) const
void clearCache() const
static const char * name()
void gradient_of_k_function(const FV &x, const FV &y, FVGradient &gradient) const
static const char * description()
The Kernel_LINEAR class specifies a linear kernel function: u&#39;*v.
void updateCache(const ForwardIter1 &, const ForwardIter1 &, Accessor1, const ForwardIter2 &, const ForwardIter2 &, Accessor2, ProgressReporter *=0) const
static void getParamInfos(std::vector< ParamInfo > &)
get information about the parameters, that are used in loadParameters() and saveParameters().
void saveParameters(STDATA &stData) const
void loadParameters(STDATA &)
void updateCache(const ForwardIter &, const ForwardIter &, Accessor, ProgressReporter *) const