X-Boost  2.3.8
RealDecisionStump.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 _REAL_DECISION_STUMP_H
22 #define _REAL_DECISION_STUMP_H
23 
29 #include <iostream>
30 #include <vector>
31 #include <string>
32 #include <cmath>
33 #include "Types.h"
34 
35 
41 template<class DataType>
43 
45  DataType th;
46 
48  float pr, nr;
49 public:
50 
51  typedef float ReturnType;
52 
55 
56 public:
57 
58  static std::string signature() { return "realdecisionstump"; }
59 
61  inline float evaluate_feature(DataType value) const
62  {
63  return (value > th) ? pr : nr;
64  }
65 
66 
68  inline void rescale(int sx, int sy,int sgn)
69  {
70  //std::cout << "th "<<th<<std::endl;
71  th = (int) (th*sx*sy)*sgn;
72  //std::cout << "th*sx*sy "<<th<<std::endl;
73  }
74 
76  float getAlpha() const {
77  return std::max(std::abs(pr), std::abs(nr));
78  }
79 
80 };
81 
82 
83 template<class DataType>
84 inline std::istream & operator >> (std::istream & in, RealDecisionStump<DataType> & s)
85  {
86  in >> s.th >> s.pr >> s.nr;
87  return in;
88  }
89 
90 template<class DataType>
91 inline std::ostream & operator << (std::ostream & out, const RealDecisionStump<DataType> & s)
92  {
93  out << s.th << ' ' << s.pr << ' ' << s.nr;
94  return out;
95  }
96 
97 #endif
void rescale(int sx, int sy, int sgn)
this function permits to change the th for rescaling
Definition: RealDecisionStump.h:68
Types involved in boosting.
static const ClassifierType Type
NaiveDecisionStump is a DiscreteClassifier.
Definition: RealDecisionStump.h:54
ClassifierType
Definition: Types.h:31
float pr
weight associated to positive response (pr) and negative response (nr)
Definition: RealDecisionStump.h:48
A Weak Classifier based on a Feature Extractor policy.
Definition: RealDecisionStump.h:42
float evaluate_feature(DataType value) const
convert the feature value to {p,n} using internal parity and threshold
Definition: RealDecisionStump.h:61
a real classifier return a number between -1,+1
Definition: Types.h:34
DataType th
threshold value
Definition: RealDecisionStump.h:45
float getAlpha() const
return the maximum range of data returned
Definition: RealDecisionStump.h:76