public void MaxTest() { Gaussian actual, expected; actual = MaxGaussianOp.MaxAverageConditional(Gaussian.FromNatural(6053.7946407740192, 2593.4559834344436), Gaussian.FromNatural(-1.57090676324773, 1.3751262174888785), Gaussian.FromNatural(214384.78500926663, 96523.508973471908)); Assert.False(actual.IsProper()); actual = MaxGaussianOp.MaxAverageConditional(Gaussian.FromNatural(146.31976467723146, 979.371757950659), Gaussian.FromNatural(0.075442729439046508, 0.086399540048904114), Gaussian.PointMass(0)); Assert.False(actual.IsProper()); actual = MaxGaussianOp.MaxAverageConditional(Gaussian.Uniform(), Gaussian.PointMass(0), new Gaussian(-7.357e+09, 9.75)); expected = Gaussian.PointMass(0); Assert.True(expected.MaxDiff(actual) < 1e-4); Gaussian max; max = new Gaussian(4, 5); actual = MaxGaussianOp.MaxAverageConditional(max, new Gaussian(0, 1), new Gaussian(2, 3)); actual *= max; expected = new Gaussian(2.720481395499785, 1.781481142817509); //expected = MaxPosterior(max, new Gaussian(0, 1), new Gaussian(2, 3)); Assert.True(expected.MaxDiff(actual) < 1e-4); max = new Gaussian(); max.MeanTimesPrecision = 0.2; max.Precision = 1e-10; actual = MaxGaussianOp.MaxAverageConditional(max, new Gaussian(0, 1), new Gaussian(0, 1)); actual *= max; expected = new Gaussian(0.702106815765215, 0.697676918460236); Assert.True(expected.MaxDiff(actual) < 1e-4); }
private void Max_MaxPointMass(Gaussian a, Gaussian b) { double point = 3; Gaussian toPoint = MaxGaussianOp.MaxAverageConditional(Gaussian.PointMass(point), a, b); //Console.WriteLine($"{point} {toPoint} {toPoint.MeanTimesPrecision} {toPoint.Precision}"); double oldDiff = double.PositiveInfinity; for (int i = 5; i < 100; i++) { Gaussian max = Gaussian.FromMeanAndPrecision(point, System.Math.Pow(10, i)); Gaussian to_max = MaxGaussianOp.MaxAverageConditional(max, a, b); double diff = toPoint.MaxDiff(to_max); //Console.WriteLine($"{max} {to_max} {to_max.MeanTimesPrecision} {to_max.Precision} {diff}"); if (diff < 1e-14) { diff = 0; } Assert.True(diff <= oldDiff); oldDiff = diff; } }