X-Boost  2.3.8
BayesianStump.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 _BAYESIAN_STUMP_H
22 #define _BAYESIAN_STUMP_H
23 
29 #include <iostream>
30 #include <vector>
31 #include <string>
32 #include "_stdint.h"
33 #include "Types.h"
34 
35 
38 template<class DataType>
39 struct BayesianStump {
40 
42  static const int bin_size = 32;
43 
44 // int m_binsze;
45 
47  DataType m_minFeatValue;
49  DataType m_featRange;
50 
52  uint32_t m_truthTable;
53 
54 public:
55  typedef int ReturnType;
56 
59 
60 public:
61 
62 
63  int evaluate_feature(DataType response) const {
64  int bin = ((response - m_minFeatValue) * bin_size) / m_featRange;
65  if(bin>=bin_size) bin=bin_size-1;
66  if(bin<0) bin=0;
67 
68  return ((m_truthTable & (1<<bin))!=0) ? 1 : -1;
69  }
70 
71  static std::string signature() {
72  return "bayesianstump";
73  }
74 
75 };
76 
77 template<class DataType>
78 std::istream & operator >> (std::istream & in, BayesianStump<DataType> & s)
79  {
80  unsigned int tt;
81  int bin_size; // TODO check
82  in >> bin_size >> s.m_minFeatValue >> s.m_featRange >> tt;
83  s.m_truthTable = tt;
84  return in;
85  }
86 
87 template<class DataType>
88 std::ostream & operator << (std::ostream & out, const BayesianStump<DataType> & s)
89  {
90  out << s.bin_size << ' ' << s.m_minFeatValue << ' ' << s.m_featRange << ' ' << (unsigned int) s.m_truthTable;
91  return out;
92  }
93 
94 #endif
uint32_t m_truthTable
truth table (BinSize bin) 1:+ 0:-
Definition: BayesianStump.h:52
Types involved in boosting.
ClassifierType
Definition: Types.h:31
static const ClassifierType Type
BayesianStump is a DiscreteClassifier.
Definition: BayesianStump.h:58
Definition: BayesianStump.h:39
DataType m_minFeatValue
minimum feature value
Definition: BayesianStump.h:47
static const int bin_size
limit to 32bit thruth table
Definition: BayesianStump.h:42
additional typedef, for portability under win32
DataType m_featRange
feature range values
Definition: BayesianStump.h:49
a dicrete classifier returns {-1,+1}
Definition: Types.h:32