public void ValidateProbabilityLn(double p, int x, double dln)
 {
     var b = new Bernoulli(p);
     AssertEx.AreEqual(dln, b.ProbabilityLn(x));
 }
Esempio n. 2
0
 public void ValidateProbabilityLn(
     [Values(0.0, 0.0, 0.0, 0.0, 0.3, 0.3, 0.3, 0.3, 1.0, 1.0, 1.0, 1.0)] double p, 
     [Values(-1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2)] int x, 
     [Values(Double.NegativeInfinity, 0.0, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, -0.35667494393873244235395440410727451457180907089949815, -1.2039728043259360296301803719337238685164245381839102, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, 0.0, Double.NegativeInfinity)] double dln)
 {
     var b = new Bernoulli(p);
     Assert.AreEqual(dln, b.ProbabilityLn(x));
 }
Esempio n. 3
0
        public void ValidateProbabilityLn(double p, int x, double dln)
        {
            var b = new Bernoulli(p);

            Assert.AreEqual(dln, b.ProbabilityLn(x));
        }
Esempio n. 4
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Bernoulli_distribution">Bernoulli distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the Bernoulli distribution class with parameter P = 0.2
            var bernoulli = new Bernoulli(0.2);

            Console.WriteLine(@"1. Initialize the new instance of the Bernoulli distribution class with parameter P = {0}", bernoulli.P);
            Console.WriteLine();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // 4. Generate 100000 samples of the Bernoulli(0.2) distribution and display histogram
            Console.WriteLine(@"4. Generate 100000 samples of the Bernoulli(0.2) distribution and display histogram");
            var data = new int[100000];

            Bernoulli.Samples(data, 0.2);
            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 5. Generate 100000 samples of the Bernoulli(4) distribution and display histogram
            Console.WriteLine(@"5. Generate 100000 samples of the Bernoulli(0.9) distribution and display histogram");
            Bernoulli.Samples(data, 0.9);
            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 6. Generate 100000 samples of the Bernoulli(8) distribution and display histogram
            Console.WriteLine(@"6. Generate 100000 samples of the Bernoulli(0.5) distribution and display histogram");
            Bernoulli.Samples(data, 0.5);
            ConsoleHelper.DisplayHistogram(data);
        }