Class BernoulliDistribution
java.lang.Object
smile.stat.distribution.DiscreteDistribution
smile.stat.distribution.BernoulliDistribution
- All Implemented Interfaces:
Serializable, Distribution
Bernoulli's distribution is a discrete probability distribution, which takes
value 1 with success probability p and value 0 with failure probability
q = 1 - p.
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.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBernoulliDistribution(boolean[] data) Construct a Bernoulli from the given samples.BernoulliDistribution(double p) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiondoublecdf(double k) Cumulative distribution function.doubleentropy()Returns Shannon entropy of the distribution.static BernoulliDistributionfit(int[] data) Estimates the distribution parameters by MLE.intlength()Returns the number of parameters of the distribution.doublelogp(int k) The probability mass function in log scale.doublemean()Returns the mean of distribution.doublep(int k) The probability mass function.doublequantile(double p) The quantile, the probability to the left of quantile is p.doublerand()Generates a random number following this distribution.toString()doublevariance()Returns the variance of distribution.Methods inherited from class DiscreteDistribution
likelihood, logLikelihood, logp, p, quantile, randi, randiMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Distribution
inverseTransformSampling, likelihood, logLikelihood, quantile, quantile, rand, rejectionSampling, sd
-
Field Details
-
p
public final double pProbability of success. -
q
public final double qProbability of failure.
-
-
Constructor Details
-
BernoulliDistribution
public BernoulliDistribution(double p) Constructor.- Parameters:
p- the probability of success.
-
BernoulliDistribution
public BernoulliDistribution(boolean[] data) Construct a Bernoulli from the given samples. Parameter will be estimated from the data by MLE.- Parameters:
data- the boolean array to indicate if the i-th trail success.
-
-
Method Details
-
fit
Estimates the distribution parameters by MLE.- Parameters:
data- data[i] == 1 if the i-th trail is success. Otherwise, 0.- Returns:
- the distribution.
-
length
public int length()Description copied from interface:DistributionReturns the number of parameters of the distribution. The "length" is in the sense of the minimum description length principle.- Returns:
- The number of parameters.
-
mean
public double mean()Description copied from interface:DistributionReturns the mean of distribution.- Returns:
- The mean.
-
variance
public double variance()Description copied from interface:DistributionReturns the variance of distribution.- Returns:
- The variance.
-
entropy
public double entropy()Description copied from interface:DistributionReturns Shannon entropy of the distribution.- Returns:
- Shannon entropy.
-
toString
-
rand
public double rand()Description copied from interface:DistributionGenerates a random number following this distribution.- Returns:
- a random number.
-
p
public double p(int k) Description copied from class:DiscreteDistributionThe probability mass function.- Specified by:
pin classDiscreteDistribution- Parameters:
k- a real value.- Returns:
- the probability.
-
logp
public double logp(int k) Description copied from class:DiscreteDistributionThe probability mass function in log scale.- Specified by:
logpin classDiscreteDistribution- Parameters:
k- a real value.- Returns:
- the log probability.
-
cdf
public double cdf(double k) Description copied from interface:DistributionCumulative distribution function. That is the probability to the left of x.- Parameters:
k- a real number.- Returns:
- the probability.
-
quantile
public double quantile(double p) Description copied from interface:DistributionThe quantile, the probability to the left of quantile is p. It is actually the inverse of cdf.- Parameters:
p- the probability.- Returns:
- the quantile.
-