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 2afa38d2 authored by Dahua Lin's avatar Dahua Lin

add probs to lambda

parent b9d6e24e
......@@ -9,21 +9,6 @@ end
@_jl_dist_1p Poisson pois
function entropy(d::Poisson)
λ = d.lambda
if λ < 50.0
s = 0.0
for k in 1:100
s += λ^k * lgamma(k + 1.0) / gamma(k + 1.0)
end
return λ * (1.0 - log(λ)) + exp(-λ) * s
else
return 0.5 * log(2 * pi * e * λ) -
(1 / (12 * λ)) -
(1 / (24 * λ * λ)) -
(19 / (360 * λ * λ * λ))
end
end
isupperbounded(::Union(Poisson, Type{Poisson})) = false
islowerbounded(::Union(Poisson, Type{Poisson})) = true
......@@ -35,12 +20,52 @@ maximum(::Union(Poisson, Type{Poisson})) = Inf
insupport(::Poisson, x::Real) = isinteger(x) && zero(x) <= x
insupport(::Type{Poisson}, x::Real) = isinteger(x) && zero(x) <= x
kurtosis(d::Poisson) = 1.0 / d.lambda
function probs(d::Poisson, rgn::UnitRange)
λ = d.lambda
f, l = rgn[1], rgn[end]
0 <= f <= l || throw(BoundsError())
r = Array(Float64, l - f + 1)
v = r[1] = pdf(d, f)
if l > f
b = f - 1
for x = f+1:l
c = λ / x
r[x - b] = (v *= c)
end
end
return r
end
mean(d::Poisson) = d.lambda
median(d::Poisson) = quantile(d, 0.5)
mode(d::Poisson) = ifloor(d.lambda)
modes(d::Poisson) = isinteger(d.lambda) ? [int(d.lambda)-1,int(d.lambda)] : [ifloor(d.lambda)]
var(d::Poisson) = d.lambda
skewness(d::Poisson) = 1.0 / sqrt(d.lambda)
kurtosis(d::Poisson) = 1.0 / d.lambda
function entropy(d::Poisson)
λ = d.lambda
if λ < 50.0
s = 0.0
for k in 1:100
s += λ^k * lgamma(k + 1.0) / gamma(k + 1.0)
end
return λ * (1.0 - log(λ)) + exp(-λ) * s
else
return 0.5 * log(2 * pi * e * λ) -
(1 / (12 * λ)) -
(1 / (24 * λ * λ)) -
(19 / (360 * λ * λ * λ))
end
end
function mgf(d::Poisson, t::Real)
l = d.lambda
return exp(l * (exp(t) - 1.0))
......@@ -51,13 +76,6 @@ function cf(d::Poisson, t::Real)
return exp(l * (exp(im * t) - 1.0))
end
mode(d::Poisson) = ifloor(d.lambda)
modes(d::Poisson) = isinteger(d.lambda) ? [int(d.lambda)-1,int(d.lambda)] : [ifloor(d.lambda)]
skewness(d::Poisson) = 1.0 / sqrt(d.lambda)
var(d::Poisson) = d.lambda
# model fitting
immutable PoissonStats <: SufficientStats
......
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