gov.sandia.cognition.statistics.distribution
Class BernoulliDistribution

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.BernoulliDistribution
All Implemented Interfaces:
Vectorizable, ClosedFormComputableDistribution<Number>, ClosedFormDiscreteUnivariateDistribution<Number>, ClosedFormDistribution<Number>, ClosedFormUnivariateDistribution<Number>, ComputableDistribution<Number>, DiscreteDistribution<Number>, Distribution<Number>, DistributionWithMean<Number>, UnivariateDistribution<Number>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
BernoulliDistribution.CDF, BernoulliDistribution.PMF

@PublicationReference(author="Wikipedia",
                      title="Bernoulli distribution",
                      type=WebPage,
                      year=2009,
                      url="http://en.wikipedia.org/wiki/Bernoulli_distribution")
public class BernoulliDistribution
extends AbstractClosedFormUnivariateDistribution<Number>
implements ClosedFormDiscreteUnivariateDistribution<Number>

A Bernoulli distribution, which takes a value of "1" with probability "p" and value of "0" with probability "1-p". This is also known as flipping a weighted coin. A sum of Bernoulli random variables is a Binomial distribution.

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

Nested Class Summary
static class BernoulliDistribution.CDF
          CDF of a Bernoulli distribution.
static class BernoulliDistribution.PMF
          PMF of the Bernoulli distribution.
 
Field Summary
static double DEFAULT_P
          Default Bernoulli parameter, 0.5
 
Constructor Summary
BernoulliDistribution()
          Creates a new instance of BernoulliDistribution
BernoulliDistribution(BernoulliDistribution other)
          Copy Constructor
BernoulliDistribution(double p)
          Creates a new instance of BernoulliDistribution
 
Method Summary
 void convertFromVector(Vector parameters)
          Converts the object from a Vector of parameters.
 Vector convertToVector()
          Converts the object to a vector.
 BernoulliDistribution.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.
 Integer getMaxSupport()
          Gets the minimum support (domain or input) of the distribution.
 Double 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.
 double getP()
          Getter for p
 BernoulliDistribution.PMF getProbabilityFunction()
          Gets the distribution function associated with this Distribution, either the PDF or PMF.
 double getVariance()
          Gets the variance of the distribution.
 ArrayList<Integer> sample(Random random, int numSamples)
          Draws multiple random samples from the distribution.
 void setP(double p)
          Setter for p
 String toString()
           
 
Methods inherited from class gov.sandia.cognition.statistics.AbstractClosedFormUnivariateDistribution
clone
 
Methods inherited from class gov.sandia.cognition.statistics.AbstractDistribution
sample
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.statistics.Distribution
sample
 
Methods inherited from interface gov.sandia.cognition.math.matrix.Vectorizable
clone
 

Field Detail

DEFAULT_P

public static final double DEFAULT_P
Default Bernoulli parameter, 0.5

See Also:
Constant Field Values
Constructor Detail

BernoulliDistribution

public BernoulliDistribution()
Creates a new instance of BernoulliDistribution


BernoulliDistribution

public BernoulliDistribution(double p)
Creates a new instance of BernoulliDistribution

Parameters:
p - Bernoulli parameter, where the distribution takes value "1" with probability "p" and value "0" with probability 1-p.

BernoulliDistribution

public BernoulliDistribution(BernoulliDistribution other)
Copy Constructor

Parameters:
other - BernoulliDistribution to copy
Method Detail

getMean

public Double 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.

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.

sample

public ArrayList<Integer> 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.

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.

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.

getP

public double getP()
Getter for p

Returns:
Bernoulli parameter, where the distribution takes value "1" with probability "p" and value "0" with probability 1-p.

setP

public void setP(double p)
Setter for p

Parameters:
p - Bernoulli parameter, where the distribution takes value "1" with probability "p" and value "0" with probability 1-p.

getCDF

public BernoulliDistribution.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.

getProbabilityFunction

public BernoulliDistribution.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.

toString

public String toString()
Overrides:
toString in class Object