Skip to content
Open
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
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "Copulas"
uuid = "ae264745-0b69-425e-9d9d-cf662c5eec93"
version = "0.1.33"
authors = ["Oskar Laverny"]
version = "0.1.33"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand Down Expand Up @@ -32,6 +33,7 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
CopulasPlotsExt = ["Plots", "RecipesBase"]

[compat]
ADTypes = "1.21.0"
Aqua = "v0.8"
Combinatorics = "1"
Distributions = "0.25"
Expand All @@ -43,7 +45,7 @@ LambertW = "1.0.0"
LinearAlgebra = "1"
LogExpFunctions = "0.3"
MvNormalCDF = "0.2, 0.3"
Optim = "1.13.2"
Optim = "1.13.2, 2"
Plots = "1"
PolyLog = "2.6.0"
Printf = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/ArchimedeanCopula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function _fit(CT::Type{<:ArchimedeanCopula{d, GT} where {d, GT<:UnivariateGenera
θ₀[1] = Distributions.params(_example(CT, d))[1]
end
f(θ) = -Distributions.loglikelihood(CT(d, θ[1]), U)
res = Optim.optimize(f, lo, hi, θ₀, Optim.Fminbox(Optim.LBFGS()), autodiff = :forward)
res = Optim.optimize(f, lo, hi, θ₀, Optim.Fminbox(Optim.LBFGS()), autodiff = ADTypes.AutoForwardDiff())
θ = Optim.minimizer(res)[1]
return CT(d, θ), (; θ̂=(θ=θ,), optimizer=Optim.summary(res),
xtol=xtol, converged=Optim.converged(res),
Expand Down
1 change: 1 addition & 0 deletions src/Copulas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Copulas
import Optim
import Printf
import TaylorSeries
import ADTypes

# Main code
include("utils.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/ExtremeValueCopula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function _fit(CT::Type{<:ExtremeValueCopula{d, GT} where {d, GT<:UnivariateTail2
end
θ0_clamped = clamp(θ0_val, lo, hi)
f(θ) = -Distributions.loglikelihood(CT(d, θ[1]), U)
res = Optim.optimize(f, lo, hi, [θ0_clamped], Optim.Fminbox(Optim.LBFGS()), autodiff = :forward)
res = Optim.optimize(f, lo, hi, [θ0_clamped], Optim.Fminbox(Optim.LBFGS()), autodiff = ADTypes.AutoForwardDiff())
θ̂ = Optim.minimizer(res)[1]
return CT(d, θ̂), (; θ̂=(;θ=θ̂), optimizer=:GradientDescent,
xtol=xtol, converged=Optim.converged(res),
Expand Down
2 changes: 1 addition & 1 deletion src/Fitting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function _fit(CT::Type{<:Copula}, U, ::Val{:mle})
α₀ = _unbound_params(CT, d, Distributions.params(_example(CT, d)))
loss(C) = -Distributions.loglikelihood(C, U)
res = try
Optim.optimize(loss ∘ cop, α₀, Optim.LBFGS(); autodiff=:forward)
Optim.optimize(loss ∘ cop, α₀, Optim.LBFGS(); autodiff=ADTypes.AutoForwardDiff())
catch err
Optim.optimize(loss ∘ cop, α₀, Optim.NelderMead())
end
Expand Down
4 changes: 2 additions & 2 deletions src/MiscellaneousCopulas/FGMCopula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function _fit(CT::Type{<:FGMCopula}, U, ::Val{:mle})
α -> -Distributions.loglikelihood(FGMCopula(2, tanh(α[1])), U),
[0.1],
Optim.LBFGS();
autodiff=:forward
autodiff=ADTypes.AutoForwardDiff()
)
θ = tanh(Optim.minimizer(res)[1])
return CT(d, θ), (; θ̂=(θ=θ,),
Expand Down Expand Up @@ -205,7 +205,7 @@ function _fit(CT::Type{<:FGMCopula}, U, ::Val{:mle})
end

# Optimise in θ-space directly (no need for unbound/rebound)
res = Optim.optimize(loss, θ₀, Optim.LBFGS(); autodiff=:forward)
res = Optim.optimize(loss, θ₀, Optim.LBFGS(); autodiff=ADTypes.AutoForwardDiff())
θhat = Optim.minimizer(res)
return FGMCopula(d, θhat),
(; θ̂ = (θ = θhat,),
Expand Down
Loading