src/mlpack/tests/knn_test.cpp
BOOST_AUTO_TEST_CASE(SingleCoverTreeTest)
{
  arma::mat data;
  data.randu(75, 1000); // 75 dimensional, 1000 points.

  StandardCoverTree<EuclideanDistance, NeighborSearchStat<NearestNeighborSort>,
      arma::mat> tree(data);

  NeighborSearch<NearestNeighborSort, LMetric<2>, arma::mat, StandardCoverTree>
      coverTreeSearch(std::move(tree), SINGLE_TREE_MODE);

  KNN naive(data, NAIVE_MODE);

  arma::Mat<size_t> coverTreeNeighbors;
  arma::mat coverTreeDistances;
  coverTreeSearch.Search(15, coverTreeNeighbors, coverTreeDistances);

  arma::Mat<size_t> naiveNeighbors;
  arma::mat naiveDistances;
  naive.Search(15, naiveNeighbors, naiveDistances);

  for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i)
  {
    BOOST_REQUIRE_EQUAL(coverTreeNeighbors[i], naiveNeighbors[i]);
    BOOST_REQUIRE_CLOSE(coverTreeDistances[i], naiveDistances[i], 1e-5);
  }
}
/**
 * Test the cover tree single-tree nearest-neighbors method against the naive
 * method.  This uses only a random reference dataset.
 *
 * Errors are produced if the results are not identical.
 */
Test the cover tree single-tree nearest-neighbors method against the naive
method.  This uses only a random reference dataset.

Errors are produced if the results are not identical.
Test the cover tree single - tree nearest - neighbors method against the naive method . This uses only a random reference dataset . Errors are produced if the results are not identical .
BOOST_AUTO_TEST_CASE(SingleCoverTreeTest)
{
  arma::mat data;
  data.randu(75, 1000); 
  StandardCoverTree<EuclideanDistance, NeighborSearchStat<NearestNeighborSort>,
      arma::mat> tree(data);
  NeighborSearch<NearestNeighborSort, LMetric<2>, arma::mat, StandardCoverTree>
      coverTreeSearch(std::move(tree), SINGLE_TREE_MODE);
  KNN naive(data, NAIVE_MODE);
  arma::Mat<size_t> coverTreeNeighbors;
  arma::mat coverTreeDistances;
  coverTreeSearch.Search(15, coverTreeNeighbors, coverTreeDistances);
  arma::Mat<size_t> naiveNeighbors;
  arma::mat naiveDistances;
  naive.Search(15, naiveNeighbors, naiveDistances);
  for (size_t i = 0; i < coverTreeNeighbors.n_elem; ++i)
  {
    BOOST_REQUIRE_EQUAL(coverTreeNeighbors[i], naiveNeighbors[i]);
    BOOST_REQUIRE_CLOSE(coverTreeDistances[i], naiveDistances[i], 1e-5);
  }
}
BOOST_AUTO_TEST_CASE ( SingleCoverTreeTest ) { arma :: mat data ; data . randu ( 75 , 1000 ) ; StandardCoverTree < EuclideanDistance , NeighborSearchStat < NearestNeighborSort > , arma :: mat > tree ( data ) ; NeighborSearch < NearestNeighborSort , LMetric < 2 > , arma :: mat , StandardCoverTree > coverTreeSearch ( std :: move ( tree ) , SINGLE_TREE_MODE ) ; KNN naive ( data , NAIVE_MODE ) ; arma :: Mat < size_t > coverTreeNeighbors ; arma :: mat coverTreeDistances ; coverTreeSearch . Search ( 15 , coverTreeNeighbors , coverTreeDistances ) ; arma :: Mat < size_t > naiveNeighbors ; arma :: mat naiveDistances ; naive . Search ( 15 , naiveNeighbors , naiveDistances ) ; for ( size_t i = 0 ; i < coverTreeNeighbors . n_elem ; ++ i ) { BOOST_REQUIRE_EQUAL ( coverTreeNeighbors [ i ] , naiveNeighbors [ i ] ) ; BOOST_REQUIRE_CLOSE ( coverTreeDistances [ i ] , naiveDistances [ i ] , 1e-5 ) ; } }
Test the cover tree single-tree nearest-neighbors method against the naive
 method.
Test the cover tree single - tree nearest - neighbors method against the naive method .
// 75 dimensional, 1000 points.