/// Computes the absolute difference between two Gaussians
 public static double AbsoluteDifference(GaussianDistribution left, GaussianDistribution right)
 {
     return Math.Max(
         Math.Abs(left.PrecisionMean - right.PrecisionMean),
         Math.Sqrt(Math.Abs(left.Precision - right.Precision)));
 }
 public GaussianDistribution Clone()
 {
     var result = new GaussianDistribution();
     result.Mean = Mean;
     result.StandardDeviation = StandardDeviation;
     result.Variance = Variance;
     result.Precision = Precision;
     result.PrecisionMean = PrecisionMean;
     return result;
 }
        public static double LogProductNormalization(GaussianDistribution left, GaussianDistribution right)
        {
            if ((left.Precision == 0) || (right.Precision == 0))
            {
                return 0;
            }

            double varianceSum = left.Variance + right.Variance;
            double meanDifference = left.Mean - right.Mean;

            double logSqrt2Pi = Math.Log(Math.Sqrt(2*Math.PI));
            return -logSqrt2Pi - (Math.Log(varianceSum)/2.0) - (Square(meanDifference)/(2.0*varianceSum));
        }
        public static double LogRatioNormalization(GaussianDistribution numerator, GaussianDistribution denominator)
        {
            if ((numerator.Precision == 0) || (denominator.Precision == 0))
            {
                return 0;
            }

            double varianceDifference = denominator.Variance - numerator.Variance;
            double meanDifference = numerator.Mean - denominator.Mean;

            double logSqrt2Pi = Math.Log(Math.Sqrt(2*Math.PI));

            return Math.Log(denominator.Variance) + logSqrt2Pi - Math.Log(varianceDifference)/2.0 +
                   Square(meanDifference)/(2*varianceDifference);
        }
 public static GaussianDistribution FromPrecisionMean(double precisionMean, double precision)
 {
     var gaussianDistribution = new GaussianDistribution();
     gaussianDistribution.Precision = precision;
     gaussianDistribution.PrecisionMean = precisionMean;
     gaussianDistribution.Variance = 1.0/precision;
     gaussianDistribution.StandardDeviation = Math.Sqrt(gaussianDistribution.Variance);
     gaussianDistribution.Mean = gaussianDistribution.PrecisionMean/gaussianDistribution.Precision;
     return gaussianDistribution;
 }