Class TrapezoidalDistribution

  • All Implemented Interfaces:
    ContinuousDistribution

    public abstract class TrapezoidalDistribution
    extends Object
    Implementation of the trapezoidal distribution.

    The probability density function of X is:

    f(x;a,b,c,d)={2d+cabxabafor ax<b2d+cabfor bx<c2d+cabdxdcfor cxd

    for <abcd< and x[a,d].

    Note the special cases:

    • b=c is the triangular distribution
    • a=b and c=d is the uniform distribution
    See Also:
    Trapezoidal distribution (Wikipedia)
    • Field Detail

      • a

        protected final double a
        Lower limit of this distribution (inclusive).
      • b

        protected final double b
        Start of the trapezoid constant density.
      • c

        protected final double c
        End of the trapezoid constant density.
      • d

        protected final double d
        Upper limit of this distribution (inclusive).
    • Method Detail

      • of

        public static TrapezoidalDistribution of​(double a,
                                                 double b,
                                                 double c,
                                                 double d)
        Creates a trapezoidal distribution.

        The distribution density is represented as an up sloping line from a to b, constant from b to c, and then a down sloping line from c to d.

        Parameters:
        a - Lower limit of this distribution (inclusive).
        b - Start of the trapezoid constant density (first shape parameter).
        c - End of the trapezoid constant density (second shape parameter).
        d - Upper limit of this distribution (inclusive).
        Returns:
        the distribution
        Throws:
        IllegalArgumentException - if a >= d, if b < a, if c < b or if c > d.
      • getMean

        public abstract double getMean()
        Gets the mean of this distribution.

        For lower limit a, start of the density constant region b, end of the density constant region c and upper limit d, the mean is:

        13(d+cba)(d3c3dcb3a3ba)

        Returns:
        the mean.
      • getVariance

        public abstract double getVariance()
        Gets the variance of this distribution.

        For lower limit a, start of the density constant region b, end of the density constant region c and upper limit d, the variance is:

        16(d+cba)(d4c4dcb4a4ba)μ2

        where μ is the mean.

        Returns:
        the variance.
      • getB

        public double getB()
        Gets the start of the constant region of the density function.

        This is the first shape parameter b of the distribution.

        Returns:
        the first shape parameter b
      • getC

        public double getC()
        Gets the end of the constant region of the density function.

        This is the second shape parameter c of the distribution.

        Returns:
        the second shape parameter c
      • getSupportLowerBound

        public double getSupportLowerBound()
        Gets the lower bound of the support. It must return the same value as inverseCumulativeProbability(0), i.e. inf{xR:P(Xx)>0}.

        The lower bound of the support is equal to the lower limit parameter a of the distribution.

        Returns:
        the lower bound of the support.
      • getSupportUpperBound

        public double getSupportUpperBound()
        Gets the upper bound of the support. It must return the same value as inverseCumulativeProbability(1), i.e. inf{xR:P(Xx)=1}.

        The upper bound of the support is equal to the upper limit parameter d of the distribution.

        Returns:
        the upper bound of the support.
      • probability

        public double probability​(double x0,
                                  double x1)
        For a random variable X whose values are distributed according to this distribution, this method returns P(x0 < X <= x1). The default implementation uses the identity P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)
        Specified by:
        probability in interface ContinuousDistribution
        Parameters:
        x0 - Lower bound (exclusive).
        x1 - Upper bound (inclusive).
        Returns:
        the probability that a random variable with this distribution takes a value between x0 and x1, excluding the lower and including the upper endpoint.
      • inverseSurvivalProbability

        public double inverseSurvivalProbability​(double p)
        Computes the inverse survival probability function of this distribution. For a random variable X distributed according to this distribution, the returned value is:

        x={inf{xR:P(X>x)p}for 0p<1inf{xR:P(X>x)<1}for p=1

        By default, this is defined as inverseCumulativeProbability(1 - p), but the specific implementation may be more accurate.

        The default implementation returns:

        Specified by:
        inverseSurvivalProbability in interface ContinuousDistribution
        Parameters:
        p - Survival probability.
        Returns:
        the smallest (1-p)-quantile of this distribution (largest 0-quantile for p = 1).
        Throws:
        IllegalArgumentException - if p < 0 or p > 1
      • createSampler

        public ContinuousDistribution.Sampler createSampler​(org.apache.commons.rng.UniformRandomProvider rng)
        Creates a sampler.
        Specified by:
        createSampler in interface ContinuousDistribution
        Parameters:
        rng - Generator of uniformly distributed numbers.
        Returns:
        a sampler that produces random numbers according this distribution.