Skip to content

Commit 29216bf

Browse files
authored
[Internals] Switch to TaylorDiff.jl for generator derivatives. (#38)
1 parent fde2193 commit 29216bf

File tree

13 files changed

+20
-22
lines changed

13 files changed

+20
-22
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
version:
21-
- '1.6'
21+
- 'lts'
2222
- '1'
2323
os:
2424
- ubuntu-latest

Project.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Copulas"
22
uuid = "ae264745-0b69-425e-9d9d-cf662c5eec93"
3+
version = "0.1.30"
34
authors = ["Oskar Laverny"]
4-
version = "0.1.29"
55

66
[deps]
77
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
@@ -19,7 +19,6 @@ Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
1919
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2020
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
2121
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
22-
TaylorSeries = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"
2322
WilliamsonTransforms = "48feb556-9bdd-43a2-8e10-96100ec25e22"
2423

2524
[compat]
@@ -41,10 +40,9 @@ SpecialFunctions = "2"
4140
StableRNGs = "1"
4241
StatsBase = "0.33, 0.34"
4342
StatsFuns = "0.9, 1.3"
44-
TaylorSeries = "0.15, 0.16, 0.17, 0.18, 0.19, 0.20"
4543
Test = "1"
4644
TestItemRunner = "1"
47-
WilliamsonTransforms = "0.1"
45+
WilliamsonTransforms = "0.2"
4846
julia = "1"
4947

5048
[extras]

src/ArchimedeanCopula.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ end
5252
ϕ⁻¹(C::ArchimedeanCopula{d,TG},t) where {d,TG} = ϕ⁻¹(C.G,t)
5353
ϕ⁽¹⁾(C::ArchimedeanCopula{d,TG},t) where {d,TG} = ϕ⁽¹⁾(C.G,t)
5454
ϕ⁽ᵏ⁾(C::ArchimedeanCopula{d,TG},t) where {d,TG} = ϕ⁽ᵏ⁾(C.G, Val(d), t)
55-
williamson_dist(C::ArchimedeanCopula{d,TG}) where {d,TG} = williamson_dist(C.G,d)
55+
williamson_dist(C::ArchimedeanCopula{d,TG}) where {d,TG} = williamson_dist(C.G,Val(d))
5656

5757

5858
function _cdf(C::CT,u) where {CT<:ArchimedeanCopula}
@@ -66,7 +66,7 @@ function Distributions._logpdf(C::ArchimedeanCopula{d,TG}, u) where {d,TG}
6666
if !all(0 .<= u .<= 1)
6767
return eltype(u)(-Inf)
6868
end
69-
T = promote_type(Float64, eltype(u)) # the FLoat64 here should be eltype(C) when copulas wil be type agnostic...
69+
T = promote_type(Float64, eltype(u)) # the Float64 here should be eltype(C) when copulas will be type agnostic...
7070
logdenom = sum_ϕ⁻¹u = zero(T)
7171
for us in u
7272
ϕ⁻¹u = ϕ⁻¹(C,us)

src/Copulas.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module Copulas
88
import Distributions
99
import StatsBase
1010
import StatsFuns
11-
import TaylorSeries
1211
import ForwardDiff
1312
import HCubature
1413
import MvNormalCDF

src/Generator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ max_monotony(G::Generator) = throw("This generator does not have a defined max m
3636
ϕ⁻¹( G::Generator, x) = Roots.find_zero(t -> ϕ(G,t) - x, (0.0, Inf))
3737
ϕ⁽¹⁾(G::Generator, t) = ForwardDiff.derivative(x -> ϕ(G,x), t)
3838
function ϕ⁽ᵏ⁾(G::Generator, ::Val{k}, t) where k
39-
coef = WilliamsonTransforms.taylor(x -> ϕ(G, x), t, k)[end]
39+
coef = WilliamsonTransforms.taylor(x -> ϕ(G, x), t, Val(k))[end]
4040
der = coef * factorial(k)
4141
return der
4242
end
43-
williamson_dist(G::Generator, d) = WilliamsonTransforms.𝒲₋₁(t -> ϕ(G,t),d)
43+
williamson_dist(G::Generator, ::Val{d}) where d = WilliamsonTransforms.𝒲₋₁(t -> ϕ(G,t), Val(d))
4444

4545
# τ(G::Generator) = @error("This generator has no kendall tau implemented.")
4646
# ρ(G::Generator) = @error ("This generator has no Spearman rho implemented.")

src/Generator/UnivariateGenerator/AMHGenerator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ max_monotony(::AMHGenerator) = Inf
3838
ϕ⁻¹(G::AMHGenerator, t) = log(G.θ + (1-G.θ)/t)
3939
# ϕ⁽¹⁾(G::AMHGenerator, t) = First derivative of ϕ
4040
# ϕ⁽ᵏ⁾(G::AMHGenerator, k, t) = kth derivative of ϕ
41-
williamson_dist(G::AMHGenerator, d) = G.θ >= 0 ? WilliamsonFromFrailty(1 + Distributions.Geometric(1-G.θ),d) : WilliamsonTransforms.𝒲₋₁(t -> ϕ(G,t),d)
41+
williamson_dist(G::AMHGenerator, ::Val{d}) where d = G.θ >= 0 ? WilliamsonFromFrailty(1 + Distributions.Geometric(1-G.θ), Val(d)) : WilliamsonTransforms.𝒲₋₁(t -> ϕ(G,t), Val(d))
4242

4343
function τ(G::AMHGenerator)
4444
θ = G.θ

src/Generator/UnivariateGenerator/ClaytonGenerator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ max_monotony(G::ClaytonGenerator) = G.θ >= 0 ? Inf : Int(floor(1 - 1/G.θ))
4646
# ϕ⁽ᵏ⁾(G::ClaytonGenerator, k, t) = kth derivative of ϕ
4747
τ(G::ClaytonGenerator) = ifelse(isfinite(G.θ), G.θ/(G.θ+2), 1)
4848
τ⁻¹(::Type{T},τ) where T<:ClaytonGenerator = ifelse== 1,Inf,2τ/(1-τ))
49-
williamson_dist(G::ClaytonGenerator, d) = G.θ >= 0 ? WilliamsonFromFrailty(Distributions.Gamma(1/G.θ,G.θ),d) : ClaytonWilliamsonDistribution(G.θ,d)
49+
williamson_dist(G::ClaytonGenerator, ::Val{d}) where d = G.θ >= 0 ? WilliamsonFromFrailty(Distributions.Gamma(1/G.θ,G.θ), Val(d)) : ClaytonWilliamsonDistribution(G.θ,d)

src/Generator/UnivariateGenerator/FrankGenerator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ struct FrankGenerator{T} <: UnivariateGenerator
3939
end
4040
max_monotony(G::FrankGenerator) = G.θ < 0 ? 2 : Inf
4141
ϕ( G::FrankGenerator, t) = G.θ > 0 ? -LogExpFunctions.log1mexp(LogExpFunctions.log1mexp(-G.θ)-t)/G.θ : -log1p(exp(-t) * expm1(-G.θ))/G.θ
42-
ϕ( G::FrankGenerator, t::TaylorSeries.Taylor1) = G.θ > 0 ? -log(-expm1(LogExpFunctions.log1mexp(-G.θ)-t))/G.θ : -log1p(exp(-t) * expm1(-G.θ))/G.θ
42+
# ϕ( G::FrankGenerator, t::TaylorSeries.Taylor1) = G.θ > 0 ? -log(-expm1(LogExpFunctions.log1mexp(-G.θ)-t))/G.θ : -log1p(exp(-t) * expm1(-G.θ))/G.θ
4343
ϕ⁻¹(G::FrankGenerator, t) = G.θ > 0 ? LogExpFunctions.log1mexp(-G.θ) - LogExpFunctions.log1mexp(-t*G.θ) : -log(expm1(-t*G.θ)/expm1(-G.θ))
4444
ϕ⁽¹⁾(G::FrankGenerator, t) = (one(t) - one(t) / (one(t) + exp(-t)*expm1(-G.θ))) / G.θ # First derivative of ϕ
4545
# ϕ⁽ᵏ⁾(G::FrankGenerator, k, t) = kth derivative of ϕ
46-
williamson_dist(G::FrankGenerator, d) = G.θ > 0 ? WilliamsonFromFrailty(Logarithmic(-G.θ), d) : WilliamsonTransforms.𝒲₋₁(t -> ϕ(G,t),d)
46+
williamson_dist(G::FrankGenerator, ::Val{d}) where d = G.θ > 0 ? WilliamsonFromFrailty(Logarithmic(-G.θ), Val(d)) : WilliamsonTransforms.𝒲₋₁(t -> ϕ(G,t), Val(d))
4747

4848
Debye(x, k::Int=1) = k / x^k * QuadGK.quadgk(t -> t^k/expm1(t), 0, x)[1]
4949
function τ(G::FrankGenerator)

src/Generator/UnivariateGenerator/GumbelGenerator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ function τ⁻¹(::Type{T},τ) where T<:GumbelGenerator
5959
return θ
6060
end
6161
end
62-
williamson_dist(G::GumbelGenerator, d) = WilliamsonFromFrailty(AlphaStable= 1/G.θ, β = 1,scale = cos/(2G.θ))^G.θ, location = (G.θ == 1 ? 1 : 0)), d)
62+
williamson_dist(G::GumbelGenerator, ::Val{d}) where d = WilliamsonFromFrailty(AlphaStable= 1/G.θ, β = 1,scale = cos/(2G.θ))^G.θ, location = (G.θ == 1 ? 1 : 0)), Val(d))

src/Generator/UnivariateGenerator/InvGaussianGenerator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ function τ⁻¹(::Type{T}, tau) where T<:InvGaussianGenerator
7373
end
7474
return Roots.find_zero(x -> τ(InvGaussianGenerator(x)) - tau, (sqrt(eps(tau)), Inf))
7575
end
76-
williamson_dist(G::InvGaussianGenerator, d) = WilliamsonFromFrailty(Distributions.InverseGaussian(G.θ,1),d)
76+
williamson_dist(G::InvGaussianGenerator, ::Val{d}) where d = WilliamsonFromFrailty(Distributions.InverseGaussian(G.θ,1), Val(d))

0 commit comments

Comments
 (0)