[mlpack-git] master: Split implementation of different split methods in separated files, and move all of them to a separated directory, so they can be used by other tree types. (8f32156)
gitdub at mlpack.org
gitdub at mlpack.org
Mon Aug 8 16:26:57 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/0f4b25acd6aaa14294c044874ba6cc0751712baa...0a19d07bd39e6223991976474bc79671ba8aa0f0
>---------------------------------------------------------------
commit 8f3215645f335bf1a96e3ae401c0e66d51517c8b
Author: MarcosPividori <marcos.pividori at gmail.com>
Date: Mon Aug 8 17:26:57 2016 -0300
Split implementation of different split methods in separated files, and move all of them to a separated directory, so they can be used by other tree types.
>---------------------------------------------------------------
8f3215645f335bf1a96e3ae401c0e66d51517c8b
src/mlpack/core/tree/CMakeLists.txt | 12 ++++--
.../{spill_tree => space_split}/hyperplane.hpp | 0
.../core/tree/space_split/mean_space_split.hpp | 45 +++++++++++++++++++
.../tree/space_split/mean_space_split_impl.hpp | 45 +++++++++++++++++++
.../core/tree/space_split/midpoint_space_split.hpp | 45 +++++++++++++++++++
.../tree/space_split/midpoint_space_split_impl.hpp | 40 +++++++++++++++++
.../projection_vector.hpp | 0
.../{spill_tree => space_split}/space_split.hpp | 49 +--------------------
.../space_split_impl.hpp | 50 +---------------------
src/mlpack/core/tree/spill_tree/spill_tree.hpp | 4 +-
src/mlpack/core/tree/spill_tree/typedef.hpp | 5 +--
11 files changed, 190 insertions(+), 105 deletions(-)
diff --git a/src/mlpack/core/tree/CMakeLists.txt b/src/mlpack/core/tree/CMakeLists.txt
index 030a8c0..f3ab9cc 100644
--- a/src/mlpack/core/tree/CMakeLists.txt
+++ b/src/mlpack/core/tree/CMakeLists.txt
@@ -75,15 +75,19 @@ set(SOURCES
rectangle_tree/r_plus_plus_tree_split_policy.hpp
rectangle_tree/r_plus_plus_tree_auxiliary_information.hpp
rectangle_tree/r_plus_plus_tree_auxiliary_information_impl.hpp
+ space_split/hyperplane.hpp
+ space_split/mean_space_split.hpp
+ space_split/mean_space_split_impl.hpp
+ space_split/midpoint_space_split.hpp
+ space_split/midpoint_space_split_impl.hpp
+ space_split/projection_vector.hpp
+ space_split/space_split.hpp
+ space_split/space_split_impl.hpp
spill_tree.hpp
spill_tree/spill_tree.hpp
spill_tree/spill_tree_impl.hpp
spill_tree/dual_tree_traverser.hpp
spill_tree/dual_tree_traverser_impl.hpp
- spill_tree/hyperplane.hpp
- spill_tree/projection_vector.hpp
- spill_tree/space_split.hpp
- spill_tree/space_split_impl.hpp
spill_tree/single_tree_traverser.hpp
spill_tree/single_tree_traverser_impl.hpp
spill_tree/traits.hpp
diff --git a/src/mlpack/core/tree/spill_tree/hyperplane.hpp b/src/mlpack/core/tree/space_split/hyperplane.hpp
similarity index 100%
rename from src/mlpack/core/tree/spill_tree/hyperplane.hpp
rename to src/mlpack/core/tree/space_split/hyperplane.hpp
diff --git a/src/mlpack/core/tree/space_split/mean_space_split.hpp b/src/mlpack/core/tree/space_split/mean_space_split.hpp
new file mode 100644
index 0000000..d405d42
--- /dev/null
+++ b/src/mlpack/core/tree/space_split/mean_space_split.hpp
@@ -0,0 +1,45 @@
+/**
+ * @file mean_space_split.hpp
+ * @author Marcos Pividori
+ *
+ * Definition of MeanSpaceSplit, to create a splitting hyperplane considering
+ * the mean of the values in a certain projection.
+ */
+#ifndef MLPACK_CORE_TREE_SPILL_TREE_MEAN_SPACE_SPLIT_HPP
+#define MLPACK_CORE_TREE_SPILL_TREE_MEAN_SPACE_SPLIT_HPP
+
+#include <mlpack/core.hpp>
+#include "hyperplane.hpp"
+
+namespace mlpack {
+namespace tree {
+
+template<typename MetricType, typename MatType>
+class MeanSpaceSplit
+{
+ public:
+ /**
+ * Create a splitting hyperplane considering the mean of the values in a
+ * certain projection.
+ *
+ * @param bound The bound used for this node.
+ * @param data The dataset used by the tree.
+ * @param points Vector of indexes of points to be considered.
+ * @param hyp Resulting splitting hyperplane.
+ * @return Flag to determine if split is possible.
+ */
+ template<typename HyperplaneType>
+ static bool SplitSpace(
+ const typename HyperplaneType::BoundType& bound,
+ const MatType& data,
+ const arma::Col<size_t>& points,
+ HyperplaneType& hyp);
+};
+
+} // namespace tree
+} // namespace mlpack
+
+// Include implementation.
+#include "mean_space_split_impl.hpp"
+
+#endif
diff --git a/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp b/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp
new file mode 100644
index 0000000..6edacec
--- /dev/null
+++ b/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp
@@ -0,0 +1,45 @@
+/**
+ * @file mean_space_split_impl.hpp
+ * @author Marcos Pividori
+ *
+ * Implementation of MeanSpaceSplit, to create a splitting hyperplane
+ * considering the midpoint/mean of the values in a certain projection.
+ */
+#ifndef MLPACK_CORE_TREE_SPILL_TREE_MEAN_SPACE_SPLIT_IMPL_HPP
+#define MLPACK_CORE_TREE_SPILL_TREE_MEAN_SPACE_SPLIT_IMPL_HPP
+
+#include "mean_space_split.hpp"
+#include "space_split.hpp"
+
+namespace mlpack {
+namespace tree {
+
+template<typename MetricType, typename MatType>
+template<typename HyperplaneType>
+bool MeanSpaceSplit<MetricType, MatType>::SplitSpace(
+ const typename HyperplaneType::BoundType& bound,
+ const MatType& data,
+ const arma::Col<size_t>& points,
+ HyperplaneType& hyp)
+{
+ typename HyperplaneType::ProjVectorType projVector;
+ double midValue;
+
+ if (!SpaceSplit<MetricType, MatType>::GetProjVector(bound, data, points,
+ projVector, midValue))
+ return false;
+
+ double splitVal = 0.0;
+ for (size_t i = 0; i < points.n_elem; i++)
+ splitVal += projVector.Project(data.col(points[i]));
+ splitVal /= points.n_elem;
+
+ hyp = HyperplaneType(projVector, splitVal);
+
+ return true;
+}
+
+} // namespace tree
+} // namespace mlpack
+
+#endif
diff --git a/src/mlpack/core/tree/space_split/midpoint_space_split.hpp b/src/mlpack/core/tree/space_split/midpoint_space_split.hpp
new file mode 100644
index 0000000..e239d66
--- /dev/null
+++ b/src/mlpack/core/tree/space_split/midpoint_space_split.hpp
@@ -0,0 +1,45 @@
+/**
+ * @file midpoing_space_split.hpp
+ * @author Marcos Pividori
+ *
+ * Definition of MidpointSpaceSplit, to create a splitting hyperplane
+ * considering the midpoint of the values in a certain projection.
+ */
+#ifndef MLPACK_CORE_TREE_SPILL_TREE_MIDPOINT_SPACE_SPLIT_HPP
+#define MLPACK_CORE_TREE_SPILL_TREE_MIDPOINT_SPACE_SPLIT_HPP
+
+#include <mlpack/core.hpp>
+#include "hyperplane.hpp"
+
+namespace mlpack {
+namespace tree {
+
+template<typename MetricType, typename MatType>
+class MidpointSpaceSplit
+{
+ public:
+ /**
+ * Create a splitting hyperplane considering the midpoint of the values in a
+ * certain projection.
+ *
+ * @param bound The bound used for this node.
+ * @param data The dataset used by the tree.
+ * @param points Vector of indexes of points to be considered.
+ * @param hyp Resulting splitting hyperplane.
+ * @return Flag to determine if split is possible.
+ */
+ template<typename HyperplaneType>
+ static bool SplitSpace(
+ const typename HyperplaneType::BoundType& bound,
+ const MatType& data,
+ const arma::Col<size_t>& points,
+ HyperplaneType& hyp);
+};
+
+} // namespace tree
+} // namespace mlpack
+
+// Include implementation.
+#include "midpoint_space_split_impl.hpp"
+
+#endif
diff --git a/src/mlpack/core/tree/space_split/midpoint_space_split_impl.hpp b/src/mlpack/core/tree/space_split/midpoint_space_split_impl.hpp
new file mode 100644
index 0000000..f716b4e
--- /dev/null
+++ b/src/mlpack/core/tree/space_split/midpoint_space_split_impl.hpp
@@ -0,0 +1,40 @@
+/**
+ * @file midpoint_space_split_impl.hpp
+ * @author Marcos Pividori
+ *
+ * Implementation of MidpointSpaceSplit, to create a splitting hyperplane
+ * considering the midpoint of the values in a certain projection.
+ */
+#ifndef MLPACK_CORE_TREE_SPILL_TREE_MIDPOINT_SPACE_SPLIT_IMPL_HPP
+#define MLPACK_CORE_TREE_SPILL_TREE_MIDPOINT_SPACE_SPLIT_IMPL_HPP
+
+#include "midpoint_space_split.hpp"
+#include "space_split.hpp"
+
+namespace mlpack {
+namespace tree {
+
+template<typename MetricType, typename MatType>
+template<typename HyperplaneType>
+bool MidpointSpaceSplit<MetricType, MatType>::SplitSpace(
+ const typename HyperplaneType::BoundType& bound,
+ const MatType& data,
+ const arma::Col<size_t>& points,
+ HyperplaneType& hyp)
+{
+ typename HyperplaneType::ProjVectorType projVector;
+ double midValue;
+
+ if (!SpaceSplit<MetricType, MatType>::GetProjVector(bound, data, points,
+ projVector, midValue))
+ return false;
+
+ hyp = HyperplaneType(projVector, midValue);
+
+ return true;
+}
+
+} // namespace tree
+} // namespace mlpack
+
+#endif
diff --git a/src/mlpack/core/tree/spill_tree/projection_vector.hpp b/src/mlpack/core/tree/space_split/projection_vector.hpp
similarity index 100%
rename from src/mlpack/core/tree/spill_tree/projection_vector.hpp
rename to src/mlpack/core/tree/space_split/projection_vector.hpp
diff --git a/src/mlpack/core/tree/spill_tree/space_split.hpp b/src/mlpack/core/tree/space_split/space_split.hpp
similarity index 56%
rename from src/mlpack/core/tree/spill_tree/space_split.hpp
rename to src/mlpack/core/tree/space_split/space_split.hpp
index da2d9b5..c4c526d 100644
--- a/src/mlpack/core/tree/spill_tree/space_split.hpp
+++ b/src/mlpack/core/tree/space_split/space_split.hpp
@@ -2,9 +2,8 @@
* @file space_split.hpp
* @author Marcos Pividori
*
- * Definition of MidpointSpaceSplit and MeanSpaceSplit, to create a splitting
- * hyperplane considering the midpoint/mean of the values in a certain
- * projection.
+ * Definition of SpaceSplit, implementing some methods to create a projection
+ * vector based on a given set of points.
*/
#ifndef MLPACK_CORE_TREE_SPILL_TREE_SPACE_SPLIT_HPP
#define MLPACK_CORE_TREE_SPILL_TREE_SPACE_SPLIT_HPP
@@ -16,50 +15,6 @@ namespace mlpack {
namespace tree {
template<typename MetricType, typename MatType>
-class MeanSpaceSplit
-{
- public:
- /**
- * Create a splitting hyperplane considering the mean of the values in a
- * certain projection.
- *
- * @param bound The bound used for this node.
- * @param data The dataset used by the tree.
- * @param points Vector of indexes of points to be considered.
- * @param hyp Resulting splitting hyperplane.
- * @return Flag to determine if split is possible.
- */
- template<typename HyperplaneType>
- static bool SplitSpace(
- const typename HyperplaneType::BoundType& bound,
- const MatType& data,
- const arma::Col<size_t>& points,
- HyperplaneType& hyp);
-};
-
-template<typename MetricType, typename MatType>
-class MidpointSpaceSplit
-{
- public:
- /**
- * Create a splitting hyperplane considering the midpoint of the values in a
- * certain projection.
- *
- * @param bound The bound used for this node.
- * @param data The dataset used by the tree.
- * @param points Vector of indexes of points to be considered.
- * @param hyp Resulting splitting hyperplane.
- * @return Flag to determine if split is possible.
- */
- template<typename HyperplaneType>
- static bool SplitSpace(
- const typename HyperplaneType::BoundType& bound,
- const MatType& data,
- const arma::Col<size_t>& points,
- HyperplaneType& hyp);
-};
-
-template<typename MetricType, typename MatType>
class SpaceSplit
{
public:
diff --git a/src/mlpack/core/tree/spill_tree/space_split_impl.hpp b/src/mlpack/core/tree/space_split/space_split_impl.hpp
similarity index 62%
rename from src/mlpack/core/tree/spill_tree/space_split_impl.hpp
rename to src/mlpack/core/tree/space_split/space_split_impl.hpp
index a9628c0..96b4235 100644
--- a/src/mlpack/core/tree/spill_tree/space_split_impl.hpp
+++ b/src/mlpack/core/tree/space_split/space_split_impl.hpp
@@ -2,9 +2,8 @@
* @file space_split_impl.hpp
* @author Marcos Pividori
*
- * Implementation of MidpointSpaceSplit and MeanSpaceSplit, to create a
- * splitting hyperplane considering the midpoint/mean of the values in a certain
- * projection.
+ * Implementation of SpaceSplit, to create a projection vector based on a given
+ * set of points.
*/
#ifndef MLPACK_CORE_TREE_SPILL_TREE_SPACE_SPLIT_IMPL_HPP
#define MLPACK_CORE_TREE_SPILL_TREE_SPACE_SPLIT_IMPL_HPP
@@ -15,51 +14,6 @@ namespace mlpack {
namespace tree {
template<typename MetricType, typename MatType>
-template<typename HyperplaneType>
-bool MeanSpaceSplit<MetricType, MatType>::SplitSpace(
- const typename HyperplaneType::BoundType& bound,
- const MatType& data,
- const arma::Col<size_t>& points,
- HyperplaneType& hyp)
-{
- typename HyperplaneType::ProjVectorType projVector;
- double midValue;
-
- if (!SpaceSplit<MetricType, MatType>::GetProjVector(bound, data, points,
- projVector, midValue))
- return false;
-
- double splitVal = 0.0;
- for (size_t i = 0; i < points.n_elem; i++)
- splitVal += projVector.Project(data.col(points[i]));
- splitVal /= points.n_elem;
-
- hyp = HyperplaneType(projVector, splitVal);
-
- return true;
-}
-
-template<typename MetricType, typename MatType>
-template<typename HyperplaneType>
-bool MidpointSpaceSplit<MetricType, MatType>::SplitSpace(
- const typename HyperplaneType::BoundType& bound,
- const MatType& data,
- const arma::Col<size_t>& points,
- HyperplaneType& hyp)
-{
- typename HyperplaneType::ProjVectorType projVector;
- double midValue;
-
- if (!SpaceSplit<MetricType, MatType>::GetProjVector(bound, data, points,
- projVector, midValue))
- return false;
-
- hyp = HyperplaneType(projVector, midValue);
-
- return true;
-}
-
-template<typename MetricType, typename MatType>
bool SpaceSplit<MetricType, MatType>::GetProjVector(
const bound::HRectBound<MetricType>& bound,
const MatType& data,
diff --git a/src/mlpack/core/tree/spill_tree/spill_tree.hpp b/src/mlpack/core/tree/spill_tree/spill_tree.hpp
index 7e99d6f..24c97f2 100644
--- a/src/mlpack/core/tree/spill_tree/spill_tree.hpp
+++ b/src/mlpack/core/tree/spill_tree/spill_tree.hpp
@@ -7,10 +7,8 @@
#define MLPACK_CORE_TREE_SPILL_TREE_SPILL_TREE_HPP
#include <mlpack/core.hpp>
-
+#include "../space_split/midpoint_space_split.hpp"
#include "../statistic.hpp"
-#include "space_split.hpp"
-#include "hyperplane.hpp"
namespace mlpack {
namespace tree /** Trees and tree-building procedures. */ {
diff --git a/src/mlpack/core/tree/spill_tree/typedef.hpp b/src/mlpack/core/tree/spill_tree/typedef.hpp
index edf29f7..6773442 100644
--- a/src/mlpack/core/tree/spill_tree/typedef.hpp
+++ b/src/mlpack/core/tree/spill_tree/typedef.hpp
@@ -9,9 +9,8 @@
#ifndef MLPACK_CORE_TREE_SPILL_TREE_TYPEDEF_HPP
#define MLPACK_CORE_TREE_SPILL_TREE_TYPEDEF_HPP
-// In case it hasn't been included yet.
-#include "../spill_tree.hpp"
-#include "space_split.hpp"
+#include "../space_split/mean_space_split.hpp"
+#include "../space_split/midpoint_space_split.hpp"
namespace mlpack {
namespace tree {
More information about the mlpack-git
mailing list