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 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 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 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 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 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 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 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);
 }