예제 #1
0
        public void BetaInversion()
        {
            // test that beta distribution is accurately inverted over a wide range of a, b, P

            foreach (double a in TestUtilities.GenerateRealValues(0.01, 100.0, 8))
            {
                foreach (double b in cs)
                {
                    BetaDistribution B = new BetaDistribution(a, b);

                    foreach (double P in probabilities)
                    {
                        Console.WriteLine("a={0} b={1} P={2}", a, b, P);
                        double x = B.InverseLeftProbability(P);
                        Console.WriteLine("  x={0} P(x)={1}", x, B.LeftProbability(x));
                        // we would like to test that P(x) = P, but floating point limitations prevent us from meeting this standard
                        // P(x) changes so fast at extremes that sometimes even the minimal change in x causes a change
                        // in P(x) larger than our target precision; so instead we test that our routine gets us
                        // as close as it can, by checking that P(x-e) < P < P(x+e)
                        double Px  = B.LeftProbability(x);
                        double Pxm = B.LeftProbability(Math.Min(0.0, x * (1.0 - TestUtilities.TargetPrecision)));
                        double Pxp = B.LeftProbability(Math.Max(x * (1.0 + TestUtilities.TargetPrecision), 1.0));
                        Assert.IsTrue((Pxm <= P) && (P <= Pxp));
                    }
                }
            }
        }
예제 #2
0
        public void Bug7684()
        {
            // These values caused incomplete Beta to be called with argument outside the interval [0,1].

            double           I1 = 0.9999902;
            double           a1 = 0.0000434313636267175;
            double           b1 = 18474.36071078790000;
            BetaDistribution D1 = new BetaDistribution(a1, b1);
            double           x1 = D1.InverseLeftProbability(I1);

            Console.WriteLine("{0} {1} {2}", x1, D1.LeftProbability(x1), I1);

            double           I2 = 0.9998063099306;
            double           a2 = 0.00034509911609819255;
            double           b2 = 6.8453983996634218;
            BetaDistribution D2 = new BetaDistribution(a2, b2);
            double           x2 = D2.InverseLeftProbability(I2);

            Console.WriteLine("{0} {1} {2}", x2, D2.LeftProbability(x2), I2);
        }