Skip to content

Commit

Permalink
Update logistic.jl (#782)
Browse files Browse the repository at this point in the history
* Update logistic.jl

The prior version of this function failed the test

print("Lo(-2;6,0.01) = ",pdf4(Logistic(6,0.01),-2)," = 0, ", "Lo(-2;6,0.01) = ",pdf4(Logistic(6,0.01),6)," = 25");

* Update continuous.jl

Test for the pdf of the logistic distribution for an extreme case which commonly happens but where the previous pdf would yield a NaN instead of zero.
  • Loading branch information
janrpeters authored and andreasnoack committed Oct 3, 2018
1 parent 0db2a12 commit 7a756c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/univariate/continuous/logistic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ entropy(d::Logistic) = log(d.θ) + 2
zval(d::Logistic, x::Real) = (x - d.μ) / d.θ
xval(d::Logistic, z::Real) = d.μ + z * d.θ

pdf(d::Logistic, x::Real) = (e = exp(-zval(d, x)); e / (d.θ * (1 + e)^2))
pdf(d::Logistic, x::Real) = (lz = logistic(-abs(zval(d, x))); lz*(1-lz)/d.θ)
logpdf(d::Logistic, x::Real) = (u = -abs(zval(d, x)); u - 2*log1pexp(u) - log(d.θ))

cdf(d::Logistic, x::Real) = logistic(zval(d, x))
Expand Down
3 changes: 3 additions & 0 deletions test/continuous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ using ForwardDiff
@test string(logpdf(Normal(0,1),big(1))) == "-1.418938533204672741780329736405617639861397473637783412817151540482765695927251"
@test derivative(t -> logpdf(Normal(1.0, 0.15), t), 2.5) -66.66666666666667
@test derivative(t -> pdf(Normal(t, 1.0), 0.0), 0.0) == 0.0

# Test for numerical problems
@test pdf(Logistic(6,0.01),-2) == 0

0 comments on commit 7a756c5

Please sign in to comment.