Exemple #1
0
        public void CauchyDistributionConstructorTest2()
        {
            double location = 0.42;
            double scale    = 1.57;

            CauchyDistribution cauchy = new CauchyDistribution(location, scale);

            double mean   = cauchy.Mean;                                                     // NaN - Cauchy's mean is undefined.
            double var    = cauchy.Variance;                                                 // NaN - Cauchy's variance is undefined.
            double median = cauchy.Median;                                                   // 0.42

            double cdf  = cauchy.DistributionFunction(x: 0.27);                              // 0.46968025841608563
            double pdf  = cauchy.ProbabilityDensityFunction(x: 0.27);                        // 0.2009112009763413
            double lpdf = cauchy.LogProbabilityDensityFunction(x: 0.27);                     // -1.6048922547266871
            double ccdf = cauchy.ComplementaryDistributionFunction(x: 0.27);                 // 0.53031974158391437
            double icdf = cauchy.InverseDistributionFunction(p: 0.69358638272337991);        // 1.5130304686978195

            double hf  = cauchy.HazardFunction(x: 0.27);                                     // 0.3788491832800277
            double chf = cauchy.CumulativeHazardFunction(x: 0.27);                           // 0.63427516833243092

            string str = cauchy.ToString(System.Globalization.CultureInfo.InvariantCulture); // "Cauchy(x; x0 = 0.42, γ = 1.57)

            Assert.IsTrue(Double.IsNaN(mean));
            Assert.IsTrue(Double.IsNaN(var));
            Assert.AreEqual(0.42, median);

            Assert.AreEqual(0.63427516833243092, chf);
            Assert.AreEqual(0.46968025841608563, cdf);
            Assert.AreEqual(0.2009112009763413, pdf);
            Assert.AreEqual(-1.6048922547266871, lpdf);
            Assert.AreEqual(0.3788491832800277, hf);
            Assert.AreEqual(0.53031974158391437, ccdf);
            Assert.AreEqual(1.5130304686978195, icdf);
            Assert.AreEqual("Cauchy(x; x0 = 0.42, γ = 1.57)", str);
        }
Exemple #2
0
        public void CauchyDistributionConstructorTest2()
        {
            double location = 0.42;
            double scale    = 1.57;

            CauchyDistribution cauchy = new CauchyDistribution(location, scale);

            double mean   = cauchy.Mean;                                                     // NaN - Cauchy's mean is undefined.
            double var    = cauchy.Variance;                                                 // NaN - Cauchy's variance is undefined.
            double median = cauchy.Median;                                                   // 0.42
            double mode   = cauchy.Mode;                                                     // 0.42

            double cdf  = cauchy.DistributionFunction(x: 0.27);                              // 0.46968025841608563
            double pdf  = cauchy.ProbabilityDensityFunction(x: 0.27);                        // 0.2009112009763413
            double lpdf = cauchy.LogProbabilityDensityFunction(x: 0.27);                     // -1.6048922547266871
            double ccdf = cauchy.ComplementaryDistributionFunction(x: 0.27);                 // 0.53031974158391437
            double icdf = cauchy.InverseDistributionFunction(p: 0.69358638272337991);        // 1.5130304686978195

            double hf  = cauchy.HazardFunction(x: 0.27);                                     // 0.3788491832800277
            double chf = cauchy.CumulativeHazardFunction(x: 0.27);                           // 0.63427516833243092

            string str = cauchy.ToString(System.Globalization.CultureInfo.InvariantCulture); // "Cauchy(x; x0 = 0.42, γ = 1.57)

            Assert.IsTrue(Double.IsNaN(mean));
            Assert.IsTrue(Double.IsNaN(var));
            Assert.AreEqual(0.42, median);
            Assert.AreEqual(0.42, mode, 1e-6);
            Assert.AreEqual(0.63427516833243092, chf);
            Assert.AreEqual(0.46968025841608563, cdf);
            Assert.AreEqual(0.2009112009763413, pdf);
            Assert.AreEqual(-1.6048922547266871, lpdf);
            Assert.AreEqual(0.3788491832800277, hf);
            Assert.AreEqual(0.53031974158391437, ccdf);
            Assert.AreEqual(1.5130304686978195, icdf);
            Assert.AreEqual("Cauchy(x; x0 = 0.42, γ = 1.57)", str);

            var range1 = cauchy.GetRange(0.95);
            var range2 = cauchy.GetRange(0.99);
            var range3 = cauchy.GetRange(0.01);

            Assert.AreEqual(-9.4925897567183526, range1.Min, 1e-10);
            Assert.AreEqual(10.332589895085842, range1.Max, 1e-10);
            Assert.AreEqual(-49.538210069999685, range2.Min, 1e-10);
            Assert.AreEqual(50.378210075966564, range2.Max, 1e-10);
            Assert.AreEqual(-49.538210069999892, range3.Min, 1e-10);
            Assert.AreEqual(50.378210075966564, range3.Max, 1e-10);

            Assert.AreEqual(Double.NegativeInfinity, cauchy.Support.Min);
            Assert.AreEqual(Double.PositiveInfinity, cauchy.Support.Max);

            Assert.AreEqual(cauchy.InverseDistributionFunction(0), cauchy.Support.Min);
            Assert.AreEqual(cauchy.InverseDistributionFunction(1), cauchy.Support.Max);
        }
Exemple #3
0
        public void DistributionFunctionTest()
        {
            double[] expected =
            {
                0.7729505, 0.7931890, 0.8105287, 0.8254671, 0.8384167, 0.8497145,
                0.8596339, 0.8683966, 0.8761824, 0.8831381, 0.8893841, 0.8950196
            };

            CauchyDistribution target = new CauchyDistribution(location: -7.2, scale: 6.23);

            for (int i = 0; i < expected.Length; i++)
            {
                double actual = target.DistributionFunction(i);
                Assert.AreEqual(expected[i], actual, 1e-7);
                Assert.IsFalse(Double.IsNaN(actual));
            }
        }
        public void DistributionFunctionTest()
        {
            double[] expected = 
            {
                0.7729505, 0.7931890, 0.8105287, 0.8254671, 0.8384167, 0.8497145, 
                0.8596339, 0.8683966, 0.8761824, 0.8831381, 0.8893841, 0.8950196
            };

            CauchyDistribution target = new CauchyDistribution(location: -7.2, scale: 6.23);

            for (int i = 0; i < expected.Length; i++)
            {
                double actual = target.DistributionFunction(i);
                Assert.AreEqual(expected[i], actual, 1e-7);
                Assert.IsFalse(Double.IsNaN(actual));
            }
        }
        public void CauchyDistributionConstructorTest2()
        {
            double location = 0.42;
            double scale = 1.57;

            CauchyDistribution cauchy = new CauchyDistribution(location, scale);

            double mean = cauchy.Mean; // NaN - Cauchy's mean is undefined.
            double var = cauchy.Variance; // NaN - Cauchy's variance is undefined.
            double median = cauchy.Median; // 0.42

            double cdf = cauchy.DistributionFunction(x: 0.27); // 0.46968025841608563
            double pdf = cauchy.ProbabilityDensityFunction(x: 0.27); // 0.2009112009763413
            double lpdf = cauchy.LogProbabilityDensityFunction(x: 0.27); // -1.6048922547266871
            double ccdf = cauchy.ComplementaryDistributionFunction(x: 0.27); // 0.53031974158391437
            double icdf = cauchy.InverseDistributionFunction(p: 0.69358638272337991); // 1.5130304686978195

            double hf = cauchy.HazardFunction(x: 0.27); // 0.3788491832800277
            double chf = cauchy.CumulativeHazardFunction(x: 0.27); // 0.63427516833243092

            string str = cauchy.ToString(System.Globalization.CultureInfo.InvariantCulture); // "Cauchy(x; x0 = 0.42, γ = 1.57)

            Assert.IsTrue(Double.IsNaN(mean));
            Assert.IsTrue(Double.IsNaN(var));
            Assert.AreEqual(0.42, median);

            Assert.AreEqual(0.63427516833243092, chf);
            Assert.AreEqual(0.46968025841608563, cdf);
            Assert.AreEqual(0.2009112009763413, pdf);
            Assert.AreEqual(-1.6048922547266871, lpdf);
            Assert.AreEqual(0.3788491832800277, hf);
            Assert.AreEqual(0.53031974158391437, ccdf);
            Assert.AreEqual(1.5130304686978195, icdf);
            Assert.AreEqual("Cauchy(x; x0 = 0.42, γ = 1.57)", str);
        }