yat  0.14.5pre
SVM.h
1 #ifndef _theplu_yat_classifier_svm_
2 #define _theplu_yat_classifier_svm_
3 
4 // $Id: SVM.h 2384 2010-12-22 14:03:36Z peter $
5 
6 /*
7  Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
9  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
10  Copyright (C) 2009, 2010 Peter Johansson
11 
12  This file is part of the yat library, http://dev.thep.lu.se/yat
13 
14  The yat library is free software; you can redistribute it and/or
15  modify it under the terms of the GNU General Public License as
16  published by the Free Software Foundation; either version 3 of the
17  License, or (at your option) any later version.
18 
19  The yat library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with yat. If not, see <http://www.gnu.org/licenses/>.
26 */
27 
28 #include "SVindex.h"
29 #include "Target.h"
30 #include "yat/utility/Vector.h"
31 
32 #include <utility>
33 #include <vector>
34 
35 namespace theplu {
36 namespace yat {
37 namespace utility{
38  class Matrix;
39 }
40 
41 namespace classifier {
42 
43  class DataLookup1D;
44  class DataLookupWeighted1D;
45  class KernelLookup;
46 
50  class SVM
51  {
52 
53  public:
57  SVM(void);
58 
62  SVM(const SVM&);
63 
67  virtual ~SVM();
68 
75  SVM* make_classifier(void) const;
76 
80  const utility::Vector& alpha(void) const;
81 
96  double C(void) const;
97 
103  unsigned long int max_epochs(void) const;
104 
108  void max_epochs(unsigned long int);
109 
116  const theplu::yat::utility::Vector& output(void) const;
117 
132  void predict(const KernelLookup& input, utility::Matrix& predict) const;
133 
134  /*
139  double predict(const DataLookup1D& input) const;
140 
145  double predict(const DataLookupWeighted1D& input) const;
146  */
147 
155  void reset(void);
156 
160  void set_C(const double);
161 
195  void train(const KernelLookup& kernel, const Target& target);
196 
202  bool trained(void) const;
203 
204  private:
208  void bounds(double&, double&) const;
209 
215  void calculate_bias(void);
216 
220  void calculate_margin(void);
221 
232  bool choose(const theplu::yat::utility::Vector&);
233 
237  double kernel_mod(const size_t i, const size_t j) const;
238 
242  int target(size_t i) const;
243 
244  utility::Vector alpha_;
245  double bias_;
246  double C_inverse_;
247  // not owned by SVM
248  const KernelLookup* kernel_;
249  double margin_;
250  unsigned long int max_epochs_;
251  utility::Vector output_;
252  SVindex sample_;
253  Target target_;
254  double tolerance_;
255  bool trained_;
256 
257  };
258 
259 }}} // of namespace classifier, yat, and theplu
260 
261 #endif
unsigned long int max_epochs(void) const
Class for containing sample labels.
Definition: Target.h:47
double C(void) const
virtual ~SVM()
Destructor.
Definition: SVindex.h:45
const theplu::yat::utility::Vector & output(void) const
void set_C(const double)
sets the C-Parameter
void train(const KernelLookup &kernel, const Target &target)
This is the yat interface to GSL vector.
Definition: Vector.h:57
SVM(void)
Constructor.
void predict(const KernelLookup &input, utility::Matrix &predict) const
void reset(void)
make SVM untrained
Lookup into Kernel.
Definition: KernelLookup.h:67
SVM * make_classifier(void) const
Create an untrained copy of SVM.
const utility::Vector & alpha(void) const
Support Vector Machine.
Definition: SVM.h:50
Interface to GSL matrix.
Definition: Matrix.h:63
bool trained(void) const

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5