Browse Source

Enabled Beta entropy test.

Signed-off-by: jvangael <jurgen.vangael@gmail.com>

Signed-off-by: jvangael <jurgen.vangael@gmail.com>
pull/36/head
Jurgen Van Gael 17 years ago
parent
commit
db4a70cbe4
  1. 32
      src/Numerics/Distributions/Continuous/Beta.cs
  2. 10
      src/UnitTests/DistributionTests/Continuous/BetaTests.cs

32
src/Numerics/Distributions/Continuous/Beta.cs

@ -36,7 +36,14 @@ namespace MathNet.Numerics.Distributions
/// Implements the Beta distribution. For details about this distribution, see
/// <a href="http://en.wikipedia.org/wiki/Beta_distribution">Wikipedia - Beta distribution</a>.
/// </summary>
/// <remarks><para>The distribution will use the <see cref="System.Random"/> by default.
/// <remarks>
/// <para>There are a few special cases for the parameterization of the Beta distribution. When both
/// shape parameters are positive infinity, the Beta distribution degenerates to a point distribution
/// at 0.5. When one of the shape parameters is positive infinity, the distribution degenerates to a point
/// distribution at the positive infinity. When both shape parameters are 0.0, the Beta distribution
/// degenerates to a Bernoulli distribution with parameter 0.5. When one shape parameter is 0.0, the
/// distribution degenerates to a point distribution at the non-zero shape parameter.</para>
/// <para>The distribution will use the <see cref="System.Random"/> by default.
/// Users can get/set the random number generator by using the <see cref="RandomSource"/> property.</para>
/// <para>The statistics classes will check all the incoming parameters whether they are in the allowed
/// range. This might involve heavy computation. Optionally, by setting Control.CheckDistributionParameters
@ -217,10 +224,25 @@ namespace MathNet.Numerics.Distributions
{
get
{
return SpecialFunctions.BetaLn(_shapeA, _shapeB)
- ((_shapeA - 1.0) * SpecialFunctions.DiGamma(_shapeA))
- ((_shapeB - 1.0) * SpecialFunctions.DiGamma(_shapeB))
+ ((_shapeA + _shapeB - 2.0) * SpecialFunctions.DiGamma(_shapeA + _shapeB));
if (Double.IsPositiveInfinity(_shapeA) || Double.IsPositiveInfinity(_shapeB))
{
return 0.0;
}
else if (_shapeA == 0.0 && _shapeB == 0.0)
{
return -Math.Log(0.5);
}
else if (_shapeA == 0.0 || _shapeB == 0.0)
{
return 0.0;
}
else
{
return SpecialFunctions.BetaLn(_shapeA, _shapeB)
- ((_shapeA - 1.0) * SpecialFunctions.DiGamma(_shapeA))
- ((_shapeB - 1.0) * SpecialFunctions.DiGamma(_shapeB))
+ ((_shapeA + _shapeB - 2.0) * SpecialFunctions.DiGamma(_shapeA + _shapeB));
}
}
}

10
src/UnitTests/DistributionTests/Continuous/BetaTests.cs

@ -139,10 +139,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests
AssertEx.AreEqual<double>(mean, n.Mean);
}
[Test, Ignore("Depending on Special Functions")]
[Row(0.0, 0.0, 0.5)]
[Row(0.0, 0.1, 0.1)]
[Row(1.0, 0.0, 1.0)]
[Test]
[Row(0.0, 0.0, 0.693147180559945309417232121458176568075500134360255)]
[Row(0.0, 0.1, 0.0)]
[Row(1.0, 0.0, 0.0)]
[Row(1.0, 1.0, 0.0)]
[Row(9.0, 1.0, -1.3083356884473304939016015849561625204060922267565917)]
[Row(5.0, 100.0, -2.5201623187602743679459255108827601222133603091753153)]
@ -153,7 +153,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests
public void ValidateEntropy(double a, double b, double entropy)
{
var n = new Beta(a, b);
AssertEx.AreEqual<double>(entropy, n.Entropy);
AssertHelpers.AlmostEqual(entropy, n.Entropy, 14);
}
[Test]

Loading…
Cancel
Save