Skip to content

Commit 2b00d94

Browse files
salbert83devmotion
andauthored
fix fit for Laplace distribution (#1309)
Co-authored-by: David Widmann <[email protected]>
1 parent ac372f0 commit 2b00d94

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Distributions"
22
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
33
authors = ["JuliaStats"]
4-
version = "0.24.17"
4+
version = "0.24.18"
55

66
[deps]
77
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"

src/univariate/continuous/laplace.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ rand(rng::AbstractRNG, d::Laplace) =
114114

115115
#### Fitting
116116

117-
function fit_mle(::Type{<:Laplace}, x::Array)
118-
xc = copy(x)
119-
a = median!(xc)
120-
Laplace(a, StatsBase.mad!(xc, center=a))
117+
function fit_mle(::Type{<:Laplace}, x::AbstractArray{<:Real})
118+
xc = similar(x)
119+
copyto!(xc, x)
120+
m = median!(xc)
121+
xc .= abs.(x .- m)
122+
return Laplace(m, mean(xc))
121123
end

test/fit.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ end
355355

356356
@testset "Testing fit for Laplace" begin
357357
for func in funcs, dist in (Laplace, Laplace{Float64})
358-
d = fit(dist, func[2](dist(5.0, 3.0), N))
358+
d = fit(dist, func[2](dist(5.0, 3.0), N + 1))
359359
@test isa(d, dist)
360-
@test isapprox(location(d), 5.0, atol=0.1)
361-
@test isapprox(scale(d) , 3.0, atol=0.2)
360+
@test isapprox(location(d), 5.0, atol=0.02)
361+
@test isapprox(scale(d) , 3.0, atol=0.02)
362362
end
363363
end
364364

0 commit comments

Comments
 (0)