|
|
|
@ -36,8 +36,6 @@ using NUnit.Framework; |
|
|
|
|
|
|
|
namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests |
|
|
|
{ |
|
|
|
using Random = System.Random; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Metropolis hastings sampler tests.
|
|
|
|
/// </summary>
|
|
|
|
@ -53,13 +51,13 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests |
|
|
|
var normal = new Normal(0.0, 1.0); |
|
|
|
var rnd = new MersenneTwister(); |
|
|
|
|
|
|
|
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => (new Normal(x, 0.1)).Density(y), x => Normal.Sample(rnd, x, 0.1), 10) |
|
|
|
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => Normal.PDF(x, 0.1, y), x => Normal.Sample(rnd, x, 0.1), 10) |
|
|
|
{ |
|
|
|
RandomSource = rnd |
|
|
|
}; |
|
|
|
Assert.IsNotNull(ms.RandomSource); |
|
|
|
|
|
|
|
ms.RandomSource = new System.Random(); |
|
|
|
ms.RandomSource = new System.Random(0); |
|
|
|
Assert.IsNotNull(ms.RandomSource); |
|
|
|
} |
|
|
|
|
|
|
|
@ -72,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests |
|
|
|
var normal = new Normal(0.0, 1.0); |
|
|
|
var rnd = new MersenneTwister(); |
|
|
|
|
|
|
|
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => (new Normal(x, 0.1)).Density(y), x => Normal.Sample(rnd, x, 0.1), 10) |
|
|
|
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => Normal.PDF(x, 0.1, y), x => Normal.Sample(rnd, x, 0.1), 10) |
|
|
|
{ |
|
|
|
RandomSource = rnd |
|
|
|
}; |
|
|
|
@ -89,7 +87,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests |
|
|
|
var normal = new Normal(0.0, 1.0); |
|
|
|
var rnd = new MersenneTwister(); |
|
|
|
|
|
|
|
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => (new Normal(x, 0.1)).Density(y), x => Normal.Sample(rnd, x, 0.1), 10) |
|
|
|
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => Normal.PDF(x, 0.1, y), x => Normal.Sample(rnd, x, 0.1), 10) |
|
|
|
{ |
|
|
|
RandomSource = rnd |
|
|
|
}; |
|
|
|
@ -103,8 +101,9 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests |
|
|
|
[Test] |
|
|
|
public void NullRandomNumberGenerator() |
|
|
|
{ |
|
|
|
var normal = new Normal(0.0, 1.0); |
|
|
|
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => (new Normal(x, 0.1)).Density(y), x => Normal.Sample(new Random(), x, 0.1), 10); |
|
|
|
var random = MersenneTwister.Default; |
|
|
|
var normal = new Normal(0.0, 1.0, random); |
|
|
|
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => Normal.PDF(x, 0.1, y), x => Normal.Sample(random, x, 0.1), 10); |
|
|
|
Assert.Throws<ArgumentNullException>(() => ms.RandomSource = null); |
|
|
|
} |
|
|
|
} |
|
|
|
|