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

  KNN tree(dataset);

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

  StandardCoverTree<EuclideanDistance, NeighborSearchStat<NearestNeighborSort>,
      arma::mat> referenceTree(dataset);

  NeighborSearch<NearestNeighborSort, EuclideanDistance, arma::mat,
      StandardCoverTree> coverTreeSearch(std::move(referenceTree));

  arma::Mat<size_t> coverNeighbors;
  arma::mat coverDistances;
  coverTreeSearch.Search(dataset, 5, coverNeighbors, coverDistances);

  for (size_t i = 0; i < coverNeighbors.n_elem; ++i)
  {
    BOOST_REQUIRE_EQUAL(coverNeighbors(i), kdNeighbors(i));
    BOOST_REQUIRE_CLOSE(coverDistances(i), kdDistances(i), 1e-5);
  }
}
/**
 * Test the cover tree dual-tree nearest neighbors method against the naive
 * method.
 */
Test the cover tree dual-tree nearest neighbors method against the naive
method.
Test the cover tree dual - tree nearest neighbors method against the naive method .
BOOST_AUTO_TEST_CASE(DualCoverTreeTest)
{
  arma::mat dataset;
  data::Load("test_data_3_1000.csv", dataset);
  KNN tree(dataset);
  arma::Mat<size_t> kdNeighbors;
  arma::mat kdDistances;
  tree.Search(dataset, 5, kdNeighbors, kdDistances);
  StandardCoverTree<EuclideanDistance, NeighborSearchStat<NearestNeighborSort>,
      arma::mat> referenceTree(dataset);
  NeighborSearch<NearestNeighborSort, EuclideanDistance, arma::mat,
      StandardCoverTree> coverTreeSearch(std::move(referenceTree));
  arma::Mat<size_t> coverNeighbors;
  arma::mat coverDistances;
  coverTreeSearch.Search(dataset, 5, coverNeighbors, coverDistances);
  for (size_t i = 0; i < coverNeighbors.n_elem; ++i)
  {
    BOOST_REQUIRE_EQUAL(coverNeighbors(i), kdNeighbors(i));
    BOOST_REQUIRE_CLOSE(coverDistances(i), kdDistances(i), 1e-5);
  }
}
BOOST_AUTO_TEST_CASE ( DualCoverTreeTest ) { arma :: mat dataset ; data :: Load ( " " , dataset ) ; KNN tree ( dataset ) ; arma :: Mat < size_t > kdNeighbors ; arma :: mat kdDistances ; tree . Search ( dataset , 5 , kdNeighbors , kdDistances ) ; StandardCoverTree < EuclideanDistance , NeighborSearchStat < NearestNeighborSort > , arma :: mat > referenceTree ( dataset ) ; NeighborSearch < NearestNeighborSort , EuclideanDistance , arma :: mat , StandardCoverTree > coverTreeSearch ( std :: move ( referenceTree ) ) ; arma :: Mat < size_t > coverNeighbors ; arma :: mat coverDistances ; coverTreeSearch . Search ( dataset , 5 , coverNeighbors , coverDistances ) ; for ( size_t i = 0 ; i < coverNeighbors . n_elem ; ++ i ) { BOOST_REQUIRE_EQUAL ( coverNeighbors ( i ) , kdNeighbors ( i ) ) ; BOOST_REQUIRE_CLOSE ( coverDistances ( i ) , kdDistances ( i ) , 1e-5 ) ; } }
Test the cover tree dual-tree nearest neighbors method against the naive
 method.
Test the cover tree dual - tree nearest neighbors method against the naive method .