MCPcopy Create free account
hub / github.com/davisking/dlib / regression_tree

Class regression_tree

dlib/image_processing/shape_predictor.h:56–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54 !*/
55
56 struct regression_tree
57 {
58 std::vector<split_feature> splits;
59 std::vector<matrix<float,0,1> > leaf_values;
60
61 unsigned long num_leaves() const { return leaf_values.size(); }
62
63 inline const matrix<float,0,1>& operator()(
64 const std::vector<float>& feature_pixel_values,
65 unsigned long& i
66 ) const
67 /*!
68 requires
69 - All the index values in splits are less than feature_pixel_values.size()
70 - leaf_values.size() is a power of 2.
71 (i.e. we require a tree with all the levels fully filled out.
72 - leaf_values.size() == splits.size()+1
73 (i.e. there needs to be the right number of leaves given the number of splits in the tree)
74 ensures
75 - runs through the tree and returns the vector at the leaf we end up in.
76 - #i == the selected leaf node index.
77 !*/
78 {
79 i = 0;
80 while (i < splits.size())
81 {
82 if ((float)feature_pixel_values[splits[i].idx1] - (float)feature_pixel_values[splits[i].idx2] > splits[i].thresh)
83 i = left_child(i);
84 else
85 i = right_child(i);
86 }
87 i = i - splits.size();
88 return leaf_values[i];
89 }
90
91 friend void serialize (const regression_tree& item, std::ostream& out)
92 {
93 dlib::serialize(item.splits, out);
94 dlib::serialize(item.leaf_values, out);
95 }
96 friend void deserialize (regression_tree& item, std::istream& in)
97 {
98 dlib::deserialize(item.splits, in);
99 dlib::deserialize(item.leaf_values, in);
100 }
101 };
102
103 // ------------------------------------------------------------------------------------
104

Callers

nothing calls this directly

Calls 3

left_childFunction · 0.85
right_childFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected