public void CumulativeDistributionMustNotOverflow_CodePlexIssue5729()
 {
     var d = new Hypergeometric(10000, 2, 9800);
     Assert.That(d.CumulativeDistribution(0.0), Is.Not.NaN);
     Assert.That(d.CumulativeDistribution(0.1), Is.Not.NaN);
 }
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Hypergeometric_distribution">Hypergeometric distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the Hypergeometric distribution class with parameters PopulationSize = 10, M = 2, N = 8
            var hypergeometric = new Hypergeometric(30, 15, 10);
            Console.WriteLine(@"1. Initialize the new instance of the Hypergeometric distribution class with parameters PopulationSize = {0}, M = {1}, N = {2}", hypergeometric.PopulationSize, hypergeometric.M, hypergeometric.N);
            Console.WriteLine();

            // 2. Distributuion properties:
            Console.WriteLine(@"2. {0} distributuion properties:", hypergeometric);

            // Cumulative distribution function
            Console.WriteLine(@"{0} - Сumulative distribution at location '3'", hypergeometric.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000"));

            // Probability density
            Console.WriteLine(@"{0} - Probability mass at location '3'", hypergeometric.Probability(3).ToString(" #0.00000;-#0.00000"));

            // Log probability density
            Console.WriteLine(@"{0} - Log probability mass at location '3'", hypergeometric.ProbabilityLn(3).ToString(" #0.00000;-#0.00000"));

            // Largest element in the domain
            Console.WriteLine(@"{0} - Largest element in the domain", hypergeometric.Maximum.ToString(" #0.00000;-#0.00000"));

            // Smallest element in the domain
            Console.WriteLine(@"{0} - Smallest element in the domain", hypergeometric.Minimum.ToString(" #0.00000;-#0.00000"));

            // Mean
            Console.WriteLine(@"{0} - Mean", hypergeometric.Mean.ToString(" #0.00000;-#0.00000"));

            // Mode
            Console.WriteLine(@"{0} - Mode", hypergeometric.Mode.ToString(" #0.00000;-#0.00000"));

            // Variance
            Console.WriteLine(@"{0} - Variance", hypergeometric.Variance.ToString(" #0.00000;-#0.00000"));

            // Standard deviation
            Console.WriteLine(@"{0} - Standard deviation", hypergeometric.StdDev.ToString(" #0.00000;-#0.00000"));

            // Skewness
            Console.WriteLine(@"{0} - Skewness", hypergeometric.Skewness.ToString(" #0.00000;-#0.00000"));
            Console.WriteLine();

            // 3. Generate 10 samples of the Hypergeometric distribution
            Console.WriteLine(@"3. Generate 10 samples of the Hypergeometric distribution");
            for (var i = 0; i < 10; i++)
            {
                Console.Write(hypergeometric.Sample().ToString("N05") + @" ");
            }

            Console.WriteLine();
            Console.WriteLine();

            // 4. Generate 100000 samples of the Hypergeometric(30, 15, 10) distribution and display histogram
            Console.WriteLine(@"4. Generate 100000 samples of the Hypergeometric(30, 15, 10) distribution and display histogram");
            var data = new double[100000];
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = hypergeometric.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 5. Generate 100000 samples of the Hypergeometric(52, 13, 5) distribution and display histogram
            Console.WriteLine(@"5. Generate 100000 samples of the Hypergeometric(52, 13, 5) distribution and display histogram");
            hypergeometric.PopulationSize = 52;
            hypergeometric.M = 13;
            hypergeometric.N = 5;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = hypergeometric.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
        }
 public void ValidateCumulativeDistribution(int population, int success, int draws, double x, double cdf)
 {
     var d = new Hypergeometric(population, success, draws);
     AssertHelpers.AlmostEqualRelative(cdf, d.CumulativeDistribution(x), 9);
 }