Package smile.stat.distribution
Class EmpiricalDistribution
java.lang.Object
smile.stat.distribution.DiscreteDistribution
smile.stat.distribution.EmpiricalDistribution
- All Implemented Interfaces:
Serializable
,Distribution
An empirical distribution function or empirical cdf, is a cumulative
probability distribution function that concentrates probability 1/n at
each of the n numbers in a sample. As n grows the empirical distribution
will get closer to the true distribution.
Empirical distribution is a very important estimator in Statistics. In
particular, the Bootstrap method rely heavily on the empirical distribution.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionEmpiricalDistribution
(double[] prob) Constructor.EmpiricalDistribution
(double[] prob, IntSet x) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiondouble
cdf
(double k) Cumulative distribution function.double
entropy()
Returns Shannon entropy of the distribution.static EmpiricalDistribution
fit
(int[] data) Estimates the distribution.static EmpiricalDistribution
Estimates the distribution.int
length()
Returns the number of parameters of the distribution.double
logp
(int k) The probability mass function in log scale.double
mean()
Returns 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.int[]
randi
(int n) Generates a set of integer random numbers following this discrete distribution.double
sd()
Returns the standard deviation of distribution.toString()
double
variance()
Returns the variance of distribution.Methods inherited from class smile.stat.distribution.DiscreteDistribution
likelihood, logLikelihood, logp, p, quantile, randi
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface smile.stat.distribution.Distribution
inverseTransformSampling, likelihood, logLikelihood, quantile, quantile, rand, rejectionSampling
-
Field Details
-
p
public final double[] pThe probabilities for each x.
-
-
Constructor Details
-
EmpiricalDistribution
public EmpiricalDistribution(double[] prob) Constructor.- Parameters:
prob
- the probabilities.
-
EmpiricalDistribution
Constructor.- Parameters:
prob
- the probabilities.x
- the values of random variable.
-
-
Method Details
-
fit
Estimates the distribution.- Parameters:
data
- the training data.- Returns:
- the distribution.
-
fit
Estimates the distribution. Sometimes, the data may not contain all possible values. In this case, the user should provide the value set.- Parameters:
data
- the training data.x
- the value set.- Returns:
- the distribution.
-
length
public int length()Description copied from interface:Distribution
Returns 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:Distribution
Returns the mean of distribution.- Returns:
- The mean.
-
variance
public double variance()Description copied from interface:Distribution
Returns the variance of distribution.- Returns:
- The variance.
-
sd
public double sd()Description copied from interface:Distribution
Returns the standard deviation of distribution.- Returns:
- The standard deviation.
-
entropy
public double entropy()Description copied from interface:Distribution
Returns Shannon entropy of the distribution.- Returns:
- Shannon entropy.
-
toString
-
rand
public double rand()Description copied from interface:Distribution
Generates a random number following this distribution.- Returns:
- a random number.
-
randi
public int[] randi(int n) Description copied from class:DiscreteDistribution
Generates a set of integer random numbers following this discrete distribution.- Overrides:
randi
in classDiscreteDistribution
- Parameters:
n
- the number of random numbers to generate.- Returns:
- an array of integer random numbers.
-
p
public double p(int k) Description copied from class:DiscreteDistribution
The probability mass function.- Specified by:
p
in classDiscreteDistribution
- Parameters:
k
- a real value.- Returns:
- the probability.
-
logp
public double logp(int k) Description copied from class:DiscreteDistribution
The probability mass function in log scale.- Specified by:
logp
in classDiscreteDistribution
- Parameters:
k
- a real value.- Returns:
- the log probability.
-
cdf
public double cdf(double k) Description copied from interface:Distribution
Cumulative 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:Distribution
The quantile, the probability to the left of quantile is p. It is actually the inverse of cdf.- Parameters:
p
- the probability.- Returns:
- the quantile.
-