Class AbstractRealDistribution

  • All Implemented Interfaces:
    org.apache.commons.statistics.distribution.ContinuousDistribution
    Direct Known Subclasses:
    EmpiricalDistribution

    public abstract class AbstractRealDistribution
    extends Object
    implements org.apache.commons.statistics.distribution.ContinuousDistribution
    Base class for probability distributions on the reals. Default implementations are provided for some of the methods that do not vary from distribution to distribution.

    This base class provides a default factory method for creating a sampler instance that uses the inversion method for generating random samples that follow the distribution.

    Since:
    3.0
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.apache.commons.statistics.distribution.ContinuousDistribution

        org.apache.commons.statistics.distribution.ContinuousDistribution.Sampler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double SOLVER_DEFAULT_ABSOLUTE_ACCURACY
      Default absolute accuracy for inverse cumulative computation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.commons.statistics.distribution.ContinuousDistribution.Sampler createSampler​(org.apache.commons.rng.UniformRandomProvider rng)
      protected double getSolverAbsoluteAccuracy()
      Returns the solver absolute accuracy for inverse cumulative computation.
      double inverseCumulativeProbability​(double p)
      The default implementation returns ContinuousDistribution.getSupportLowerBound() for p = 0, ContinuousDistribution.getSupportUpperBound() for p = 1.
      double logDensity​(double x)
      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).
      static double[] sample​(int n, org.apache.commons.statistics.distribution.ContinuousDistribution.Sampler sampler)
      Utility function for allocating an array and filling it with n samples generated by the given sampler.
      • Methods inherited from interface org.apache.commons.statistics.distribution.ContinuousDistribution

        cumulativeProbability, density, getMean, getSupportLowerBound, getSupportUpperBound, getVariance, inverseSurvivalProbability, survivalProbability
    • Method Detail

      • 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).
        Specified by:
        probability in interface org.apache.commons.statistics.distribution.ContinuousDistribution
        Parameters:
        x0 - Lower bound (excluded).
        x1 - Upper bound (included).
        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.
        Throws:
        NumberIsTooLargeException - if x0 > x1. The default implementation uses the identity P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)
        Since:
        3.1
      • inverseCumulativeProbability

        public double inverseCumulativeProbability​(double p)
                                            throws OutOfRangeException
        The default implementation returns
        • ContinuousDistribution.getSupportLowerBound() for p = 0,
        • ContinuousDistribution.getSupportUpperBound() for p = 1.
        Specified by:
        inverseCumulativeProbability in interface org.apache.commons.statistics.distribution.ContinuousDistribution
        Throws:
        OutOfRangeException
      • getSolverAbsoluteAccuracy

        protected double getSolverAbsoluteAccuracy()
        Returns the solver absolute accuracy for inverse cumulative computation. You can override this method in order to use a Brent solver with an absolute accuracy different from the default.
        Returns:
        the maximum absolute error in inverse cumulative probability estimates
      • logDensity

        public double logDensity​(double x)

        The default implementation simply computes the logarithm of density(x).

        Specified by:
        logDensity in interface org.apache.commons.statistics.distribution.ContinuousDistribution
      • sample

        public static double[] sample​(int n,
                                      org.apache.commons.statistics.distribution.ContinuousDistribution.Sampler sampler)
        Utility function for allocating an array and filling it with n samples generated by the given sampler.
        Parameters:
        n - Number of samples.
        sampler - Sampler.
        Returns:
        an array of size n.
      • createSampler

        public org.apache.commons.statistics.distribution.ContinuousDistribution.Sampler createSampler​(org.apache.commons.rng.UniformRandomProvider rng)
        Specified by:
        createSampler in interface org.apache.commons.statistics.distribution.ContinuousDistribution