38 #ifndef PCL_ML_FERNS_FERN_EVALUATOR_HPP_ 39 #define PCL_ML_FERNS_FERN_EVALUATOR_HPP_ 41 #include <pcl/common/common.h> 43 #include <pcl/ml/ferns/fern.h> 44 #include <pcl/ml/feature_handler.h> 45 #include <pcl/ml/stats_estimator.h> 51 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
57 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
63 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
70 std::vector<ExampleIndex> & examples,
71 std::vector<LabelType> & label_data)
73 const size_t num_of_examples = examples.size ();
77 label_data.resize (num_of_examples);
79 std::vector<std::vector<float> > results (num_of_features);
80 std::vector<std::vector<unsigned char> > flags (num_of_features);
81 std::vector<std::vector<unsigned char> > branch_indices (num_of_features);
83 for (
size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
85 results[feature_index].reserve (num_of_examples);
86 flags[feature_index].reserve (num_of_examples);
87 branch_indices[feature_index].reserve (num_of_examples);
93 for (
size_t example_index = 0; example_index < num_of_examples; ++example_index)
95 size_t node_index = 0;
96 for (
size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
98 node_index *= num_of_branches;
99 node_index += branch_indices[feature_index][example_index];
102 label_data[example_index] = stats_estimator.
getLabelOfNode (fern[node_index]);
107 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
114 std::vector<ExampleIndex> & examples,
115 std::vector<LabelType> & label_data)
117 const size_t num_of_examples = examples.size ();
121 std::vector<std::vector<float> > results (num_of_features);
122 std::vector<std::vector<unsigned char> > flags (num_of_features);
123 std::vector<std::vector<unsigned char> > branch_indices (num_of_features);
125 for (
size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
127 results[feature_index].reserve (num_of_examples);
128 flags[feature_index].reserve (num_of_examples);
129 branch_indices[feature_index].reserve (num_of_examples);
135 for (
size_t example_index = 0; example_index < num_of_examples; ++example_index)
137 size_t node_index = 0;
138 for (
size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
140 node_index *= num_of_branches;
141 node_index += branch_indices[feature_index][example_index];
144 label_data[example_index] = stats_estimator.
getLabelOfNode (fern[node_index]);
149 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
156 std::vector<ExampleIndex> & examples,
157 std::vector<NodeType*> & nodes)
159 const size_t num_of_examples = examples.size ();
163 nodes.reserve (num_of_examples);
165 std::vector<std::vector<float> > results (num_of_features);
166 std::vector<std::vector<unsigned char> > flags (num_of_features);
167 std::vector<std::vector<unsigned char> > branch_indices (num_of_features);
169 for (
size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
171 results[feature_index].reserve (num_of_examples);
172 flags[feature_index].reserve (num_of_examples);
173 branch_indices[feature_index].reserve (num_of_examples);
179 for (
size_t example_index = 0; example_index < num_of_examples; ++example_index)
181 size_t node_index = 0;
182 for (
size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
184 node_index *= num_of_branches;
185 node_index += branch_indices[feature_index][example_index];
188 nodes.push_back (&(fern[node_index]));
void evaluate(pcl::Fern< FeatureType, NodeType > &fern, pcl::FeatureHandler< FeatureType, DataSet, ExampleIndex > &feature_handler, pcl::StatsEstimator< LabelType, NodeType, DataSet, ExampleIndex > &stats_estimator, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelType > &label_data)
Evaluates the specified examples using the supplied tree.
size_t getNumOfFeatures()
Returns the number of features the Fern has.
virtual void evaluateFeature(const FeatureType &feature, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< float > &results, std::vector< unsigned char > &flags) const =0
Evaluates a feature on the specified data.
float & accessThreshold(const size_t threshold_index)
Access operator for thresholds.
virtual void computeBranchIndices(std::vector< float > &results, std::vector< unsigned char > &flags, const float threshold, std::vector< unsigned char > &branch_indices) const =0
Computes the branch indices obtained by the specified threshold on the supplied feature evaluation re...
FernEvaluator()
Constructor.
FeatureType & accessFeature(const size_t feature_index)
Access operator for features.
virtual size_t getNumOfBranches() const =0
Returns the number of brances a node can have (e.g.
Class representing a Fern.
virtual LabelDataType getLabelOfNode(NodeType &node) const =0
Returns the label of the specified node.
void getNodes(pcl::Fern< FeatureType, NodeType > &fern, pcl::FeatureHandler< FeatureType, DataSet, ExampleIndex > &feature_handler, pcl::StatsEstimator< LabelType, NodeType, DataSet, ExampleIndex > &stats_estimator, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< NodeType * > &nodes)
Evaluates the specified examples using the supplied tree.
void evaluateAndAdd(pcl::Fern< FeatureType, NodeType > &fern, pcl::FeatureHandler< FeatureType, DataSet, ExampleIndex > &feature_handler, pcl::StatsEstimator< LabelType, NodeType, DataSet, ExampleIndex > &stats_estimator, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelType > &label_data)
Evaluates the specified examples using the supplied tree and adds the results to the supplied results...
virtual ~FernEvaluator()
Destructor.
Utility class interface which is used for creating and evaluating features.