Class BetaDistribution

  • All Implemented Interfaces:
    Distribution

    public class BetaDistribution
    extends java.lang.Object
    implements Distribution
    Beta Distribution with implementation of the regularized incomplete beta function
    Since:
    0.5.0
    Author:
    Jan Brusis, Erich Schubert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double alpha
      Shape parameter of beta distribution
      private double beta
      Shape parameter of beta distribution
      (package private) static double[] GAUSSLEGENDRE_W
      Weights for Gauss-Legendre quadrature
      (package private) static double[] GAUSSLEGENDRE_Y
      Abscissas for Gauss-Legendre quadrature
      private double logbab
      Log beta(a, b) cache
      (package private) static double NUM_PRECISION
      Numerical precision to use
      (package private) static double SWITCH
      Limit of when to switch to quadrature method
    • Constructor Summary

      Constructors 
      Constructor Description
      BetaDistribution​(double a, double b)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double cdf​(double x)
      Return the cumulative density function at the given value.
      static double cdf​(double val, double alpha, double beta)
      Static version of the CDF of the beta distribution
      static double logBeta​(double alpha, double beta)
      Compute log beta(a,b)
      double logpdf​(double val)
      Return the log density of an existing value
      static double logpdf​(double val, double alpha, double beta)
      Static version of the PDF of the beta distribution
      double nextRandom​(java.util.Random random)
      Generate a new random value
      double pdf​(double val)
      Return the density of an existing value
      static double pdf​(double val, double alpha, double beta)
      Static version of the PDF of the beta distribution
      double quantile​(double x)
      Quantile aka probit (for normal) aka inverse CDF (invcdf, cdf^-1) function.
      static double quantile​(double p, double alpha, double beta)
      Compute quantile (inverse cdf) for Beta distributions.
      protected static double rawQuantile​(double p, double alpha, double beta, double logbeta)
      Raw quantile function
      static double regularizedIncBeta​(double x, double alpha, double beta)
      Computes the regularized incomplete beta function I_x(a, b) which is also the CDF of the beta distribution.
      protected static double regularizedIncBeta​(double x, double alpha, double beta, double logbab)
      Computes the regularized incomplete beta function I_x(a, b) which is also the CDF of the beta distribution.
      protected static double regularizedIncBetaCF​(double alpha, double beta, double x)
      Returns the regularized incomplete beta function I_x(a, b) Includes the continued fraction way of computing, based on the book "Numerical Recipes".
      protected static double regularizedIncBetaQuadrature​(double alpha, double beta, double x)
      Returns the regularized incomplete beta function I_x(a, b) by quadrature, based on the book "Numerical Recipes".
      java.lang.String toString()
      Describe the distribution
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NUM_PRECISION

        static final double NUM_PRECISION
        Numerical precision to use
        See Also:
        Constant Field Values
      • SWITCH

        static final double SWITCH
        Limit of when to switch to quadrature method
        See Also:
        Constant Field Values
      • GAUSSLEGENDRE_Y

        static final double[] GAUSSLEGENDRE_Y
        Abscissas for Gauss-Legendre quadrature
      • GAUSSLEGENDRE_W

        static final double[] GAUSSLEGENDRE_W
        Weights for Gauss-Legendre quadrature
      • alpha

        private final double alpha
        Shape parameter of beta distribution
      • beta

        private final double beta
        Shape parameter of beta distribution
      • logbab

        private double logbab
        Log beta(a, b) cache
    • Constructor Detail

      • BetaDistribution

        public BetaDistribution​(double a,
                                double b)
        Constructor.
        Parameters:
        a - shape Parameter a
        b - shape Parameter b
    • Method Detail

      • pdf

        public double pdf​(double val)
        Description copied from interface: Distribution
        Return the density of an existing value
        Specified by:
        pdf in interface Distribution
        Parameters:
        val - existing value
        Returns:
        distribution density
      • logpdf

        public double logpdf​(double val)
        Description copied from interface: Distribution
        Return the log density of an existing value
        Specified by:
        logpdf in interface Distribution
        Parameters:
        val - existing value
        Returns:
        log distribution density
      • cdf

        public double cdf​(double x)
        Description copied from interface: Distribution
        Return the cumulative density function at the given value.
        Specified by:
        cdf in interface Distribution
        Parameters:
        x - existing value
        Returns:
        cumulative density
      • quantile

        public double quantile​(double x)
        Description copied from interface: Distribution
        Quantile aka probit (for normal) aka inverse CDF (invcdf, cdf^-1) function.
        Specified by:
        quantile in interface Distribution
        Parameters:
        x - Quantile to find
        Returns:
        Quantile position
      • nextRandom

        public double nextRandom​(java.util.Random random)
        Description copied from interface: Distribution
        Generate a new random value
        Specified by:
        nextRandom in interface Distribution
        Parameters:
        random - Random number generator
        Returns:
        new random value
      • toString

        public java.lang.String toString()
        Description copied from interface: Distribution
        Describe the distribution
        Specified by:
        toString in interface Distribution
        Overrides:
        toString in class java.lang.Object
        Returns:
        description
      • cdf

        public static double cdf​(double val,
                                 double alpha,
                                 double beta)
        Static version of the CDF of the beta distribution
        Parameters:
        val - Value
        alpha - Shape parameter a
        beta - Shape parameter b
        Returns:
        cumulative density
      • pdf

        public static double pdf​(double val,
                                 double alpha,
                                 double beta)
        Static version of the PDF of the beta distribution
        Parameters:
        val - Value
        alpha - Shape parameter a
        beta - Shape parameter b
        Returns:
        probability density
      • logpdf

        public static double logpdf​(double val,
                                    double alpha,
                                    double beta)
        Static version of the PDF of the beta distribution
        Parameters:
        val - Value
        alpha - Shape parameter a
        beta - Shape parameter b
        Returns:
        probability density
      • logBeta

        public static double logBeta​(double alpha,
                                     double beta)
        Compute log beta(a,b)
        Parameters:
        alpha - Shape parameter a
        beta - Shape parameter b
        Returns:
        Logarithm of result
      • regularizedIncBeta

        public static double regularizedIncBeta​(double x,
                                                double alpha,
                                                double beta)
        Computes the regularized incomplete beta function I_x(a, b) which is also the CDF of the beta distribution. Based on the book "Numerical Recipes"
        Parameters:
        alpha - Parameter a
        beta - Parameter b
        x - Parameter x
        Returns:
        Value of the regularized incomplete beta function
      • regularizedIncBeta

        protected static double regularizedIncBeta​(double x,
                                                   double alpha,
                                                   double beta,
                                                   double logbab)
        Computes the regularized incomplete beta function I_x(a, b) which is also the CDF of the beta distribution. Based on the book "Numerical Recipes"
        Parameters:
        x - Parameter x
        alpha - Parameter a
        beta - Parameter b
        logbab - Cached logBeta(alpha, beta)
        Returns:
        Value of the regularized incomplete beta function
      • regularizedIncBetaCF

        protected static double regularizedIncBetaCF​(double alpha,
                                                     double beta,
                                                     double x)
        Returns the regularized incomplete beta function I_x(a, b) Includes the continued fraction way of computing, based on the book "Numerical Recipes".
        Parameters:
        alpha - Parameter a
        beta - Parameter b
        x - Parameter x
        Returns:
        result
      • regularizedIncBetaQuadrature

        protected static double regularizedIncBetaQuadrature​(double alpha,
                                                             double beta,
                                                             double x)
        Returns the regularized incomplete beta function I_x(a, b) by quadrature, based on the book "Numerical Recipes".
        Parameters:
        alpha - Parameter a
        beta - Parameter b
        x - Parameter x
        Returns:
        result
      • quantile

        public static double quantile​(double p,
                                      double alpha,
                                      double beta)
        Compute quantile (inverse cdf) for Beta distributions.
        Parameters:
        p - Probability
        alpha - Shape parameter a
        beta - Shape parameter b
        Returns:
        Probit for Beta distribution
      • rawQuantile

        protected static double rawQuantile​(double p,
                                            double alpha,
                                            double beta,
                                            double logbeta)
        Raw quantile function
        Parameters:
        p - P, must be 0 < p <= .5
        alpha - Alpha
        beta - Beta
        logbeta - log Beta(alpha, beta)
        Returns:
        Position