Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 98defb83 authored by Martin O'Leary's avatar Martin O'Leary

Gumbel distribution

parent a501f948
......@@ -26,12 +26,14 @@ export # types
Chisq,
Dirichlet,
DiscreteUniform,
DoubleExponential,
EmpiricalDistribution,
Erlang,
Exponential,
FDist,
Gamma,
Geometric,
Gumbel,
HyperGeometric,
IdentityLink,
InverseLink,
......@@ -997,6 +999,51 @@ function ccdf(d::Geometric, q::Real)
end
insupport(d::Geometric, x::Number) = integer_valued(x) && 0 <= x
##############################################################################
#
# Gumbel/double-exponential distribution
#
##############################################################################
immutable Gumbel <: ContinuousUnivariateDistribution
mu::Float64 # location
beta::Float64 # scale
function Gumbel(mu::Real, beta::Real)
if beta <= 0
error("beta must be positive")
end
new(float64(mu), float64(beta))
end
end
Gumbel() = Gumbel(0.0, 1.0)
insupport(d::Gumbel, x::Number) = isreal(x) && isfinite(x)
function pdf(d::Gumbel, x::Real)
z = (x - d.mu)/d.beta
exp(-z - exp(-z))/d.beta
end
function logpdf(d::Gumbel, x::Real)
z = (x - d.mu)/d.beta
-z - exp(-z) - log(d.beta)
end
cdf(d::Gumbel, x::Real) = exp(-exp((d.mu - x)/d.beta))
logcdf(d::Gumbel, x::Real) = -exp((d.mu - x)/d.beta)
quantile(d::Gumbel, p::Real) = d.mu - d.beta * log(-log(p))
mean(d::Gumbel) = d.mu - d.beta * digamma(1.0)
median(d::Gumbel) = d.mu - d.beta * log(log(2.0))
modes(d::Gumbel) = [d.mu]
var(d::Gumbel) = pi^2 / 6.0 * d.beta^2
skewness(d::Gumbel) = 12.0 * sqrt(6.0) * zeta(3.0) / pi^3
kurtosis(d::Gumbel) = 2.4
entropy(d::Gumbel) = log(d.beta) - digamma(1.0) + 1.0
rand(d::Gumbel) = d.mu - d.beta * log(-log(rand()))
const DoubleExponential = Gumbel
immutable HyperGeometric <: DiscreteUnivariateDistribution
ns::Float64 # number of successes in population
nf::Float64 # number of failures in population
......
......@@ -24,10 +24,10 @@ end
## Checks on ContinuousDistribution instances
for d in (Beta(), Cauchy(), Chisq(12), Exponential(), Exponential(23.1),
FDist(2, 21), Gamma(3), Gamma(), Logistic(), logNormal(),
Normal(), TDist(1), TDist(28), TruncatedNormal(0, 1, -3, 3),
TruncatedNormal(-100, 1, 0, 1), TruncatedNormal(27, 3, 0, Inf),
Uniform(), Weibull(2.3))
FDist(2, 21), Gamma(3), Gamma(), Gumbel(), Gumbel(5, 3),
Logistic(), logNormal(), Normal(), TDist(1), TDist(28),
TruncatedNormal(0, 1, -3, 3), TruncatedNormal(-100, 1, 0, 1),
TruncatedNormal(27, 3, 0, Inf), Uniform(), Weibull(2.3))
## println(d) # uncomment if an assertion fails
qq = quantile(d, pp)
@test_approx_eq cdf(d, qq) pp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment