@PublicationReference(author="Wikipedia", title="Bernoulli distribution", type=WebPage, year=2009, url="http://en.wikipedia.org/wiki/Bernoulli_distribution") public class BernoulliDistribution extends AbstractClosedFormIntegerDistribution implements ClosedFormDiscreteUnivariateDistribution<java.lang.Number>
Modifier and Type | Class and Description |
---|---|
static class |
BernoulliDistribution.CDF
CDF of a Bernoulli distribution.
|
static class |
BernoulliDistribution.PMF
PMF of the Bernoulli distribution.
|
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_P
Default Bernoulli parameter, 0.5
|
Constructor and Description |
---|
BernoulliDistribution()
Creates a new instance of BernoulliDistribution
|
BernoulliDistribution(BernoulliDistribution other)
Copy Constructor
|
BernoulliDistribution(double p)
Creates a new instance of BernoulliDistribution
|
Modifier and Type | Method and Description |
---|---|
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.
|
java.lang.Integer |
getMaxSupport()
Gets the minimum support (domain or input) of the distribution.
|
java.lang.Double |
getMean()
Gets the arithmetic mean, or "first central moment" or "expectation",
of the distribution.
|
double |
getMeanAsDouble()
Gets the mean of the distribution as a double.
|
java.lang.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.
|
boolean |
sampleAsBoolean(java.util.Random random)
Samples from the Bernoulli distribution as a boolean.
|
int |
sampleAsInt(java.util.Random random)
Draws a single random sample from the distribution as an int.
|
void |
sampleInto(java.util.Random random,
int sampleCount,
java.util.Collection<? super java.lang.Number> output)
Draws multiple random samples from the distribution and puts the result
into the given collection.
|
void |
setP(double p)
Setter for p
|
java.lang.String |
toString() |
sampleAsInts, sampleInto
clone
sample, sample
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
sample, sample
clone
public static final double DEFAULT_P
public BernoulliDistribution()
public BernoulliDistribution(double p)
p
- Bernoulli parameter, where the distribution takes value "1" with
probability "p" and value "0" with probability 1-p.public BernoulliDistribution(BernoulliDistribution other)
other
- BernoulliDistribution to copypublic java.lang.Double getMean()
DistributionWithMean
getMean
in interface DistributionWithMean<java.lang.Number>
public double getMeanAsDouble()
UnivariateDistribution
getMeanAsDouble
in interface UnivariateDistribution<java.lang.Number>
public java.lang.Integer getMinSupport()
UnivariateDistribution
getMinSupport
in interface UnivariateDistribution<java.lang.Number>
public java.lang.Integer getMaxSupport()
UnivariateDistribution
getMaxSupport
in interface UnivariateDistribution<java.lang.Number>
public void sampleInto(java.util.Random random, int sampleCount, java.util.Collection<? super java.lang.Number> output)
Distribution
sampleInto
in interface Distribution<java.lang.Number>
random
- Random number generator to use.sampleCount
- The number of samples to draw. Cannot be negative.output
- The collection to add the samples into.public int sampleAsInt(java.util.Random random)
IntegerDistribution
sampleAsInt
in interface IntegerDistribution
random
- The random number generator to use.public boolean sampleAsBoolean(java.util.Random random)
random
- The random number generator to use.public Vector convertToVector()
Vectorizable
convertToVector
in interface Vectorizable
public void convertFromVector(Vector parameters)
Vectorizable
convertFromVector
in interface Vectorizable
parameters
- The parameters to incorporate.public double getVariance()
UnivariateDistribution
getVariance
in interface UnivariateDistribution<java.lang.Number>
public IntegerSpan getDomain()
DiscreteDistribution
getDomain
in interface DiscreteDistribution<java.lang.Number>
public int getDomainSize()
DiscreteDistribution
getDomainSize
in interface DiscreteDistribution<java.lang.Number>
public double getP()
public void setP(double p)
p
- Bernoulli parameter, where the distribution takes value "1" with
probability "p" and value "0" with probability 1-p.public BernoulliDistribution.CDF getCDF()
UnivariateDistribution
getCDF
in interface ClosedFormUnivariateDistribution<java.lang.Number>
getCDF
in interface UnivariateDistribution<java.lang.Number>
public BernoulliDistribution.PMF getProbabilityFunction()
ComputableDistribution
getProbabilityFunction
in interface ComputableDistribution<java.lang.Number>
getProbabilityFunction
in interface DiscreteDistribution<java.lang.Number>
public java.lang.String toString()
toString
in class java.lang.Object