// 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);
        }
        protected override double GetPlayerWinProbability(GameInfo gameInfo, double playerRating, double opponentRating)
        {
            double ratingDifference = playerRating - opponentRating;

            // See equation 1.1 in the TrueSkill paper
            return(GaussianDistribution.CumulativeTo(
                       ratingDifference
                       /
                       (Math.Sqrt(2) * gameInfo.Beta)));
        }
Esempio 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);
        }
Esempio n. 5
0
        private double WExceedsMargin(double drawMargin, double performanceDiff)
        {
            var denominator = GaussianDistribution.CumulativeTo(performanceDiff - drawMargin);

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

            var vWin = VExceedsMargin(performanceDiff, drawMargin);

            return(vWin * (vWin + performanceDiff - drawMargin));
        }
Esempio n. 6
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);
        }
        public static double WExceedsMargin(double teamPerformanceDifference, double drawMargin)
        {
            double denominator = GaussianDistribution.CumulativeTo(teamPerformanceDifference - drawMargin);

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

            double vWin = VExceedsMargin(teamPerformanceDifference, drawMargin);

            return(vWin * (vWin + teamPerformanceDifference - drawMargin));
        }
Esempio n. 8
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);
        }
Esempio n. 10
0
 public void CumulativeToTests()
 {
     // Verified with WolframAlpha
     // (e.g. http://www.wolframalpha.com/input/?i=CDF%5BNormalDistribution%5B0%2C1%5D%2C+0.5%5D )
     Assert.AreEqual(0.691462, GaussianDistribution.CumulativeTo(0.5), ErrorTolerance);
 }
Esempio n. 11
0
 public void CumulativeToTests()
 {
     Assert.AreEqual(0.691462, GaussianDistribution.CumulativeTo(0.5), ErrorTolerance);
 }
Esempio n. 12
0
 /// <summary>
 /// Given a difficulty, return the chance of success for it.
 /// </summary>
 /// <param name="difficulty"></param>
 /// <returns>Higher means easier</returns>
 public static double ChanceOfSuccess(double difficulty)
 {
     return(GaussianDistribution.CumulativeTo(difficulty, World.Mean, World.StandardDeviation));
 }