Skip to content

Commit

Permalink
fix fit for Laplace distribution (#1309)
Browse files Browse the repository at this point in the history
Co-authored-by: David Widmann <dev+github@devmotion.de>
  • Loading branch information
salbert83 and devmotion authored Apr 21, 2021
1 parent ac372f0 commit 2b00d94
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Distributions"
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
authors = ["JuliaStats"]
version = "0.24.17"
version = "0.24.18"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand Down
10 changes: 6 additions & 4 deletions src/univariate/continuous/laplace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ rand(rng::AbstractRNG, d::Laplace) =

#### Fitting

function fit_mle(::Type{<:Laplace}, x::Array)
xc = copy(x)
a = median!(xc)
Laplace(a, StatsBase.mad!(xc, center=a))
function fit_mle(::Type{<:Laplace}, x::AbstractArray{<:Real})
xc = similar(x)
copyto!(xc, x)
m = median!(xc)
xc .= abs.(x .- m)
return Laplace(m, mean(xc))
end
6 changes: 3 additions & 3 deletions test/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ end

@testset "Testing fit for Laplace" begin
for func in funcs, dist in (Laplace, Laplace{Float64})
d = fit(dist, func[2](dist(5.0, 3.0), N))
d = fit(dist, func[2](dist(5.0, 3.0), N + 1))
@test isa(d, dist)
@test isapprox(location(d), 5.0, atol=0.1)
@test isapprox(scale(d) , 3.0, atol=0.2)
@test isapprox(location(d), 5.0, atol=0.02)
@test isapprox(scale(d) , 3.0, atol=0.02)
end
end

Expand Down

2 comments on commit 2b00d94

@devmotion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/34931

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.24.18 -m "<description of version>" 2b00d941009a78ec73dbd74bbe53e719431db411
git push origin v0.24.18

Please sign in to comment.