<p>In <a href="https://github.com/mlpack/mlpack/pull/751#discussion_r73780342">src/mlpack/tests/distribution_test.cpp</a>:</p>
<pre style='color:#555'>&gt; +  // Combine into one 2-dimensional distribution.
&gt; +  const arma::vec a3(&quot;2.0 3.1&quot;), b3(&quot;0.9 1.4&quot;);
&gt; +  arma::mat x3(2, 2);
&gt; +  x3
&gt; +    &lt;&lt; 2.0 &lt;&lt; 2.94 &lt;&lt; arma::endr
&gt; +    &lt;&lt; 2.0 &lt;&lt; 2.94;
&gt; +  arma::vec prob3;
&gt; +
&gt; +  // Expect that the 2-dimensional distribution returns the product of the
&gt; +  // 1-dimensional distributions (evaluated at wolfram|alpha).
&gt; +  GammaDistribution d3(a3, b3);
&gt; +  d3.LogProbability(x3, prob3);
&gt; +  BOOST_REQUIRE_CLOSE(prob3(0), std::log(0.04408), 1e-3);
&gt; +  BOOST_REQUIRE_CLOSE(prob3(1), std::log(0.026165), 1e-3);
&gt; +}
&gt; +
</pre>
<p>Can you add a test for the <code>Random()</code> function?  Here's some idea:</p>

<pre><code>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 &lt; 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]?
}
</code></pre>

<p>To test the tolerance, add a <code>math::RandomSeed(std::time(NULL))</code> at the top, recompile, and run this: <code>while(true); do bin/mlpack_test -t GammaDistributionTest/RandomTest; sleep 1; done</code> 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.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/pull/751/files/9cb117f671f55186baddf38ce71107a2a3ae027f#r73780342">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJ4bFFpmwH4QGqL_01BO5us6Y3lzQPn6ks5qdAVLgaJpZM4Jd7IK">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFKkXSRxtWiOQFgnxCwjTj1sAsgsqks5qdAVLgaJpZM4Jd7IK.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/751/files/9cb117f671f55186baddf38ce71107a2a3ae027f#r73780342"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/mlpack/mlpack","title":"mlpack/mlpack","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/modules/aws/aws-bg.jpg","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/mlpack/mlpack"}},"updates":{"snippets":[{"icon":"PERSON","message":"@rcurtin in #751: Can you add a test for the `Random()` function?  Here's some idea:\r\n\r\n```\r\nBOOST_AUTO_TEST_CASE(RandomTest)\r\n{\r\n  arma::vec alphas(\"1.0 2.0 3.0\");\r\n  arma::vec beta(\"1.5 2.5 3.5\");\r\n\r\n  GammaDistribution d(alphas, betas);\r\n\r\n  arma::mat observations(1000, 3);\r\n  for (size_t i = 0; i \u003c 1000; ++i)\r\n    observations.col(i) = d.Random();\r\n\r\n  // Train a second distribution, then ensure it is similar to the first.\r\n  GammaDistribution d2(observations);\r\n\r\n  // Check the values, with a fairly large tolerance (3%).\r\n  BOOST_REQUIRE_CLOSE(d.Alpha(0), d2.Alpha(0), 3.0);\r\n  BOOST_REQUIRE_CLOSE(d.Alpha(1), d2.Alpha(1), 3.0);\r\n  BOOST_REQUIRE_CLOSE(d.Alpha(2), d2.Alpha(2), 3.0);\r\n  BOOST_REQUIRE_CLOSE(d.Beta(0), d2.Beta(0), 3.0);\r\n  BOOST_REQUIRE_CLOSE(d.Beta(1), d2.Beta(1), 3.0);\r\n  BOOST_REQUIRE_CLOSE(d.Beta(2), d2.Beta(2), 3.0);\r\n  // Should these all be Alphas()[i] and Betas()[i]?\r\n}\r\n```\r\n\r\nTo 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."}],"action":{"name":"View Pull Request","url":"https://github.com/mlpack/mlpack/pull/751/files/9cb117f671f55186baddf38ce71107a2a3ae027f#r73780342"}}}</script>