[mlpack-git] master: Add new tree trait. (822efa5)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed May 20 23:06:14 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/77d750c8fd46140b1d6060424f68768a21c89377...7e9cd46afb53817ae93ccbd02637d7726137ce4d
>---------------------------------------------------------------
commit 822efa58c71981c263e246c1d1e8512d24c528cd
Author: Ryan Curtin <ryan at ratml.org>
Date: Wed May 20 10:16:42 2015 -0400
Add new tree trait.
>---------------------------------------------------------------
822efa58c71981c263e246c1d1e8512d24c528cd
src/mlpack/core/tree/binary_space_tree/traits.hpp | 5 +++
src/mlpack/core/tree/cover_tree/traits.hpp | 5 +++
src/mlpack/core/tree/rectangle_tree/traits.hpp | 5 +++
src/mlpack/core/tree/tree_traits.hpp | 5 +++
src/mlpack/tests/tree_traits_test.cpp | 39 ++++++++++++++++++++---
5 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/src/mlpack/core/tree/binary_space_tree/traits.hpp b/src/mlpack/core/tree/binary_space_tree/traits.hpp
index 9d7dcf3..f809a5d 100644
--- a/src/mlpack/core/tree/binary_space_tree/traits.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/traits.hpp
@@ -46,6 +46,11 @@ class TreeTraits<BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>>
* Points are rearranged during building of the tree.
*/
static const bool RearrangesDataset = true;
+
+ /**
+ * This is always a binary tree.
+ */
+ static const bool BinaryTree = true;
};
} // namespace tree
diff --git a/src/mlpack/core/tree/cover_tree/traits.hpp b/src/mlpack/core/tree/cover_tree/traits.hpp
index 5db5040..dabc55a 100644
--- a/src/mlpack/core/tree/cover_tree/traits.hpp
+++ b/src/mlpack/core/tree/cover_tree/traits.hpp
@@ -47,6 +47,11 @@ class TreeTraits<CoverTree<MetricType, RootPointPolicy, StatisticType, MatType>>
* Points are not rearranged when the tree is built.
*/
static const bool RearrangesDataset = false;
+
+ /**
+ * The cover tree is not necessarily a binary tree.
+ */
+ static const bool BinaryTree = false;
};
}; // namespace tree
diff --git a/src/mlpack/core/tree/rectangle_tree/traits.hpp b/src/mlpack/core/tree/rectangle_tree/traits.hpp
index 069f417..0839c78 100644
--- a/src/mlpack/core/tree/rectangle_tree/traits.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/traits.hpp
@@ -46,6 +46,11 @@ class TreeTraits<RectangleTree<SplitType, DescentType, StatisticType, MatType> >
* AND REARRANGE THE MATRIX
*/
static const bool RearrangesDataset = false;
+
+ /**
+ * This tree is not necessarily a binary tree.
+ */
+ static const bool BinaryTree = false;
};
}; // namespace tree
diff --git a/src/mlpack/core/tree/tree_traits.hpp b/src/mlpack/core/tree/tree_traits.hpp
index 77ac166..ea701ab 100644
--- a/src/mlpack/core/tree/tree_traits.hpp
+++ b/src/mlpack/core/tree/tree_traits.hpp
@@ -94,6 +94,11 @@ class TreeTraits
* This is true if the tree rearranges points in the dataset when it is built.
*/
static const bool RearrangesDataset = false;
+
+ /**
+ * This is true if the tree always has only two children.
+ */
+ static const bool BinaryTree = false;
};
}; // namespace tree
diff --git a/src/mlpack/tests/tree_traits_test.cpp b/src/mlpack/tests/tree_traits_test.cpp
index f4182b0..0de745f 100644
--- a/src/mlpack/tests/tree_traits_test.cpp
+++ b/src/mlpack/tests/tree_traits_test.cpp
@@ -36,31 +36,60 @@ BOOST_AUTO_TEST_CASE(DefaultsTraitsTest)
BOOST_REQUIRE_EQUAL(b, true);
b = TreeTraits<int>::HasSelfChildren;
BOOST_REQUIRE_EQUAL(b, false);
+ b = TreeTraits<int>::FirstPointIsCentroid;
+ BOOST_REQUIRE_EQUAL(b, false);
+ b = TreeTraits<int>::RearrangesDataset;
+ BOOST_REQUIRE_EQUAL(b, false);
+ b = TreeTraits<int>::BinaryTree;
+ BOOST_REQUIRE_EQUAL(b, false);
}
// Test the binary space tree traits.
BOOST_AUTO_TEST_CASE(BinarySpaceTreeTraitsTest)
{
+ typedef BinarySpaceTree<LMetric<2, false>> TreeType;
+
// Children are non-overlapping.
- bool b =
- TreeTraits<BinarySpaceTree<LMetric<2, false> > >::HasOverlappingChildren;
+ bool b = TreeTraits<TreeType>::HasOverlappingChildren;
BOOST_REQUIRE_EQUAL(b, false);
// Points are not contained at multiple levels.
- b = TreeTraits<BinarySpaceTree<LMetric<2, false> > >::HasSelfChildren;
+ b = TreeTraits<TreeType>::HasSelfChildren;
BOOST_REQUIRE_EQUAL(b, false);
+
+ // The first point is not the centroid.
+ b = TreeTraits<TreeType>::FirstPointIsCentroid;
+ BOOST_REQUIRE_EQUAL(b, false);
+
+ // The dataset gets rearranged at build time.
+ b = TreeTraits<TreeType>::RearrangesDataset;
+ BOOST_REQUIRE_EQUAL(b, true);
+
+ // It is a binary tree.
+ b = TreeTraits<TreeType>::BinaryTree;
+ BOOST_REQUIRE_EQUAL(b, true);
}
// Test the cover tree traits.
BOOST_AUTO_TEST_CASE(CoverTreeTraitsTest)
{
// Children may be overlapping.
- bool b = TreeTraits<CoverTree<> >::HasOverlappingChildren;
+ bool b = TreeTraits<CoverTree<>>::HasOverlappingChildren;
BOOST_REQUIRE_EQUAL(b, true);
// The cover tree has self-children.
- b = TreeTraits<CoverTree<> >::HasSelfChildren;
+ b = TreeTraits<CoverTree<>>::HasSelfChildren;
+ BOOST_REQUIRE_EQUAL(b, true);
+
+ // The first point is the center of the node.
+ b = TreeTraits<CoverTree<>>::FirstPointIsCentroid;
BOOST_REQUIRE_EQUAL(b, true);
+
+ b = TreeTraits<CoverTree<>>::RearrangesDataset;
+ BOOST_REQUIRE_EQUAL(b, false);
+
+ b = TreeTraits<CoverTree<>>::BinaryTree;
+ BOOST_REQUIRE_EQUAL(b, false); // Not necessarily binary.
}
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-git
mailing list