iRoCS Toolbox  1.1.0
TwoClassSVMnu.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: two class NU-SVM
26 ** $RCSfile$
27 ** $Revision: 2824 $$Name$
28 ** $Date: 2009-09-14 09:30:46 +0200 (Mon, 14 Sep 2009) $
29 ** Copyright: GPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.3 2004/09/08 14:40:39 ronneber
38 ** - changed key for two class svm selection from "svm_type" to "two_class_type"
39 ** - adapted to new ParamInfo class
40 **
41 ** Revision 1.2 2004/09/01 14:43:36 ronneber
42 ** changed IterToPointerTraits stuff to
43 ** DirectAccessor and DereferencingAccessor, to make code more
44 ** intuitive understandable
45 **
46 ** Revision 1.1 2004/08/26 08:36:59 ronneber
47 ** initital import
48 **
49 ** Revision 1.8 2003/05/19 11:29:55 ronneber
50 ** - converted from MapTools to ParamMapWrapper
51 **
52 ** Revision 1.7 2002/09/05 13:10:54 pigorsch
53 ** - modified to use new MapTools
54 **
55 ** Revision 1.6 2002/06/07 12:23:15 ronneber
56 ** - clean up of source code
57 **
58 ** - made ModelType in train() an own template parameter to make
59 ** it more flexible (e.g. when using a slightly different but
60 ** compatible Feature Vector class)
61 **
62 ** - added two additional interfaces for train() method
63 **
64 ** - moved functionality of train_one() and solve_nu_svc() method
65 ** into low-level train() method
66 **
67 ** Revision 1.5 2002/06/05 17:18:31 mechnich
68 ** Made minor corrections for compilation under Win32
69 **
70 ** Revision 1.4 2002/05/21 18:31:31 ronneber
71 ** - now all parameters can be queried
72 **
73 ** Revision 1.3 2002/05/10 11:07:03 ronneber
74 ** - removed FV template for all public classes, because Feature Vector type
75 ** can be extracted automatically from passed iterators or other
76 ** parameters -- this makes the public interface much more intuitive
77 **
78 ** Revision 1.2 2002/05/06 13:42:25 ronneber
79 ** - removed Parameters struct
80 ** - added setNu()
81 **
82 ** Revision 1.1 2002/03/26 12:44:02 ronneber
83 ** restructured for autoconf
84 **
85 ** Revision 1.1 2002/03/13 14:08:58 pigorsch
86 ** * initial revision
87 **
88 **
89 **
90 **************************************************************************/
91 
92 #ifndef TWOCLASSSVMNU_HH
93 #define TWOCLASSSVMNU_HH
94 
95 #ifdef HAVE_CONFIG_H
96 #include <config.hh>
97 #endif
98 
99 // std includes
100 #include <map>
101 #include <string>
102 
103 // libsvmtl includes
104 
105 #include "TwoClassSVM.hh"
106 #include "Solver_NU.hh"
107 #include "SVC_Q.hh"
108 #include "DirectAccessor.hh"
109 
110 // requirements of template parameters
113 
114 
115 namespace svt
116 {
117 /*======================================================================*/
124 /*======================================================================*/
125  template< typename KF>
126  class TwoClassSVMnu: public TwoClassSVM<KF>
127  {
128  public:
129 
130  /*====================================================================*/
134  /*====================================================================*/
135  TwoClassSVMnu();
136 
137 
138  /*====================================================================*/
144  /*====================================================================*/
145  TwoClassSVMnu(const KF& kernel);
146 
147 
148  /*====================================================================*/
152  /*====================================================================*/
153  ~TwoClassSVMnu();
154 
155 
156  /*====================================================================*/
167  /*====================================================================*/
168  template<typename FV>
169  void train( const SVM_Problem<FV>& problem,
170  Model<FV>& model) const;
171 
172 
173  /*====================================================================*/
190  /*====================================================================*/
191  template<typename ForwardIter>
192  void train( ForwardIter FV_begin, const ForwardIter& FV_end,
193  svt::Model<typename std::iterator_traits<ForwardIter>::value_type>& model) const
194  {
195  train( FV_begin, FV_end, model, DirectAccessor());
196  }
197 
198 
199  /*====================================================================*/
220  /*====================================================================*/
221  template<typename ForwardIter, typename Accessor>
222  void train( ForwardIter FV_begin, const ForwardIter& FV_end,
223  svt::Model<typename Accessor::template Traits<ForwardIter>::value_type>& model,
224  Accessor accessor) const;
225 
226 
227  /*======================================================================*/
234  /*======================================================================*/
235  void setNu( double nu)
236  {
237  _nu = nu;
238  }
239 
240  double nu() const
241  {
242  return _nu;
243  }
244 
245 
246  /*======================================================================*/
250  /*======================================================================*/
251  template<typename STDATA>
252  void loadParameters( STDATA& stData)
253  {
255 
257  stData.getValue( "nu", _nu);
258  }
259 
260  template<typename STDATA>
261  void saveParameters( STDATA& stData) const
262  {
264 
266  stData.setValue( "two_class_type", name());
267  stData.setValue( "nu", _nu);
268  }
269 
270  static const char* name()
271  {
272  return "nu_svc";
273  }
274 
275  static const char* description()
276  {
277  return "Two class SVM using nu-SVC algorithm for training";
278  }
279 
280  /*======================================================================*/
289  /*======================================================================*/
290  static void getParamInfos( std::vector<ParamInfo>& p)
291  {
292  p.push_back(
293  ParamInfo( "nu", "n", "value",
294  "parameter nu in nu-SVC. (default 0.5)"));
296  }
297 
298  protected:
299  template<typename FV>
300  void solve_nu_svc( const SVM_Problem<FV>* prob,
301  double *alpha,
302  SolutionInfo* si,
303  Model<FV>& model) const;
304 
305 
306 
307  private:
308  double _nu; // Parameter 'nu' for nu-SVM
309  };
310 
311 }
312 
313 #include "TwoClassSVMnu.icc"
314 
315 
316 #endif
double nu() const
static void getParamInfos(std::vector< ParamInfo > &p)
get information about the parameters, that are used in loadParameters() and saveParameters().
Definition: SVMBase.hh:326
#define CHECK_MEMBER_TEMPLATE(c)
~TwoClassSVMnu()
(description)
void solve_nu_svc(const SVM_Problem< FV > *prob, double *alpha, SolutionInfo *si, Model< FV > &model) const
static const char * name()
static void getParamInfos(std::vector< ParamInfo > &p)
get information about the parameters, that are used in loadParameters() and saveParameters().
void loadParameters(STDATA &stData)
Load parameters from structured data object.
Definition: SVMBase.hh:290
static const char * description()
void train(const SVM_Problem< FV > &problem, Model< FV > &model) const
train SVM with given Feature Vectors.
TwoClassSVMnu()
(description)
void saveParameters(STDATA &stData) const
save parameters to structured data object
Definition: SVMBase.hh:306
void setNu(double nu)
set the parameter nu of nu-SVC.
The TwoClassSVM class is the basic class for TwoClassSVMc and TwoClassSVMnu and maybe some more later...
Definition: TwoClassSVM.hh:133
void saveParameters(STDATA &stData) const
void train(ForwardIter FV_begin, const ForwardIter &FV_end, svt::Model< typename std::iterator_traits< ForwardIter >::value_type > &model) const
train (STL-like interface) Your feature vector class must provide a method double getLabel()...
void loadParameters(STDATA &stData)
Load and save parameter nu from map.
The TwoClassSVMnu class (is/provides/specifies/contains)
The ParamInfo class contains informations about one parameter like key, help text, guiHints etc.
Definition: ParamInfo.hh:82
KF & kernel()
access the kernel function
Definition: SVMBase.hh:164