Package smile.stat.distribution
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
-
Method Summary
Modifier and TypeMethodDescriptiondouble
likelihood
(int[] x) The likelihood given a sample set following the distribution.double
logLikelihood
(int[] x) The likelihood given a sample set following the distribution.double
logp
(double x) The density at x in log scale, which may prevents the underflow problem.abstract double
logp
(int x) The probability mass function in log scale.double
p
(double x) The probability density function for continuous distribution or probability mass function for discrete distribution at x.abstract double
p
(int x) The probability mass function.protected double
quantile
(double p, int xmin, int xmax) Inversion of cdf by bisection numeric root finding ofcdf(x) = p
for discrete distribution.int
randi()
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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface smile.stat.distribution.Distribution
cdf, entropy, inverseTransformSampling, length, likelihood, logLikelihood, mean, quantile, quantile, quantile, rand, rand, rejectionSampling, sd, variance
-
Constructor Details
-
DiscreteDistribution
public DiscreteDistribution()
-
-
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:Distribution
The probability density function for continuous distribution or probability mass function for discrete distribution at x.- Specified by:
p
in 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:Distribution
The density at x in log scale, which may prevents the underflow problem.- Specified by:
logp
in 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) = p
for discrete distribution.- Parameters:
p
- the probability.xmin
- the lower bound of search range.xmax
- the upper bound of search range.- Returns:
- an integer
n
such thatP(<n) <= p <= P(<n+1)
.
-