Browse Source

Distributions: fix Geometric distribution sampling

provider
Christoph Ruegg 13 years ago
parent
commit
5ea5de07a1
  1. 2
      src/Numerics/Distributions/Geometric.cs
  2. 2
      src/UnitTests/DistributionTests/CommonDistributionTests.cs

2
src/Numerics/Distributions/Geometric.cs

@ -241,7 +241,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>One sample from the distribution implied by <paramref name="p"/>.</returns> /// <returns>One sample from the distribution implied by <paramref name="p"/>.</returns>
static int SampleUnchecked(System.Random rnd, double p) static int SampleUnchecked(System.Random rnd, double p)
{ {
return p == 1.0 ? 1 : (int) Math.Ceiling(-Math.Log(1.0 - rnd.NextDouble(), 1.0 - p)); return p == 1.0 ? 1 : (int)Math.Ceiling(Math.Log(1.0 - rnd.NextDouble(), 1.0 - p));
} }
/// <summary> /// <summary>

2
src/UnitTests/DistributionTests/CommonDistributionTests.cs

@ -59,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests
new Categorical(new[] { 0.7, 0.3 }), new Categorical(new[] { 0.7, 0.3 }),
//new ConwayMaxwellPoisson(0.2, 0.4), //new ConwayMaxwellPoisson(0.2, 0.4),
new DiscreteUniform(1, 10), new DiscreteUniform(1, 10),
//new Geometric(0.2), new Geometric(0.2),
new Hypergeometric(20, 3, 5), new Hypergeometric(20, 3, 5),
//new NegativeBinomial(4, 0.6), //new NegativeBinomial(4, 0.6),
//new Poisson(0.4), //new Poisson(0.4),

Loading…
Cancel
Save