iRoCS Toolbox  1.1.0
TwoClassSVM.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: abstract two class SVM
26 ** $RCSfile$
27 ** $Revision: 766 $$Name$
28 ** $Date: 2005-10-26 09:42:23 +0200 (Wed, 26 Oct 2005) $
29 ** Copyright: LGPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.4 2005/10/26 07:42:23 ronneber
38 ** - corrected some comments (confusion between alpha and decision value)
39 ** - added first version calcGradientCache() and
40 ** gradientOfDecisionFunction() for planned feature selection (not
41 ** functional yet)
42 **
43 ** Revision 1.3 2004/09/13 10:13:13 ronneber
44 ** - adapted to rename SVM -> SVMBase
45 **
46 ** Revision 1.2 2004/09/13 10:04:04 ronneber
47 ** - documentation update
48 **
49 ** Revision 1.1 2004/08/26 08:36:59 ronneber
50 ** initital import
51 **
52 ** Revision 1.9 2003/05/19 11:25:28 ronneber
53 ** - converted from MapTools to ParamMapWrapper
54 ** - added verboseLevel
55 **
56 ** Revision 1.8 2002/09/05 13:10:54 pigorsch
57 ** - modified to use new MapTools
58 **
59 ** Revision 1.7 2002/06/07 11:37:04 ronneber
60 ** - made ModelType in classify() aa own template parameter to make
61 ** it more flexible (e.g. when using a slightly different but
62 ** compatible Feature Vector class)
63 **
64 ** Revision 1.6 2002/05/21 18:55:33 ronneber
65 ** - added const version of kernel()
66 **
67 ** Revision 1.5 2002/05/21 18:31:31 ronneber
68 ** - now all parameters can be queried
69 **
70 ** Revision 1.4 2002/05/13 12:49:07 ronneber
71 ** sync
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:30:51 ronneber
79 ** - removed Parameters struct
80 ** - added setTerminationEpsilon(), setCacheSizeMB(), setShrinkingFlag() instead
81 ** - added typedefs for kernel function and feature vector type
82 ** (for use with MultiClassSVM)
83 **
84 ** Revision 1.1 2002/03/26 12:44:02 ronneber
85 ** restructured for autoconf
86 **
87 ** Revision 1.2 2002/03/13 13:48:13 pigorsch
88 ** * this is now an abstract base class
89 ** * made parameter param of train const
90 **
91 ** Revision 1.1 2002/01/28 13:44:22 pigorsch
92 ** * initial revision
93 **
94 **
95 **
96 **
97 **************************************************************************/
98 
99 #ifndef TWOCLASSSVM_HH
100 #define TWOCLASSSVM_HH
101 
102 #ifdef HAVE_CONFIG_H
103 #include <config.hh>
104 #endif
105 
106 // std includes
107 #include <iostream>
108 #include <string>
109 
110 // libsvmtl includes
111 
112 #include "Model.hh"
113 #include "SVMError.hh"
114 #include "SVMBase.hh"
115 
116 // requirements of template parameters
120 
121 namespace svt
122 {
123 /*======================================================================*/
131 /*======================================================================*/
132  template< typename KF>
133  class TwoClassSVM : public SVMBase<KF>
134  {
135  public:
136 
137  typedef KF KF_type;
138  template< typename FV>
139  struct Traits
140  {
142  };
143 
144 
145 
146  /*====================================================================*/
150  /*====================================================================*/
152  {}
153 
154 
155 
156  /*====================================================================*/
162  /*====================================================================*/
163  TwoClassSVM(const KF& kernel)
164  : SVMBase<KF>( kernel)
165  {}
166 
167 
168 
169  /*====================================================================*/
173  /*====================================================================*/
175  {}
176 
177 
178 
179 
180  /*======================================================================*/
201  /*======================================================================*/
202  template< typename FV, typename ForwardIter>
203  void calcClassificationCache(const FV& testObject,
204  const ForwardIter& SVP_begin,
205  const ForwardIter& SVP_end,
206  std::vector<double>& kernelResultByUID) const;
207 
208  /*======================================================================*/
226  /*======================================================================*/
227  template< typename FV>
228  double classifyWithCache( const Model<FV>& model,
229  const std::vector<double>& kernelResultByUID) const;
230 
231 
232  /*======================================================================*/
250  /*======================================================================*/
251  template< typename FV, typename ForwardIter, typename FVGradient>
252  void calcGradientCache(
253  const FV& testObject,
254  const ForwardIter& SVP_begin,
255  const ForwardIter& SVP_end,
256  std::vector<FVGradient>& gradientOfKernelResultByUID) const;
257 
258 
259 
260 
261  /*======================================================================*/
279  /*======================================================================*/
280  template< typename FV, typename FVGradient>
282  const Model<FV>& model,
283  const std::vector<FVGradient>& gradientOfKernelResultByUID,
284  FVGradient& gradient) const;
285 
286  };
287 
288 #include "TwoClassSVM.icc"
289 
290 }
291 
292 #endif
void calcGradientCache(const FV &testObject, const ForwardIter &SVP_begin, const ForwardIter &SVP_end, std::vector< FVGradient > &gradientOfKernelResultByUID) const
compute the gradient of the kernel Result for given testObject and support vectors.
void calcClassificationCache(const FV &testObject, const ForwardIter &SVP_begin, const ForwardIter &SVP_end, std::vector< double > &kernelResultByUID) const
caculcate the Classification Cache kernelResultByUID, which contains kernel evaluations for classific...
Definition: TwoClassSVM.hh:93
double classifyWithCache(const Model< FV > &model, const std::vector< double > &kernelResultByUID) const
classify testObject (that was passed to calcClassificationCache() before) using the given model...
Definition: TwoClassSVM.hh:118
The SVMBase class is the the base class for all SVM&#39;s.
Definition: SVMBase.hh:101
TwoClassSVM(const KF &kernel)
(description)
Definition: TwoClassSVM.hh:163
svt::Model< FV > ModelType
Definition: TwoClassSVM.hh:141
The TwoClassSVM class is the basic class for TwoClassSVMc and TwoClassSVMnu and maybe some more later...
Definition: TwoClassSVM.hh:133
void gradientOfDecisionFunction(const Model< FV > &model, const std::vector< FVGradient > &gradientOfKernelResultByUID, FVGradient &gradient) const
compute the gradient of the decision function at testObject&#39;s position in the feature space for the g...
~TwoClassSVM()
(description)
Definition: TwoClassSVM.hh:174
KF & kernel()
access the kernel function
Definition: SVMBase.hh:164