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 doubleapproximateCDF(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 doublebetaContinuedFraction(double x, double a, double b)Computes the continued fraction for the incomplete beta function.static doublebetaFunction(double z1, double z2)Computes Beta(z1,z2)doublecdf(double x)Computes the CDF, has accuracy to about 10e-9doublegetAlpha1()doublegetAlpha2()IntervalgetDomain()doublegetMean()Returns the mean or expected value of a distributiondouble[]getParameters()Gets the parametersRVariableIfcgetRandomVariable(RNStreamIfc rng)doublegetVariance()Returns the variance of the distribution if definedstatic doubleincompleteBetaFunction(double x, double a, double b)Computes the incomplete beta function at the supplied x Beta(x, a, b)/Beta(a, b)doubleinvCDF(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 doubleinverseBetaCDF(double p)Computes the inverse of the beta CDF at the supplied probability point using an initial approximation and a root finding techniquestatic doublelogBetaFunction(double z1, double z2)The natural logarithm of Beta(z1,z2)static voidmain(java.lang.String[] args)BetanewInstance()Returns a new instancedoublepdf(double x)Returns the f(x) where f represents the probability density function for the distribution.static doubleregularizedIncompleteBetaFunction(double x, double a, double b)Computes the regularized incomplete beta function at the supplied xprotected static doubleregularizedIncompleteBetaFunction(double x, double a, double b, double lnbeta)Computes the regularized incomplete beta function at the supplied xstatic voidsetContinuedFractionDesiredPrecision(double prec)Sets the desired precision in the continued fraction expansion for the computation of the incompleteBetaFunctionstatic voidsetContinuedFractionMaximumIterations(int maxIter)Sets the maximum number of iterations in the continued fraction expansion for the computation of the incompleteBetaFunctionvoidsetParameters(double[] parameters)Sets the parameters parameter[0] is alpha 1 parameter[1] is alpha 2voidsetParameters(double alpha1, double alpha2)Changes the parameters to the supplied valuesstatic voidsetRootFindingDesiredPrecision(double prec)Sets the desired precision of the root finding algorithm in the CDF inversion computationstatic voidsetRootFindingMaximumIterations(int maxIter)Sets the maximum number of iterations of the root finding algorithm in the CDF inversion computationjava.lang.StringtoString()-
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:NewInstanceIfcReturns a new instance- Specified by:
newInstancein interfaceNewInstanceIfc- Specified by:
newInstancein 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:
setParametersin interfaceParametersIfc- Parameters:
parameters- an array holding the parameters
-
getMean
public final double getMean()
Description copied from interface:MeanIfcReturns the mean or expected value of a distribution
-
getParameters
public final double[] getParameters()
Description copied from interface:ParametersIfcGets the parameters- Specified by:
getParametersin interfaceParametersIfc- Returns:
- Returns an array of the parameters
-
getVariance
public final double getVariance()
Description copied from interface:VarianceIfcReturns the variance of the distribution if defined- Specified by:
getVariancein 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:InverseCDFIfcProvides 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:
invCDFin 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:PDFIfcReturns 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:
toStringin 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:
getRandomVariablein interfaceGetRVariableIfc- Overrides:
getRandomVariablein classDistribution- Parameters:
rng- the stream to use- Returns:
- a random variable
-
main
public static void main(java.lang.String[] args)
-
-