示例#1
0
        private static void compare(TukeyLambdaDistribution target,
                                    UnivariateContinuousDistribution comparison, double tol)
        {
            Assert.AreEqual(comparison.Mean, target.Mean);
            Assert.AreEqual(comparison.Variance, target.Variance, tol);
            Assert.AreEqual(comparison.Entropy, target.Entropy, 1e-4);
            Assert.AreEqual(comparison.StandardDeviation, target.StandardDeviation, tol);
            Assert.AreEqual(comparison.Mode, target.Mode);
            Assert.AreEqual(comparison.Median, target.Median);

            for (double x = -10; x < 10; x += 0.0001)
            {
                double actual   = target.ProbabilityDensityFunction(x);
                double expected = comparison.ProbabilityDensityFunction(x);
                Assert.AreEqual(expected, actual, tol);
                Assert.IsFalse(Double.IsNaN(actual));
            }

            for (double x = -10; x < 10; x += 0.0001)
            {
                double actual   = target.DistributionFunction(x);
                double expected = comparison.DistributionFunction(x);
                Assert.AreEqual(expected, actual, tol);
                Assert.IsFalse(Double.IsNaN(actual));
            }

            for (double x = -10; x < 10; x += 0.0001)
            {
                double actual   = target.LogProbabilityDensityFunction(x);
                double expected = comparison.LogProbabilityDensityFunction(x);
                Assert.AreEqual(expected, actual, tol);
                Assert.IsFalse(Double.IsNaN(actual));
            }
        }
        public void ConstructorTest()
        {
            var tukey = new TukeyLambdaDistribution(lambda: 0.14);

            double mean   = tukey.Mean;                                    // 0.0
            double median = tukey.Median;                                  // 0.0
            double mode   = tukey.Mode;                                    // 0.0
            double var    = tukey.Variance;                                // 2.1102970222144855
            double stdDev = tukey.StandardDeviation;                       // 1.4526861402982014

            double cdf  = tukey.DistributionFunction(x: 1.4);              // 0.83252947230217966
            double pdf  = tukey.ProbabilityDensityFunction(x: 1.4);        // 0.17181242109370659
            double lpdf = tukey.LogProbabilityDensityFunction(x: 1.4);     // -1.7613519723149427

            double ccdf = tukey.ComplementaryDistributionFunction(x: 1.4); // 0.16747052769782034
            double icdf = tukey.InverseDistributionFunction(p: cdf);       // 1.4000000000000004

            double hf  = tukey.HazardFunction(x: 1.4);                     // 1.0219566231014163
            double chf = tukey.CumulativeHazardFunction(x: 1.4);           // 1.7842102556452939

            string str = tukey.ToString(CultureInfo.InvariantCulture);     // Tukey(x; λ = 0.14)

            Assert.AreEqual(0.0, mean);
            Assert.AreEqual(0.0, median);
            Assert.AreEqual(0.0, mode);
            Assert.AreEqual(2.1102970222144855, var);
            Assert.AreEqual(1.4526861402982014, stdDev);
            Assert.AreEqual(1.7869478972416082, chf);
            Assert.AreEqual(0.83252947230217966, cdf);
            Assert.AreEqual(0.17181242109370659, pdf);
            Assert.AreEqual(-1.7613519723149427, lpdf);
            Assert.AreEqual(1.0259263134569006, hf);
            Assert.AreEqual(0.16747052769782034, ccdf);
            Assert.AreEqual(1.4000000000000004, icdf);
            Assert.AreEqual("Tukey(x; λ = 0.14)", str);

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

            Assert.AreEqual(-2.395751074495986, range1.Min);
            Assert.AreEqual(2.395751074495986, range1.Max);
            Assert.AreEqual(-3.3841891582663117, range2.Min);
            Assert.AreEqual(3.3841891582663117, range2.Max);
            Assert.AreEqual(-3.3841891582663126, range3.Min);
            Assert.AreEqual(3.3841891582663117, range3.Max);
        }