X-Boost  2.3.8
DecisionStump.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 _DECISION_STUMP_H
22 #define _DECISION_STUMP_H
23 
29 #include <string>
30 #include <iosfwd>
31 #include "Types.h"
32 
33 #include <iostream>
34 
44 template<class DataType>
45 struct DecisionStump {
47  int parity;
48 
50  DataType th;
51 public:
52  typedef int ReturnType;
53 
56 
57 public:
58 
62  inline int evaluate_feature(DataType value) const
63  {
64  return (parity * value < parity * th) ? 1 : -1;
65  }
66 
67  static std::string signature() {
68  return "decisionstump";
69  }
70 
72  inline void rescale(int sx, int sy,int sgn)
73  {
74  th = (int) (th*sx*sy)*sgn;
75  }
76 
77 };
78 
79 template<class DataType>
80 inline std::istream & operator >> (std::istream & in, DecisionStump<DataType> & s)
81 {
82  in >> s.parity >> s.th;
83  return in;
84 }
85 
86 template<class DataType>
87 inline std::ostream & operator << (std::ostream & out, const DecisionStump<DataType> & s)
88 {
89  out << s.parity << ' ' << s.th;
90  return out;
91 }
92 
93 #endif
Types involved in boosting.
int parity
parity for this classifier (-1, 1)
Definition: DecisionStump.h:47
A Weak Classifier based on a Feature Extractor policy.
Definition: DecisionStump.h:45
static const ClassifierType Type
DecisionStump is a Discrete Classifier.
Definition: DecisionStump.h:55
ClassifierType
Definition: Types.h:31
int evaluate_feature(DataType value) const
Definition: DecisionStump.h:62
void rescale(int sx, int sy, int sgn)
this function permits to change the th for rescaling
Definition: DecisionStump.h:72
a dicrete classifier returns {-1,+1}
Definition: Types.h:32
DataType th
threshold value
Definition: DecisionStump.h:50