Accord.Statistics.Distributions.Univariate.TrapezoidalDistribution.DistributionFunction C# (CSharp) Method

DistributionFunction() public method

Gets the cumulative distribution function (cdf) for this distribution evaluated at point x.
The Cumulative Distribution Function (CDF) describes the cumulative probability that a given value or any value smaller than it will occur.
public DistributionFunction ( double x ) : double
x double A single point in the distribution range.
return double
        public override double DistributionFunction(double x)
        {
            if (x < a)
                return 0;

            if (x > d)
                return 1;

            if (x < b)
            {
                double num = 2 * alpha * (b - a) * n3;
                double den = 2 * alpha * (b - a) * n3
                    + (alpha + 1) * (c - b) * n1 * n3
                    + 2 * (d - c) * n1;

                return (num / den) * Math.Pow((x - a) / (b - a), n1);
            }

            if (x < c)
            {
                double num = 2 * alpha * (b - a) * n3
                    + 2 * (x - b) * n1 * n3 * (1 + ((alpha - 1) * (2 * c - b - x)) / (2 * (c - b)));

                double den = 2 * alpha * (b - a) * n3
                    + (alpha + 1) * (c - b) * n1 * n3
                    + 2 * (c - d) * n1;

                return num / den;
            }

            if (x < d)
            {
                double num = 2 * (c - d) * n1;
                double den = 2 * alpha * (b - a) * n3
                    + (alpha + 1) * (c - b) * n1 * n3
                    + 2 * (c - d) * n1;

                return 1 - num / den * Math.Pow((d - x) / (d - c), n3);
            }

            return 1;
        }

Usage Example

        public void TrapezoidalDistributionConstructorTest()
        {
            double x = 0.75d;

            double a = 0;
            double b = (1.0d/3.0d);
            double c = (2.0d/3.0d);
            double d = 1.0d;
            double n1 = 2.0d;
            double n3 = 2.0d;

            var trapDist = new TrapezoidalDistribution(a, b, c, d, n1, n3);
            double mean = trapDist.Mean; //0.62499999999999989
            double variance = trapDist.Variance; //0.37103174603174593
            double pdf = trapDist.ProbabilityDensityFunction(x); //1.1249999999999998
            double cdf = trapDist.DistributionFunction(x); //1.28125
            string tostr = trapDist.ToString("N2", CultureInfo.InvariantCulture);

            Assert.AreEqual(mean, 0.625d, 0.00000001);
            Assert.AreEqual(variance, 0.37103175d, 0.00000001);
            Assert.AreEqual(pdf, 1.125, 0.000000001, "should match output from dtrapezoid in R");
            Assert.AreEqual(cdf, 1.28125,0.000000001);
            Assert.AreEqual(tostr, "Trapezoidal(x; a = 0.00, b = 0.33, c = 0.67, d = 1.00, n1 = 2.00, n3 = 2.00, α = 1.00)");
            //Verified using R package 'trapezoid'
        }
All Usage Examples Of Accord.Statistics.Distributions.Univariate.TrapezoidalDistribution::DistributionFunction