21 #ifndef _DECISION_TREE_H
22 #define DECISION_TREE_H
33 template<
class T,
class DataType =
int>
60 template<
class P1,
class SrcFeature>
74 template<
class P1,
class P2,
class SrcFeature>
88 template<
class P1,
class P2,
class P3>
138 bool load(std::istream &in)
163 std::cerr << c <<
" at " << in.tellg() << std::endl;
164 throw std::runtime_error(
"wrong file format");
169 void save(std::ostream &out)
const
175 out <<
'n' <<
' ' <<
th <<
' ' <<
classifier <<
' ' << *left <<
' ' << *right;
189 static std::string signature() {
190 return T::signature() +
"-decision-tree";
198 template<
class FeatureType>
199 bool export_features(std::vector<FeatureType> & out)
const
206 template<
class Param1>
207 float classify(
const unsigned int *image, Param1 stride)
const {
210 return (
classifier.response(image, stride) >
th ) ? right->classify(image, stride) : left->
classify(image, stride);
226 template<
class Param1>
227 inline float operator()(
const unsigned int *image, Param1 stride)
const {
231 inline float operator()(
const unsigned int *image)
const {
241 right->scale_response(factor);
253 return 1.0 + (left->
MeasureAvgDepth() + right->MeasureAvgDepth()) * 0.5f;
285 std::ostream & operator << (std::ostream & out, const DecisionTree<T> & s);
297 std::ostream & operator << (std::ostream & out, const DecisionTree<T> & s)
DataType th
Classifier Threshold.
Definition: DecisionTree.h:41
Types involved in boosting.
float classify(const unsigned int *image) const
perform the classification stage (no params)
Definition: DecisionTree.h:217
DecisionTree< T, DataType > * left
sub-nodes (if null is a leaf)
Definition: DecisionTree.h:44
float category
if there are not subnodes, this value -1 .. 1 return the class and probability
Definition: DecisionTree.h:47
void scale_response(float factor)
scale the response of the decision tree
Definition: DecisionTree.h:236
ClassifierType
Definition: Types.h:31
DecisionTree(const DecisionTree< T, DataType > &src, P1 p1, P2 p2, P3 p3)
Copy & convert constructor.
Definition: DecisionTree.h:89
static const ClassifierType Type
DecisionTree is (generic) a RealClassifier.
Definition: DecisionTree.h:55
DecisionTree(const DecisionTree< SrcFeature, DataType > &src, const P1 &p1)
Copy & convert constructor.
Definition: DecisionTree.h:61
DecisionTree(const DecisionTree< SrcFeature, DataType > &src, P1 p1, const P2 &p2)
Copy & convert constructor.
Definition: DecisionTree.h:75
float getAlpha() const
MMMMH?
Definition: DecisionTree.h:276
T classifier
a feature extractor
Definition: DecisionTree.h:38
static float max_response()
internally normalized
Definition: DecisionTree.h:194
a real classifier return a number between -1,+1
Definition: Types.h:34
float classify(const unsigned int *image, Param1 stride) const
perform the classification stage (1 params)
Definition: DecisionTree.h:207
float MeasureAvgDepth() const
estimate the number of layer evaluated (roughly)
Definition: DecisionTree.h:250
void Discrete()
transform a Probabilistic Decision Tree in a Discrete Decision Tree
Definition: DecisionTree.h:262
Definition: DecisionTree.h:34