Skip to content

Commit

Permalink
test and fix ForwardDiff on fit_mean_Σ(Normal
Browse files Browse the repository at this point in the history
  • Loading branch information
bgctw committed Aug 9, 2024
1 parent 75f0d07 commit 50962e9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/univariate/continuous/normal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ end

function fit_mean_Σ(::Type{Normal}, mean::T1, σ::T2) where {T1 <: Real, T2 <: Real}
_T = promote_type(T1,T2)
fit_mean_Σ(Normal{_T}, mean, σ)
mean_p = _T(mean)
σ_p = _T(σ)
#(mean_p, σ_p) = (mean, σ) # first make test fit_mean_Σ_ForwardDiff fail
fit_mean_Σ(Normal{_T}, mean_p, σ_p)
end
function fit_mean_Σ(D::Type{Normal{T}}, mean::Real, σ::Real) where {T}
Normal{T}(mean, σ)
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
Expand Down
11 changes: 11 additions & 0 deletions test/univariate/continuous/normal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ end;
@test mean(d) == m
@test scale(d) == σ
end;

@testset "fit_mean_Σ_ForwardDiff" begin
m = 3.0
σ = 2.0
f(m) = begin
d = fit_mean_Σ(Normal, m, σ)
mode(d)
end
f(m)
dm = ForwardDiff.derivative(f, m)
end;
1 change: 1 addition & 0 deletions test/univariate/test_univariate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using Test
using Random: Random
using LoggingExtras
using Optim
using ForwardDiff

pkgdir = dirname(dirname(pathof(DistributionFits)))
testdir = joinpath(pkgdir, "test")
Expand Down

0 comments on commit 50962e9

Please sign in to comment.