コード例 #1
0
        public void GradientTest()
        {
            for (double a = 0.1; a < 3; a += 0.1)
            {
                for (double b = 0.1; b < 3; b += 0.1)
                {
                    var target = new BetaDistribution(a, b);

                    Assert.AreEqual(a, target.Alpha);
                    Assert.AreEqual(b, target.Beta);

                    FiniteDifferences fd = new FiniteDifferences(2);
                    fd.Function = (double[] parameters) => BetaDistribution.LogLikelihood(samples, parameters[0], parameters[1]);

                    double[] expected = fd.Compute(a, b);
                    double[] actual   = BetaDistribution.Gradient(samples, a, b);

                    Assert.IsTrue(expected[0].IsRelativelyEqual(actual[0], 0.05));
                    Assert.IsTrue(expected[1].IsRelativelyEqual(actual[1], 0.05));
                }
            }
        }