src/mlpack/tests/knn_test.cpp
BOOST_AUTO_TEST_CASE(DualBallTreeTest)
{
  arma::mat dataset;
  data::Load("test_data_3_1000.csv", dataset);

  KNN tree(dataset);

  arma::Mat<size_t> kdNeighbors;
  arma::mat kdDistances;
  tree.Search(5, kdNeighbors, kdDistances);

  NeighborSearch<NearestNeighborSort, EuclideanDistance, arma::mat, BallTree>
      ballTreeSearch(dataset);

  arma::Mat<size_t> ballNeighbors;
  arma::mat ballDistances;
  ballTreeSearch.Search(5, ballNeighbors, ballDistances);

  for (size_t i = 0; i < ballNeighbors.n_elem; ++i)
  {
    BOOST_REQUIRE_EQUAL(ballNeighbors(i), kdNeighbors(i));
    BOOST_REQUIRE_CLOSE(ballDistances(i), kdDistances(i), 1e-5);
  }
}
/**
 * Test the ball tree dual-tree nearest neighbors method against the naive
 * method.
 */
Test the ball tree dual-tree nearest neighbors method against the naive
method.
Test the ball tree dual - tree nearest neighbors method against the naive method .
BOOST_AUTO_TEST_CASE(DualBallTreeTest)
{
  arma::mat dataset;
  data::Load("test_data_3_1000.csv", dataset);
  KNN tree(dataset);
  arma::Mat<size_t> kdNeighbors;
  arma::mat kdDistances;
  tree.Search(5, kdNeighbors, kdDistances);
  NeighborSearch<NearestNeighborSort, EuclideanDistance, arma::mat, BallTree>
      ballTreeSearch(dataset);
  arma::Mat<size_t> ballNeighbors;
  arma::mat ballDistances;
  ballTreeSearch.Search(5, ballNeighbors, ballDistances);
  for (size_t i = 0; i < ballNeighbors.n_elem; ++i)
  {
    BOOST_REQUIRE_EQUAL(ballNeighbors(i), kdNeighbors(i));
    BOOST_REQUIRE_CLOSE(ballDistances(i), kdDistances(i), 1e-5);
  }
}
BOOST_AUTO_TEST_CASE ( DualBallTreeTest ) { arma :: mat dataset ; data :: Load ( " " , dataset ) ; KNN tree ( dataset ) ; arma :: Mat < size_t > kdNeighbors ; arma :: mat kdDistances ; tree . Search ( 5 , kdNeighbors , kdDistances ) ; NeighborSearch < NearestNeighborSort , EuclideanDistance , arma :: mat , BallTree > ballTreeSearch ( dataset ) ; arma :: Mat < size_t > ballNeighbors ; arma :: mat ballDistances ; ballTreeSearch . Search ( 5 , ballNeighbors , ballDistances ) ; for ( size_t i = 0 ; i < ballNeighbors . n_elem ; ++ i ) { BOOST_REQUIRE_EQUAL ( ballNeighbors ( i ) , kdNeighbors ( i ) ) ; BOOST_REQUIRE_CLOSE ( ballDistances ( i ) , kdDistances ( i ) , 1e-5 ) ; } }
Test the ball tree dual-tree nearest neighbors method against the naive
 method.
Test the ball tree dual - tree nearest neighbors method against the naive method .