public void SetupDistributions()
        {
            dists = new IDistribution[8];

            dists[0] = new Beta(1.0, 1.0);
            dists[1] = new ContinuousUniform(0.0, 1.0);
            dists[2] = new Gamma(1.0, 1.0);
            dists[3] = new Normal(0.0, 1.0);
            dists[4] = new Bernoulli(0.6);
            dists[5] = new Weibull(1.0, 1.0);
            dists[6] = new DiscreteUniform(1, 10);
            dists[7] = new LogNormal(1.0, 1.0);
        }
 public void ValidateMaximum()
 {
     var n = new Weibull(1.0, 1.0);
     Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
 }
 public void ValidateDensityLn(double shape, double scale, double x, double pdfln)
 {
     var n = new Weibull(shape, scale);
     AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
 }
 public void SetShapeFailsWithNegativeShape(double shape)
 {
     var n = new Weibull(1.0, 1.0);
     n.Shape = shape;
 }
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Weibull_distribution">Weibull distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the Weibull distribution class with parameters Scale = 1, Shape = 0.5
            var weibull = new Weibull(0.5, 1);
            Console.WriteLine(@"1. Initialize the new instance of the Weibull distribution class with parameterы Scale = {0}, Shape = {1}", weibull.Scale, weibull.Shape);
            Console.WriteLine();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // 4. Generate 100000 samples of the Weibull(0.5, 1) distribution and display histogram
            Console.WriteLine(@"4. Generate 100000 samples of the Weibull(0.5, 1) distribution and display histogram");
            var data = new double[100000];
            Weibull.Samples(data, 0.5, 1.0);
            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 5. Generate 100000 samples of the Weibull(1.5, 1) distribution and display histogram
            Console.WriteLine(@"5. Generate 100000 samples of the Weibull(1.5, 1) distribution and display histogram");
            Weibull.Samples(data, 1.5, 1.0);
            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 6. Generate 100000 samples of the Weibull(5, 1) distribution and display histogram
            Console.WriteLine(@"6. Generate 100000 samples of the Weibull(5, 1) distribution and display histogram");
            Weibull.Samples(data, 5.0, 1.0);
            ConsoleHelper.DisplayHistogram(data);
        }
 public void ValidateVariance(double shape, double scale, double var)
 {
     var n = new Weibull(shape, scale);
     AssertHelpers.AlmostEqual(var, n.Variance, 13);
 }
 public void ValidateStdDev(double shape, double scale, double sdev)
 {
     var n = new Weibull(shape, scale);
     AssertHelpers.AlmostEqual(sdev, n.StdDev, 13);
 }
 public void ValidateMode(double shape, double scale, double mode)
 {
     var n = new Weibull(shape, scale);
     Assert.AreEqual(mode, n.Mode);
 }
示例#9
0
        public void CanEstimateParameters(double shape, double scale)
        {
            var original = new Weibull(shape, scale, new Random(100));
            var estimated = Weibull.Estimate(original.Samples().Take(10000));

            AssertHelpers.AlmostEqualRelative(shape, estimated.Shape, 1);
            AssertHelpers.AlmostEqualRelative(scale, estimated.Scale, 1);
        }
示例#10
0
 public void CanSetShape(double shape)
 {
     var n = new Weibull(1.0, 1.0);
     n.Shape = shape;
 }
示例#11
0
 public void CanSetScale(double scale)
 {
     var n = new Weibull(1.0, 1.0);
     n.Scale = scale;
 }
示例#12
0
 public void WeibullCreateFailsWithBadParameters(double shape, double scale)
 {
     var n = new Weibull(shape, scale);
 }
示例#13
0
 public void ValidateToString()
 {
     var n = new Weibull(1.0, 2.0);
     AssertEx.AreEqual<string>("Weibull(Shape = 1, Scale = 2)", n.ToString());
 }
示例#14
0
 public void ValidateMaximum()
 {
     var n = new Weibull(1.0, 1.0);
     AssertEx.AreEqual<double>(System.Double.PositiveInfinity, n.Maximum);
 }
示例#15
0
 public void ValidateMedian(double shape, double scale, double median)
 {
     var n = new Weibull(shape, scale);
     AssertHelpers.AlmostEqual(median, n.Median, 13);
 }
示例#16
0
 public void ValidateMinimum()
 {
     var n = new Weibull(1.0, 1.0);
     Assert.AreEqual(0.0, n.Minimum);
 }
 public void SetScaleFailsWithNegativeScale(double scale)
 {
     var n = new Weibull(1.0, 1.0);
     Assert.That(() => n.Scale = scale, Throws.ArgumentException);
 }
示例#18
0
 public void ValidateSkewness(double shape, double scale, double skewness)
 {
     var n = new Weibull(shape, scale);
     AssertHelpers.AlmostEqual(skewness, n.Skewness, 11);
 }
 public void SetShapeFailsWithNegativeShape(double shape)
 {
     var n = new Weibull(1.0, 1.0);
     Assert.That(() => n.Shape = shape, Throws.ArgumentException);
 }
示例#20
0
 public void ValidateToString()
 {
     var n = new Weibull(1d, 2d);
     Assert.AreEqual("Weibull(k = 1, λ = 2)", n.ToString());
 }
 public void ValidateDensity(double shape, double scale, double x, double pdf)
 {
     var n = new Weibull(shape, scale);
     AssertHelpers.AlmostEqualRelative(pdf, n.Density(x), 13);
 }
示例#22
0
 public void CanCreateWeibull(double shape, double scale)
 {
     var n = new Weibull(shape, scale);
     Assert.AreEqual(shape, n.Shape);
     Assert.AreEqual(scale, n.Scale);
 }
示例#23
0
 public void SetShapeFailsWithNegativeShape(double shape)
 {
     var n = new Weibull(1.0, 1.0);
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Shape = shape);
 }
示例#24
0
 public void ValidateCumulativeDistribution(double shape, double scale, double x, double cdf)
 {
     var n = new Weibull(shape, scale);
     AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 15);
 }
示例#25
0
 public void SetScaleFailsWithNegativeScale(double scale)
 {
     var n = new Weibull(1.0, 1.0);
     n.Scale = scale;
 }