Esempio n. 1
0
        public void ValidateDensityLn(int shape, double invScale, double x, double pdfln)
        {
            var n = new Erlang(shape, invScale);

            AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
            AssertHelpers.AlmostEqual(pdfln, Erlang.PDFLn(shape, invScale, x), 14);
        }
Esempio n. 2
0
        public void ValidateDensityLn(
            [Values(0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10)] int shape,
            [Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double invScale,
            [Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
            [Values(Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, -2.3025850929940456285068402234265387271634735938763824, -2.402585092994045634057955346552321429281631934330484, -3.3025850929940456285068402234265387271634735938763824, 0.0, -1.0, -10.0, Double.NegativeInfinity, 0.22402344985898722897219667227693591172986563062456522, -69.052710713194601614865880235563786219860220971716511, Double.NegativeInfinity, -13.801827480081469611207717874566706164281149255663166, -2.0785616431350584550457947824074282958712358580042068, Double.NegativeInfinity, Double.NegativeInfinity, Double.PositiveInfinity)] double pdfln)
        {
            var n = new Erlang(shape, invScale);

            AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
        }
Esempio n. 3
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Erlang_distribution">Erlang distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the Erlang distribution class with parameters Shape = 1, Scale = 2.
            var erlang = new Erlang(1, 2.0);

            Console.WriteLine(@"1. Initialize the new instance of the Erlang distribution class with parameters Shape = {0}, Scale = {1}", erlang.Shape, erlang.Scale);
            Console.WriteLine();

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

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

            // Probability density
            Console.WriteLine(@"{0} - Probability density at location '0.3'", erlang.Density(0.3).ToString(" #0.00000;-#0.00000"));

            // Log probability density
            Console.WriteLine(@"{0} - Log probability density at location '0.3'", erlang.DensityLn(0.3).ToString(" #0.00000;-#0.00000"));

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

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

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

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

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

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

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

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

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

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

            // 4. Generate 100000 samples of the Erlang(1, 2.0) distribution and display histogram
            Console.WriteLine(@"4. Generate 100000 samples of the Erlang(1, 2.0) distribution and display histogram");
            var data = new double[100000];

            for (var i = 0; i < data.Length; i++)
            {
                data[i] = erlang.Sample();
            }

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

            // 5. Generate 100000 samples of the Erlang(3, 2.0) distribution and display histogram
            Console.WriteLine(@"5. Generate 100000 samples of the Erlang(3, 2.0) distribution and display histogram");
            erlang.Shape = 3;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = erlang.Sample();
            }

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

            // 6. Generate 100000 samples of the Erlang(9, 0.5) distribution and display histogram
            Console.WriteLine(@"6. Generate 100000 samples of the Erlang(9, 0.5) distribution and display histogram");
            erlang.Shape = 9;
            erlang.Scale = 0.5;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = erlang.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
        }
Esempio n. 4
0
 public void ValidateDensityLn(
     [Values(0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10)] int shape, 
     [Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double invScale, 
     [Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x, 
     [Values(Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, -2.3025850929940456285068402234265387271634735938763824, -2.402585092994045634057955346552321429281631934330484, -3.3025850929940456285068402234265387271634735938763824, 0.0, -1.0, -10.0, Double.NegativeInfinity, 0.22402344985898722897219667227693591172986563062456522, -69.052710713194601614865880235563786219860220971716511, Double.NegativeInfinity, -13.801827480081469611207717874566706164281149255663166, -2.0785616431350584550457947824074282958712358580042068, Double.NegativeInfinity, Double.NegativeInfinity, Double.PositiveInfinity)] double pdfln)
 {
     var n = new Erlang(shape, invScale);
     AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
 }
Esempio n. 5
0
 public void ValidateDensityLn(int shape, double invScale, double x, double pdfln)
 {
     var n = new Erlang(shape, invScale);
     AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
 }