Ejemplo n.º 1
0
        public void LongCombination_Test(int n, int k)
        {
            if (k == 0 || n == k)
            {
                Assert.AreEqual(1, MathTool.Combinations(n, k));
            }

            long c = MathTool.Combinations(n, k).AsLong();

            Console.WriteLine("Combination ({0},{1}) = {2}", n, k, c);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 확률 분포 계산을 위한 누적분포함수
        /// </summary>
        /// <param name="x">The location at which to compute the cumulative distribution function.</param>
        /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
        public double CumulativeDistribution(double x)
        {
            if (x < 0.0)
            {
                return(0.0);
            }

            if (x > _n)
            {
                return(1.0);
            }

            var cdf = 0.0;

            for (var i = 0; i <= (int)Math.Floor(x); i++)
            {
                cdf += MathTool.Combinations(_n, i) * Math.Pow(_p, i) * Math.Pow(1.0 - _p, _n - i);
            }

            return(cdf);
        }