Point Cloud Library (PCL)  1.12.1-dev
stats_estimator.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #pragma once
39 
40 #include <pcl/common/common.h>
41 
42 #include <ostream>
43 #include <vector>
44 
45 namespace pcl {
46 
47 /** Class interface for gathering statistics for decision tree learning. */
48 template <class LabelDataType, class NodeType, class DataSet, class ExampleIndex>
50 
51 public:
52  /** Destructor. */
53  virtual ~StatsEstimator() = default;
54 
55  /** Returns the number of brances a node can have (e.g. a binary tree has 2). */
56  virtual std::size_t
57  getNumOfBranches() const = 0;
58 
59  /** Computes and sets the statistics for a node.
60  *
61  * \param[in] data_set the data set used for training
62  * \param[in] examples the examples used for computing the statistics for the
63  * specified node
64  * \param[in] label_data the labels corresponding to the examples
65  * \param[out] node The destination node for the statistics
66  */
67  virtual void
68  computeAndSetNodeStats(DataSet& data_set,
69  std::vector<ExampleIndex>& examples,
70  std::vector<LabelDataType>& label_data,
71  NodeType& node) const = 0;
72 
73  /** Returns the label of the specified node.
74  *
75  * \param[in] node The node from which the label is extracted
76  */
77  virtual LabelDataType
78  getLabelOfNode(NodeType& node) const = 0;
79 
80  /** Computes the information gain obtained by the specified threshold on the supplied
81  * feature evaluation results.
82  *
83  * \param[in] data_set the data set used for extracting the supplied result values.
84  * \param[in] examples the examples used to extract the supplied result values
85  * \param[in] label_data the labels corresponding to the examples
86  * \param[in] results the results obtained from the feature evaluation
87  * \param[in] flags the flags obtained together with the results
88  * \param[in] threshold the threshold which is used to compute the information gain
89  */
90  virtual float
91  computeInformationGain(DataSet& data_set,
92  std::vector<ExampleIndex>& examples,
93  std::vector<LabelDataType>& label_data,
94  std::vector<float>& results,
95  std::vector<unsigned char>& flags,
96  const float threshold) const = 0;
97 
98  /** Computes the branch indices obtained by the specified threshold on the supplied
99  * feature evaluation results.
100  *
101  * \param[in] results the results obtained from the feature evaluation
102  * \param[in] flags the flags obtained together with the results.
103  * \param[in] threshold the threshold which is used to compute the branch indices
104  * \param[out] branch_indices the destination for the computed branch indices.
105  */
106  virtual void
107  computeBranchIndices(std::vector<float>& results,
108  std::vector<unsigned char>& flags,
109  const float threshold,
110  std::vector<unsigned char>& branch_indices) const = 0;
111 
112  /** Computes the branch indices obtained by the specified threshold on the supplied
113  * feature evaluation results.
114  *
115  * \param[in] result the result obtained from the feature evaluation
116  * \param[in] flag the flag obtained together with the result
117  * \param[in] threshold the threshold which is used to compute the branch index
118  * \param[out] branch_index the destination for the computed branch index
119  */
120  virtual void
121  computeBranchIndex(const float result,
122  const unsigned char flag,
123  const float threshold,
124  unsigned char& branch_index) const = 0;
125 
126  /** Generates code for computing the branch indices for the specified node and writes
127  * it to the specified stream.
128  *
129  * \param[in] node the node for which the branch index estimation code is generated
130  * \param[out] stream the destination for the code
131  */
132  virtual void
133  generateCodeForBranchIndexComputation(NodeType& node, std::ostream& stream) const = 0;
134 
135  /** Generates code for computing the output for the specified node and writes it to
136  * the specified stream.
137  *
138  * \param[in] node the node for which the output estimation code is generated
139  * \param[out] stream the destination for the code
140  */
141  virtual void
142  generateCodeForOutput(NodeType& node, std::ostream& stream) const = 0;
143 };
144 
145 } // namespace pcl
Class interface for gathering statistics for decision tree learning.
virtual std::size_t getNumOfBranches() const =0
Returns the number of brances a node can have (e.g.
virtual float computeInformationGain(DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelDataType > &label_data, std::vector< float > &results, std::vector< unsigned char > &flags, const float threshold) const =0
Computes the information gain obtained by the specified threshold on the supplied feature evaluation ...
virtual void generateCodeForOutput(NodeType &node, std::ostream &stream) const =0
Generates code for computing the output for the specified node and writes it to the specified stream.
virtual void generateCodeForBranchIndexComputation(NodeType &node, std::ostream &stream) const =0
Generates code for computing the branch indices for the specified node and writes it to the specified...
virtual void computeAndSetNodeStats(DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelDataType > &label_data, NodeType &node) const =0
Computes and sets the statistics for a node.
virtual LabelDataType getLabelOfNode(NodeType &node) const =0
Returns the label of the specified node.
virtual ~StatsEstimator()=default
Destructor.
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...
virtual void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char &branch_index) const =0
Computes the branch indices obtained by the specified threshold on the supplied feature evaluation re...
Define standard C methods and C++ classes that are common to all methods.
#define PCL_EXPORTS
Definition: pcl_macros.h:323