X-Boost  2.3.8
HyperplaneClassifier.h
1 /* XBoost: Ada-Boost and Friends on Haar/ICF/HOG Features, Library and ToolBox
2  *
3  * Copyright (c) 2008-2014 Paolo Medici <medici@ce.unipr.it>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _HYPERPLANE_CLASSIFIER_H
22 #define _HYPERPLANE_CLASSIFIER_H
23 
24 #include "Descriptor/RawData.h"
25 
26 template<class ScalarType>
28 public:
29  int n;
30  ScalarType *w;
31  ScalarType bias;
32 
33 public:
34 
35  HyperPlaneClassifier() : w(0) { }
36  ~HyperPlaneClassifier() { delete [] w; }
37 
38  static const char *signature() { return "linear-hog"; }
39 
40  // w should be n+1 element long
41  template<class SrcScalarType>
42  void import(int _n, const SrcScalarType *_w)
43  {
44  delete [] w;
45  n = _n;
46  w = new ScalarType[n];
47  for(int i =0;i<n;++i)
48  w[i] =_w[i];
49  bias = _w[n];
50  }
51 
52  template<class T>
53  ScalarType response(const RawData<T> & src) const
54  {
55  ScalarType r = bias;
56  for(int i =0;i<n; i++)
57  r += src.data[i] * w[i];
58 
59  return r;
60  }
61 
62 };
63 
64 template<class DataType>
65 inline std::istream & operator >> (std::istream & in, HyperPlaneClassifier<DataType> & s)
66 {
67  in >> s.n;
68  s.w = new DataType[s.n];
69  for(int i=0;i<s.n;++i)
70  {
71  in >> s.w[i];
72 // std::cerr << s.w[i] << ' ';
73  }
74  in >> s.bias;
75 
76 // std::cerr << std::endl;
77 
78  return in;
79 }
80 
81 template<class DataType>
82 inline std::ostream & operator << (std::ostream & out, const HyperPlaneClassifier<DataType> & s)
83 {
84  out << s.n;
85  for(int i=0;i<s.n;++i)
86  out << ' ' << s.w[i];
87  out << ' ' << s.bias;
88  return out;
89 }
90 
91 
92 #endif
Definition: HyperplaneClassifier.h:27
Definition: RawData.h:35