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 CanGetMeanLocation(double meanLocation, double meanScale, double precShape, double precInvScale)
 {
     var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
     Assert.AreEqual(meanLocation, ng.MeanLocation);
 }
 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 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).ToArray();
            var precs = samples.Select(mp => mp.Precision).ToArray();
            var meanMarginal = cd.MeanMarginal();
            var precMarginal = cd.PrecisionMarginal();

            // Check the precision distribution.
            CommonDistributionTests.ContinuousVapnikChervonenkisTest(
                CommonDistributionTests.ErrorTolerance,
                CommonDistributionTests.ErrorProbability,
                precs,
                precMarginal);

            // Check the mean distribution.
            CommonDistributionTests.ContinuousVapnikChervonenkisTest(
                CommonDistributionTests.ErrorTolerance,
                CommonDistributionTests.ErrorProbability,
                means,
                meanMarginal);
        }
 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 HasRandomSource()
 {
     var ng = new NormalGamma(0.0, 1.0, 1.0, 1.0);
     Assert.IsNotNull(ng.RandomSource);
 }
 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 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 CanGetPrecisionShape(double meanLocation, double meanScale, double precShape, double precInvScale)
 {
     var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
     Assert.AreEqual(precShape, ng.PrecisionShape);
 }