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

Archimedeans #73

Merged
merged 10 commits into from
Nov 20, 2023
10 changes: 3 additions & 7 deletions src/ArchimedeanCopulas/GumbelBarnettCopula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ end
ϕ( C::GumbelBarnettCopula, t) = exp((1-exp(t))/C.θ)
ϕ⁻¹(C::GumbelBarnettCopula, t) = log(1-C.θ*log(t))
function τ(C::GumbelBarnettCopula)
# Define the function to integrate
f(x) = -x * (1 - C.θ * log(x)) * log(1 - C.θ * log(x)) / C.θ
result = Distributions.expectation(f,Distributions.Uniform(0,1))
# Calculate the integral using GSL
# result =
# result, _ = GSL.integration_qags(f, 0.0, 1.0, [C.θ], 1e-7, 1000)
# Use a numerical integration method to obtain tau
result, _ = quadgk(x -> -((x-C.θ*x*log(x))*log(1-C.θ*ln(x))/C.θ), 0, 1)

return 1+4*result
end
Expand All @@ -58,4 +54,4 @@ function τ⁻¹(::Type{GumbelBarnettCopula}, tau)
# Use the bisection method to find the root
x = Roots.find_zero(x -> τ_func(x) - tau, (0.0, 1.0))
return x
end
end
5 changes: 2 additions & 3 deletions src/ArchimedeanCopulas/InvGaussianCopula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ end

ϕ( C::InvGaussianCopula, t) = exp((1-sqrt(1+2*((C.θ)^(2))*t))/C.θ)
ϕ⁻¹(C::InvGaussianCopula, t) = ((1-C.θ*log(t))^(2)-1)/(2*(C.θ)^(2))

function τ(C::InvGaussianCopula)
# Define the function to integrate
f(x) = -x * (((1 - C.θ * log(x))^2 - 1) / (2 * C.θ * (1 - C.θ * log(x))))

# Calculate the integral using an appropriate numerical integration method
result, _ = gsl_integration_qags(f, 0.0, 1.0, [C.θ], 1e-7, 1000)
result, _ = quadgk( x -> (x*((1-C.θ*log(x))^2-1))/(-2*C.θ*(1-C.θ*log(x))),0,1)

return 1+4*result
end
Expand Down
9 changes: 4 additions & 5 deletions test/archimedean_tests.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

@testitem "Test of τ ∘ τ_inv bijection" begin
using Random
taus = [0.0, 0.1, 0.5, 0.9, 1.0]

for T in (
# AMHCopula,
ClaytonCopula,
#ClaytonCopula,
# FrankCopula,
GumbelCopula,
#GumbelCopula,
# IndependentCopula,
# JoeCopula,
# GumbelBarnettCopula,
# InvGaussianCopula
GumbelBarnettCopula,
InvGaussianCopula
)
for τ in taus
@test Copulas.τ(T(2,Copulas.τ⁻¹(T,τ))) ≈ τ
Expand Down
Loading