X-Boost  2.3.8
MultiClassClassifier.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 _MULTICLASS_CLASSIFIER_H
22 #define _MULTICLASS_CLASSIFIER_H
23 
29 #include "Types.h"
30 #include <vector>
31 
34 template<class FeatureExtractor, class MultiClassPolicy>
35 struct MultiClassClassifier : public FeatureExtractor, public MultiClassPolicy {
36 
37 public:
38 
39  typedef FeatureExtractor FeatureType;
40 
43 
44 public:
45 
46  MultiClassClassifier(int n_classes) : MultiClassPolicy(n_classes) { }
48 
50  const char *str() const {
51  return FeatureExtractor::name;
52  }
53 
55  static std::string signature() {
56  return MultiClassPolicy::signature() + "-" + FeatureExtractor::signature();
57  }
58 
64  template<class D1, class D2>
65  inline void classify(int *response, const D1 d1, const D2 d2) const
66  {
67  evaluate_feature(response, FeatureExtractor::response(d1, d2) );
68  }
69 
72  template<class D1>
73  inline void classify(int *response, const D1 d1) const
74  {
75  evaluate_feature(response, FeatureExtractor::response(d1) );
76  }
77 
79  template<class D1, class D2>
80  inline void operator()(int *response, const D1 d1, const D2 d2) const
81  {
82  evaluate_feature(response, FeatureExtractor::response(d1) );
83  }
84 
86  void rescale(float sx, float sy)
87  {
88  // TODO: rescale th
89  FeatureExtractor::rescale(sx,sy);
90  }
91 
92  template<class FeatureType>
93  bool export_features(std::vector<FeatureType> & out) const
94  {
95  out.push_back( static_cast<const FeatureType&>(*this) );
96  }
97 
98 };
99 
100 template<class T, class MultiClassPolicy>
101 std::istream & operator >> (std::istream & in, MultiClassClassifier<T, MultiClassPolicy> & s)
102 {
103  in >> static_cast<MultiClassPolicy &>(s) >> static_cast<T&>(s);
104  return in;
105 }
106 
107 template<class T, class MultiClassPolicy>
108 std::ostream & operator << (std::ostream & out, const MultiClassClassifier<T, MultiClassPolicy> & s)
109 {
110  out << static_cast<const MultiClassPolicy &>(s) << ' ' << static_cast<const T&>(s);
111  return out;
112 }
113 
114 
115 #endif
Types involved in boosting.
A Multi-Class Classifier based on a Feature Extractor policy.
Definition: MultiClassClassifier.h:35
void rescale(float sx, float sy)
this function permits to change the geometry of haar feature: integral value should be used ...
Definition: MultiClassClassifier.h:86
ClassifierType
Definition: Types.h:31
const char * str() const
return the "feature" name (for debug purpose)
Definition: MultiClassClassifier.h:50
void classify(int *response, const D1 d1) const
Definition: MultiClassClassifier.h:73
void operator()(int *response, const D1 d1, const D2 d2) const
classify wrapper.
Definition: MultiClassClassifier.h:80
a FeatureExtractor return a scalar number without relationship with classification ...
Definition: Types.h:35
void classify(int *response, const D1 d1, const D2 d2) const
Definition: MultiClassClassifier.h:65
static const ClassifierType Type
DecisionStump is a DiscreteClassifier.
Definition: MultiClassClassifier.h:42
static std::string signature()
signature name is the name of provider (for simplicity)
Definition: MultiClassClassifier.h:55
a dicrete classifier returns {-1,+1}
Definition: Types.h:32