[mlpack-git] master, mlpack-1.0.x: Also test ParentDistance() in the case where the tree is built and mappings are used. (9f9b4fe)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:42:11 EST 2015
Repository : https://github.com/mlpack/mlpack
On branches: master,mlpack-1.0.x
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 9f9b4fe458f9c54fc9d0d515f165b0d523cec0ff
Author: Ryan Curtin <ryan at ratml.org>
Date: Thu Feb 6 19:58:04 2014 +0000
Also test ParentDistance() in the case where the tree is built and mappings are
used.
>---------------------------------------------------------------
9f9b4fe458f9c54fc9d0d515f165b0d523cec0ff
src/mlpack/tests/tree_test.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/src/mlpack/tests/tree_test.cpp b/src/mlpack/tests/tree_test.cpp
index b26d088..41d1576 100644
--- a/src/mlpack/tests/tree_test.cpp
+++ b/src/mlpack/tests/tree_test.cpp
@@ -1673,6 +1673,49 @@ BOOST_AUTO_TEST_CASE(ParentDistanceTest)
}
}
+BOOST_AUTO_TEST_CASE(ParentDistanceTestWithMapping)
+{
+ arma::mat dataset;
+ dataset.randu(5, 500);
+ std::vector<size_t> oldFromNew;
+
+ BinarySpaceTree<HRectBound<2> > tree(dataset, oldFromNew);
+
+ // The root's parent distance should be 0 (although maybe it doesn't actually
+ // matter; I just want to be sure it's not an uninitialized value, which this
+ // test *sort* of checks).
+ BOOST_REQUIRE_EQUAL(tree.ParentDistance(), 0.0);
+
+ // Do a depth-first traversal and make sure the parent distance is the same as
+ // we calculate.
+ std::stack<BinarySpaceTree<HRectBound<2> >*> nodeStack;
+ nodeStack.push(&tree);
+
+ while (!nodeStack.empty())
+ {
+ BinarySpaceTree<HRectBound<2> >* node = nodeStack.top();
+ nodeStack.pop();
+
+ // If it's a leaf, nothing to check.
+ if (node->NumChildren() == 0)
+ continue;
+
+ arma::vec centroid, leftCentroid, rightCentroid;
+ node->Centroid(centroid);
+ node->Left()->Centroid(leftCentroid);
+ node->Right()->Centroid(rightCentroid);
+
+ const double leftDistance = LMetric<2>::Evaluate(centroid, leftCentroid);
+ const double rightDistance = LMetric<2>::Evaluate(centroid, rightCentroid);
+
+ BOOST_REQUIRE_CLOSE(leftDistance, node->Left()->ParentDistance(), 1e-5);
+ BOOST_REQUIRE_CLOSE(rightDistance, node->Right()->ParentDistance(), 1e-5);
+
+ nodeStack.push(node->Left());
+ nodeStack.push(node->Right());
+ }
+}
+
// Forward declaration of methods we need for the next test.
template<typename TreeType, typename MatType>
bool CheckPointBounds(TreeType* node, const MatType& data);
More information about the mlpack-git
mailing list