iRoCS Toolbox  1.1.0
Kernel_DS_RBF.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: Kernel_DS_RBF.hh
26 ** $RCSfile$
27 ** $Revision: 740 $$Name$
28 ** $Date: 2005-07-19 15:42:59 +0200 (Tue, 19 Jul 2005) $
29 ** Copyright: LGPL $Author: haasdonk $
30 ** Description: DS_RBF kernel functor
31 ** Distance-Substitution-RBF Kernel
32 **
33 **-------------------------------------------------------------------------
34 **
35 ** $Log$
36 ** Revision 1.2 2005/07/19 13:42:59 haasdonk
37 ** adapted header for automatic CVS-Information extraction
38 **
39 **
40 **************************************************************************/
41 
42 #ifndef KERNEL_DS_RBF_HH
43 #define KERNEL_DS_RBF_HH
44 
45 #ifdef HAVE_CONFIG_H
46 #include <config.hh>
47 #endif
48 
49 // std includes
50 #include <cmath>
51 #include <map>
52 #include <set>
53 #include <string>
54 
55 // libsvmtl includes
56 #include "ProgressReporter.hh"
57 
58 // requirements of template parameters
61 
62 namespace svt
63 {
64 
65  template< typename KERNEL>
67  {
68  public:
69  Kernel_DS_RBF(double gamma=1.)
70  :p_gamma(gamma)
71  {};
72 
74  {};
75 
76  void setGamma( double gamma) { p_gamma = gamma; }
77  double gamma() const { return p_gamma; }
78 
79  // new updateCache-Syntax:
80  template< typename ForwardIter1, typename Accessor1,
81  typename ForwardIter2, typename Accessor2 >
82  void updateCache( const ForwardIter1& fvBegin1,
83  const ForwardIter1& fvEnd1,
84  Accessor1 accessor1,
85  const ForwardIter2& fvBegin2,
86  const ForwardIter2& fvEnd2,
87  Accessor2 accessor2,
88  ProgressReporter* pr = 0) const
89  {
90  _kernel.updateCache(fvBegin1, fvEnd1,accessor1,
91  fvBegin2,fvEnd2,accessor2,pr);
92  }
93 
94  // old updateCache-Syntax:
95 
96  template< typename ForwardIter, typename Accessor>
97  void updateCache( const ForwardIter& fvBegin,
98  const ForwardIter& fvEnd,
99  Accessor accessor,
100  ProgressReporter* pr = 0) const
101  {
102  _kernel.updateCache(fvBegin, fvEnd,accessor,pr);
103  }
104 
105  void clearCache() const
106  {
107  // nothing to do here
108  }
109 
110  template< typename FV>
111  double k_function( const FV& x, const FV& y) const
112  {
115  return exp(-p_gamma* _kernel.k_function(x,y));
116  };
117 
118  template<typename STDATA>
119  void loadParameters( STDATA& stData)
120  {
122  if( stData.valueExists( "gamma"))
123  {
124  stData.getValue( "gamma", p_gamma);
125  }
126  _kernel.loadParameters(stData);
127  };
128 
129  template<typename STDATA>
130  void saveParameters( STDATA& stData) const
131  {
133  _kernel.saveParameters(stData);
134  stData.setValue( "kernel_type", name());
135  stData.setValue( "gamma", p_gamma);
136  };
137 
138  static std::string name()
139  {
140  return std::string("DS_rbf_") + KERNEL::name();
141  }
142 
143  static const char* description()
144  {
145  return "distance substitution radial basis function"
146  " kernel: exp(-gamma*d^2)";
147  }
148 
149  static void getParamInfos( std::vector<ParamInfo>& p)
150  {
151  p.push_back(
152  ParamInfo( "gamma", "g", "value",
153  "gamma for DS-rbf-kernel. (default 1.0)"));
154  KERNEL::getParamInfos(p);
155  }
156 
157  protected:
158  KERNEL _kernel;
159  double p_gamma;
160  };
161 }
162 
163 #endif
164 
165 
166 
167 
168 
169 
static std::string name()
void updateCache(const ForwardIter1 &fvBegin1, const ForwardIter1 &fvEnd1, Accessor1 accessor1, const ForwardIter2 &fvBegin2, const ForwardIter2 &fvEnd2, Accessor2 accessor2, ProgressReporter *pr=0) const
#define CHECK_MEMBER_TEMPLATE(c)
void setGamma(double gamma)
Kernel_DS_RBF(double gamma=1.)
void updateCache(const ForwardIter &fvBegin, const ForwardIter &fvEnd, Accessor accessor, ProgressReporter *pr=0) const
double gamma() const
static void getParamInfos(std::vector< ParamInfo > &p)
void loadParameters(STDATA &stData)
double k_function(const FV &x, const FV &y) const
void saveParameters(STDATA &stData) const
void clearCache() const
static const char * description()
The ParamInfo class contains informations about one parameter like key, help text, guiHints etc.
Definition: ParamInfo.hh:82