org.apache.commons.math.distribution
Class BetaDistributionImpl

java.lang.Object
  extended by org.apache.commons.math.distribution.AbstractDistribution
      extended by org.apache.commons.math.distribution.AbstractContinuousDistribution
          extended by org.apache.commons.math.distribution.BetaDistributionImpl
All Implemented Interfaces:
Serializable, BetaDistribution, ContinuousDistribution, Distribution, HasDensity<Double>

public class BetaDistributionImpl
extends AbstractContinuousDistribution
implements BetaDistribution

Implements the Beta distribution.

References:

Since:
2.0
Version:
$Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
See Also:
Serialized Form

Field Summary
private  double alpha
          First shape parameter.
private  double beta
          Second shape parameter.
private static long serialVersionUID
          Serializable version identifier.
private  double z
          Normalizing factor used in density computations.
 
Constructor Summary
BetaDistributionImpl(double alpha, double beta)
          Build a new instance.
 
Method Summary
 double cumulativeProbability(double x)
          For a random variable X whose values are distributed according to this distribution, this method returns P(X ≤ x).
 double cumulativeProbability(double x0, double x1)
          For a random variable X whose values are distributed according to this distribution, this method returns P(x0 ≤ X ≤ x1).
 double density(Double x)
          Return the probability density for a particular point.
 double getAlpha()
          Access the shape parameter, alpha
 double getBeta()
          Access the shape parameter, beta
protected  double getDomainLowerBound(double p)
          Access the domain value lower bound, based on p, used to bracket a CDF root.
protected  double getDomainUpperBound(double p)
          Access the domain value upper bound, based on p, used to bracket a CDF root.
protected  double getInitialDomain(double p)
          Access the initial domain value, based on p, used to bracket a CDF root.
 double inverseCumulativeProbability(double p)
          For this distribution, X, this method returns the critical point x, such that P(X < x) = p.
private  void recomputeZ()
          Recompute the normalization factor.
 void setAlpha(double alpha)
          Modify the shape parameter, alpha.
 void setBeta(double beta)
          Modify the shape parameter, beta.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serializable version identifier.

See Also:
Constant Field Values

alpha

private double alpha
First shape parameter.


beta

private double beta
Second shape parameter.


z

private double z
Normalizing factor used in density computations. updated whenever alpha or beta are changed.

Constructor Detail

BetaDistributionImpl

public BetaDistributionImpl(double alpha,
                            double beta)
Build a new instance.

Parameters:
alpha - first shape parameter (must be positive)
beta - second shape parameter (must be positive)
Method Detail

setAlpha

public void setAlpha(double alpha)
Modify the shape parameter, alpha.

Specified by:
setAlpha in interface BetaDistribution
Parameters:
alpha - the new shape parameter.

getAlpha

public double getAlpha()
Access the shape parameter, alpha

Specified by:
getAlpha in interface BetaDistribution
Returns:
alpha.

setBeta

public void setBeta(double beta)
Modify the shape parameter, beta.

Specified by:
setBeta in interface BetaDistribution
Parameters:
beta - the new scale parameter.

getBeta

public double getBeta()
Access the shape parameter, beta

Specified by:
getBeta in interface BetaDistribution
Returns:
beta.

recomputeZ

private void recomputeZ()
Recompute the normalization factor.


density

public double density(Double x)
               throws MathException
Return the probability density for a particular point.

Specified by:
density in interface BetaDistribution
Specified by:
density in interface HasDensity<Double>
Parameters:
x - The point at which the density should be computed.
Returns:
The pdf at point x.
Throws:
MathException - if probability density cannot be computed

inverseCumulativeProbability

public double inverseCumulativeProbability(double p)
                                    throws MathException
For this distribution, X, this method returns the critical point x, such that P(X < x) = p.

Specified by:
inverseCumulativeProbability in interface ContinuousDistribution
Overrides:
inverseCumulativeProbability in class AbstractContinuousDistribution
Parameters:
p - the desired probability
Returns:
x, such that P(X < x) = p
Throws:
MathException - if the inverse cumulative probability can not be computed due to convergence or other numerical errors.

getInitialDomain

protected double getInitialDomain(double p)
Access the initial domain value, based on p, used to bracket a CDF root. This method is used by AbstractContinuousDistribution.inverseCumulativeProbability(double) to find critical values.

Specified by:
getInitialDomain in class AbstractContinuousDistribution
Parameters:
p - the desired probability for the critical value
Returns:
initial domain value

getDomainLowerBound

protected double getDomainLowerBound(double p)
Access the domain value lower bound, based on p, used to bracket a CDF root. This method is used by AbstractContinuousDistribution.inverseCumulativeProbability(double) to find critical values.

Specified by:
getDomainLowerBound in class AbstractContinuousDistribution
Parameters:
p - the desired probability for the critical value
Returns:
domain value lower bound, i.e. P(X < lower bound) < p

getDomainUpperBound

protected double getDomainUpperBound(double p)
Access the domain value upper bound, based on p, used to bracket a CDF root. This method is used by AbstractContinuousDistribution.inverseCumulativeProbability(double) to find critical values.

Specified by:
getDomainUpperBound in class AbstractContinuousDistribution
Parameters:
p - the desired probability for the critical value
Returns:
domain value upper bound, i.e. P(X < upper bound) > p

cumulativeProbability

public double cumulativeProbability(double x)
                             throws MathException
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 (cumulative) distribution function, or CDF, for this distribution.

Specified by:
cumulativeProbability in interface Distribution
Parameters:
x - the value at which the distribution function is evaluated.
Returns:
the probability that a random variable with this distribution takes a value less than or equal to x
Throws:
MathException - if the cumulative probability can not be computed due to convergence or other numerical errors.

cumulativeProbability

public double cumulativeProbability(double x0,
                                    double x1)
                             throws MathException
For a random variable X whose values are distributed according to this distribution, this method returns P(x0 ≤ X ≤ x1).

The default implementation uses the identity

P(x0 ≤ X ≤ x1) = P(X ≤ x1) - P(X ≤ x0)

Specified by:
cumulativeProbability in interface Distribution
Overrides:
cumulativeProbability in class AbstractDistribution
Parameters:
x0 - the (inclusive) lower bound
x1 - the (inclusive) upper bound
Returns:
the probability that a random variable with this distribution will take a value between x0 and x1, including the endpoints.
Throws:
MathException - if the cumulative probability can not be computed due to convergence or other numerical errors.


Copyright (c) 2003-2010 Apache Software Foundation