예제 #1
0
        public void EquivalencyTest3()
        {
            // when ksi -> 0, the shifted log-logistic reduces to the logistic distribution.

            double sigma = 0.42; // scale
            double ksi   = 0;    // shape
            double mu    = 2.4;  // location

            var target = new ShiftedLogLogisticDistribution(location: mu, scale: sigma, shape: ksi);
            var log    = new LogisticDistribution(mu, sigma);

            Assert.AreEqual(log.Mean, target.Mean);
            Assert.AreEqual(log.Median, target.Median);
            Assert.AreEqual(log.Mode, target.Mode);
            Assert.AreEqual(log.Variance, target.Variance);

            double actual, expected;

            for (double i = -10; i < 10; i += 0.1)
            {
                expected = log.DistributionFunction(i);
                actual   = target.DistributionFunction(i);
                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-15));

                expected = log.ProbabilityDensityFunction(i);
                actual   = target.ProbabilityDensityFunction(i);
                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-15));

                expected = log.LogProbabilityDensityFunction(i);
                actual   = target.LogProbabilityDensityFunction(i);
                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-10));

                expected = log.ComplementaryDistributionFunction(i);
                actual   = target.ComplementaryDistributionFunction(i);
                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-15));

                double p = log.DistributionFunction(i);
                expected = log.InverseDistributionFunction(p);
                actual   = target.InverseDistributionFunction(p);
                Assert.AreEqual(expected, actual, 1e-5);

                expected = log.HazardFunction(i);
                actual   = target.HazardFunction(i);
                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-15));

                expected = log.CumulativeHazardFunction(i);
                actual   = target.CumulativeHazardFunction(i);
                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-15));
            }
        }
        public void ConstructorTest1()
        {
            var log = new LogisticDistribution(location: 0.42, scale: 1.2);

            double mean   = log.Mean;                                    // 0.42
            double median = log.Median;                                  // 0.42
            double mode   = log.Mode;                                    // 0.42
            double var    = log.Variance;                                // 4.737410112522892

            double cdf  = log.DistributionFunction(x: 1.4);              // 0.693528308197921
            double pdf  = log.ProbabilityDensityFunction(x: 1.4);        // 0.17712232827170876
            double lpdf = log.LogProbabilityDensityFunction(x: 1.4);     // -1.7309146649427332

            double ccdf = log.ComplementaryDistributionFunction(x: 1.4); // 0.306471691802079
            double icdf = log.InverseDistributionFunction(p: cdf);       // 1.3999999999999997

            double hf  = log.HazardFunction(x: 1.4);                     // 0.57794025683160088
            double chf = log.CumulativeHazardFunction(x: 1.4);           // 1.1826298874077226

            string str = log.ToString(CultureInfo.InvariantCulture);     // Logistic(x; μ = 0.42, scale = 1.2)

            Assert.AreEqual(0.41999999999999998, mean);
            Assert.AreEqual(0.41999999999999998, median);
            Assert.AreEqual(4.737410112522892, var);
            Assert.AreEqual(1.1826298874077226, chf);
            Assert.AreEqual(0.693528308197921, cdf);
            Assert.AreEqual(0.17712232827170876, pdf);
            Assert.AreEqual(-1.7309146649427332, lpdf);
            Assert.AreEqual(0.57794025683160088, hf);
            Assert.AreEqual(0.306471691802079, ccdf);
            Assert.AreEqual(1.3999999999999997, icdf);
            Assert.AreEqual("Logistic(x; μ = 0.42, scale = 1.2)", str);
        }
예제 #3
0
        public void ConstructorTest1()
        {
            var log = new LogisticDistribution(location: 0.42, scale: 1.2);

            double mean   = log.Mean;                                    // 0.42
            double median = log.Median;                                  // 0.42
            double mode   = log.Mode;                                    // 0.42
            double var    = log.Variance;                                // 4.737410112522892

            double cdf  = log.DistributionFunction(x: 1.4);              // 0.693528308197921
            double pdf  = log.ProbabilityDensityFunction(x: 1.4);        // 0.17712232827170876
            double lpdf = log.LogProbabilityDensityFunction(x: 1.4);     // -1.7309146649427332

            double ccdf = log.ComplementaryDistributionFunction(x: 1.4); // 0.306471691802079
            double icdf = log.InverseDistributionFunction(p: cdf);       // 1.3999999999999997

            double hf  = log.HazardFunction(x: 1.4);                     // 0.57794025683160088
            double chf = log.CumulativeHazardFunction(x: 1.4);           // 1.1826298874077226

            string str = log.ToString(CultureInfo.InvariantCulture);     // Logistic(x; μ = 0.42, s = 1.2)

            Assert.AreEqual(0.41999999999999998, mean);
            Assert.AreEqual(0.41999999999999998, median);
            Assert.AreEqual(0.41999999999999998, mode);
            Assert.AreEqual(4.737410112522892, var);
            Assert.AreEqual(1.1826298874077226, chf);
            Assert.AreEqual(0.693528308197921, cdf);
            Assert.AreEqual(0.17712232827170876, pdf);
            Assert.AreEqual(-1.7309146649427332, lpdf);
            Assert.AreEqual(0.57794025683160088, hf);
            Assert.AreEqual(0.306471691802079, ccdf);
            Assert.AreEqual(1.3999999999999997, icdf);
            Assert.AreEqual("Logistic(x; μ = 0.42, s = 1.2)", str);

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

            Assert.AreEqual(-3.1133267749997273, range1.Min);
            Assert.AreEqual(3.9533267749997272, range1.Max);
            Assert.AreEqual(-5.0941438201615066, range2.Min);
            Assert.AreEqual(5.9341438201615064, range2.Max);
            Assert.AreEqual(-5.0941438201615075, range3.Min);
            Assert.AreEqual(5.9341438201615064, range3.Max);

            Assert.AreEqual(double.NegativeInfinity, log.Support.Min);
            Assert.AreEqual(double.PositiveInfinity, log.Support.Max);

            Assert.AreEqual(log.InverseDistributionFunction(0), log.Support.Min);
            Assert.AreEqual(log.InverseDistributionFunction(1), log.Support.Max);
        }