iRoCS Toolbox  1.1.0
FVwithMultiClassCoefs.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: wrapper for feature vectors to add multiclass coeficients
26 ** $RCSfile$
27 ** $Revision: 1292 $$Name$
28 ** $Date: 2007-11-10 14:51:29 +0100 (Sat, 10 Nov 2007) $
29 ** Copyright: GPL $Author: tschmidt $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.1 2007/11/10 13:51:29 tschmidt
38 ** - initial revision (taken from polsoft-extsrc)
39 **
40 ** Revision 1.4 2002/05/23 19:03:59 ronneber
41 ** - operator<< now also writes coefficients
42 **
43 ** Revision 1.3 2002/05/23 15:22:54 ronneber
44 ** - added svCoef( int) and operator<<()
45 **
46 ** Revision 1.2 2002/05/21 18:22:05 ronneber
47 ** - added double #include guards
48 **
49 ** Revision 1.1 2002/05/13 16:16:25 ronneber
50 ** initial revision
51 **
52 **
53 **
54 **************************************************************************/
55 
56 #ifndef FVWITHMULTICLASSCOEFS_HH
57 #define FVWITHMULTICLASSCOEFS_HH
58 
59 #ifdef HAVE_CONFIG_H
60 #include <config.hh>
61 #endif
62 
63 #include <vector>
64 #include <iostream>
65 
66 
67 namespace svt
68 {
69  template< typename FV>
71  {
72  public:
73 
74  /*======================================================================*/
84  /*======================================================================*/
85  void setSVCoef( unsigned int otherClassLabel, double coef)
86  {
87  _sVCoefs[otherClassLabel] = coef;
88  }
89 
90  double sVCoef( unsigned int otherClassLabel) const
91  {
92  return _sVCoefs[otherClassLabel];
93  }
94 
95  unsigned int sVCoefs_size() const
96  {
97  return _sVCoefs.size();
98  }
99 
100 
101  const std::vector<double>& sVCoefs() const
102  {
103  return _sVCoefs;
104  }
105 
106  std::vector<double>& sVCoefs()
107  {
108  return _sVCoefs;
109  }
110 
111 
112  // essential forwarding methods for TwoClassSVM's
113  int getLabel() const
114  { return _fv.getLabel(); }
115 
116  // essential forwarding methods for MultiClassSVM's
117  void setLabel( int label)
118  { _fv.setLabel( label); }
119 
120  // essential forwarding methods for Kernel_...
122  { return _fv.dotProduct( fv.origFeatureVector()); }
123 
124  double square() const
125  { return _fv.square(); }
126 
127 
128  // nice to have, but not essential methods
129  typedef typename FV::iterator iterator;
130  typedef typename FV::const_iterator const_iterator;
131  typedef typename FV::reference reference;
132  typedef typename FV::const_reference const_reference;
133  typedef typename FV::size_type size_type;
134 
135  const_reference operator[]( int index) const
136  { return _fv.operator[](index); }
137 
138  reference operator[]( int index)
139  { return _fv.operator[](index); }
140 
141  const_iterator begin() const
142  { return _fv.begin(); }
143 
144  iterator begin()
145  { return _fv.begin(); }
146 
147  const_iterator end() const
148  { return _fv.end(); }
149 
150  iterator end()
151  { return _fv.end(); }
152 
153  size_type size() const
154  { return _fv.size(); }
155 
156  void resize( size_type s)
157  { return _fv.resize( s); }
158 
159 
160  FV& origFeatureVector() { return _fv; }
161  const FV& origFeatureVector() const { return _fv; }
162 
163  private:
164  FV _fv;
165  std::vector<double> _sVCoefs;
166  };
167 
168  template< typename FV>
169  inline std::ostream&
170  operator<<( std::ostream& os, const FVwithMultiClassCoefs<FV>& fv)
171  {
172  os << "(coefs:";
173  for( unsigned int i = 0; i < fv.sVCoefs_size(); ++i)
174  {
175  os << " "<< fv.sVCoef(i);
176  }
177 
178  os << ") " << fv.origFeatureVector();
179  return os;
180 
181  }
182 
183 }
184 
185 #endif
void setSVCoef(unsigned int otherClassLabel, double coef)
set Coeficients
double sVCoef(unsigned int otherClassLabel) const
std::vector< double > & sVCoefs()
unsigned int sVCoefs_size() const
double dotProduct(const svt::FVwithMultiClassCoefs< FV > &fv) const
const std::vector< double > & sVCoefs() const
const_reference operator[](int index) const