iRoCS Toolbox  1.1.0
Model_MC_OneVsOne.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 MultiClassSVMOneVsOne 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 2006/01/25 08:53:51 fehr
38 ** added HistIntersect to Kmatrix Kernels and new BasicSVMAdapter interface to TwoClassModels
39 **
40 ** Revision 1.1 2004/08/26 08:36:59 ronneber
41 ** initital import
42 **
43 **
44 **
45 **************************************************************************/
46 
47 
48 #ifndef MODEL_MC_ONEVSONE_HH
49 #define MODEL_MC_ONEVSONE_HH
50 
51 #ifdef HAVE_CONFIG_H
52 #include <config.hh>
53 #endif
54 
55 #include "SVMError.hh"
56 #include "TriangularMatrix.hh"
57 #include "Model_MC.hh"
58 
59 // requirements of template parameters
63 
64 namespace svt
65 {
66 
67 template< typename TCModel>
68 class Model_MC_OneVsOne : public Model_MC<TCModel>
69 {
71 
72 public:
73 
74  typedef typename TCModel::FV_type FV;
75 
76  void resizeTriangularMatrix( unsigned int nClasses)
77  {
78  _triangMat.resizeWidth( nClasses);
79  }
80 
81  unsigned int nClasses() const
82  {
83  return static_cast<unsigned int>(_triangMat.width());
84  }
85 
86  unsigned int nTwoClassModels() const
87  {
88  return static_cast<unsigned int>(_triangMat.nElements());
89  }
90 
91 
92 
93  TCModel& twoClassModel( unsigned int class1, unsigned int class2)
94  {
95  return _triangMat(class1, class2);
96  }
97 
98  const TCModel& twoClassModel( unsigned int class1, unsigned int class2) const
99  {
100  return _triangMat(class1, class2);
101  }
102 
103  const TCModel& twoClassModel( unsigned int class1) const
104  {
105  return _triangMat[class1];
106  }
107 
108  TCModel& twoClassModel( unsigned int class1)
109  {
110  return _triangMat[class1];
111  }
112 
114  {
116  _triangMat.begin(), _triangMat.end());
117  }
118 
119  template< typename STDATA>
120  void saveTCTrainingInfos( STDATA& statistics)
121  {
123 
124  /*---------------------------------------------------------------
125  * Run throgh all two-class models and store their training infos
126  *---------------------------------------------------------------*/
127  for( unsigned int firstClass = 0;
128  firstClass < _triangMat.width()-1; ++firstClass)
129  {
130  for( unsigned int secondClass = firstClass+1;
131  secondClass < _triangMat.width(); ++secondClass)
132  {
133  std::ostringstream prefix_os;
134  prefix_os << firstClass << "vs" << secondClass << "_";
135  _triangMat( firstClass ,secondClass).saveTrainingInfo(
136  statistics, prefix_os.str());
137  }
138  }
139  }
140 
141 
142  template< typename STDATA>
143  void saveTrainingInfoStatistics( STDATA& statistics)
144  {
146 
148  _triangMat.begin(), _triangMat.end(), statistics);
149  }
150 
151 
152 
153  /*======================================================================*/
167  /*======================================================================*/
168  template<typename STDATA>
169  void saveParameters( STDATA& stData) const;
170 
171 
172  /*======================================================================*/
184  /*======================================================================*/
185  template<typename STDATA>
186  void loadParameters( STDATA& stData);
187 
188 
189 
190 
191 private:
192  TriangularMatrix< TCModel> _triangMat;
193 
194 };
195 
196 
197 }
198 
199 
200 #include "Model_MC_OneVsOne.icc"
201 
202 #endif
TCModel & twoClassModel(unsigned int class1, unsigned int class2)
void saveTrainingInfoStatistics(STDATA &statistics)
#define CHECK_MEMBER_TEMPLATE(c)
void resizeTriangularMatrix(unsigned int nClasses)
const TCModel & twoClassModel(unsigned int class1, unsigned int class2) const
Ensure that TCMODEL provides minimal functions to be used With Multiclass-Algortithms.
const_iterator end() const
void collectSupportVectorsFromTCModels(const ForwardIter &modelsBegin, const ForwardIter &modelsEnd)
#define CHECK_CLASS_TEMPLATE1(c)
TCModel & twoClassModel(unsigned int class1)
size_type width() const
unsigned int nClasses() const
size_type nElements() 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...
const_iterator begin() const
void saveTCTrainingInfos(STDATA &statistics)
const TCModel & twoClassModel(unsigned int class1) const
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...
void resizeWidth(size_type width, const T &defaultVal=T())
resize triangular matrix to new width.
unsigned int nTwoClassModels() const
void calcTrainingStatisticsFromTCModels(const ForwardIter &modelsBegin, const ForwardIter &modelsEnd, STDATA &statistics)