Exemplo n.º 1
0
void
pcl::DecisionTreeEvaluator<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>::evaluateAndAdd (
  pcl::DecisionTree<NodeType> & tree,
  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)
{
  const size_t num_of_examples = examples.size ();
  for (int example_index = 0; example_index < num_of_examples; ++example_index)
  {
    NodeType * node = &(tree.getRoot ());

    while (node->sub_nodes.size () != 0)
    {
      float feature_result = 0.0f;
      unsigned char flag = 0;
      unsigned char branch_index = 0;

      feature_handler.evaluateFeature (node->feature, data_set, examples[example_index], feature_result, flag);
      stats_estimator.computeBranchIndex (feature_result, flag, node->threshold, branch_index);

      node = &(node->sub_nodes[branch_index]);
    }

    label_data[example_index] += stats_estimator.getLabelOfNode (*node);
  }
}
Exemplo n.º 2
0
void
pcl::FernEvaluator<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>::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)
{
  const size_t num_of_examples = examples.size ();
  const size_t num_of_branches = stats_estimator.getNumOfBranches ();
  const size_t num_of_features = fern.getNumOfFeatures ();

  label_data.resize (num_of_examples);

  std::vector<std::vector<float> > results (num_of_features);
  std::vector<std::vector<unsigned char> > flags (num_of_features);
  std::vector<std::vector<unsigned char> > branch_indices (num_of_features);

  for (size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
  {
    results[feature_index].reserve (num_of_examples);
    flags[feature_index].reserve (num_of_examples);
    branch_indices[feature_index].reserve (num_of_examples);

    feature_handler.evaluateFeature (fern.accessFeature (feature_index), data_set, examples, results[feature_index], flags[feature_index]);
    stats_estimator.computeBranchIndices (results[feature_index], flags[feature_index], fern.accessThreshold (feature_index), branch_indices[feature_index]);
  }

  for (size_t example_index = 0; example_index < num_of_examples; ++example_index)
  {
    size_t node_index = 0;
    for (size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
    {
      node_index *= num_of_branches;
      node_index += branch_indices[feature_index][example_index];
    }

    label_data[example_index] = stats_estimator.getLabelOfNode (fern[node_index]);
  }
}