ProbabilityDensityFunction() public method

Gets the probability density function (pdf) for this distribution evaluated at point x.
The Probability Density Function (PDF) describes the probability that a given value x will occur.
public ProbabilityDensityFunction ( double x ) : double
x double A single point in the distribution range.
return double
Ejemplo n.º 1
0
        public void LaplaceDistributionConstructorTest()
        {
            {
                LaplaceDistribution target = new LaplaceDistribution(0, 0.2);

                double[] expected = { 2.5, 1.5163266, 0.919699, 0.557825, 0.338338 };

                for (int i = 0; i < expected.Length; i++)
                {

                    double x = i / 10.0;
                    double actual = target.ProbabilityDensityFunction(x);
                    Assert.AreEqual(expected[i], actual, 1e-6);
                    Assert.IsFalse(double.IsNaN(actual));
                }
            }

            {
                LaplaceDistribution target = new LaplaceDistribution(-2, 5.79);

                double[] expected = { 0.0666469, 0.0655057, 0.06438406, 0.0632816234, 0.062198060, 0.061133051 };

                for (int i = 0; i < expected.Length; i++)
                {

                    double x = (i - 5) / 10.0;
                    double actual = target.ProbabilityDensityFunction(x);
                    Assert.AreEqual(expected[i], actual, 1e-8);
                    Assert.IsFalse(double.IsNaN(actual));
                }
            }
        }
Ejemplo n.º 2
0
        public void ConstructorTest2()
        {
            var laplace = new LaplaceDistribution(location: 4, scale: 2);

            double mean = laplace.Mean;     // 4.0
            double median = laplace.Median; // 4.0
            double var = laplace.Variance;  // 8.0
            double mode = laplace.Mode;     // 4.0

            double cdf = laplace.DistributionFunction(x: 0.27); // 0.077448104942453522
            double pdf = laplace.ProbabilityDensityFunction(x: 0.27); // 0.038724052471226761
            double lpdf = laplace.LogProbabilityDensityFunction(x: 0.27); // -3.2512943611198906

            double ccdf = laplace.ComplementaryDistributionFunction(x: 0.27); // 0.92255189505754642
            double icdf = laplace.InverseDistributionFunction(p: cdf); // 0.27

            double hf = laplace.HazardFunction(x: 0.27); // 0.041974931360160776
            double chf = laplace.CumulativeHazardFunction(x: 0.27); // 0.080611649844768624

            string str = laplace.ToString(CultureInfo.InvariantCulture); // Laplace(x; μ = 4, b = 2)

            Assert.AreEqual(4.0, mean);
            Assert.AreEqual(4.0, median);
            Assert.AreEqual(8.0, var);
            Assert.AreEqual(4.0, mode);
            Assert.AreEqual(0.080611649844768624, chf);
            Assert.AreEqual(0.077448104942453522, cdf);
            Assert.AreEqual(0.038724052471226761, pdf);
            Assert.AreEqual(-3.2512943611198906, lpdf);
            Assert.AreEqual(0.041974931360160776, hf);
            Assert.AreEqual(0.92255189505754642, ccdf);
            Assert.AreEqual(0.26999999840794775, icdf);
            Assert.AreEqual("Laplace(x; μ = 4, b = 2)", str);

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

            Assert.AreEqual(-0.60517019072231026, range1.Min);
            Assert.AreEqual(8.6051701894643209, range1.Max);
            Assert.AreEqual(-3.8240460108561982, range2.Min);
            Assert.AreEqual(11.824046011144626, range2.Max);
            Assert.AreEqual(-3.8240460108561951, range3.Min);
            Assert.AreEqual(11.824046011144626, range3.Max);
        }
Ejemplo n.º 3
0
        public void ConstructorTest2()
        {
            var laplace = new LaplaceDistribution(location: 4, scale: 2);

            double mean = laplace.Mean;     // 4.0
            double median = laplace.Median; // 4.0
            double var = laplace.Variance;  // 8.0

            double cdf = laplace.DistributionFunction(x: 0.27); // 0.077448104942453522
            double pdf = laplace.ProbabilityDensityFunction(x: 0.27); // 0.038724052471226761
            double lpdf = laplace.LogProbabilityDensityFunction(x: 0.27); // -3.2512943611198906

            double ccdf = laplace.ComplementaryDistributionFunction(x: 0.27); // 0.92255189505754642
            double icdf = laplace.InverseDistributionFunction(p: cdf); // 0.27

            double hf = laplace.HazardFunction(x: 0.27); // 0.041974931360160776
            double chf = laplace.CumulativeHazardFunction(x: 0.27); // 0.080611649844768624

            string str = laplace.ToString(CultureInfo.InvariantCulture); // Laplace(x; μ = 4, b = 2)

            Assert.AreEqual(4.0, mean);
            Assert.AreEqual(4.0, median);
            Assert.AreEqual(8.0, var);
            Assert.AreEqual(0.080611649844768624, chf);
            Assert.AreEqual(0.077448104942453522, cdf);
            Assert.AreEqual(0.038724052471226761, pdf);
            Assert.AreEqual(-3.2512943611198906, lpdf);
            Assert.AreEqual(0.041974931360160776, hf);
            Assert.AreEqual(0.92255189505754642, ccdf);
            Assert.AreEqual(0.26999999840794775, icdf);
            Assert.AreEqual("Laplace(x; μ = 4, b = 2)", str);
        }
        public void ConstructorTest6()
        {
            var original = new LaplaceDistribution(location: 4, scale: 2);

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

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

                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-4));
            }

            testLaplace(laplace);
        }
        public void ConstructorTest6()
        {
            var original = new LaplaceDistribution(location: 4, scale: 2);

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

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

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

            testLaplace(laplace);
        }