Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply clang-format to ml module (part 2) #3393

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 67 additions & 85 deletions ml/include/pcl/ml/dt/decision_forest.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#pragma once

#include <pcl/common/common.h>
Expand All @@ -44,89 +44,71 @@
#include <istream>
#include <ostream>

namespace pcl
{
namespace pcl {

/** Class representing a decision forest. */
template <class NodeType>
class PCL_EXPORTS DecisionForest : public std::vector<pcl::DecisionTree<NodeType>> {

public:
/** Constructor. */
DecisionForest() {}

/** \brief Class representing a decision forest. */
template <class NodeType>
class PCL_EXPORTS DecisionForest
: public std::vector<pcl::DecisionTree<NodeType> >
/** Destructor. */
virtual ~DecisionForest() {}

/** Serializes the decision tree.
*
* \param[out] stream The destination for the serialization
*/
void
serialize(::std::ostream& stream) const
{
const int num_of_trees = static_cast<int>(this->size());
stream.write(reinterpret_cast<const char*>(&num_of_trees), sizeof(num_of_trees));

for (size_t tree_index = 0; tree_index < this->size(); ++tree_index) {
(*this)[tree_index].serialize(stream);
}

// const int num_of_trees = static_cast<int> (trees_.size ());
// stream.write (reinterpret_cast<const char*> (&num_of_trees), sizeof
// (num_of_trees));

// for (size_t tree_index = 0; tree_index < trees_.size (); ++tree_index)
//{
// tree_[tree_index].serialize (stream);
//}
}

/** Deserializes the decision tree.
*
* \param[in] stream The source for the deserialization
*/
void
deserialize(::std::istream& stream)
{

public:

/** \brief Constructor. */
DecisionForest () {}
/** \brief Destructor. */
virtual
~DecisionForest () {}

/* \brief Adds the specified tree to the forest.
* \param[in] tree The tree to be added to the forest. */
//
//void
//addTree (DecisionTree<NodeType> & tree)
//{
// trees_.push_back (tree);
//}

///brief Returns the number of trees in the forest.
//inline size_t

/** \brief Serializes the decision tree.
* \param[out] stream The destination for the serialization.
*/
void
serialize (::std::ostream &stream) const
{
const int num_of_trees = static_cast<int> (this->size ());
stream.write (reinterpret_cast<const char*> (&num_of_trees), sizeof (num_of_trees));

for (size_t tree_index = 0; tree_index < this->size (); ++tree_index)
{
(*this) [tree_index].serialize (stream);
}

//const int num_of_trees = static_cast<int> (trees_.size ());
//stream.write (reinterpret_cast<const char*> (&num_of_trees), sizeof (num_of_trees));

//for (size_t tree_index = 0; tree_index < trees_.size (); ++tree_index)
//{
// tree_[tree_index].serialize (stream);
//}
}

/** \brief Deserializes the decision tree.
* \param[in] stream The source for the deserialization.
*/
void
deserialize (::std::istream & stream)
{
int num_of_trees;
stream.read (reinterpret_cast<char*> (&num_of_trees), sizeof (num_of_trees));
this->resize (num_of_trees);

for (size_t tree_index = 0; tree_index < this->size (); ++tree_index)
{
(*this) [tree_index].deserialize (stream);
}

//int num_of_trees;
//stream.read (reinterpret_cast<char*> (&num_of_trees), sizeof (num_of_trees));
//trees_.resize (num_of_trees);

//for (size_t tree_index = 0; tree_index < trees_.size (); ++tree_index)
//{
// tree_[tree_index].deserialize (stream);
//}
}

private:

/** \brief The decision trees contained in the forest. */
//std::vector<DecisionTree<NodeType> > trees_;

};


}
int num_of_trees;
stream.read(reinterpret_cast<char*>(&num_of_trees), sizeof(num_of_trees));
this->resize(num_of_trees);

for (size_t tree_index = 0; tree_index < this->size(); ++tree_index) {
(*this)[tree_index].deserialize(stream);
}

// int num_of_trees;
// stream.read (reinterpret_cast<char*> (&num_of_trees), sizeof (num_of_trees));
// trees_.resize (num_of_trees);

// for (size_t tree_index = 0; tree_index < trees_.size (); ++tree_index)
//{
// tree_[tree_index].deserialize (stream);
//}
}

private:
/** The decision trees contained in the forest. */
// std::vector<DecisionTree<NodeType> > trees_;
};

} // namespace pcl
114 changes: 59 additions & 55 deletions ml/include/pcl/ml/dt/decision_forest_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,74 +34,78 @@
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#pragma once

#include <pcl/common/common.h>

#include <pcl/ml/dt/decision_tree_evaluator.h>
#include <pcl/ml/dt/decision_forest.h>
#include <pcl/ml/dt/decision_tree_evaluator.h>
#include <pcl/ml/feature_handler.h>
#include <pcl/ml/stats_estimator.h>

#include <vector>

namespace pcl
{
namespace pcl {

/** Utility class for evaluating a decision forests. */
template <class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
class DecisionForestEvaluator {
public:
/** Constructor. */
DecisionForestEvaluator();

/** Destructor. */
virtual ~DecisionForestEvaluator();

/** \brief Utility class for evaluating a decision forests. */
template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType >
class DecisionForestEvaluator
{
public:
/** \brief Constructor. */
DecisionForestEvaluator();
/** \brief Destructor. */
virtual
~DecisionForestEvaluator();
/** Evaluates the specified examples using the supplied forest.
*
* \param[in] DecisionForestEvaluator the decision forest
* \param[in] feature_handler the feature handler used to train the tree
* \param[in] stats_estimator the statistics estimation instance used while training
* the tree
* \param[in] data_set the data set used for evaluation
* \param[in] examples the examples that have to be evaluated
* \param[out] label_data the destination for the resulting label data
*/
void
evaluate(
pcl::DecisionForest<NodeType>& DecisionForestEvaluator,
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);

/** \brief Evaluates the specified examples using the supplied forest.
* \param[in] DecisionForestEvaluator The decision forest.
* \param[in] feature_handler The feature handler used to train the tree.
* \param[in] stats_estimator The statistics estimation instance used while training the tree.
* \param[in] data_set The data set used for evaluation.
* \param[in] examples The examples that have to be evaluated.
* \param[out] label_data The destination for the resulting label data.
*/
void
evaluate (pcl::DecisionForest<NodeType> & DecisionForestEvaluator,
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 a specific patch using the supplied forest.
*
* \param[in] DecisionForestEvaluator the decision forest
* \param[in] feature_handler the feature handler used to train the tree
* \param[in] stats_estimator the statistics estimation instance used while training
* the tree
* \param[in] data_set the data set used for evaluation
* \param[in] example the examples that have to be evaluated
* \param[out] leaves the leaves where the patch arrives
*/
void
evaluate(
pcl::DecisionForest<NodeType>& DecisionForestEvaluator,
pcl::FeatureHandler<FeatureType, DataSet, ExampleIndex>& feature_handler,
pcl::StatsEstimator<LabelType, NodeType, DataSet, ExampleIndex>& stats_estimator,
DataSet& data_set,
ExampleIndex example,
std::vector<NodeType>& leaves);

/** \brief Evaluates a specific patch using the supplied forest.
* \param[in] DecisionForestEvaluator The decision forest.
* \param[in] feature_handler The feature handler used to train the tree.
* \param[in] stats_estimator The statistics estimation instance used while training the tree.
* \param[in] data_set The data set used for evaluation.
* \param[in] example The examples that have to be evaluated.
* \param[out] leaves The leaves where the patch arrives
*/
void
evaluate (pcl::DecisionForest<NodeType> & DecisionForestEvaluator,
pcl::FeatureHandler<FeatureType, DataSet, ExampleIndex> & feature_handler,
pcl::StatsEstimator<LabelType, NodeType, DataSet, ExampleIndex> & stats_estimator,
DataSet & data_set,
ExampleIndex example,
std::vector<NodeType> & leaves);

private:
/** \brief Evaluator for decision trees. */
DecisionTreeEvaluator<FeatureType, DataSet, LabelType, ExampleIndex, NodeType> tree_evaluator_;
};
private:
/** Evaluator for decision trees. */
DecisionTreeEvaluator<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>
tree_evaluator_;
};

}
} // namespace pcl

#include <pcl/ml/impl/dt/decision_forest_evaluator.hpp>
Loading