Class DiscreteDistribution
java.lang.Object
smile.stat.distribution.DiscreteDistribution
- All Implemented Interfaces:
Serializable, Distribution
- Direct Known Subclasses:
BernoulliDistribution, BinomialDistribution, DiscreteMixture, EmpiricalDistribution, GeometricDistribution, HyperGeometricDistribution, NegativeBinomialDistribution, PoissonDistribution, ShiftedGeometricDistribution
Univariate discrete distributions. Basically, this class adds common
distribution methods that accept integer argument beside float argument.
A quantile function is provided based on bisection searching.
Likelihood and log likelihood functions are also implemented here.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublelikelihood(int[] x) The likelihood given a sample set following the distribution.doublelogLikelihood(int[] x) The likelihood given a sample set following the distribution.doublelogp(double x) The density at x in log scale, which may prevents the underflow problem.abstract doublelogp(int x) The probability mass function in log scale.doublep(double x) The probability density function for continuous distribution or probability mass function for discrete distribution at x.abstract doublep(int x) The probability mass function.protected doublequantile(double p, int xmin, int xmax) Inversion of cdf by bisection numeric root finding ofcdf(x) = pfor discrete distribution.intrandi()Generates an integer random number following this discrete distribution.int[]randi(int n) Generates a set of integer random numbers following this discrete distribution.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Distribution
cdf, entropy, inverseTransformSampling, length, likelihood, logLikelihood, mean, quantile, quantile, quantile, rand, rand, rejectionSampling, sd, variance
-
Constructor Details
-
DiscreteDistribution
public DiscreteDistribution()Constructor.
-
-
Method Details
-
randi
public int randi()Generates an integer random number following this discrete distribution.- Returns:
- an integer random number.
-
randi
public int[] randi(int n) Generates a set of integer random numbers following this discrete distribution.- Parameters:
n- the number of random numbers to generate.- Returns:
- an array of integer random numbers.
-
p
public abstract double p(int x) The probability mass function.- Parameters:
x- a real value.- Returns:
- the probability.
-
p
public double p(double x) Description copied from interface:DistributionThe probability density function for continuous distribution or probability mass function for discrete distribution at x.- Specified by:
pin interfaceDistribution- Parameters:
x- a real number.- Returns:
- the density.
-
logp
public abstract double logp(int x) The probability mass function in log scale.- Parameters:
x- a real value.- Returns:
- the log probability.
-
logp
public double logp(double x) Description copied from interface:DistributionThe density at x in log scale, which may prevents the underflow problem.- Specified by:
logpin interfaceDistribution- Parameters:
x- a real number.- Returns:
- the log density.
-
likelihood
public double likelihood(int[] x) The likelihood given a sample set following the distribution.- Parameters:
x- a set of samples.- Returns:
- the likelihood.
-
logLikelihood
public double logLikelihood(int[] x) The likelihood given a sample set following the distribution.- Parameters:
x- a set of samples.- Returns:
- the log likelihood.
-
quantile
protected double quantile(double p, int xmin, int xmax) Inversion of cdf by bisection numeric root finding ofcdf(x) = pfor discrete distribution.- Parameters:
p- the probability.xmin- the lower bound of search range.xmax- the upper bound of search range.- Returns:
- an integer
nsuch thatP(<n) <= p <= P(<n+1).
-