public void CanGetMean(double meanLocation, double meanScale, double precShape, double precInvScale, double meanMean, double meanPrecision) { NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual<double>(meanMean, ng.Mean.Mean); Assert.AreEqual<double>(meanPrecision, ng.Mean.Precision); }
public void SampleFollowsCorrectDistribution() { var cd = new NormalGamma(1.0, 4.0, 7.0, 3.5); // Sample from the distribution. var samples = new MeanPrecisionPair[CommonDistributionTests.NumberOfTestSamples]; for (var i = 0; i < CommonDistributionTests.NumberOfTestSamples; i++) { samples[i] = cd.Sample(); } // Extract the mean and precisions. var means = samples.Select(mp => mp.Mean); var precs = samples.Select(mp => mp.Precision); var meanMarginal = cd.MeanMarginal(); var precMarginal = cd.PrecisionMarginal(); // Check the precision distribution. CommonDistributionTests.VapnikChervonenkisTest( CommonDistributionTests.Error, CommonDistributionTests.ErrorProbability, precs, precMarginal); // Check the mean distribution. CommonDistributionTests.VapnikChervonenkisTest( CommonDistributionTests.Error, CommonDistributionTests.ErrorProbability, means, meanMarginal); }
public void CanGetMean(double meanLocation, double meanScale, double precShape, double precInvScale, double meanMean, double meanPrecision) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(meanMean, ng.Mean.Mean); Assert.AreEqual(meanPrecision, ng.Mean.Precision); }
public void CanGetMean([Values(0.0, 10.0, 10.0)] double meanLocation, [Values(1.0, 1.0, 1.0)] double meanScale, [Values(1.0, 2.0, 2.0)] double precShape, [Values(1.0, 2.0, Double.PositiveInfinity)] double precInvScale, [Values(0.0, 10.0, 10.0)] double meanMean, [Values(1.0, 1.0, 2.0)] double meanPrecision) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(meanMean, ng.Mean.Mean); Assert.AreEqual(meanPrecision, ng.Mean.Precision); }
public void SamplesFollowsCorrectDistribution() { var cd = new NormalGamma(1.0, 4.0, 3.0, 3.5); // Sample from the distribution. var samples = cd.Samples().Take(CommonDistributionTests.NumberOfTestSamples).ToArray(); // Extract the mean and precisions. var means = samples.Select(mp => mp.Mean); var precs = samples.Select(mp => mp.Precision); var meanMarginal = cd.MeanMarginal(); var precMarginal = cd.PrecisionMarginal(); // Check the precision distribution. CommonDistributionTests.VapnikChervonenkisTest( CommonDistributionTests.Error, CommonDistributionTests.ErrorProbability, precs, precMarginal); // Check the mean distribution. CommonDistributionTests.VapnikChervonenkisTest( CommonDistributionTests.Error, CommonDistributionTests.ErrorProbability, means, meanMarginal); }
public void CanGetPrecisionMarginal(double meanLocation, double meanScale, double precShape, double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); var pm = ng.PrecisionMarginal(); Assert.AreEqual(precShape, pm.Shape); Assert.AreEqual(precInvScale, pm.Rate); }
public void CanGetPrecisionMarginal([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0, Double.PositiveInfinity)] double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); var pm = ng.PrecisionMarginal(); Assert.AreEqual(precShape, pm.Shape); Assert.AreEqual(precInvScale, pm.InvScale); }
public void CanCreateNormalGamma(double meanLocation, double meanScale, double precShape, double precInvScale) { NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual <double>(meanLocation, ng.MeanLocation); Assert.AreEqual <double>(meanScale, ng.MeanScale); Assert.AreEqual <double>(precShape, ng.PrecisionShape); Assert.AreEqual <double>(precInvScale, ng.PrecisionInverseScale); }
public void CanCreateNormalGamma(double meanLocation, double meanScale, double precShape, double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(meanLocation, ng.MeanLocation); Assert.AreEqual(meanScale, ng.MeanScale); Assert.AreEqual(precShape, ng.PrecisionShape); Assert.AreEqual(precInvScale, ng.PrecisionInverseScale); }
public void CanGetMeanMarginal([Values(0.0, 10.0, 10.0)] double meanLocation, [Values(1.0, 1.0, 1.0)] double meanScale, [Values(1.0, 2.0, 2.0)] double precShape, [Values(1.0, 2.0, Double.PositiveInfinity)] double precInvScale, [Values(0.0, 10.0, 10.0)] double meanMarginalMean, [Values(1.0, 1.0, 0.5)] double meanMarginalScale, [Values(2.0, 4.0, Double.PositiveInfinity)] double meanMarginalDoF) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); var mm = ng.MeanMarginal(); Assert.AreEqual(meanMarginalMean, mm.Location); Assert.AreEqual(meanMarginalScale, mm.Scale); Assert.AreEqual(meanMarginalDoF, mm.DegreesOfFreedom); }
public void ValidateVariance([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0, Double.PositiveInfinity)] double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); var x = precInvScale / (meanScale * (precShape - 1)); var t = precShape / Math.Sqrt(precInvScale); Assert.AreEqual(x, ng.Variance.Mean); Assert.AreEqual(t, ng.Variance.Precision); }
public void CanCreateNormalGamma([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(meanLocation, ng.MeanLocation); Assert.AreEqual(meanScale, ng.MeanScale); Assert.AreEqual(precShape, ng.PrecisionShape); Assert.AreEqual(precInvScale, ng.PrecisionInverseScale); }
public void CanGetMeanMarginal(double meanLocation, double meanScale, double precShape, double precInvScale, double meanMarginalMean, double meanMarginalScale, double meanMarginalDoF) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); var mm = ng.MeanMarginal(); Assert.AreEqual(meanMarginalMean, mm.Location); Assert.AreEqual(meanMarginalScale, mm.Scale); Assert.AreEqual(meanMarginalDoF, mm.DegreesOfFreedom); }
public void ValidateVariance(double meanLocation, double meanScale, double precShape, double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); var x = precInvScale / (meanScale * (precShape - 1)); var t = precShape / Math.Sqrt(precInvScale); Assert.AreEqual(x, ng.Variance.Mean); Assert.AreEqual(t, ng.Variance.Precision); }
public void CanSetPrecisionPrecisionInverseScale(double meanLocation, double meanScale, double precShape, double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale) { PrecisionInverseScale = 5.0 }; Assert.AreEqual(meanLocation, ng.MeanLocation); Assert.AreEqual(meanScale, ng.MeanScale); Assert.AreEqual(precShape, ng.PrecisionShape); Assert.AreEqual(5.0, ng.PrecisionInverseScale); }
public void CanGetMeanLocation(double meanLocation, double meanScale, double precShape, double precInvScale) { NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual <double>(meanLocation, ng.MeanLocation); }
public void CanSetRandomSource() { NormalGamma ng = new NormalGamma(0.0, 1.0, 1.0, 1.0); ng.RandomSource = new Random(); }
public void CanGetDensityAndDensityLn([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 1.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(ng.DensityLn(meanLocation, precShape), Math.Log(ng.Density(meanLocation, precShape)), 1e-14); }
public void CanGetMeanLocation([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(meanLocation, ng.MeanLocation); }
public void CanGetPrecisionShape(double meanLocation, double meanScale, double precShape, double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(precShape, ng.PrecisionShape); }
public void CanSetPrecisionShape(double meanLocation, double meanScale, double precShape, double precInvScale) { NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); ng.PrecisionShape = 5.0; Assert.AreEqual<double>(meanLocation, ng.MeanLocation); Assert.AreEqual<double>(meanScale, ng.MeanScale); Assert.AreEqual<double>(5.0, ng.PrecisionShape); Assert.AreEqual<double>(precInvScale, ng.PrecisionInverseScale); }
public void NormalGammaConstructorFailsWithInvalidParams(double meanLocation, double meanScale, double precShape, double precInvScale) { var nb = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); }
public void CanSetPrecisionPrecisionInverseScale([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale) { PrecisionInverseScale = 5.0 }; Assert.AreEqual(meanLocation, ng.MeanLocation); Assert.AreEqual(meanScale, ng.MeanScale); Assert.AreEqual(precShape, ng.PrecisionShape); Assert.AreEqual(5.0, ng.PrecisionInverseScale); }
public void CanGetDensityAndDensityLn(double meanLocation, double meanScale, double precShape, double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(ng.DensityLn(meanLocation, precShape), Math.Log(ng.Density(meanLocation, precShape))); }
public void CanGetDensityAndDensityLn(double meanLocation, double meanScale, double precShape, double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(ng.DensityLn(meanLocation, precShape), Math.Log(ng.Density(meanLocation, precShape)), 1e-14); }
public void CanGetMeanLocation(double meanLocation, double meanScale, double precShape, double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); Assert.AreEqual(meanLocation, ng.MeanLocation); }
public void CanGetPrecisionMarginal(double meanLocation, double meanScale, double precShape, double precInvScale) { var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); var pm = ng.PrecisionMarginal(); Assert.AreEqual(precShape, pm.Shape); Assert.AreEqual(precInvScale, pm.InvScale); }
public void CanGetMeanScale(double meanLocation, double meanScale, double precShape, double precInvScale) { NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); AssertEx.AreEqual<double>(meanScale, ng.MeanScale); }
public void HasRandomSource() { var ng = new NormalGamma(0.0, 1.0, 1.0, 1.0); Assert.IsNotNull(ng.RandomSource); }