From 2c78ee93fdefd4d9dc2760d2d3ae6ef31b4ad23b Mon Sep 17 00:00:00 2001 From: Richard Reeve Date: Fri, 31 Jul 2015 16:49:48 +0100 Subject: [PATCH 1/2] Allow for rate to be 0 in Poisson distribution, everything worked already except entropy (which is corrected to 0) and maximum (which is corrected to 0). --- src/univariate/discrete/poisson.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/univariate/discrete/poisson.jl b/src/univariate/discrete/poisson.jl index c0edc5867..20b861e83 100644 --- a/src/univariate/discrete/poisson.jl +++ b/src/univariate/discrete/poisson.jl @@ -2,7 +2,7 @@ immutable Poisson <: DiscreteUnivariateDistribution λ::Float64 function Poisson(λ::Float64) - λ > 0.0 || error("λ must be positive.") + λ >= 0.0 || error("λ must be non-negative.") new(λ) end @@ -10,7 +10,7 @@ immutable Poisson <: DiscreteUnivariateDistribution Poisson() = new(1.0) end -@distr_support Poisson 0 Inf +@distr_support Poisson 0 (d.λ == 0.0 ? 0 : Inf) ### Parameters @@ -39,7 +39,9 @@ kurtosis(d::Poisson) = 1.0 / d.λ function entropy(d::Poisson) λ = rate(d) - if λ < 50.0 + if λ == 0.0 + return 0.0 + elseif λ < 50.0 s = 0.0 λk = 1.0 for k = 1:100 From 9e8cfb420e194b61d502bf1a14dec8dd79d8da23 Mon Sep 17 00:00:00 2001 From: Richard Reeve Date: Fri, 31 Jul 2015 16:50:08 +0100 Subject: [PATCH 2/2] Add tests for Poisson(0.0) distribution. --- test/discrete_test.json | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/discrete_test.json b/test/discrete_test.json index bb5a65b21..9f1d9447e 100644 --- a/test/discrete_test.json +++ b/test/discrete_test.json @@ -1375,6 +1375,33 @@ "var": 1.0 } ], + [ + "Poisson(0.0)", + { + "dtype": "Poisson", + "entropy": 0.0, + "maximum": 0, + "mean": 0.0, + "median": 0.0, + "minimum": 0, + "params": { + "rate": 0.0 + }, + "points": [ + { + "cdf": 1.0, + "logpdf": 0.0, + "x": 0 + } + ], + "q10": 0.0, + "q25": 0.0, + "q50": 0.0, + "q75": 0.0, + "q90": 0.0, + "var": 0.0 + } + ], [ "Poisson(0.5)", {