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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEmpiricalDistribution(double[] prob) Constructor.EmpiricalDistribution(double[] prob, IntSet x) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiondoublecdf(double k) Cumulative distribution function.doubleentropy()Returns Shannon entropy of the distribution.static EmpiricalDistributionfit(int[] data) Estimates the distribution.static EmpiricalDistributionEstimates the distribution.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.int[]randi(int n) Generates a set of integer random numbers following this discrete distribution.doublesd()Returns the standard deviation of distribution.toString()doublevariance()Returns the variance of distribution.Methods inherited from class DiscreteDistribution
likelihood, logLikelihood, logp, p, quantile, 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
-
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: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.
-
sd
public double sd()Description copied from interface:DistributionReturns the standard deviation of distribution.- Returns:
- The standard deviation.
-
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.
-
randi
public int[] randi(int n) Description copied from class:DiscreteDistributionGenerates a set of integer random numbers following this discrete distribution.- Overrides:
randiin 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: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.
-