X-Boost  2.3.8
IndirectBinaryClassifier.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 _INDIRECT_BINARY_CLASSIFIER_H
22 #define _INDIRECT_BINARY_CLASSIFIER_H
23 
29 #include <iostream>
30 #include <vector>
31 #include <string>
32 #include "Types.h"
33 
36 template<class Policy>
37 struct IndirectBinaryClassifier : public Policy {
38 
39 public:
40 
41  typedef typename Policy::ReturnType ReturnType;
42 
45 
46 public:
47 
50 
52  static const ClassifierType Type = Policy::Type;
53 
54 public:
55 
58 
59  static std::string signature() {
60  return "x-decision-stump";
61  }
62 
67  template<class DataType>
68  inline int operator() (const DataType *features, long stride) const
69  {
70  return Policy::evaluate_feature( features[(long)(feature_index) * stride] ); // it is 64 bit?
71  }
72 
73 };
74 
75 // IO operators
76 
77 template<class Policy>
78 std::istream & operator >> (std::istream & in, IndirectBinaryClassifier<Policy> & s);
79 
80 template<class Policy>
81 std::ostream & operator << (std::ostream & out, const IndirectBinaryClassifier<Policy> & s);
82 
84 
85 
86 template<class Policy>
87 std::istream & operator >> (std::istream & in, IndirectBinaryClassifier<Policy> & s)
88 {
89  in >> static_cast<Policy&>(s) >> s.feature_index;
90  return in;
91 }
92 
93 template<class Policy>
94 std::ostream & operator << (std::ostream & out, const IndirectBinaryClassifier<Policy> & s)
95 {
96  out << static_cast<const Policy&>(s) << ' ' << s.feature_index;
97  return out;
98 }
99 
100 
101 #endif
Types involved in boosting.
IndirectBinaryClassifier< Policy > OptimizedType
no more optimization
Definition: IndirectBinaryClassifier.h:44
ClassifierType
Definition: Types.h:31
static const ClassifierType Type
BinaryClassifier inherits type from Policy.
Definition: IndirectBinaryClassifier.h:52
int feature_index
the index of the feature used during the classification stage
Definition: IndirectBinaryClassifier.h:49
A classifier composed by an index of a feature and an Evaluation Policy.
Definition: IndirectBinaryClassifier.h:37
int operator()(const DataType *features, long stride) const
Definition: IndirectBinaryClassifier.h:68