Class BaseDistribution

    • Field Detail

      • random

        protected Random random
      • solverAbsoluteAccuracy

        protected double solverAbsoluteAccuracy
    • Constructor Detail

      • BaseDistribution

        public BaseDistribution​(Random rng)
      • BaseDistribution

        public BaseDistribution()
    • 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).
        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:
        org.apache.commons.math3.exception.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 org.apache.commons.math3.exception.OutOfRangeException
        Computes the quantile function of this distribution. For a random variable X distributed according to this distribution, the returned value is
        • inf{x in R | P(X<=x) >= p} for 0 < p <= 1,
        • inf{x in R | P(X<=x) > 0} for p = 0.

        The default implementation returns

        Specified by:
        inverseCumulativeProbability in interface Distribution
        Parameters:
        p - the cumulative probability
        Returns:
        the smallest p-quantile of this distribution (largest 0-quantile for p = 0)
        Throws:
        org.apache.commons.math3.exception.OutOfRangeException - if p < 0 or p > 1
      • 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
      • reseedRandomGenerator

        public void reseedRandomGenerator​(long seed)
        Reseed the random generator used to generate samples.
        Specified by:
        reseedRandomGenerator in interface Distribution
        Parameters:
        seed - the new seed
      • sample

        public double sample()
        Generate a random value sampled from this distribution.

        The default implementation uses the inversion method.

        Specified by:
        sample in interface Distribution
        Returns:
        a random value.
      • sample

        public double[] sample​(long sampleSize)
        Generate a random sample from the distribution.

        The default implementation generates the sample by calling sample() in a loop.

        Specified by:
        sample in interface Distribution
        Parameters:
        sampleSize - the number of random values to generate
        Returns:
        an array representing the random sample
      • probability

        public double probability​(double x)
        For a random variable X whose values are distributed according to this distribution, this method returns P(X = x). In other words, this method represents the probability mass function (PMF) for the distribution.
        Specified by:
        probability in interface Distribution
        Parameters:
        x - the point at which the PMF is evaluated
        Returns:
        zero.
        Since:
        3.1
      • sample

        public INDArray sample​(int[] shape)
        Description copied from interface: Distribution
        Sample the given shape
        Specified by:
        sample in interface Distribution
        Parameters:
        shape - the given shape
        Returns:
        an ndarray with random samples from this distribution
      • sample

        public INDArray sample​(INDArray target)
        Description copied from interface: Distribution
        Fill the target array by sampling from the distribution
        Specified by:
        sample in interface Distribution
        Parameters:
        target - target array
        Returns:
        an ndarray with random samples from this distribution