iRoCS Toolbox  1.1.0
PlattProb.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: Platts Probability estimates
26 ** $RCSfile$
27 ** $Revision: 604 $$Name$
28 ** $Date: 2005-02-11 13:26:53 +0100 (Fri, 11 Feb 2005) $
29 ** Copyright: GPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.1 2005/02/11 12:26:45 ronneber
38 ** - initial revision
39 **
40 **
41 **
42 **************************************************************************/
43 
44 #ifndef PLATTPROB_HH
45 #define PLATTPROB_HH
46 
47 #ifdef HAVE_CONFIG_H
48 #include <config.hh>
49 #endif
50 
51 #include <PlattProbModel.hh>
52 #include <GroupedTrainingData.hh>
53 
54 namespace svt
55 {
56  template< typename WrappedSVM>
57  class PlattProb
58  {
59 
60  public:
61 
62  template< typename FV>
63  struct Traits
64  {
66  };
67 
68 
69  PlattProb( WrappedSVM* svm = 0)
70  :_svm( svm),
71  _owningSVM( false)
72  {
73  if( _svm == 0)
74  {
75  _svm = new WrappedSVM;
76  _owningSVM = true;
77  }
78  }
79 
81  {
82  if( _owningSVM)
83  {
84  delete _svm;
85  }
86  }
87 
88  private:
89  // forbid copying
90  PlattProb( const PlattProb<WrappedSVM>& orig) {}
91  void operator=( const PlattProb<WrappedSVM>& orig) {}
92  public:
93 
94 
95  static std::string name()
96  {
97  return std::string( "plattprob_") + WrappedSVM::name();
98  }
99 
100  static std::string description()
101  {
102  return std::string( "Platts Probability estimates for ")
103  + WrappedSVM::description();
104  }
105 
106 
107  /*====================================================================*/
118  /*====================================================================*/
119  template<typename FV>
120  void train( const GroupedTrainingData<FV>& trainData,
121  typename Traits<FV>::ModelType& model) const;
122 
123  /*====================================================================*/
140  /*====================================================================*/
141  template<typename ForwardIter>
142  void train( ForwardIter FV_begin, const ForwardIter& FV_end,
143  typename Traits<typename std::iterator_traits<ForwardIter>::value_type>::ModelType& model) const
144  {
145  train( FV_begin, FV_end, model, DirectAccessor());
146  }
147 
148 
149  /*====================================================================*/
171  /*====================================================================*/
172  template<typename ForwardIter, typename Accessor>
173  void train( ForwardIter FV_begin, const ForwardIter& FV_end,
174  typename Traits<typename Accessor::template Traits<ForwardIter>::value_type>::ModelType& model,
175  Accessor accessor) const;
176 
177  /*====================================================================*/
188  /*====================================================================*/
189  template<typename FV>
190  double classify( const FV& testObject,
191  const typename Traits<FV>::ModelType& model) const;
192 
193 
194  private:
195  WrappedSVM* _svm;
196  bool _owningSVM;
197 
198  };
199 
200 }
201 
202 #include "PlattProb.icc"
203 
204 #endif
The GroupedTrainingData class is a container for feature vectors.
svt::PlattProbModel< typename WrappedSVM::Traits< FV >::ModelType > ModelType
Definition: PlattProb.hh:65
void train(ForwardIter FV_begin, const ForwardIter &FV_end, typename Traits< typename std::iterator_traits< ForwardIter >::value_type >::ModelType &model) const
train (STL-like interface) Your feature vector class must provide a method double getLabel()...
Definition: PlattProb.hh:142
void train(const GroupedTrainingData< FV > &trainData, typename Traits< FV >::ModelType &model) const
train SVM with given Feature Vectors.
PlattProb(WrappedSVM *svm=0)
Definition: PlattProb.hh:69
double classify(const FV &testObject, const typename Traits< FV >::ModelType &model) const
standard classification without caching the kernel evaluations.
static std::string name()
Definition: PlattProb.hh:95
static std::string description()
Definition: PlattProb.hh:100