Skip to content

Commit fde2193

Browse files
CompatHelper: bump compat for TaylorSeries to 0.20, (keep existing compat) (#251)
1 parent fa14803 commit fde2193

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ SpecialFunctions = "2"
4141
StableRNGs = "1"
4242
StatsBase = "0.33, 0.34"
4343
StatsFuns = "0.9, 1.3"
44-
TaylorSeries = "0.15, 0.16, 0.17, 0.18"
44+
TaylorSeries = "0.15, 0.16, 0.17, 0.18, 0.19, 0.20"
4545
Test = "1"
4646
TestItemRunner = "1"
4747
WilliamsonTransforms = "0.1"

src/ArchimedeanCopula.jl

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

5757

@@ -73,7 +73,7 @@ function Distributions._logpdf(C::ArchimedeanCopula{d,TG}, u) where {d,TG}
7373
sum_ϕ⁻¹u += ϕ⁻¹u
7474
logdenom += log(-ϕ⁽¹⁾(C,ϕ⁻¹u)) # log of negative here because ϕ⁽¹⁾ is necessarily negative
7575
end
76-
numer = abs(ϕ⁽ᵏ⁾(C, d, sum_ϕ⁻¹u))
76+
numer = abs(ϕ⁽ᵏ⁾(C, sum_ϕ⁻¹u))
7777
if numer > 0
7878
r = log(numer) - logdenom
7979
!isnan(r) && return r

src/Generator.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ max_monotony(G::Generator) = throw("This generator does not have a defined max m
3535
ϕ( G::Generator, t) = throw("This generator has not been defined correctly, the function `ϕ(G,t)` is not defined.")
3636
ϕ⁻¹( G::Generator, x) = Roots.find_zero(t -> ϕ(G,t) - x, (0.0, Inf))
3737
ϕ⁽¹⁾(G::Generator, t) = ForwardDiff.derivative(x -> ϕ(G,x), t)
38-
function ϕ⁽ᵏ⁾(G::Generator, k, t)
39-
X = TaylorSeries.Taylor1(eltype(t),k)
40-
taylor_expansion = ϕ(G,t+X)
41-
coef = TaylorSeries.getcoeff(taylor_expansion,k)
38+
function ϕ⁽ᵏ⁾(G::Generator, ::Val{k}, t) where k
39+
coef = WilliamsonTransforms.taylor(x -> ϕ(G, x), t, k)[end]
4240
der = coef * factorial(k)
4341
return der
4442
end

src/Generator/UnivariateGenerator/JoeGenerator.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ struct JoeGenerator{T} <: UnivariateGenerator
3636
end
3737
end
3838
end
39-
max_monotony(G::JoeGenerator) = Inf
39+
max_monotony(::JoeGenerator) = Inf
4040
ϕ( G::JoeGenerator, t) = 1-(-expm1(-t))^(1/G.θ)
4141
ϕ⁻¹(G::JoeGenerator, t) = -log1p(-(1-t)^G.θ)
4242
# ϕ⁽¹⁾(G::JoeGenerator, t) = First derivative of ϕ
43-
function ϕ⁽ᵏ⁾(G::JoeGenerator, k, t)
44-
t==0 && return iseven(k) ? Inf : -Inf
45-
X = TaylorSeries.Taylor1(eltype(t),k)
46-
taylor_expansion = ϕ(G,t+X)
47-
coef = TaylorSeries.getcoeff(taylor_expansion,k)
48-
der = coef * factorial(k)
49-
return der
43+
function ϕ⁽ᵏ⁾(G::JoeGenerator, ::Val{k}, t) where k
44+
t==0 && return iseven(k) ? eltype(t)(Inf) : eltype(t)(-Inf)
45+
t==Inf && return zero(t)
46+
return @invoke ϕ⁽ᵏ⁾(G::Generator, Val(k), t)
5047
end
5148
τ(G::JoeGenerator) = 1 - 4sum(1/(k*(2+k*G.θ)*(G.θ*(k-1)+2)) for k in 1:1000) # 446 in R copula.
5249
function τ⁻¹(::Type{T},tau) where T<:JoeGenerator

test/WilliamsonCopula.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
@testitem "williamson test" begin
33
using Distributions, Random
44
using StableRNGs
5-
rng = StableRNG(123)
5+
rng = StableRNG(12)
66
taus = [0.0, 0.1, 0.5, 0.9, 1.0]
77

8-
ϕ_clayton(x, θ) = max((1 + θ * x),zero(x))^(-1/θ)
8+
# ϕ_clayton(x, θ) = max((1 + θ * x),zero(x))^(-1/θ)
99

1010
Cops = (
1111
ArchimedeanCopula(10,i𝒲(Dirac(1),10)),
1212
ArchimedeanCopula(2,i𝒲(Pareto(1),5)),
1313
ArchimedeanCopula(2,i𝒲(LogNormal(3),5)),
1414
)
1515
for C in Cops
16-
x = rand(rng,C,10)
16+
rand(rng,C,10)
1717
end
1818
end

0 commit comments

Comments
 (0)