Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fit for Laplace distribution #1309

Merged
merged 6 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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