public void MaxTest2()
 {
     foreach (double max in new[] { 0.0, 2.0 })
     {
         double oldm = double.NaN;
         double oldv = double.NaN;
         for (int i = 0; i < 300; i++)
         {
             Gaussian a    = new Gaussian(System.Math.Pow(10, i), 177);
             Gaussian to_a = MaxGaussianOp.AAverageConditional(max, a, 0);
             Gaussian to_b = MaxGaussianOp.BAverageConditional(max, 0, a);
             Assert.Equal(to_a, to_b);
             if (max == 0)
             {
                 Gaussian to_a2 = IsPositiveOp.XAverageConditional(false, a);
                 double   error = System.Math.Max(MMath.AbsDiff(to_a.MeanTimesPrecision, to_a2.MeanTimesPrecision, double.Epsilon),
                                                  MMath.AbsDiff(to_a.Precision, to_a2.Precision, double.Epsilon));
                 //Trace.WriteLine($"{a} {to_a} {to_a2} {error}");
                 Assert.True(error < 1e-12);
             }
             //else Trace.WriteLine($"{a} {to_a}");
             double m, v;
             to_a.GetMeanAndVariance(out m, out v);
             if (!double.IsNaN(oldm))
             {
                 Assert.True(v <= oldv);
                 double olddiff = System.Math.Abs(max - oldm);
                 double diff    = System.Math.Abs(max - m);
                 Assert.True(diff <= olddiff);
             }
             oldm = m;
             oldv = v;
         }
     }
 }
Пример #2
0
 // Test inference on a model where precision is scaled.
 internal void GammaProductTest()
 {
     for (int i = 0; i <= 20; i++)
     {
         double minutesPlayed = System.Math.Pow(0.1, i);
         if (i == 20)
         {
             minutesPlayed = 0;
         }
         var EventCountMean_F           = Gaussian.PointMass(0);
         var EventCountPrecision_F      = GammaRatioOp.RatioAverageConditional(Gamma.PointMass(1), minutesPlayed);
         var realCount_F                = GaussianOp_PointPrecision.SampleAverageConditional(EventCountMean_F, EventCountPrecision_F);
         var realCount_use_B            = MaxGaussianOp.BAverageConditional(0.0, 0.0, realCount_F);
         var EventCountPrecision_B      = GaussianOp_PointPrecision.PrecisionAverageConditional(realCount_use_B, EventCountMean_F, EventCountPrecision_F);
         var EventsPerMinutePrecision_B = GammaRatioOp.AAverageConditional(EventCountPrecision_B, minutesPlayed);
         Console.WriteLine($"realCount_use_B = {realCount_use_B}, EventCountPrecision_B = {EventCountPrecision_B},  EventsPerMinutePrecision_B = {EventsPerMinutePrecision_B}");
     }
 }