I've concluded that this test isn't useful.

Basically, the test is just checking that the implementation is exactly the same
as in the test, and that's not actually a great test, because the implementation
may change without breaking anything.
This commit is contained in:
Ryan Curtin
2015-03-02 20:24:04 -05:00
parent 2b76e6d0ac
commit b7769dcffb
-72
View File
@@ -23,78 +23,6 @@ using namespace mlpack::bound;
BOOST_AUTO_TEST_SUITE(AllkRANNTest);
// Test AllkRANN in naive mode for exact results when the random seeds are set
// the same. This may not be the best test; if the implementation of RANN-RS
// gets random numbers in a different way, then this test might fail.
BOOST_AUTO_TEST_CASE(NaiveSearchExact)
{
// First test on a small set.
arma::mat rdata(2, 10);
rdata << 3 << 2 << 4 << 3 << 5 << 6 << 0 << 8 << 3 << 1 << arma::endr <<
0 << 3 << 4 << 7 << 8 << 4 << 1 << 0 << 4 << 3 << arma::endr;
arma::mat qdata(2, 3);
qdata << 3 << 2 << 0 << arma::endr
<< 5 << 3 << 4 << arma::endr;
metric::SquaredEuclideanDistance dMetric;
double rankApproximation = 30;
double successProb = 0.95;
// Search for 1 rank-approximate nearest-neighbors in the top 30% of the point
// (rank error of 3).
arma::Mat<size_t> neighbors;
arma::mat distances;
// Test naive rank-approximate search.
// Predict what the actual RANN-RS result would be.
math::RandomSeed(0);
size_t numSamples = (size_t) ceil(log(1.0 / (1.0 - successProb)) /
log(1.0 / (1.0 - (rankApproximation / 100.0))));
arma::Mat<size_t> samples(qdata.n_cols, numSamples);
for (size_t j = 0; j < qdata.n_cols; j++)
for (size_t i = 0; i < numSamples; i++)
samples(j, i) = (size_t) math::RandInt(10);
arma::Col<size_t> rann(qdata.n_cols);
arma::vec rannDistances(qdata.n_cols);
rannDistances.fill(DBL_MAX);
for (size_t j = 0; j < qdata.n_cols; j++)
{
for (size_t i = 0; i < numSamples; i++)
{
double dist = dMetric.Evaluate(qdata.unsafe_col(j),
rdata.unsafe_col(samples(j, i)));
if (dist < rannDistances[j])
{
rann[j] = samples(j, i);
rannDistances[j] = dist;
}
}
}
// Use RANN-RS implementation.
math::RandomSeed(0);
RASearch<> naive(rdata, qdata, true);
naive.Search(1, neighbors, distances, rankApproximation);
// Things to check:
//
// 1. (implicitly) The minimum number of required samples for guaranteed
// approximation.
// 2. (implicitly) Check the samples obtained.
// 3. Check the neighbor returned.
for (size_t i = 0; i < qdata.n_cols; i++)
{
BOOST_REQUIRE_EQUAL(neighbors(0, i), rann[i]);
BOOST_REQUIRE_CLOSE(distances(0, i), rannDistances[i], 1e-5);
}
}
// Test the correctness and guarantees of AllkRANN when in naive mode.
BOOST_AUTO_TEST_CASE(NaiveGuaranteeTest)
{