Copyright | Copyright (c) Patrick Perry <patperry@stanford.edu> |
---|---|
License | BSD3 |
Maintainer | Patrick Perry <patperry@stanford.edu> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
- The Gaussian Distribution
- The Flat (Uniform) Distribution
- The Exponential Distribution
- The Levy alpha-Stable Distributions
- The Poisson Distribution
- The Cauchy Distribution
- The Beta Distribution
- The Logistic Distribution
- The Log-Normal Distribution
- The Pareto Distribution
- The Weibull Distribution
- The Gamma Distribution
- The Multinomial Distribution
- The Dirichlet Distribution
Random number distributions. Functions for generating random variates and computing their probability distributions.
- gaussianPdf :: Double -> Double -> Double
- gaussianP :: Double -> Double -> Double
- gaussianQ :: Double -> Double -> Double
- gaussianPInv :: Double -> Double -> Double
- gaussianQInv :: Double -> Double -> Double
- getGaussian :: RNG -> Double -> IO Double
- getGaussianZiggurat :: RNG -> Double -> IO Double
- getGaussianRatioMethod :: RNG -> Double -> IO Double
- ugaussianPdf :: Double -> Double
- ugaussianP :: Double -> Double
- ugaussianQ :: Double -> Double
- ugaussianPInv :: Double -> Double
- ugaussianQInv :: Double -> Double
- getUGaussian :: RNG -> IO Double
- getUGaussianRatioMethod :: RNG -> IO Double
- flatPdf :: Double -> Double -> Double -> Double
- flatP :: Double -> Double -> Double -> Double
- flatQ :: Double -> Double -> Double -> Double
- flatPInv :: Double -> Double -> Double -> Double
- flatQInv :: Double -> Double -> Double -> Double
- getFlat :: RNG -> Double -> Double -> IO Double
- exponentialPdf :: Double -> Double -> Double
- exponentialP :: Double -> Double -> Double
- exponentialQ :: Double -> Double -> Double
- exponentialPInv :: Double -> Double -> Double
- exponentialQInv :: Double -> Double -> Double
- getExponential :: RNG -> Double -> IO Double
- getLevy :: RNG -> Double -> Double -> IO Double
- getLevySkew :: RNG -> Double -> Double -> Double -> IO Double
- poissonPdf :: Int -> Double -> Double
- poissonP :: Int -> Double -> Double
- poissonQ :: Int -> Double -> Double
- getPoisson :: RNG -> Double -> IO Int
- getCauchy :: RNG -> Double -> IO Double
- cauchyPdf :: Double -> Double -> Double
- cauchyP :: Double -> Double -> Double
- cauchyQ :: Double -> Double -> Double
- cauchyPInv :: Double -> Double -> Double
- cauchyQInv :: Double -> Double -> Double
- getBeta :: RNG -> Double -> Double -> IO Double
- betaPdf :: Double -> Double -> Double -> Double
- betaP :: Double -> Double -> Double -> Double
- betaQ :: Double -> Double -> Double -> Double
- betaPInv :: Double -> Double -> Double -> Double
- betaQInv :: Double -> Double -> Double -> Double
- getLogistic :: RNG -> Double -> IO Double
- logisticPdf :: Double -> Double -> Double
- logisticP :: Double -> Double -> Double
- logisticQ :: Double -> Double -> Double
- logisticPInv :: Double -> Double -> Double
- logisticQInv :: Double -> Double -> Double
- getLognormal :: RNG -> Double -> Double -> IO Double
- lognormalPdf :: Double -> Double -> Double -> Double
- lognormalP :: Double -> Double -> Double -> Double
- lognormalQ :: Double -> Double -> Double -> Double
- lognormalPInv :: Double -> Double -> Double -> Double
- lognormalQInv :: Double -> Double -> Double -> Double
- getPareto :: RNG -> Double -> Double -> IO Double
- paretoPdf :: Double -> Double -> Double -> Double
- paretoP :: Double -> Double -> Double -> Double
- paretoQ :: Double -> Double -> Double -> Double
- paretoPInv :: Double -> Double -> Double -> Double
- paretoQInv :: Double -> Double -> Double -> Double
- getWeibull :: RNG -> Double -> Double -> IO Double
- weibullPdf :: Double -> Double -> Double -> Double
- weibullP :: Double -> Double -> Double -> Double
- weibullQ :: Double -> Double -> Double -> Double
- weibullPInv :: Double -> Double -> Double -> Double
- weibullQInv :: Double -> Double -> Double -> Double
- getGamma :: RNG -> Double -> Double -> IO Double
- getGammaKnuth :: RNG -> Double -> Double -> IO Double
- gammaPdf :: Double -> Double -> Double -> Double
- gammaP :: Double -> Double -> Double -> Double
- gammaQ :: Double -> Double -> Double -> Double
- gammaPInv :: Double -> Double -> Double -> Double
- gammaQInv :: Double -> Double -> Double -> Double
- getMultinomial :: RNG -> Int -> Vector Double -> IO (Vector Int)
- multinomialPdf :: Vector Int -> Vector Double -> Double
- multinomialLnPdf :: Vector Int -> Vector Double -> Double
- getDirichlet :: RNG -> Vector Double -> IO (Vector Double)
- dirichletPdf :: Vector Double -> Vector Double -> Double
- dirichletLnPdf :: Vector Double -> Vector Double -> Double
The Gaussian Distribution
General
gaussianPdf :: Double -> Double -> Double Source #
gaussianPdf x sigma
computes the probabililty density p(x) for
a Gaussian distribution with mean 0
and standard deviation sigma
.
gaussianP :: Double -> Double -> Double Source #
gaussianP x sigma
computes the cumulative distribution function P(x) for
a Gaussian distribution with mean 0
and standard deviation sigma
.
gaussianQ :: Double -> Double -> Double Source #
gaussianQ x sigma
computes the cumulative distribution function Q(x) for
a Gaussian distribution with mean 0
and standard deviation sigma
.
gaussianPInv :: Double -> Double -> Double Source #
gaussianPInv p sigma
computes the inverse of the cumulative distribution
function of a Gaussian distribution with mean 0
and standard deviation
sigma
. It returns x
such that P(x) = p
.
gaussianQInv :: Double -> Double -> Double Source #
gaussianPInv q sigma
computes the inverse of the cumulative distribution
function of a Gaussian distribution with mean 0
and standard deviation
sigma
. It returns x
such that Q(x) = q
.
getGaussian :: RNG -> Double -> IO Double Source #
getGaussian r sigma
gets a normal random variable with mean
0
and standard deviation sigma
.
This uses the Box-Mueller algorithm.
getGaussianZiggurat :: RNG -> Double -> IO Double Source #
getGaussianZiggurat r sigma
gets a normal random variable with mean
0
and standard deviation sigma
.
This uses the Marsaglia-Tsang ziggurat algorithm.
getGaussianRatioMethod :: RNG -> Double -> IO Double Source #
getGaussianRatioMethod r sigma
gets a normal random variable with mean
0
and standard deviation sigma
.
This uses the Kinderman-Monahan-Leva ratio method.
Unit Variance
ugaussianPdf :: Double -> Double Source #
ugaussianPdf x
computes the probabililty density p(x) for
a Gaussian distribution with mean 0
and standard deviation 1
.
ugaussianP :: Double -> Double Source #
ugaussianP x
computes the cumulative distribution function P(x) for
a Gaussian distribution with mean 0
and standard deviation 1
.
ugaussianQ :: Double -> Double Source #
ugaussianQ x
computes the cumulative distribution function Q(x) for
a Gaussian distribution with mean 0
and standard deviation 1
.
ugaussianPInv :: Double -> Double Source #
ugaussianPInv p
computes the inverse of the cumulative distribution
function of a Gaussian distribution with mean 0
and standard deviation
1
. It returns x
such that P(x) = p
.
ugaussianQInv :: Double -> Double Source #
ugaussianPInv q
computes the inverse of the cumulative distribution
function of a Gaussian distribution with mean 0
and standard deviation
1
. It returns x
such that Q(x) = q
.
getUGaussian :: RNG -> IO Double Source #
getUGaussian r
gets a normal random variable with mean
0
and standard deviation 1
.
This uses the Box-Mueller algorithm.
getUGaussianRatioMethod :: RNG -> IO Double Source #
getUGaussianRatioMethod r
gets a normal random variable with mean
0
and standard deviation 1
.
This uses the Kinderman-Monahan-Leva ratio method.
The Flat (Uniform) Distribution
flatPdf :: Double -> Double -> Double -> Double Source #
flatPdf x a b
computes the probability density p(x)
at x
for
a uniform distribution from a
to b
.
flatP :: Double -> Double -> Double -> Double Source #
flatP x a b
computes the cumulative distribution function P(x)
.
flatQ :: Double -> Double -> Double -> Double Source #
flatQ x a b
computes the cumulative distribution function Q(x)
.
flatPInv :: Double -> Double -> Double -> Double Source #
flatPInv p a b
computes the inverse of the cumulative distribution
and returns x
so that function P(x) = p
.
flatQInv :: Double -> Double -> Double -> Double Source #
flatQInv q a b
computes the inverse of the cumulative distribution
and returns x
so that function Q(x) = q
.
getFlat :: RNG -> Double -> Double -> IO Double Source #
getFlat r a b
gets a value uniformly chosen in [a,b)
.
The Exponential Distribution
exponentialPdf :: Double -> Double -> Double Source #
exponentialPdf x mu
computes the density at x
of an exponential
with mean mu
.
getExponential :: RNG -> Double -> IO Double Source #
getExponential r mu
gets a random exponential with mean mu
.
The Levy alpha-Stable Distributions
getLevy :: RNG -> Double -> Double -> IO Double Source #
getLevy r c alpha
gets a variate from the Levy symmetric stable
distribution with scale c
and exponent alpha
. The algorithm only
works for 0 <= alpha <= 2
.
getLevySkew :: RNG -> Double -> Double -> Double -> IO Double Source #
getLevySkew r c alpha beta
gets a variate from the Levy skew stable
distribution with scale c
, exponent alpha
, and skewness parameter
beta
. The skewness parameter must lie in the range [-1,1]
. The
algorithm only works for 0 <= alpha <= 2
.
The Poisson Distribution
poissonPdf :: Int -> Double -> Double Source #
poissonPdf k mu
evaluates the probability density p(k)
at k
for
a Poisson distribution with mean mu
.
poissonP :: Int -> Double -> Double Source #
poissonP k mu
evaluates the cumulative distribution function P(k)
at k
for a Poisson distribution with mean mu
.
poissonQ :: Int -> Double -> Double Source #
poissonQ k mu
evaluates the cumulative distribution function Q(k)
at k
for a Poisson distribution with mean mu
.
getPoisson :: RNG -> Double -> IO Int Source #
getPoisson r mu
gets a poisson random variable with mean mu
.
The Cauchy Distribution
cauchyPdf :: Double -> Double -> Double Source #
cauchyPdf x a
evaluates the probability density p(x)
at x
for a Cauchy distribution with scale parameter a
. The density
is given by p(x) dx = { 1 over api (1 + (x/a^2)) } dx
.
The Beta Distribution
getBeta :: RNG -> Double -> Double -> IO Double Source #
getBeta r a b
gets a random beta with parameters a
and b
.
betaPdf :: Double -> Double -> Double -> Double Source #
betaPdf x a b
evaluates the probability density p(x)
at x
for a Beta distribution with parameters a
and b
. The density
is given by p(x) dx = {Gamma(a+b) over Gamma(a) Gamma(b)} x^{a-1} (1-x)^{b-1} dx
for 0 <= x <= 1
.
The Logistic Distribution
getLogistic :: RNG -> Double -> IO Double Source #
getLogistic r a
gets a random logistic with scale a
.
logisticPdf :: Double -> Double -> Double Source #
logisticPdf x a
evaluates the probability density p(x)
at x
for a logistic distribution with scale parameter a
. The density
is given by p(x) dx = { exp(-xa) over a (1 + exp(-xa))^2 } dx
.
The Log-Normal Distribution
getLognormal :: RNG -> Double -> Double -> IO Double Source #
getLognormal zeta sigma
gets a random lognormal with parameters zeta
and sigma
.
lognormalPdf :: Double -> Double -> Double -> Double Source #
lognormalPdf x zeta sigma
evaluates the probability density
p(x)
at x
for a log-normal distribution with parameters zeta
and sigma
, given. The density is given by
p(x) dx = p(x) {1 over x sqrt{2 pi sigma^2} } exp(-(ln(x) - zeta)^2/2 sigma^2) dx
The Pareto Distribution
getPareto :: RNG -> Double -> Double -> IO Double Source #
getPareto r a b
gets a random Pareto with exponent a
and scale b
.
paretoPdf :: Double -> Double -> Double -> Double Source #
paretoPdf x a b
evaluates the probability density p(x)
at x
for a Pareto distribution with exponent a
and scale b
. The density
is given by p(x) dx = (ab) (x/b)^{a+1} dx
for x >= b
.
The Weibull Distribution
getWeibull :: RNG -> Double -> Double -> IO Double Source #
getWeibull r a b
gets a random Weibull with scale a
and exponent b
.
weibullPdf :: Double -> Double -> Double -> Double Source #
weibullPdf x a b
evaluates the probability density p(x)
at x
for a Weibull distribution with scale a
and exponent b
. The density
is given by p(x) dx = {b over a^b} x^{b-1} exp(-(x/a)^b) dx
for x >= 0
.
The Gamma Distribution
getGamma :: RNG -> Double -> Double -> IO Double Source #
getGamma r a b
gets a random gamma with parameters a
and b
.
Uses the Marsagli-Tsang fast gamma method.
getGammaKnuth :: RNG -> Double -> Double -> IO Double Source #
getGammaKnuth r a b
gets a random gamma with parameters a
and b
.
Uses the algorithms from Knuth (vol 2).
gammaPdf :: Double -> Double -> Double -> Double Source #
gammaPdf x a b
evaluates the probability density p(x)
at x
for a gamma distribution with parameters a
and b
. The density
is given by p(x) dx = p(x) dx = {1 over Gamma(a) b^a} x^{a-1} e^{-x/b} dx
for x > 0
.
The Multinomial Distribution
getMultinomial :: RNG -> Int -> Vector Double -> IO (Vector Int) Source #
getMultinomial r n ps
gets a random sample from a
multinomial distribution with parameters ps
formed by n
trials.
multinomialPdf ns ps
evaluates the probability density
p(ns)
at ns
for a multinomial distribution with parameters
ps
, where all ps
are non-negative and sum to 1
. Note
that xs
and alphas
should have the same length.
multinomialLnPdf xs alphas == log (multinomialPdf xs alphas)
,
but more efficient.
The Dirichlet Distribution
getDirichlet :: RNG -> Vector Double -> IO (Vector Double) Source #
getDirichlet r alphas
gets a random sample from a
Dirichlet distribution with parameters alphas
, where all
alphas
are positive.
dirichletPdf xs alphas
evaluates the probability density
p(xs)
at xs
for a Dirichlet distribution with parameters
alphas
, where all alphas
are positive (strictly greater
than zero). Note that xs
and alphas
should have the same
length.