iRoCS Toolbox  1.1.0
SVM_Problem.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:
26 ** $RCSfile$
27 ** $Revision: 2824 $$Name$
28 ** $Date: 2009-09-14 09:30:46 +0200 (Mon, 14 Sep 2009) $
29 ** Copyright: LGPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.2 2005/03/29 18:03:55 ronneber
38 ** - added FV_begin() and FV_end()
39 **
40 ** Revision 1.1 2004/08/26 08:36:59 ronneber
41 ** initital import
42 **
43 **
44 **
45 **************************************************************************/
46 
47 #ifndef SVM_PROBLEM_HH
48 #define SVM_PROBLEM_HH
49 
50 #ifdef HAVE_CONFIG_H
51 #include <config.hh>
52 #endif
53 
54 namespace svt
55 {
56  template< typename FV>
57  struct SVM_Problem
58  {
60  : l(0),
61  y(0),
62  x(0)
63  {}
64 
65  SVM_Problem( int size)
66  : l(0),
67  y(0),
68  x(0)
69  {
70  resize( size);
71  }
72 
73  private:
74  // forbid copying of SVM_Problem
75  SVM_Problem( const SVM_Problem<FV>& orig) {}
76  void operator=( const SVM_Problem<FV>& orig) {}
77  public:
78 
79 
81  {
82  free_memory();
83  }
84 
85 
86  void resize( int size)
87  {
88  if( y != 0 || x != 0)
89  {
90  free_memory();
91  }
92  y = new double[ size];
93  x = new FV*[size];
94  l = size;
95  }
96 
97  void free_memory()
98  {
99  if( y != 0 || x != 0)
100  {
101  delete[] x;
102  delete[] y;
103  }
104 
105  l = 0;
106  x = 0;
107  y = 0;
108  }
109 
110  unsigned int nFeatureVectors() const
111  {
112  return l;
113  }
114 
115  FV* featureVector( unsigned int i) const
116  {
117  return x[i];
118  }
119 
120  double label( unsigned int i) const
121  {
122  return y[i];
123  }
124 
125  FV** FV_begin() const
126  {
127  return x;
128  }
129 
130  FV** FV_end() const
131  {
132  return x + l;
133  }
134 
135 
136 
137  int l;
138  double* y; // array of y's (labels)
139  FV** x; // array of pointers to Feature Vectors
140 
141  };
142 
143 
144 }
145 
146 #endif
FV ** FV_end() const
Definition: SVM_Problem.hh:130
FV * featureVector(unsigned int i) const
Definition: SVM_Problem.hh:115
unsigned int nFeatureVectors() const
Definition: SVM_Problem.hh:110
void resize(int size)
Definition: SVM_Problem.hh:86
FV ** FV_begin() const
Definition: SVM_Problem.hh:125
SVM_Problem(int size)
Definition: SVM_Problem.hh:65
double label(unsigned int i) const
Definition: SVM_Problem.hh:120