X-Boost  2.3.8
BoostableClassifier.h
Go to the documentation of this file.
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 _BOOSTABLE_CLASSIFIER_H
22 #define _BOOSTABLE_CLASSIFIER_H
23 
24 #include <string>
25 #include <vector>
26 #include "Types.h"
27 
31 
39 template<class WeakClassifier>
40 struct BoostableClassifier : public WeakClassifier {
41 
43  float alpha;
44 
45 public:
46 
48  typedef WeakClassifier WeakClassifierType;
49 
52 
53 public:
54 
55  BoostableClassifier() : alpha(0.0f) { }
56  BoostableClassifier(const WeakClassifier & weak, float a) : WeakClassifier(weak), alpha(a) { }
57 
58 // NOTE build and convert costructor with 1 parameter overlapps with previous constructor
59 
61  template<class R, class P1, class P2>
62  explicit BoostableClassifier(const R & src, P1 p1, P2 p2) : WeakClassifier(static_cast<const typename R::WeakClassifierType &>(src), p1, p2), alpha(src.alpha) { }
63 
65  template<class R, class P0, class P1, class P2>
66  explicit BoostableClassifier(const R & src, P0 p0, P1 p1, P2 p2) : WeakClassifier(static_cast<const typename R::WeakClassifierType &>(src), p0, p1, p2), alpha(src.alpha) { }
67 
68  // TODO: boost- here is not correct. Boost is BoostClassifier. This class associate only weight to a Discrete Weak Classifier
69  static std::string signature() { return std::string("boost-") + WeakClassifier::signature(); }
70 
72  template<class DataType>
73  inline float operator()(const DataType data) const;
74 
76  template<class DataType, class TParam1>
77  inline float operator()(const DataType data, TParam1 stride) const;
78 
81  inline float getAlpha() const { return alpha; }
82 
83 };
84 
85 template<class WeakClassifier>
86 inline std::istream & operator >> (std::istream & in, BoostableClassifier<WeakClassifier> & s);
87 
88 template<class WeakClassifier>
89 inline std::ostream & operator << (std::ostream & out, const BoostableClassifier<WeakClassifier> & s);
90 
91 
93 
94 template<class WeakClassifier>
95 template<class DataType, class TParam1>
96 float BoostableClassifier<WeakClassifier>::operator()(const DataType data, TParam1 stride) const
97  {
98  return WeakClassifier::operator()(data, stride) * alpha;
99  }
100 
101 template<class WeakClassifier>
102 template<class DataType>
103 float BoostableClassifier<WeakClassifier>::operator()(const DataType data) const
104  {
105  return WeakClassifier::operator()(data) * alpha;
106  }
107 
108 template<class WeakClassifier>
109 inline std::istream & operator >> (std::istream & in, BoostableClassifier<WeakClassifier> & s)
110  {
111  in >> s.alpha >> static_cast<WeakClassifier&>(s);
112  return in;
113  }
114 
115 template<class WeakClassifier>
116 inline std::ostream & operator << (std::ostream & out, const BoostableClassifier<WeakClassifier> & s)
117  {
118  out << s.alpha << ' ' << static_cast<const WeakClassifier&>(s);
119  return out;
120  }
121 
122 
123 #endif
BoostableClassifier(const R &src, P0 p0, P1 p1, P2 p2)
build and convert costructor with 3 parameters
Definition: BoostableClassifier.h:66
Types involved in boosting.
static const ClassifierType Type
BoostableClassifier convert a DiscreteClassifier in a RealClassifier.
Definition: BoostableClassifier.h:51
ClassifierType
Definition: Types.h:31
float getAlpha() const
Definition: BoostableClassifier.h:81
float alpha
Weight associated to this classifier.
Definition: BoostableClassifier.h:43
BoostableClassifier(const R &src, P1 p1, P2 p2)
build and convert costructor with 2 parameters
Definition: BoostableClassifier.h:62
a real classifier return a number between -1,+1
Definition: Types.h:34
Definition: BoostableClassifier.h:40
float operator()(const DataType data) const
Definition: BoostableClassifier.h:103