Пример #1
0
        public void ConstructorTest()
        {
            var log = new LognormalDistribution(location: 0.42, shape: 1.1);

            double mean   = log.Mean;                                      // 2.7870954605658511
            double median = log.Median;                                    // 1.5219615583481305
            double var    = log.Variance;                                  // 18.28163603621158

            double cdf  = log.DistributionFunction(x: 0.27);               // 0.057961222885664958
            double pdf  = log.ProbabilityDensityFunction(x: 0.27);         // 0.39035530085982068
            double lpdf = log.LogProbabilityDensityFunction(x: 0.27);      // -0.94069792674674835

            double ccdf = log.ComplementaryDistributionFunction(x: 0.27);  // 0.942038777114335
            double icdf = log.InverseDistributionFunction(p: cdf);         // 0.26999997937815973

            double hf  = log.HazardFunction(x: 0.27);                      // 0.41437285846720867
            double chf = log.CumulativeHazardFunction(x: 0.27);            // 0.059708840588116374

            string str = log.ToString("N2", CultureInfo.InvariantCulture); // Lognormal(x; μ = 2.79, σ = 1.10)

            Assert.AreEqual(2.7870954605658511, mean);
            Assert.AreEqual(1.5219615583481305, median, 1e-7);
            Assert.AreEqual(18.28163603621158, var);
            Assert.AreEqual(0.059708840588116374, chf);
            Assert.AreEqual(0.057961222885664958, cdf);
            Assert.AreEqual(0.39035530085982068, pdf);
            Assert.AreEqual(-0.94069792674674835, lpdf);
            Assert.AreEqual(0.41437285846720867, hf);
            Assert.AreEqual(0.942038777114335, ccdf);
            Assert.AreEqual(0.26999997937815973, icdf, 1e-7);
            Assert.AreEqual("Lognormal(x; μ = 2.79, σ = 1.10)", str);
        }
        public void ConstructorTest()
        {
            var log = new LognormalDistribution(location: 0.42, shape: 1.1);

            double mean = log.Mean;     // 2.7870954605658511
            double median = log.Median; // 1.5219615583481305
            double var = log.Variance;  // 18.28163603621158

            double cdf = log.DistributionFunction(x: 0.27); // 0.057961222885664958
            double pdf = log.ProbabilityDensityFunction(x: 0.27); // 0.39035530085982068
            double lpdf = log.LogProbabilityDensityFunction(x: 0.27); // -0.94069792674674835

            double ccdf = log.ComplementaryDistributionFunction(x: 0.27); // 0.942038777114335
            double icdf = log.InverseDistributionFunction(p: cdf); // 0.26999997937815973

            double hf = log.HazardFunction(x: 0.27); // 0.41437285846720867
            double chf = log.CumulativeHazardFunction(x: 0.27); // 0.059708840588116374

            string str = log.ToString("N2", CultureInfo.InvariantCulture); // Lognormal(x; μ = 2.79, σ = 1.10)

            Assert.AreEqual(2.7870954605658511, mean);
            Assert.AreEqual(1.5219615583481305, median, 1e-7);
            Assert.AreEqual(18.28163603621158, var);
            Assert.AreEqual(0.059708840588116374, chf);
            Assert.AreEqual(0.057961222885664958, cdf);
            Assert.AreEqual(0.39035530085982068, pdf);
            Assert.AreEqual(-0.94069792674674835, lpdf);
            Assert.AreEqual(0.41437285846720867, hf);
            Assert.AreEqual(0.942038777114335, ccdf);
            Assert.AreEqual(0.26999997937815973, icdf, 1e-7);
            Assert.AreEqual("Lognormal(x; μ = 2.79, σ = 1.10)", str);
        }
        public void ProbabilityDensityFunctionTest()
        {
            LognormalDistribution target = new LognormalDistribution(1.7, 4.2);

            double x        = 2.2;
            double expected = 0.0421705870979553;
            double actual   = target.ProbabilityDensityFunction(x);

            Assert.AreEqual(expected, actual, 1e-15);
        }
        public void ConstructorTest()
        {
            var log = new LognormalDistribution(location: 0.42, shape: 1.1);

            double mean   = log.Mean;                                      // 2.7870954605658511
            double median = log.Median;                                    // 1.5219615583481305
            double var    = log.Variance;                                  // 18.28163603621158
            double mode   = log.Mode;                                      // 0.45384479528235572

            double cdf  = log.DistributionFunction(x: 0.27);               // 0.057961222885664958
            double pdf  = log.ProbabilityDensityFunction(x: 0.27);         // 0.39035530085982068
            double lpdf = log.LogProbabilityDensityFunction(x: 0.27);      // -0.94069792674674835

            double ccdf = log.ComplementaryDistributionFunction(x: 0.27);  // 0.942038777114335
            double icdf = log.InverseDistributionFunction(p: cdf);         // 0.26999997937815973

            double hf  = log.HazardFunction(x: 0.27);                      // 0.41437285846720867
            double chf = log.CumulativeHazardFunction(x: 0.27);            // 0.059708840588116374

            string str = log.ToString("N2", CultureInfo.InvariantCulture); // Lognormal(x; μ = 2.79, σ = 1.10)

            Assert.AreEqual(2.7870954605658511, mean);
            Assert.AreEqual(1.5219615583481305, median, 1e-7);
            Assert.AreEqual(0.45384479528235572, mode);
            Assert.AreEqual(18.28163603621158, var);
            Assert.AreEqual(0.059708840588116374, chf);
            Assert.AreEqual(0.057961222885664958, cdf);
            Assert.AreEqual(0.39035530085982068, pdf);
            Assert.AreEqual(-0.94069792674674835, lpdf);
            Assert.AreEqual(0.41437285846720867, hf);
            Assert.AreEqual(0.942038777114335, ccdf);
            Assert.AreEqual(0.26999997937815973, icdf, 1e-6);
            Assert.AreEqual("Lognormal(x; μ = 2.79, σ = 1.10)", str);

            var range1 = log.GetRange(0.95);

            Assert.AreEqual(0.24923999017902393, range1.Min);
            Assert.AreEqual(9.293720885640818, range1.Max);

            var range2 = log.GetRange(0.99);

            Assert.AreEqual(0.11777446636476178, range2.Min);
            Assert.AreEqual(19.667797655030668, range2.Max);

            var range3 = log.GetRange(0.01);

            Assert.AreEqual(0.11777446636476173, range3.Min);
            Assert.AreEqual(19.667797655030668, range3.Max);

            Assert.AreEqual(0, 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);
        }
Пример #5
0
        public double CalculateDensity(double latitude, double longitude)
        {
            double density = 0;

            double d1 = DistanceTo.Satellite(latitude, longitude);
            double d2 = DistanceTo.River(latitude, longitude);
            double d3 = DistanceTo.Brandenburg(latitude, longitude);

            if (d1 >= 0)
            {
                density += satelliteDistribution.ProbabilityDensityFunction(d1);
            }

            if (d2 >= 0)
            {
                density += riverDistribution.ProbabilityDensityFunction(d2);
            }

            density += brandenburgDistribution.ProbabilityDensityFunction(d3);
            return(density);
        }
        public void ConstructorTest()
        {
            var log = new LognormalDistribution(location: 0.42, shape: 1.1);

            double mean = log.Mean;     // 2.7870954605658511
            double median = log.Median; // 1.5219615583481305
            double var = log.Variance;  // 18.28163603621158
            double mode = log.Mode;     // 0.45384479528235572

            double cdf = log.DistributionFunction(x: 0.27); // 0.057961222885664958
            double pdf = log.ProbabilityDensityFunction(x: 0.27); // 0.39035530085982068
            double lpdf = log.LogProbabilityDensityFunction(x: 0.27); // -0.94069792674674835

            double ccdf = log.ComplementaryDistributionFunction(x: 0.27); // 0.942038777114335
            double icdf = log.InverseDistributionFunction(p: cdf); // 0.26999997937815973

            double hf = log.HazardFunction(x: 0.27); // 0.41437285846720867
            double chf = log.CumulativeHazardFunction(x: 0.27); // 0.059708840588116374

            string str = log.ToString("N2", CultureInfo.InvariantCulture); // Lognormal(x; μ = 2.79, σ = 1.10)

            Assert.AreEqual(2.7870954605658511, mean);
            Assert.AreEqual(1.5219615583481305, median, 1e-7);
            Assert.AreEqual(0.45384479528235572, mode);
            Assert.AreEqual(18.28163603621158, var);
            Assert.AreEqual(0.059708840588116374, chf);
            Assert.AreEqual(0.057961222885664958, cdf);
            Assert.AreEqual(0.39035530085982068, pdf);
            Assert.AreEqual(-0.94069792674674835, lpdf);
            Assert.AreEqual(0.41437285846720867, hf);
            Assert.AreEqual(0.942038777114335, ccdf);
            Assert.AreEqual(0.26999997937815973, icdf, 1e-6);
            Assert.AreEqual("Lognormal(x; μ = 2.79, σ = 1.10)", str);

            var range1 = log.GetRange(0.95);
            Assert.AreEqual(0.24923999017902393, range1.Min);
            Assert.AreEqual(9.293720885640818, range1.Max);

            var range2 = log.GetRange(0.99);
            Assert.AreEqual(0.11777446636476178, range2.Min);
            Assert.AreEqual(19.667797655030668, range2.Max);

            var range3 = log.GetRange(0.01);
            Assert.AreEqual(0.11777446636476173, range3.Min);
            Assert.AreEqual(19.667797655030668, range3.Max);
        }
Пример #7
0
        public void ConstructorTest9()
        {
            var original = new LognormalDistribution(location: 0.42, shape: 1.1);

            var log = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual   = log.ProbabilityDensityFunction(i);

                double diff = Math.Abs(expected - actual);
                Assert.AreEqual(expected, actual, 1e-8);
            }

            testLognormal(log);
        }
        public void ProbabilityDensityFunctionTest()
        {
            LognormalDistribution target = new LognormalDistribution(1.7, 4.2);

            double x = 2.2;
            double expected = 0.0421705870979553;
            double actual = target.ProbabilityDensityFunction(x);

            Assert.AreEqual(expected, actual, 1e-15);
        }
        public void ConstructorTest9()
        {
            var original = new LognormalDistribution(location: 0.42, shape: 1.1);

            var log = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual = log.ProbabilityDensityFunction(i);

                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-7));
 
                Assert.AreEqual(expected, actual, 1e-8);
            }

            testLognormal(log);
        }