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 cdcdfaab authored by John Myles White's avatar John Myles White

Added a Laplace type

parent 379a550a
......@@ -18,6 +18,7 @@ export # types
Gamma,
Geometric,
HyperGeometric,
Laplace,
Logistic,
logNormal,
Multinomial,
......@@ -630,6 +631,49 @@ mean(d::HyperGeometric) = d.n*d.ns/(d.ns+d.nf)
var(d::HyperGeometric) = (N=d.ns+d.nf; p=d.ns/N; d.n*p*(1-p)*(N-d.n)/(N-1))
insupport(d::HyperGeometric, x::Number) = integer_valued(x) && 0 <= x <= d.n && (d.n - d.nf) <= x <= d.ns
type Laplace <: ContinuousDistribution
location::Float
scale::Float
function Laplace(l::Real, s::Real)
if s > 0.0
new(float(l), float(s))
else
error("scale must be positive")
end
end
end
Laplace(location::Real) = Laplace(location, 1.0)
Laplace() = Laplace(0.0, 1.0)
const Biexponential = Laplace
function cdf(d::Laplace, q::Real)
0.5 * (1.0 + sign(q - d.location) * (1.0 - exp(-abs(q - d.location) / d.scale)))
end
isupport(d::Laplace, x::Number) = real_valued(x) && isfinite(x)
kurtosis(d::Laplace) = 3.0
mean(d::Laplace) = d.location
median(d::Laplace) = d.location
function pdf(d::Laplace, x::Real)
(1.0 / (2.0 * d.scale)) * exp(-abs(x - d.location) / d.scale)
end
function logpdf(d::Laplace, x::Real)
-log(2.0 * d.scale) - abs(x - d.location) / d.scale
end
function quantile(d::Laplace, p::Real)
d.location - d.scale * sign(p - 0.5) * log(1.0 - 2.0 * abs(p - 0.5))
end
# Need to see whether other RNG strategies are more efficient:
# (1) Difference of two Exponential(1/b) variables
# (2) Ratio of logarithm of two Uniform(0.0, 1.0) variables
function rand(d::Laplace)
u = rand() - 0.5
return d.location - d.scale * sign(u) * log(1.0 - 2.0 * abs(u))
end
skewness(d::Laplace) = 0.0
std(d::Laplace) = sqrt(2.0) * d.scale
var(d::Laplace) = 2.0 * d.scale^2
type Logistic <: ContinuousDistribution
location::Real
scale::Real
......
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