public void SampleTest() { double Mean = 5 * rnd.NextDouble(); double Sdv = 5 * rnd.NextDouble(); Normal dis = new Normal(Mean, Sdv); UnivariateHybridMC Hybrid = new UnivariateHybridMC(0, dis.DensityLn, 10, 0.1, 1000); Hybrid.BurnInterval = 0; double[] Sample = Hybrid.Sample(10000); double Effective = MCMCDiagnostics.EffectiveSize(Sample, x => x); DescriptiveStatistics Stats = new DescriptiveStatistics(Sample); //Testing the mean using the normal distribution. double MeanConvergence = 3 * Sdv / Math.Sqrt(Effective); Assert.AreEqual(Stats.Mean, Mean, MeanConvergence, "Mean"); double DeviationRation = Math.Pow(Stats.StandardDeviation / Sdv, 2); //Approximating chi-square with normal distribution. (Degree of freedom is large) double DeviationConvergence = 3 * Math.Sqrt(2) / Math.Sqrt(Effective); Assert.AreEqual(DeviationRation, 1, DeviationConvergence, "Standard Deivation"); }
public void SampleTest(double mean, double sdv, int seed) { var dis = new Normal(mean, sdv); var hybrid = new UnivariateHybridMC(0, dis.DensityLn, 10, 0.1, 1000, 1, new System.Random(seed)) { BurnInterval = 0 }; double[] sample = hybrid.Sample(10000); double effective = MCMCDiagnostics.EffectiveSize(sample, x => x); var stats = new DescriptiveStatistics(sample); //Testing the mean using the normal distribution. double meanConvergence = 3 * sdv / Math.Sqrt(effective); Assert.AreEqual(stats.Mean, mean, meanConvergence, "Mean"); double deviationRation = Math.Pow(stats.StandardDeviation / sdv, 2); //Approximating chi-square with normal distribution. (Degree of freedom is large) double deviationConvergence = 3 * Math.Sqrt(2) / Math.Sqrt(effective); Assert.AreEqual(deviationRation, 1, deviationConvergence, "Standard Deivation"); }
public void UnivariateHybridMCConstructor() { var hybrid = new UnivariateHybridMC(0, _normal.DensityLn, 10, 0.1); Assert.IsNotNull(hybrid.RandomSource); hybrid.RandomSource = new System.Random(); Assert.IsNotNull(hybrid.RandomSource); }
public void UnivariateHybridMCConstructor() { UnivariateHybridMC Hybrid = new UnivariateHybridMC(0, normal.DensityLn, 10, 0.1); Assert.IsNotNull(Hybrid.RandomSource); Hybrid.RandomSource = new System.Random(); Assert.IsNotNull(Hybrid.RandomSource); }
public void SampleTest() { double Mean = 5 * rnd.NextDouble(); double Sdv = 5 * rnd.NextDouble(); Normal dis = new Normal(Mean, Sdv); UnivariateHybridMC Hybrid = new UnivariateHybridMC(0, dis.DensityLn, 10, 0.1, 1000); Hybrid.BurnInterval = 0; double[] Sample = Hybrid.Sample(10000); double Effective = MCMCDiagnostics.EffectiveSize(Sample,x=>x); DescriptiveStatistics Stats = new DescriptiveStatistics(Sample); //Testing the mean using the normal distribution. double MeanConvergence = 3 * Sdv / Math.Sqrt(Effective); Assert.AreEqual(Stats.Mean, Mean, MeanConvergence, "Mean"); double DeviationRation = Math.Pow(Stats.StandardDeviation / Sdv, 2); //Approximating chi-square with normal distribution. (Degree of freedom is large) double DeviationConvergence = 3 * Math.Sqrt(2) / Math.Sqrt(Effective); Assert.AreEqual(DeviationRation, 1, DeviationConvergence, "Standard Deivation"); }
public void SampleTest(double mean, double sdv, int seed) { var dis = new Normal(mean, sdv); var hybrid = new UnivariateHybridMC(0, dis.DensityLn, 10, 0.1, 1000, 1, new System.Random(seed)) { BurnInterval = 0 }; double[] sample = hybrid.Sample(10000); double effective = MCMCDiagnostics.EffectiveSize(sample, x => x); var stats = new DescriptiveStatistics(sample); //Testing the mean using the normal distribution. double meanConvergence = 3*sdv/Math.Sqrt(effective); Assert.AreEqual(stats.Mean, mean, meanConvergence, "Mean"); double deviationRation = Math.Pow(stats.StandardDeviation/sdv, 2); //Approximating chi-square with normal distribution. (Degree of freedom is large) double deviationConvergence = 3*Constants.Sqrt2/Math.Sqrt(effective); Assert.AreEqual(deviationRation, 1, deviationConvergence, "Standard Deviation"); }