private static GaussianGamma DistributionTimesFactor(double point, GaussianGamma shapeParamsDistr)
 {
     GaussianGamma factorAsDistr = new GaussianGamma(Vector.FromArray(0, -0.5 * point * point, point, -0.5));
     GaussianGamma result = new GaussianGamma();
     result.SetToProduct(factorAsDistr, shapeParamsDistr);
     return result;
 }
        private static GaussianGamma ShapeParamsAverageConditional(
            double coord, double otherCoord, Bernoulli label, GaussianGamma shapeParamsDistr, GaussianGamma otherShapeParamsDistr, GaussianGamma result)
        {
            GaussianGamma shapeParamsDistrTimesFactor = DistributionTimesFactor(coord, shapeParamsDistr);
            GaussianGamma otherShapeParamsDistrTimesFactor = DistributionTimesFactor(otherCoord, otherShapeParamsDistr);
            double labelProbFalse = label.GetProbFalse();
            double weight1 = labelProbFalse;
            double weight2 = Math.Exp(
                shapeParamsDistrTimesFactor.GetLogNormalizer() - shapeParamsDistr.GetLogNormalizer() +
                otherShapeParamsDistrTimesFactor.GetLogNormalizer() - otherShapeParamsDistr.GetLogNormalizer()) *
                (1 - 2 * labelProbFalse);
            var projectionOfSum = new GaussianGamma();
            projectionOfSum.SetToSum(weight1, shapeParamsDistr, weight2, shapeParamsDistrTimesFactor);
            result.SetToRatio(projectionOfSum, shapeParamsDistr);

            return result;
        }
 private static double CalcLogLabelMessageForSingleCoord(double point, GaussianGamma shapeParamsDistr)
 {
     GaussianGamma shapeParamsDistrTimesFactor = DistributionTimesFactor(point, shapeParamsDistr);
     return shapeParamsDistrTimesFactor.GetLogNormalizer() - shapeParamsDistr.GetLogNormalizer();
 }
 public static GaussianGamma ShapeParamsYAverageConditional(
     Vector point, Bernoulli label, GaussianGamma shapeParamsX, GaussianGamma shapeParamsY, GaussianGamma result)
 {
     return ShapeParamsAverageConditional(point[1], point[0], label, shapeParamsY, shapeParamsX, result);
 }
 public static double LogEvidenceRatio(
     Bernoulli label, Bernoulli to_label, Vector point, GaussianGamma shapeParamsX, GaussianGamma shapeParamsY)
 {
     return LogAverageFactor(label, point, shapeParamsX, shapeParamsY) - label.GetLogAverageOf(to_label);
 }
 public static double LogAverageFactor(Bernoulli label, Vector point, GaussianGamma shapeParamsX, GaussianGamma shapeParamsY)
 {
     GaussianGamma shapeParamsXDistrTimesFactor = DistributionTimesFactor(point[0], shapeParamsX);
     GaussianGamma shapeParamsYDistrTimesFactor = DistributionTimesFactor(point[1], shapeParamsY);
     double labelProbFalse = label.GetProbFalse();
     double normalizerProduct = Math.Exp(
         shapeParamsXDistrTimesFactor.GetLogNormalizer() - shapeParamsX.GetLogNormalizer() +
         shapeParamsYDistrTimesFactor.GetLogNormalizer() - shapeParamsY.GetLogNormalizer());
     double averageFactor = labelProbFalse + (1 - 2 * labelProbFalse) * normalizerProduct;
     Debug.Assert(averageFactor > 0);
     return Math.Log(averageFactor);
 }
 public static Bernoulli LabelAverageConditional(Vector point, GaussianGamma shapeParamsX, GaussianGamma shapeParamsY)
 {
     double logProbTrue =
         CalcLogLabelMessageForSingleCoord(point[0], shapeParamsX) +
         CalcLogLabelMessageForSingleCoord(point[1], shapeParamsY);
     return new Bernoulli(Math.Exp(logProbTrue));
 }