gov.sandia.cognition.statistics.distribution
Class BetaBinomialDistribution

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.statistics.AbstractDistribution<NumberType>
          extended by gov.sandia.cognition.statistics.AbstractClosedFormUnivariateDistribution<Number>
              extended by gov.sandia.cognition.statistics.distribution.BetaBinomialDistribution
All Implemented Interfaces:
Vectorizable, ClosedFormComputableDistribution<Number>, ClosedFormDiscreteUnivariateDistribution<Number>, ClosedFormDistribution<Number>, ClosedFormUnivariateDistribution<Number>, ComputableDistribution<Number>, DiscreteDistribution<Number>, Distribution<Number>, DistributionWithMean<Number>, EstimableDistribution<Number,BetaBinomialDistribution>, UnivariateDistribution<Number>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
BetaBinomialDistribution.CDF, BetaBinomialDistribution.PMF

@PublicationReference(author="Eric Weisstein",
                      title="Beta Binomial Distribution",
                      type=WebPage,
                      year=2010,
                      url="http://mathworld.wolfram.com/BetaBinomialDistribution.html")
public class BetaBinomialDistribution
extends AbstractClosedFormUnivariateDistribution<Number>
implements ClosedFormDiscreteUnivariateDistribution<Number>, EstimableDistribution<Number,BetaBinomialDistribution>

A Binomial distribution where the binomial parameter, p, is set according to a Beta distribution instead of a single value.

Since:
3.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
static class BetaBinomialDistribution.CDF
          CDF of BetaBinomialDistribution
static class BetaBinomialDistribution.MomentMatchingEstimator
          Estimates the parameters of a Beta distribution using the matching of moments, not maximum likelihood.
static class BetaBinomialDistribution.PMF
          PMF of the BetaBinomialDistribution
 
Field Summary
static int DEFAULT_N
          Default n, 1.
static double DEFAULT_SCALE
          Default scale, 1.0.
static double DEFAULT_SHAPE
          Default shape, 1.0.
protected  int n
          Number of observations, similar to the Binomial N, must be greater than zero
protected  double scale
          Scale, similar to the beta parameter scale, must be greater than zero
protected  double shape
          Shape, similar to the beta parameter shape, must be greater than zero
 
Constructor Summary
BetaBinomialDistribution()
          Creates a new instance of BetaBinomialDistribution
BetaBinomialDistribution(BetaBinomialDistribution other)
          Copy constructor
BetaBinomialDistribution(int n, double shape, double scale)
          Creates a new instance of BetaBinomialDistribution
 
Method Summary
 BetaBinomialDistribution clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 void convertFromVector(Vector parameters)
          Converts the object from a Vector of parameters.
 Vector convertToVector()
          Converts the object to a vector.
 BetaBinomialDistribution.CDF getCDF()
          Gets the CDF of a scalar distribution.
 IntegerSpan getDomain()
          Returns an object that allows an iteration through the domain (x-axis, independent variable) of the Distribution
 int getDomainSize()
          Gets the size of the domain.
 BetaBinomialDistribution.MomentMatchingEstimator getEstimator()
          Gets an estimator associated with this distribution.
 Integer getMaxSupport()
          Gets the minimum support (domain or input) of the distribution.
 Number getMean()
          Gets the arithmetic mean, or "first central moment" or "expectation", of the distribution.
 Integer getMinSupport()
          Gets the minimum support (domain or input) of the distribution.
 int getN()
          Getter for n
 BetaBinomialDistribution.PMF getProbabilityFunction()
          Gets the distribution function associated with this Distribution, either the PDF or PMF.
 double getScale()
          Getter for scale
 double getShape()
          Getter for shape
 double getVariance()
          Gets the variance of the distribution.
 ArrayList<? extends Number> sample(Random random, int numSamples)
          Draws multiple random samples from the distribution.
 void setN(int n)
          Setter for n
 void setScale(double scale)
          Setter for scale
 void setShape(double shape)
          Setter for shape
 
Methods inherited from class gov.sandia.cognition.statistics.AbstractDistribution
sample
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.statistics.Distribution
sample
 

Field Detail

DEFAULT_SHAPE

public static final double DEFAULT_SHAPE
Default shape, 1.0.

See Also:
Constant Field Values

DEFAULT_SCALE

public static final double DEFAULT_SCALE
Default scale, 1.0.

See Also:
Constant Field Values

DEFAULT_N

public static final int DEFAULT_N
Default n, 1.

See Also:
Constant Field Values

n

protected int n
Number of observations, similar to the Binomial N, must be greater than zero


shape

protected double shape
Shape, similar to the beta parameter shape, must be greater than zero


scale

protected double scale
Scale, similar to the beta parameter scale, must be greater than zero

Constructor Detail

BetaBinomialDistribution

public BetaBinomialDistribution()
Creates a new instance of BetaBinomialDistribution


BetaBinomialDistribution

public BetaBinomialDistribution(int n,
                                double shape,
                                double scale)
Creates a new instance of BetaBinomialDistribution

Parameters:
shape - Shape, similar to the beta parameter shape, must be greater than zero
scale - Scale, similar to the beta parameter scale, must be greater than zero
n - Number of observations, similar to the Binomial N, must be greater than zero

BetaBinomialDistribution

public BetaBinomialDistribution(BetaBinomialDistribution other)
Copy constructor

Parameters:
other - BetaBinomialDistribution to copy
Method Detail

clone

public BetaBinomialDistribution clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface Vectorizable
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractClosedFormUnivariateDistribution<Number>
Returns:
A clone of this object.

getShape

public double getShape()
Getter for shape

Returns:
Shape, similar to the beta parameter shape, must be greater than zero

setShape

public void setShape(double shape)
Setter for shape

Parameters:
shape - Shape, similar to the beta parameter shape, must be greater than zero

getScale

public double getScale()
Getter for scale

Returns:
Scale, similar to the beta parameter scale, must be greater than zero

setScale

public void setScale(double scale)
Setter for scale

Parameters:
scale - Scale, similar to the beta parameter scale, must be greater than zero

getN

public int getN()
Getter for n

Returns:
Number of observations, similar to the Binomial N, must be greater than zero

setN

public void setN(int n)
Setter for n

Parameters:
n - Number of observations, similar to the Binomial N, must be greater than zero

getMean

public Number getMean()
Description copied from interface: DistributionWithMean
Gets the arithmetic mean, or "first central moment" or "expectation", of the distribution.

Specified by:
getMean in interface DistributionWithMean<Number>
Returns:
Mean of the distribution.

sample

public ArrayList<? extends Number> sample(Random random,
                                          int numSamples)
Description copied from interface: Distribution
Draws multiple random samples from the distribution. It is generally more efficient to use this multiple-sample method than multiple calls of the single-sample method. (But not always.)

Specified by:
sample in interface Distribution<Number>
Parameters:
random - Random-number generator to use in order to generate random numbers.
numSamples - Number of samples to draw from the distribution.
Returns:
Samples drawn according to this distribution.

getCDF

public BetaBinomialDistribution.CDF getCDF()
Description copied from interface: UnivariateDistribution
Gets the CDF of a scalar distribution.

Specified by:
getCDF in interface ClosedFormUnivariateDistribution<Number>
Specified by:
getCDF in interface UnivariateDistribution<Number>
Returns:
CDF of the scalar distribution.

convertToVector

public Vector convertToVector()
Description copied from interface: Vectorizable
Converts the object to a vector.

Specified by:
convertToVector in interface Vectorizable
Returns:
The Vector form of the object.

convertFromVector

public void convertFromVector(Vector parameters)
Description copied from interface: Vectorizable
Converts the object from a Vector of parameters.

Specified by:
convertFromVector in interface Vectorizable
Parameters:
parameters - The parameters to incorporate.

getMinSupport

public Integer getMinSupport()
Description copied from interface: UnivariateDistribution
Gets the minimum support (domain or input) of the distribution.

Specified by:
getMinSupport in interface UnivariateDistribution<Number>
Returns:
Minimum support.

getMaxSupport

public Integer getMaxSupport()
Description copied from interface: UnivariateDistribution
Gets the minimum support (domain or input) of the distribution.

Specified by:
getMaxSupport in interface UnivariateDistribution<Number>
Returns:
Minimum support.

getVariance

public double getVariance()
Description copied from interface: UnivariateDistribution
Gets the variance of the distribution. This is sometimes called the second central moment by more pedantic people, which is equivalent to the square of the standard deviation.

Specified by:
getVariance in interface UnivariateDistribution<Number>
Returns:
Variance of the distribution.

getDomain

public IntegerSpan getDomain()
Description copied from interface: DiscreteDistribution
Returns an object that allows an iteration through the domain (x-axis, independent variable) of the Distribution

Specified by:
getDomain in interface DiscreteDistribution<Number>
Returns:
Collection that enumerates each value that the domain can take

getDomainSize

public int getDomainSize()
Description copied from interface: DiscreteDistribution
Gets the size of the domain.

Specified by:
getDomainSize in interface DiscreteDistribution<Number>
Returns:
The size of the domain.

getProbabilityFunction

public BetaBinomialDistribution.PMF getProbabilityFunction()
Description copied from interface: ComputableDistribution
Gets the distribution function associated with this Distribution, either the PDF or PMF.

Specified by:
getProbabilityFunction in interface ComputableDistribution<Number>
Specified by:
getProbabilityFunction in interface DiscreteDistribution<Number>
Returns:
Distribution function associated with this Distribution.

getEstimator

public BetaBinomialDistribution.MomentMatchingEstimator getEstimator()
Description copied from interface: EstimableDistribution
Gets an estimator associated with this distribution.

Specified by:
getEstimator in interface EstimableDistribution<Number,BetaBinomialDistribution>
Returns:
A distribution estimator associated for this distribution.