Class Beta

    • Constructor Summary

      Constructors 
      Constructor Description
      Beta()
      Creates a Beta with parameters 1.0, 1.0
      Beta​(double[] parameters)
      Creates a beta with the supplied parameters
      Beta​(double alpha1, double alpha2)
      Creates a beta with the supplied parameters
      Beta​(double alpha1, double alpha2, java.lang.String name)
      Creates a beta with the supplied parameters
    • Constructor Detail

      • Beta

        public Beta()
        Creates a Beta with parameters 1.0, 1.0
      • Beta

        public Beta​(double alpha1,
                    double alpha2)
        Creates a beta with the supplied parameters
        Parameters:
        alpha1 - the alpha1 parameter
        alpha2 - the alpha2 parameter
      • Beta

        public Beta​(double[] parameters)
        Creates a beta with the supplied parameters
        Parameters:
        parameters - alpha1 is parameter[0], alpha2 is parameter[1]
      • Beta

        public Beta​(double alpha1,
                    double alpha2,
                    java.lang.String name)
        Creates a beta with the supplied parameters
        Parameters:
        alpha1 - the alpha1 parameter
        alpha2 - the alpha2 parameter
        name - a label
    • Method Detail

      • getAlpha1

        public final double getAlpha1()
        Returns:
        the first shape parameter
      • getAlpha2

        public final double getAlpha2()
        Returns:
        the second shape parameter
      • setParameters

        public final void setParameters​(double alpha1,
                                        double alpha2)
        Changes the parameters to the supplied values
        Parameters:
        alpha1 - the alpha1 parameter
        alpha2 - the alpha2 parameter
      • setParameters

        public final void setParameters​(double[] parameters)
        Sets the parameters parameter[0] is alpha 1 parameter[1] is alpha 2
        Specified by:
        setParameters in interface ParametersIfc
        Parameters:
        parameters - an array holding the parameters
      • getMean

        public final double getMean()
        Description copied from interface: MeanIfc
        Returns the mean or expected value of a distribution
        Specified by:
        getMean in interface MeanIfc
        Returns:
        double the mean or expected value for the distribution
      • getParameters

        public final double[] getParameters()
        Description copied from interface: ParametersIfc
        Gets the parameters
        Specified by:
        getParameters in interface ParametersIfc
        Returns:
        Returns an array of the parameters
      • getVariance

        public final double getVariance()
        Description copied from interface: VarianceIfc
        Returns the variance of the distribution if defined
        Specified by:
        getVariance in interface VarianceIfc
        Returns:
        double the variance of the random variable
      • cdf

        public double cdf​(double x)
        Computes the CDF, has accuracy to about 10e-9
        Specified by:
        cdf in interface CDFIfc
        Parameters:
        x - the x value to be evaluated
        Returns:
        a double representing the probability
      • invCDF

        public double invCDF​(double p)
        Description copied from interface: InverseCDFIfc
        Provides the inverse cumulative distribution function for the distribution While closed form solutions for the inverse cdf may not exist, numerical search methods can be used to solve F(X) = U.
        Specified by:
        invCDF in interface InverseCDFIfc
        Parameters:
        p - The probability to be evaluated for the inverse, p must be [0,1] or an IllegalArgumentException is thrown
        Returns:
        The inverse cdf evaluated at the supplied probability
      • pdf

        public final double pdf​(double x)
        Description copied from interface: PDFIfc
        Returns the f(x) where f represents the probability density function for the distribution. Note this is not a probability.
        Specified by:
        pdf in interface PDFIfc
        Parameters:
        x - a double representing the value to be evaluated
        Returns:
        f(x)
      • betaFunction

        public static double betaFunction​(double z1,
                                          double z2)
        Computes Beta(z1,z2)
        Parameters:
        z1 - the first parameter
        z2 - the second parameter
        Returns:
        the computed value
      • logBetaFunction

        public static double logBetaFunction​(double z1,
                                             double z2)
        The natural logarithm of Beta(z1,z2)
        Parameters:
        z1 - the first parameter
        z2 - the second parameter
        Returns:
        natural logarithm of Beta(z1,z2)
      • incompleteBetaFunction

        public static double incompleteBetaFunction​(double x,
                                                    double a,
                                                    double b)
        Computes the incomplete beta function at the supplied x Beta(x, a, b)/Beta(a, b)
        Parameters:
        x - the point to be evaluated
        a - alpha 1
        b - alpha 2
        Returns:
        the regularized beta function at the supplied x
      • regularizedIncompleteBetaFunction

        public static double regularizedIncompleteBetaFunction​(double x,
                                                               double a,
                                                               double b)
        Computes the regularized incomplete beta function at the supplied x
        Parameters:
        x - the point to be evaluated
        a - alpha 1
        b - alpha 2
        Returns:
        the regularized incomplete beta function at the supplied x
      • regularizedIncompleteBetaFunction

        protected static double regularizedIncompleteBetaFunction​(double x,
                                                                  double a,
                                                                  double b,
                                                                  double lnbeta)
        Computes the regularized incomplete beta function at the supplied x
        Parameters:
        x - the point to be evaluated
        a - alpha 1
        b - alpha 2
        lnbeta - the natural log of Beta(alpha1,alpha2)
        Returns:
        the regularized incomplete beta function at the supplied x
      • betaContinuedFraction

        protected static double betaContinuedFraction​(double x,
                                                      double a,
                                                      double b)
        Computes the continued fraction for the incomplete beta function.
        Parameters:
        x - the point to be evaluated
        a - alpha 1
        b - alpha 2
        Returns:
        the continued fraction
      • inverseBetaCDF

        protected final double inverseBetaCDF​(double p)
        Computes the inverse of the beta CDF at the supplied probability point using an initial approximation and a root finding technique
        Parameters:
        p - the probability to evaluate
        Returns:
        the inverse value
      • approximateCDF

        public static final double approximateCDF​(double pp,
                                                  double qq,
                                                  double a,
                                                  double lnbeta)
        Computes an approximation of the CDF for the Beta distribution Uses part of algorithm AS109, Applied Statistics, vol 26, no 1, 1977, pp 111-114
        Parameters:
        pp - Alpha 1 parameter
        qq - Alpha 2 parameter
        a - The point to be evaluated
        lnbeta - The log of Beta(alpha1,alpha2)
        Returns:
        the approx cdf value
      • setContinuedFractionDesiredPrecision

        public static void setContinuedFractionDesiredPrecision​(double prec)
        Sets the desired precision in the continued fraction expansion for the computation of the incompleteBetaFunction
        Parameters:
        prec - the desired precision
      • setContinuedFractionMaximumIterations

        public static void setContinuedFractionMaximumIterations​(int maxIter)
        Sets the maximum number of iterations in the continued fraction expansion for the computation of the incompleteBetaFunction
        Parameters:
        maxIter - the maximum number of iterations
      • setRootFindingDesiredPrecision

        public static void setRootFindingDesiredPrecision​(double prec)
        Sets the desired precision of the root finding algorithm in the CDF inversion computation
        Parameters:
        prec - the desired precision
      • setRootFindingMaximumIterations

        public static void setRootFindingMaximumIterations​(int maxIter)
        Sets the maximum number of iterations of the root finding algorithm in the CDF inversion computation
        Parameters:
        maxIter - the max iterations
      • main

        public static void main​(java.lang.String[] args)