Package jsl.utilities.distributions
Class Beta
- java.lang.Object
-
- jsl.utilities.distributions.Distribution
-
- jsl.utilities.distributions.Beta
-
- All Implemented Interfaces:
ControllableIfc
,CDFIfc
,ContinuousDistributionIfc
,DistributionFunctionIfc
,DistributionIfc
,DomainIfc
,InverseCDFIfc
,MeanIfc
,PDFIfc
,VarianceIfc
,GetNameIfc
,IdentityIfc
,NewInstanceIfc
,ParametersIfc
,GetRVariableIfc
public class Beta extends Distribution implements ContinuousDistributionIfc, InverseCDFIfc, GetRVariableIfc
The standard beta distribution defined over the range from (0,1)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.utilities.distributions.Distribution
Distribution.RandomControls
-
-
Field Summary
-
Fields inherited from class jsl.utilities.distributions.Distribution
myId, myName
-
-
Constructor Summary
Constructors Constructor Description Beta()
Creates a Beta with parameters 1.0, 1.0Beta(double[] parameters)
Creates a beta with the supplied parametersBeta(double alpha1, double alpha2)
Creates a beta with the supplied parametersBeta(double alpha1, double alpha2, java.lang.String name)
Creates a beta with the supplied parameters
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static 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-114protected static double
betaContinuedFraction(double x, double a, double b)
Computes the continued fraction for the incomplete beta function.static double
betaFunction(double z1, double z2)
Computes Beta(z1,z2)double
cdf(double x)
Computes the CDF, has accuracy to about 10e-9double
getAlpha1()
double
getAlpha2()
Interval
getDomain()
double
getMean()
Returns the mean or expected value of a distributiondouble[]
getParameters()
Gets the parametersRVariableIfc
getRandomVariable(RNStreamIfc rng)
double
getVariance()
Returns the variance of the distribution if definedstatic double
incompleteBetaFunction(double x, double a, double b)
Computes the incomplete beta function at the supplied x Beta(x, a, b)/Beta(a, b)double
invCDF(double p)
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.protected double
inverseBetaCDF(double p)
Computes the inverse of the beta CDF at the supplied probability point using an initial approximation and a root finding techniquestatic double
logBetaFunction(double z1, double z2)
The natural logarithm of Beta(z1,z2)static void
main(java.lang.String[] args)
Beta
newInstance()
Returns a new instancedouble
pdf(double x)
Returns the f(x) where f represents the probability density function for the distribution.static double
regularizedIncompleteBetaFunction(double x, double a, double b)
Computes the regularized incomplete beta function at the supplied xprotected static double
regularizedIncompleteBetaFunction(double x, double a, double b, double lnbeta)
Computes the regularized incomplete beta function at the supplied xstatic void
setContinuedFractionDesiredPrecision(double prec)
Sets the desired precision in the continued fraction expansion for the computation of the incompleteBetaFunctionstatic void
setContinuedFractionMaximumIterations(int maxIter)
Sets the maximum number of iterations in the continued fraction expansion for the computation of the incompleteBetaFunctionvoid
setParameters(double[] parameters)
Sets the parameters parameter[0] is alpha 1 parameter[1] is alpha 2void
setParameters(double alpha1, double alpha2)
Changes the parameters to the supplied valuesstatic void
setRootFindingDesiredPrecision(double prec)
Sets the desired precision of the root finding algorithm in the CDF inversion computationstatic void
setRootFindingMaximumIterations(int maxIter)
Sets the maximum number of iterations of the root finding algorithm in the CDF inversion computationjava.lang.String
toString()
-
Methods inherited from class jsl.utilities.distributions.Distribution
getControls, getId, getName, getStandardDeviation, inverseContinuousCDFViaBisection, inverseContinuousCDFViaBisection, inverseDiscreteCDFViaSearchUp, setControls, setId, setName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.utilities.distributions.CDFIfc
cdf, complementaryCDF
-
Methods inherited from interface jsl.utilities.random.rvariable.GetRVariableIfc
getRandomVariable, getRandomVariable
-
-
-
-
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 parameteralpha2
- 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 parameteralpha2
- the alpha2 parametername
- a label
-
-
Method Detail
-
newInstance
public final Beta newInstance()
Description copied from interface:NewInstanceIfc
Returns a new instance- Specified by:
newInstance
in interfaceNewInstanceIfc
- Specified by:
newInstance
in classDistribution
- Returns:
- the new instance
-
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 parameteralpha2
- 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 interfaceParametersIfc
- 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
-
getParameters
public final double[] getParameters()
Description copied from interface:ParametersIfc
Gets the parameters- Specified by:
getParameters
in interfaceParametersIfc
- 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 interfaceVarianceIfc
- Returns:
- double the variance of the random variable
-
cdf
public double cdf(double x)
Computes the CDF, has accuracy to about 10e-9
-
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 interfaceInverseCDFIfc
- 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.
-
betaFunction
public static double betaFunction(double z1, double z2)
Computes Beta(z1,z2)- Parameters:
z1
- the first parameterz2
- 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 parameterz2
- 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 evaluateda
- alpha 1b
- 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 evaluateda
- alpha 1b
- 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 evaluateda
- alpha 1b
- alpha 2lnbeta
- 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 evaluateda
- alpha 1b
- 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
-
toString
public java.lang.String toString()
- Overrides:
toString
in classDistribution
-
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 parameterqq
- Alpha 2 parametera
- The point to be evaluatedlnbeta
- 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
-
getRandomVariable
public final RVariableIfc getRandomVariable(RNStreamIfc rng)
- Specified by:
getRandomVariable
in interfaceGetRVariableIfc
- Overrides:
getRandomVariable
in classDistribution
- Parameters:
rng
- the stream to use- Returns:
- a random variable
-
main
public static void main(java.lang.String[] args)
-
-