public void DensityFunctionTest()
{
double shape = 0.4;
double scale = 4.2;
double[] pdf =
{
double.PositiveInfinity, 0.987114, 0.635929, 0.486871, 0.400046,
0.341683, 0.299071, 0.266236, 0.239956, 0.218323, 0.200126
};
GammaDistribution target = new GammaDistribution(scale, shape);
for (int i = 0; i < 11; i++)
{
double x = i / 10.0;
double actual = target.ProbabilityDensityFunction(x);
double expected = pdf[i];
Assert.AreEqual(expected, actual, 1e-6);
Assert.IsFalse(double.IsNaN(actual));
double logActual = target.LogProbabilityDensityFunction(x);
double logExpected = Math.Log(pdf[i]);
Assert.AreEqual(logExpected, logActual, 1e-5);
Assert.IsFalse(double.IsNaN(logActual));
}
}