Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public void LogProbabilityDensityFunctionTest()
        {
            double[] expected =
            {
                -3.4572653, -3.2488640, -3.0165321, -2.7541678, -2.4530627, -2.1002413,
                -1.6753581, -1.1447299, -0.4515827,  0.4647080,  1.1578552, 0.4647080
            };

            CauchyDistribution target = new CauchyDistribution(location: 1, scale: 0.1);

            for (int i = 0; i < expected.Length; i++)
            {
                double actual = target.LogProbabilityDensityFunction(i / 10.0);
                Assert.AreEqual(expected[i], actual, 1e-7);
                Assert.IsFalse(Double.IsNaN(actual));
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void LogProbabilityDensityFunctionTest()
        {
            double[] expected = 
            {
                -3.4572653, -3.2488640, -3.0165321, -2.7541678, -2.4530627, -2.1002413,
                -1.6753581, -1.1447299, -0.4515827,  0.4647080,  1.1578552,  0.4647080
            };

            CauchyDistribution target = new CauchyDistribution(location: 1, scale: 0.1);

            for (int i = 0; i < expected.Length; i++)
            {
                double actual = target.LogProbabilityDensityFunction(i / 10.0);
                Assert.AreEqual(expected[i], actual, 1e-7);
                Assert.IsFalse(Double.IsNaN(actual));
            }
        }