Package smile.stat.distribution
Class AbstractDistribution
java.lang.Object
smile.stat.distribution.AbstractDistribution
- All Implemented Interfaces:
Serializable
,Distribution
- Direct Known Subclasses:
BetaDistribution
,ChiSquareDistribution
,DiscreteDistribution
,ExponentialDistribution
,FDistribution
,GammaDistribution
,GaussianDistribution
,LogisticDistribution
,LogNormalDistribution
,Mixture
,TDistribution
,WeibullDistribution
The base class of univariate distributions. Both rejection
and inverse transform sampling methods are implemented to provide some
general approaches to generate random samples based on probability density
function or quantile function. Besides, a quantile function is also
provided based on bisection searching. Likelihood and log likelihood
functions are also implemented here.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected double
Use inverse transform sampling (also known as the inverse probability integral transform or inverse transformation method or Smirnov transform) to draw a sample from the given distribution.protected double
quantile
(double p, double xmin, double xmax) Inversion of CDF by bisection numeric root finding of "cdf(x) = p" for continuous distribution.protected double
quantile
(double p, double xmin, double xmax, double eps) Inversion of CDF by bisection numeric root finding of "cdf(x) = p" for continuous distribution.protected double
rejection
(double pmax, double xmin, double xmax) Use the rejection technique to draw a sample from the given 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, length, likelihood, logLikelihood, logp, mean, p, quantile, rand, rand, sd, variance
-
Constructor Details
-
AbstractDistribution
public AbstractDistribution()
-
-
Method Details
-
rejection
protected double rejection(double pmax, double xmin, double xmax) Use the rejection technique to draw a sample from the given distribution. WARNING: this simulation technique can take a very long time. Rejection sampling is also commonly called the acceptance-rejection method or "accept-reject algorithm". It generates sampling values from an arbitrary probability distribution function f(x) by using an instrumental distribution g(x), under the only restriction thatf(x) < M g(x)
whereM > 1
is an appropriate bound onf(x) / g(x)
.Rejection sampling is usually used in cases where the form of
f(x)
makes sampling difficult. Instead of sampling directly from the distributionf(x)
, we use an envelope distributionM g(x)
where sampling is easier. These samples fromM g(x)
are probabilistically accepted or rejected.This method relates to the general field of Monte Carlo techniques, including Markov chain Monte Carlo algorithms that also use a proxy distribution to achieve simulation from the target distribution
f(x)
. It forms the basis for algorithms such as the Metropolis algorithm.- Parameters:
pmax
- the scale of instrumental distribution (uniform).xmin
- the lower bound of random variable range.xmax
- the upper bound of random variable range.- Returns:
- a random number.
-
inverseTransformSampling
protected double inverseTransformSampling()Use inverse transform sampling (also known as the inverse probability integral transform or inverse transformation method or Smirnov transform) to draw a sample from the given distribution. This is a method for generating sample numbers at random from any probability distribution given its cumulative distribution function (cdf). Subject to the restriction that the distribution is continuous, this method is generally applicable (and can be computationally efficient if the cdf can be analytically inverted), but may be too computationally expensive in practice for some probability distributions. The Box-Muller transform is an example of an algorithm which is less general but more computationally efficient. It is often the case that, even for simple distributions, the inverse transform sampling method can be improved on, given substantial research effort, e.g. the ziggurat algorithm and rejection sampling.- Returns:
- a random number.
-
quantile
protected double quantile(double p, double xmin, double xmax, double eps) Inversion of CDF by bisection numeric root finding of "cdf(x) = p" for continuous distribution.- Parameters:
p
- the probability.xmin
- the lower bound of search range.xmax
- the upper bound of search range.eps
- the epsilon close to zero.- Returns:
- the quantile.
-
quantile
protected double quantile(double p, double xmin, double xmax) Inversion of CDF by bisection numeric root finding of "cdf(x) = p" for continuous distribution. The default epsilon is 1E-6.- Parameters:
p
- the probability.xmin
- the lower bound of search range.xmax
- the upper bound of search range.- Returns:
- the quantile.
-