[mlpack-git] [mlpack/mlpack] GammaDistribution: Adds functionality to solve #749 (#751)
Ryan Curtin
notifications at github.com
Fri Aug 5 23:53:47 EDT 2016
> + // Combine into one 2-dimensional distribution.
> + const arma::vec a3("2.0 3.1"), b3("0.9 1.4");
> + arma::mat x3(2, 2);
> + x3
> + << 2.0 << 2.94 << arma::endr
> + << 2.0 << 2.94;
> + arma::vec prob3;
> +
> + // Expect that the 2-dimensional distribution returns the product of the
> + // 1-dimensional distributions (evaluated at wolfram|alpha).
> + GammaDistribution d3(a3, b3);
> + d3.LogProbability(x3, prob3);
> + BOOST_REQUIRE_CLOSE(prob3(0), std::log(0.04408), 1e-3);
> + BOOST_REQUIRE_CLOSE(prob3(1), std::log(0.026165), 1e-3);
> +}
> +
Can you add a test for the `Random()` function? Here's some idea:
```
BOOST_AUTO_TEST_CASE(RandomTest)
{
arma::vec alphas("1.0 2.0 3.0");
arma::vec beta("1.5 2.5 3.5");
GammaDistribution d(alphas, betas);
arma::mat observations(1000, 3);
for (size_t i = 0; i < 1000; ++i)
observations.col(i) = d.Random();
// Train a second distribution, then ensure it is similar to the first.
GammaDistribution d2(observations);
// Check the values, with a fairly large tolerance (3%).
BOOST_REQUIRE_CLOSE(d.Alpha(0), d2.Alpha(0), 3.0);
BOOST_REQUIRE_CLOSE(d.Alpha(1), d2.Alpha(1), 3.0);
BOOST_REQUIRE_CLOSE(d.Alpha(2), d2.Alpha(2), 3.0);
BOOST_REQUIRE_CLOSE(d.Beta(0), d2.Beta(0), 3.0);
BOOST_REQUIRE_CLOSE(d.Beta(1), d2.Beta(1), 3.0);
BOOST_REQUIRE_CLOSE(d.Beta(2), d2.Beta(2), 3.0);
// Should these all be Alphas()[i] and Betas()[i]?
}
```
To test the tolerance, add a `math::RandomSeed(std::time(NULL))` at the top, recompile, and run this: `while(true); do bin/mlpack_test -t GammaDistributionTest/RandomTest; sleep 1; done` and make sure that over a decent period of time, you don't see any failures. If so, 5% or maybe even 10% are reasonable tolerances. We just want to check that it's giving us stuff that's "reasonably close" to a Gamma distribution; checking exact precision is quite a large amount of work and here I am not sure that effort is warranted.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/pull/751/files/9cb117f671f55186baddf38ce71107a2a3ae027f#r73780342
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20160805/071efc8e/attachment.html>
More information about the mlpack-git
mailing list