Add GaussianCoverSingleKDETest

This commit is contained in:
Roberto Hueso Gomez
2019-08-26 19:34:46 +02:00
parent d232ff3455
commit bb4955fbb1
+36 -1
View File
@@ -214,13 +214,48 @@ BOOST_AUTO_TEST_CASE(EpanechnikovCoverSingleKDETest)
// Brute force KDE.
EpanechnikovKernel kernel(kernelBandwidth);
BruteForceKDE<EpanechnikovKernel>(reference,
query,
bfEstimations,
kernel);
// Optimized KDE.
metric::EuclideanDistance metric;
KDE<EpanechnikovKernel,
metric::EuclideanDistance,
arma::mat,
tree::StandardCoverTree>
kde(relError, 0.0, kernel, KDEMode::SINGLE_TREE_MODE, metric);
kde.Train(reference);
kde.Evaluate(query, treeEstimations);
// Check whether results are equal.
for (size_t i = 0; i < query.n_cols; ++i)
BOOST_REQUIRE_CLOSE(bfEstimations[i], treeEstimations[i], relError*100);
}
/**
* Test single-tree implementation results against brute force results using
* a cover-tree and Gaussian kernel.
*/
BOOST_AUTO_TEST_CASE(GaussianCoverSingleKDETest)
{
arma::mat reference = arma::randu(2, 300);
arma::mat query = arma::randu(2, 100);
arma::vec bfEstimations = arma::vec(query.n_cols, arma::fill::zeros);
arma::vec treeEstimations = arma::vec(query.n_cols, arma::fill::zeros);
const double kernelBandwidth = 1.1;
const double relError = 0.08;
// Brute force KDE.
GaussianKernel kernel(kernelBandwidth);
BruteForceKDE<GaussianKernel>(reference,
query,
bfEstimations,
kernel);
// Optimized KDE.
metric::EuclideanDistance metric;
KDE<EpanechnikovKernel,
KDE<GaussianKernel,
metric::EuclideanDistance,
arma::mat,
tree::StandardCoverTree>