Beispiel #1
0
        public void ValidateDensity(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            for (var i = 0; i < 11; i++)
            {
                var    x        = i - 5.0;
                double expected = 1.0 / ((Constants.Pi * scale) * (1.0 + (((x - location) / scale) * ((x - location) / scale))));
                Assert.AreEqual(expected, n.Density(x));
                Assert.AreEqual(expected, Cauchy.PDF(location, scale, x));
            }
        }
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Cauchy_distribution">Cauchy distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the Cauchy distribution class with parameters Location = 1 and Scale = 2.
            var cauchy = new Cauchy(1, 2);

            Console.WriteLine(@"1. Initialize the new instance of the Cauchy distribution class with parameters Location = {0} and Scale = {1}", cauchy.Location, cauchy.Scale);
            Console.WriteLine();

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

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

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

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

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

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

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

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

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

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

            Console.WriteLine();
        }
 public void ValidateDensity([Values(0.0, 0.0, 0.0, -5.0, 0.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity, 1.0)] double scale)
 {
     var n = new Cauchy(location, scale);
     for (var i = 0; i < 11; i++)
     {
         var x = i - 5.0;
         Assert.AreEqual(1.0 / ((Constants.Pi * scale) * (1.0 + (((x - location) / scale) * ((x - location) / scale)))), n.Density(x));
     }
 }
 public void ValidateDensity(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     for (var i = 0; i < 11; i++)
     {
         var x = i - 5.0;
         Assert.AreEqual(1.0 / ((Constants.Pi * scale) * (1.0 + (((x - location) / scale) * ((x - location) / scale)))), n.Density(x));
     }
 }
        public void ValidateDensity(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            for (int i = 0; i < 11; i++)
            {
                double x = i - 5.0;
                Assert.AreEqual <double>(1.0 / (Constants.Pi * scale * (1.0 + ((x - location) / scale) * ((x - location) / scale))), n.Density(x));
            }
        }
Beispiel #6
0
        public void ValidateDensity([Values(0.0, 0.0, 0.0, -5.0, 0.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity, 1.0)] double scale)
        {
            var n = new Cauchy(location, scale);

            for (var i = 0; i < 11; i++)
            {
                var x = i - 5.0;
                Assert.AreEqual(1.0 / ((Constants.Pi * scale) * (1.0 + (((x - location) / scale) * ((x - location) / scale)))), n.Density(x));
            }
        }