iRoCS Toolbox  1.1.0
Kernel_SIGMOID.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: SIGMOID 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/06/06 21:23:31 haasdonk
38 ** added updateCache() with two FV-lists, required for classification with precomputed kernel-matrices
39 **
40 ** Revision 1.6 2005/03/29 17:57:05 ronneber
41 ** - added clearCache()
42 **
43 ** Revision 1.5 2004/09/13 10:12:45 ronneber
44 ** - corrected description()
45 **
46 ** Revision 1.4 2004/09/13 10:04:04 ronneber
47 ** - documentation update
48 **
49 ** Revision 1.3 2004/09/08 14:30:39 ronneber
50 ** - adapted to new ParamInfo class
51 **
52 ** Revision 1.2 2004/09/03 07:11:50 ronneber
53 ** - updateCache now takes an Accessor
54 **
55 ** Revision 1.1 2004/08/26 08:36:59 ronneber
56 ** initital import
57 **
58 ** Revision 1.6 2003/05/19 10:54:16 ronneber
59 ** - converted from MapTools to ParamMapWrapper
60 ** - added name()
61 **
62 ** Revision 1.5 2002/09/05 13:05:39 pigorsch
63 ** - modfified to use new MapTools
64 **
65 ** Revision 1.4 2002/05/21 18:22:40 ronneber
66 ** - now all parameters can be queried
67 **
68 ** Revision 1.3 2002/05/10 11:34:14 ronneber
69 ** - added methods to modify Parameters later
70 **
71 ** Revision 1.2 2002/05/10 11:07:03 ronneber
72 ** - removed FV template for all public classes, because Feature Vector type
73 ** can be extracted automatically from passed iterators or other
74 ** parameters -- this makes the public interface much more intuitive
75 **
76 ** Revision 1.1 2002/03/26 12:44:02 ronneber
77 ** restructured for autoconf
78 **
79 ** Revision 1.2 2002/01/14 13:53:20 pigorsch
80 ** * use FV.dotProduct(...)
81 **
82 ** Revision 1.1 2001/12/11 11:03:00 pigorsch
83 ** Initial Revision
84 **
85 **
86 **
87 **************************************************************************/
88 
89 #ifndef KERNEL_SIGMOID_HH
90 #define KERNEL_SIGMOID_HH
91 
92 #ifdef HAVE_CONFIG_H
93 #include <config.hh>
94 #endif
95 
96 // std includes
97 #include <cmath>
98 #include <map>
99 #include <set>
100 #include <string>
101 
102 // libsvmtl includes
103 #include "ProgressReporter.hh"
104 
105 // requirements of template parameters
107 
108 namespace svt
109 {
110  /*======================================================================*/
117  /*======================================================================*/
119  {
120  public:
122  double gamma=1.,
123  double coef0=0.)
124  :p_gamma(gamma),
125  p_coef0(coef0)
126  {};
127 
129  {};
130 
131  void setGamma( double gamma) { p_gamma = gamma; }
132  void setCoef0( double coef0) { p_coef0 = coef0; }
133  double gamma() const { return p_gamma; }
134  double coef0() const { return p_coef0; }
135 
136  template< typename ForwardIter, typename Accessor>
137  void updateCache( const ForwardIter&,
138  const ForwardIter&,
139  Accessor,
140  ProgressReporter*) const
141  {
142  // nothing to do here
143  }
144 
145 
146  // new updateCache-Syntax:
147  template< typename ForwardIter1, typename Accessor1,
148  typename ForwardIter2, typename Accessor2 >
149  void updateCache( const ForwardIter1&,
150  const ForwardIter1&,
151  Accessor1,
152  const ForwardIter2&,
153  const ForwardIter2&,
154  Accessor2,
155  ProgressReporter* = 0) const
156  {
157  // nothing to do here
158  }
159 
160  void clearCache() const
161  {
162  // nothing to do here
163  }
164 
165  template< typename FV>
166  double k_function( const FV& x, const FV& y) const
167  {
168  return tanh(p_gamma*x.dotProduct(y)+p_coef0);
169  }
170 
171  template<typename STDATA>
172  void loadParameters( STDATA& stData)
173  {
175  stData.getValue( "gamma", p_gamma);
176  stData.getValue( "coef0", p_coef0);
177  }
178 
179  template<typename STDATA>
180  void saveParameters( STDATA& stData) const
181  {
183  stData.setValue( "kernel_type", name());
184  stData.setValue( "gamma", p_gamma);
185  stData.setValue( "coef0", p_coef0);
186  }
187 
188  static const char* name()
189  {
190  return "sigmoid";
191  }
192 
193  static const char* description()
194  {
195  return "sigmoid kernel: tanh(gamma*u'*v + coef0)";
196  }
197 
198  /*======================================================================*/
207  /*======================================================================*/
208  static void getParamInfos( std::vector<ParamInfo>& p)
209  {
210  p.push_back(
211  ParamInfo( "gamma", "g", "value",
212  "gamma for sigmoid kernel. (default 1)"));
213  p.push_back(
214  ParamInfo( "coef0", "r", "value",
215  "coef0 for sigmoid kernel. (default 0)"));
216  }
217 
218  protected:
219  double p_gamma;
220  double p_coef0;
221  };
222 }
223 
224 #endif
#define CHECK_MEMBER_TEMPLATE(c)
double coef0() const
void setGamma(double gamma)
void loadParameters(STDATA &stData)
The Kernel_SIGMOID class specifies a sigmoid kernel function: tanh(gamma*u&#39;*v + coef0) ...
double k_function(const FV &x, const FV &y) const
static void getParamInfos(std::vector< ParamInfo > &p)
get information about the parameters, that are used in loadParameters() and saveParameters().
static const char * name()
void clearCache() const
Kernel_SIGMOID(double gamma=1., double coef0=0.)
void saveParameters(STDATA &stData) const
void setCoef0(double coef0)
void updateCache(const ForwardIter1 &, const ForwardIter1 &, Accessor1, const ForwardIter2 &, const ForwardIter2 &, Accessor2, ProgressReporter *=0) const
The ParamInfo class contains informations about one parameter like key, help text, guiHints etc.
Definition: ParamInfo.hh:82
double gamma() const
void updateCache(const ForwardIter &, const ForwardIter &, Accessor, ProgressReporter *) const
static const char * description()