iRoCS Toolbox  1.1.0
Model_MC_OneVsRest.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: Model for MultiClassSVMOneVsRest SVM
26 ** $RCSfile$
27 ** $Revision: 4820 $$Name$
28 ** $Date: 2011-11-08 10:57:01 +0100 (Tue, 08 Nov 2011) $
29 ** Copyright: GPL $Author: tschmidt $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.2 2004/09/13 10:04:04 ronneber
38 ** - documentation update
39 **
40 ** Revision 1.1 2004/08/26 08:36:59 ronneber
41 ** initital import
42 **
43 **
44 **
45 **************************************************************************/
46 
47 #ifndef MODEL_MC_ONEVSREST_HH
48 #define MODEL_MC_ONEVSREST_HH
49 
50 #ifdef HAVE_CONFIG_H
51 #include <config.hh>
52 #endif
53 
54 #include <vector>
55 #include "Model_MC.hh"
56 
57 // requirements of template parameters
61 
62 namespace svt
63 {
64 
65 
66 template< typename TCModel>
67 class Model_MC_OneVsRest : public Model_MC<TCModel>
68 {
70 
71 public:
72 
73  typedef typename TCModel::FV_type FV;
74 
75  void resizeModelsVector( unsigned int nClasses)
76  {
77  _modelsVector.resize( nClasses);
78  }
79 
80  unsigned int nClasses() const
81  {
82  return static_cast<unsigned int>(_modelsVector.size());
83  }
84 
85  unsigned int nTwoClassModels() const
86  {
87  return static_cast<unsigned int>(_modelsVector.size());
88  }
89 
90  TCModel& twoClassModel( unsigned int classIndex)
91  {
92  return _modelsVector[classIndex];
93  }
94 
95  const TCModel& twoClassModel( unsigned int classIndex) const
96  {
97  return _modelsVector[classIndex];
98  }
99 
101  {
103  _modelsVector.begin(), _modelsVector.end());
104  }
105 
106  template< typename STDATA>
107  void saveTCTrainingInfos( STDATA& statistics)
108  {
110 
111  /*---------------------------------------------------------------
112  * Run throgh all two-class models and store their training infos
113  *---------------------------------------------------------------*/
114  for( unsigned int classIndex = 0; classIndex < _modelsVector.size();
115  ++classIndex)
116  {
117  std::ostringstream prefix_os;
118  prefix_os << classIndex << "vsRest_";
119  _modelsVector[classIndex].saveTrainingInfo( statistics,
120  prefix_os.str());
121  }
122  }
123 
124 
125  template< typename STDATA>
126  void saveTrainingInfoStatistics( STDATA& statistics)
127  {
129 
131  _modelsVector.begin(), _modelsVector.end(), statistics);
132  }
133 
134  /*======================================================================*/
148  /*======================================================================*/
149  template<typename STDATA>
150  void saveParameters( STDATA& stData) const;
151 
152  /*======================================================================*/
164  /*======================================================================*/
165  template<typename STDATA>
166  void loadParameters( STDATA& stData);
167 
168 
169 private:
170  std::vector< TCModel> _modelsVector;
171 
172 };
173 
174 
175 }
176 
177 
178 #include "Model_MC_OneVsRest.icc"
179 
180 #endif
#define CHECK_MEMBER_TEMPLATE(c)
Ensure that TCMODEL provides minimal functions to be used With Multiclass-Algortithms.
void collectSupportVectorsFromTCModels(const ForwardIter &modelsBegin, const ForwardIter &modelsEnd)
#define CHECK_CLASS_TEMPLATE1(c)
void saveParameters(STDATA &stData) const
save all data from two-class models to Map, where the keys of each model will be prefixed by its posi...
unsigned int nTwoClassModels() const
void loadParameters(STDATA &stData)
load all data from two-class models to Map, where the keys of each model are prefixed by its position...
void resizeModelsVector(unsigned int nClasses)
unsigned int nClasses() const
void saveTCTrainingInfos(STDATA &statistics)
const TCModel & twoClassModel(unsigned int classIndex) const
TCModel & twoClassModel(unsigned int classIndex)
void calcTrainingStatisticsFromTCModels(const ForwardIter &modelsBegin, const ForwardIter &modelsEnd, STDATA &statistics)
void saveTrainingInfoStatistics(STDATA &statistics)