Exemplo n.º 1
0
 public void ValidateMode(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     Assert.AreEqual(scale, n.Mode);
 }
Exemplo n.º 2
0
 public void ValidateSkewness(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     Assert.AreEqual((2.0 * (shape + 1.0) / (shape - 3.0)) * Math.Sqrt((shape - 2.0) / shape), n.Skewness);
 }
Exemplo n.º 3
0
 public void ValidateMedian(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     Assert.AreEqual(scale * Math.Pow(2.0, 1.0 / shape), n.Median);
 }
Exemplo n.º 4
0
 public void ValidateMinimum(double scale)
 {
     var n = new Pareto(scale, 1.0);
     Assert.AreEqual(scale, n.Minimum);
 }
Exemplo n.º 5
0
 public void CanSample()
 {
     var n = new Pareto(1.0, 1.0);
     n.Sample();
 }
Exemplo n.º 6
0
 public void SetShapeFailsWithNegativeShape()
 {
     var n = new Pareto(1.0, 1.0);
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Shape = -1.0);
 }
Exemplo n.º 7
0
 public void ValidateEntropy(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     Assert.AreEqual(Math.Log(shape / scale) - (1.0 / shape) - 1.0, n.Entropy);
 }
Exemplo n.º 8
0
 public void ValidateVariance(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     if (shape <= 2.0)
     {
         Assert.AreEqual(double.PositiveInfinity, n.Variance);
     }
     else
     {
         Assert.AreEqual(scale * scale * shape / ((shape - 1.0) * (shape - 1.0) * (shape - 2.0)), n.Variance);
     }
 }
Exemplo n.º 9
0
 public void ValidateCumulativeDistribution(double scale, double shape, double x)
 {
     var n = new Pareto(scale, shape);
     double expected = 1.0 - Math.Pow(scale/x, shape);
     Assert.AreEqual(expected, n.CumulativeDistribution(x));
     Assert.AreEqual(expected, Pareto.CDF(scale, shape, x));
 }
Exemplo n.º 10
0
        public void ValidateDensity(double scale, double shape, double x, double expected)
        {
            var dist = new Pareto(scale, shape);

            Assert.AreEqual(expected, dist.Density(x), 1e-12);
            Assert.AreEqual(expected, Pareto.PDF(scale, shape, x), 1e-12);

            Assert.AreEqual(Math.Log(expected), dist.DensityLn(x), 1e-12);
            Assert.AreEqual(Math.Log(expected), Pareto.PDFLn(scale, shape, x), 1e-12);
        }
Exemplo n.º 11
0
 public void SetShapeFailsWithNegativeShape()
 {
     var n = new Pareto(1.0, 1.0);
     Assert.That(() => n.Shape = -1.0, Throws.ArgumentException);
 }
Exemplo n.º 12
0
 public void ParetoCreateFailsWithBadParameters(double scale, double shape)
 {
     Assert.That(() => { var n = new Pareto(scale, shape); }, Throws.ArgumentException);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Pareto_distribution">Pareto distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the Pareto distribution class with parameters Shape = 3, Scale = 1
            var pareto = new Pareto(1, 3);
            Console.WriteLine(@"1. Initialize the new instance of the Pareto distribution class with parameters Shape = {0}, Scale = {1}", pareto.Shape, pareto.Scale);
            Console.WriteLine();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            ConsoleHelper.DisplayHistogram(data);
        }
Exemplo n.º 14
0
 public void ValidateStdDev(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     Assert.AreEqual((scale * Math.Sqrt(shape)) / ((shape - 1.0) * Math.Sqrt(shape - 2.0)), n.StdDev);
 }
Exemplo n.º 15
0
 public void ValidateInverseCumulativeDistribution(double scale, double shape, double x)
 {
     var n = new Pareto(scale, shape);
     double cdf = 1.0 - Math.Pow(scale / x, shape);
     Assert.AreEqual(x, n.InverseCumulativeDistribution(cdf), 1e-12);
     Assert.AreEqual(x, Pareto.InvCDF(scale, shape, cdf), 1e-12);
 }
Exemplo n.º 16
0
 public void ValidateToString()
 {
     var n = new Pareto(1d, 2d);
     Assert.AreEqual("Pareto(xm = 1, α = 2)", n.ToString());
 }
Exemplo n.º 17
0
 public void ValidateMaximum()
 {
     var n = new Pareto(1.0, 1.0);
     Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
 }
Exemplo n.º 18
0
 public void CanCreatePareto(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     Assert.AreEqual(scale, n.Scale);
     Assert.AreEqual(shape, n.Shape);
 }
Exemplo n.º 19
0
 public void ValidateMean(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     if (shape > 1)
     {
         Assert.AreEqual(shape * scale / (shape - 1.0), n.Mean);
     }
 }
Exemplo n.º 20
0
 public void CanSampleSequence()
 {
     var n = new Pareto(1.0, 1.0);
     var ied = n.Samples();
     ied.Take(5).ToArray();
 }
Exemplo n.º 21
0
 public void ParetoCreateFailsWithBadParameters(double scale, double shape)
 {
     Assert.Throws<ArgumentOutOfRangeException>(() => { var n = new Pareto(scale, shape); });
 }