public class BernoulliDistribution extends DiscreteDistribution
Although Bernoulli distribution belongs to exponential family, we don't implement DiscreteExponentialFamily interface here since it is impossible and meaningless to estimate a mixture of Bernoulli distributions.
| Modifier and Type | Field and Description |
|---|---|
double |
p
Probability of success.
|
double |
q
Probability of failure.
|
| Constructor and Description |
|---|
BernoulliDistribution(boolean[] data)
Construct an Bernoulli from the given samples.
|
BernoulliDistribution(double p)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
double |
cdf(double k)
Cumulative distribution function.
|
double |
entropy()
Shannon entropy of the distribution.
|
static BernoulliDistribution |
fit(int[] data)
Estimates the distribution parameters by MLE.
|
int |
length()
The number of parameters of the distribution.
|
double |
logp(int k)
The probability mass function in log scale.
|
double |
mean()
The mean of distribution.
|
double |
p(int k)
The probability mass function.
|
double |
quantile(double p)
The quantile, the probability to the left of quantile is p.
|
double |
rand()
Generates a random number following this distribution.
|
java.lang.String |
toString() |
double |
variance()
The variance of distribution.
|
likelihood, logLikelihood, logp, p, quantile, randi, randiinverseTransformSampling, quantile, quantile, rejectionclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitlikelihood, logLikelihood, rand, sdpublic final double p
public final double q
public BernoulliDistribution(double p)
p - the probability of success.public BernoulliDistribution(boolean[] data)
data - the boolean array to indicate if the i-th trail success.public static BernoulliDistribution fit(int[] data)
data - data[i] == 1 if the i-th trail is success. Otherwise 0.public int length()
Distributionpublic double mean()
Distributionpublic double variance()
Distributionpublic double entropy()
Distributionpublic java.lang.String toString()
toString in class java.lang.Objectpublic double rand()
Distributionpublic double p(int k)
DiscreteDistributionp in class DiscreteDistributionpublic double logp(int k)
DiscreteDistributionlogp in class DiscreteDistributionpublic double cdf(double k)
Distributionpublic double quantile(double p)
Distribution