// My original:
        //public static double VWithinMargin(double teamPerformanceDifference, double drawMargin)
        //{
        //    var teamPerformanceDifferenceAbsoluteValue = Math.Abs(teamPerformanceDifference);
        //    return (GaussianDistribution.At(-drawMargin - teamPerformanceDifferenceAbsoluteValue) - GaussianDistribution.At(drawMargin - teamPerformanceDifferenceAbsoluteValue))
        //           /
        //           (GaussianDistribution.CumulativeTo(drawMargin - teamPerformanceDifferenceAbsoluteValue) - GaussianDistribution.CumulativeTo(-drawMargin - teamPerformanceDifferenceAbsoluteValue));
        //}

        // from F#:
        public static double VWithinMargin(double teamPerformanceDifference, double drawMargin)
        {
            double teamPerformanceDifferenceAbsoluteValue = Math.Abs(teamPerformanceDifference);
            double denominator =
                GaussianDistribution.CumulativeTo(drawMargin - teamPerformanceDifferenceAbsoluteValue) -
                GaussianDistribution.CumulativeTo(-drawMargin - teamPerformanceDifferenceAbsoluteValue);

            if (denominator < 2.222758749e-162)
            {
                if (teamPerformanceDifference < 0.0)
                {
                    return(-teamPerformanceDifference - drawMargin);
                }

                return(-teamPerformanceDifference + drawMargin);
            }

            double numerator = GaussianDistribution.At(-drawMargin - teamPerformanceDifferenceAbsoluteValue) -
                               GaussianDistribution.At(drawMargin - teamPerformanceDifferenceAbsoluteValue);

            if (teamPerformanceDifference < 0.0)
            {
                return(-numerator / denominator);
            }

            return(numerator / denominator);
        }
Ejemplo n.º 2
0
 public void TestGaussianInt()
 {
     Statistics.Frequencies(
         new[]
     {
         // 0
         (float)GaussianDistribution.At(0, 5, 3) + (float)GaussianDistribution.At(-1, 5, 3) + (float)GaussianDistribution.At(-2, 5, 3),
         // 1
         (float)GaussianDistribution.At(1, 5, 3),
         // 2
         (float)GaussianDistribution.At(2, 5, 3),
         // 3
         (float)GaussianDistribution.At(3, 5, 3),
         // 4
         (float)GaussianDistribution.At(4, 5, 3),
         // 5
         (float)GaussianDistribution.At(5, 5, 3),
         // 6
         (float)GaussianDistribution.At(6, 5, 3),
         // 7
         (float)GaussianDistribution.At(7, 5, 3),
         // 8
         (float)GaussianDistribution.At(8, 5, 3),
         // 9
         (float)GaussianDistribution.At(9, 5, 3),
         // 10
         (float)GaussianDistribution.At(10, 5, 3) + (float)GaussianDistribution.At(11, 5, 3) + (float)GaussianDistribution.At(12, 5, 3)
     },
         () => Rng.GaussianInt(5, 5, 3));
     Statistics.Frequencies(
         new[]
     {
         0,
         (float)GaussianDistribution.At(1, 10, 3),
         (float)GaussianDistribution.At(2, 10, 3),
         (float)GaussianDistribution.At(3, 10, 3),
         (float)GaussianDistribution.At(4, 10, 3),
         (float)GaussianDistribution.At(5, 10, 3),
         (float)GaussianDistribution.At(6, 10, 3),
         (float)GaussianDistribution.At(7, 10, 3),
         (float)GaussianDistribution.At(8, 10, 3),
         (float)GaussianDistribution.At(9, 10, 3),
         (float)GaussianDistribution.At(10, 10, 3),
         (float)GaussianDistribution.At(11, 10, 3),
         (float)GaussianDistribution.At(12, 10, 3),
         (float)GaussianDistribution.At(13, 10, 3),
         (float)GaussianDistribution.At(14, 10, 3),
         (float)GaussianDistribution.At(15, 10, 3),
         (float)GaussianDistribution.At(16, 10, 3),
         (float)GaussianDistribution.At(17, 10, 3),
         (float)GaussianDistribution.At(18, 10, 3),
         (float)GaussianDistribution.At(19, 10, 3)
     },
         () => Rng.GaussianInt(10, 9, 3));
 }
Ejemplo n.º 3
0
        private double VExceedsMargin(double drawMargin, double performanceDiff)
        {
            var denominator = GaussianDistribution.CumulativeTo(performanceDiff - drawMargin);

            if (denominator < 2.222758749e-162)
            {
                return(-performanceDiff + drawMargin);
            }

            return(GaussianDistribution.At(performanceDiff - drawMargin) / denominator);
        }
        public static double VExceedsMargin(double teamPerformanceDifference, double drawMargin)
        {
            double denominator = GaussianDistribution.CumulativeTo(teamPerformanceDifference - drawMargin);

            if (denominator < 2.222758749e-162)
            {
                return(-teamPerformanceDifference + drawMargin);
            }

            return(GaussianDistribution.At(teamPerformanceDifference - drawMargin) / denominator);
        }
Ejemplo n.º 5
0
        private double VWithinMargin(double drawMargin, double performanceDiff)
        {
            var performanceDiffAbsoluteValue = Math.Abs(performanceDiff);
            var denominator = GaussianDistribution.CumulativeTo(drawMargin - performanceDiffAbsoluteValue) - GaussianDistribution.CumulativeTo(-drawMargin - performanceDiffAbsoluteValue);

            if (denominator < 2.222758749e-162)
            {
                return(performanceDiff < 0 ? -performanceDiff - drawMargin : -performanceDiff + drawMargin);
            }

            var numerator = GaussianDistribution.At(-drawMargin - performanceDiffAbsoluteValue) - GaussianDistribution.At(drawMargin - performanceDiffAbsoluteValue);

            return(performanceDiff < 0 ? -numerator / denominator : numerator / denominator);
        }
Ejemplo n.º 6
0
        private double WWithinMargin(double drawMargin, double performanceDiff)
        {
            var performanceDiffAbsoluteValue = Math.Abs(performanceDiff);
            var denominator = GaussianDistribution.CumulativeTo(drawMargin - performanceDiffAbsoluteValue) - GaussianDistribution.CumulativeTo(-drawMargin - performanceDiffAbsoluteValue);

            if (denominator < 2.222758749e-162)
            {
                return(1);
            }

            var vt = VWithinMargin(drawMargin, performanceDiff);

            // Separating large return math shown in original work for readability
            var factor1   = drawMargin - performanceDiffAbsoluteValue;
            var factor2   = GaussianDistribution.At(drawMargin - performanceDiffAbsoluteValue);
            var factor3   = -drawMargin - performanceDiffAbsoluteValue;
            var factor4   = GaussianDistribution.At(-drawMargin - performanceDiffAbsoluteValue);
            var numerator = (factor1 * factor2) - (factor3 * factor4);

            return((vt * vt) + (numerator / denominator));
        }
        // My original:
        //public static double WWithinMargin(double teamPerformanceDifference, double drawMargin)
        //{
        //    var teamPerformanceDifferenceAbsoluteValue = Math.Abs(teamPerformanceDifference);
        //    var vDraw = VWithinMargin(teamPerformanceDifferenceAbsoluteValue, drawMargin);
        //    return (vDraw * vDraw)
        //           +
        //           (
        //                ((drawMargin - teamPerformanceDifferenceAbsoluteValue) * GaussianDistribution.At(drawMargin - teamPerformanceDifferenceAbsoluteValue) + (drawMargin + teamPerformanceDifferenceAbsoluteValue) * GaussianDistribution.At(drawMargin + teamPerformanceDifferenceAbsoluteValue))
        //                /
        //                (GaussianDistribution.CumulativeTo(drawMargin - teamPerformanceDifferenceAbsoluteValue) - GaussianDistribution.CumulativeTo(-drawMargin - teamPerformanceDifferenceAbsoluteValue))
        //           );
        //}

        // From F#:
        public static double WWithinMargin(double teamPerformanceDifference, double drawMargin)
        {
            double teamPerformanceDifferenceAbsoluteValue = Math.Abs(teamPerformanceDifference);
            double denominator = GaussianDistribution.CumulativeTo(drawMargin - teamPerformanceDifferenceAbsoluteValue)
                                 -
                                 GaussianDistribution.CumulativeTo(-drawMargin - teamPerformanceDifferenceAbsoluteValue);

            if (denominator < 2.222758749e-162)
            {
                return(1.0);
            }

            double vt = VWithinMargin(teamPerformanceDifferenceAbsoluteValue, drawMargin);

            return(vt * vt +
                   (
                       (drawMargin - teamPerformanceDifferenceAbsoluteValue)
                       *
                       GaussianDistribution.At(
                           drawMargin - teamPerformanceDifferenceAbsoluteValue)
                       - (-drawMargin - teamPerformanceDifferenceAbsoluteValue)
                       *
                       GaussianDistribution.At(-drawMargin - teamPerformanceDifferenceAbsoluteValue)) / denominator);
        }
Ejemplo n.º 8
0
 public void AtTests()
 {
     // Verified with WolframAlpha
     // (e.g. http://www.wolframalpha.com/input/?i=PDF%5BNormalDistribution%5B0%2C1%5D%2C+0.5%5D )
     Assert.AreEqual(0.352065, GaussianDistribution.At(0.5), ErrorTolerance);
 }
Ejemplo n.º 9
0
 public void AtTests()
 {
     Assert.AreEqual(0.352065, GaussianDistribution.At(0.5), ErrorTolerance);
 }