[mlpack-svn] r16219 - mlpack/trunk/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Feb 6 14:58:04 EST 2014
Author: rcurtin
Date: Thu Feb 6 14:58:04 2014
New Revision: 16219
Log:
Also test ParentDistance() in the case where the tree is built and mappings are
used.
Modified:
mlpack/trunk/src/mlpack/tests/tree_test.cpp
Modified: mlpack/trunk/src/mlpack/tests/tree_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/tree_test.cpp (original)
+++ mlpack/trunk/src/mlpack/tests/tree_test.cpp Thu Feb 6 14:58:04 2014
@@ -1673,6 +1673,49 @@
}
}
+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-svn
mailing list