[mlpack-git] master: Adds GammaDistribution::Random() test (34d08ff)

gitdub at mlpack.org gitdub at mlpack.org
Sun Aug 7 06:32:30 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/4185aa07bbdef80ccdc78a3a3e479499058933db...931ec74894dd2fe0218d0d7dd77fc0ad9be0954d

>---------------------------------------------------------------

commit 34d08ffd75fb36a1ad521acb23d95fe5df005a07
Author: Yannis Mentekidis <mentekid at gmail.com>
Date:   Sun Aug 7 11:32:30 2016 +0100

    Adds GammaDistribution::Random() test


>---------------------------------------------------------------

34d08ffd75fb36a1ad521acb23d95fe5df005a07
 src/mlpack/tests/distribution_test.cpp | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp
index 7a411ee..5df3e16 100644
--- a/src/mlpack/tests/distribution_test.cpp
+++ b/src/mlpack/tests/distribution_test.cpp
@@ -539,6 +539,32 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainStatisticsTest)
   BOOST_REQUIRE_CLOSE(d1.Beta(0), d2.Beta(0), 1e-5);
 }
 
+/**
+ * Tests that Random() generates points that can be reasonably well fit by the
+ * distribution that generated them.
+ */
+BOOST_AUTO_TEST_CASE(GammaDistributionRandomTest)
+{
+  const arma::vec a("2.0 2.5 3.0"), b("0.4 0.6 1.3");
+  const size_t numPoints = 2000;
+
+  // Distribution to generate points.
+  GammaDistribution d1(a, b);
+  arma::mat data(3, numPoints); // 3-d points.
+
+  for (size_t i = 0; i < numPoints; ++i)
+    //std::cout << d1.Random() << "====" << std::endl;
+    data.col(i) = d1.Random();
+  
+  // Distribution to fit points.
+  GammaDistribution d2(data);
+  for (size_t i = 0; i < 3; ++i)
+  {
+    BOOST_REQUIRE_CLOSE(d2.Alpha(i), a(i), 10); // Within 10%
+    BOOST_REQUIRE_CLOSE(d2.Beta(i), b(i), 10);
+  }
+}
+
 BOOST_AUTO_TEST_CASE(GammaDistributionProbabilityTest)
 {
   // Train two 1-dimensional distributions.




More information about the mlpack-git mailing list