Skip to content

Commit ff7585c

Browse files
authored
Migrate from Cubature.jl to HCubature.jl (#236)
1 parent 684fea9 commit ff7585c

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

Project.toml

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

66
[deps]
77
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
8-
Cubature = "667455a9-e2ce-5579-9412-b964f529a492"
98
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
109
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
10+
HCubature = "19dc6840-f33b-545b-b366-655c7e3ffd49"
1111
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1212
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1313
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
@@ -25,9 +25,9 @@ WilliamsonTransforms = "48feb556-9bdd-43a2-8e10-96100ec25e22"
2525
[compat]
2626
Aqua = "v0.8"
2727
Combinatorics = "1"
28-
Cubature = "1.5"
2928
Distributions = "0.25"
3029
ForwardDiff = "0.10"
30+
HCubature = "1"
3131
HypothesisTests = "v0.11"
3232
InteractiveUtils = "1.6"
3333
LinearAlgebra = "1.6"

src/Copula.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
abstract type Copula{d} <: Distributions.ContinuousMultivariateDistribution end
22
Base.length(::Copula{d}) where d = d
33

4-
# The potential functions to code:
4+
# The potential functions to code:
55
# Distributions._logpdf
66
# Distributions.cdf
77
# Distributions.fit(::Type{CT},u) where CT<:Mycopula
88
# Distributions._rand!
99
# Base.eltype
1010
# τ, τ⁻¹
11-
# Base.eltype
11+
# Base.eltype
1212
function Distributions.cdf(C::Copula{d},u::VT) where {d,VT<:AbstractVector}
1313
length(u) != d && throw(ArgumentError("Dimension mismatch between copula and input vector"))
1414
if any(iszero,u)
@@ -25,13 +25,13 @@ end
2525
function _cdf(C::CT,u) where {CT<:Copula}
2626
f(x) = Distributions.pdf(C,x)
2727
z = zeros(eltype(u),length(C))
28-
return Cubature.hcubature(f,z,u,reltol=sqrt(eps()))[1]
28+
return HCubature.hcubature(f,z,u,rtol=sqrt(eps()))[1]
2929
end
3030
function ρ(C::Copula{d}) where d
3131
F(x) = Distributions.cdf(C,x)
3232
z = zeros(d)
3333
i = ones(d)
34-
r = Cubature.hcubature(F,z,i,reltol=sqrt(eps()))[1]
34+
r = HCubature.hcubature(F,z,i,rtol=sqrt(eps()))[1]
3535
return 12*r-3
3636
end
3737
function τ(C::Copula)
@@ -40,7 +40,7 @@ function τ(C::Copula)
4040
return 4*r-1
4141
end
4242
function StatsBase.corkendall(C::Copula{d}) where d
43-
# returns the matrix of bivariate kendall taus.
43+
# returns the matrix of bivariate kendall taus.
4444
K = ones(d,d)
4545
for i in 1:d
4646
for j in i+1:d
@@ -51,7 +51,7 @@ function StatsBase.corkendall(C::Copula{d}) where d
5151
return K
5252
end
5353
function StatsBase.corspearman(C::Copula{d}) where d
54-
# returns the matrix of bivariate spearman rhos.
54+
# returns the matrix of bivariate spearman rhos.
5555
K = ones(d,d)
5656
for i in 1:d
5757
for j in i+1:d
@@ -71,11 +71,11 @@ function measure(C::CT, u,v) where {CT<:Copula}
7171
# We use a gray code according to the proposal at https://discourse.julialang.org/t/looping-through-binary-numbers/90597/6
7272

7373
eval_pt = copy(u)
74-
d = length(C) # is known at compile time
74+
d = length(C) # is known at compile time
7575
r = zero(eltype(u))
7676
graycode = 0 # use a gray code to flip one element at a time
7777
which = fill(false, d) # false/true to use u/v for each component (so false here)
78-
r += Distributions.cdf(C,eval_pt) # the sign is always 0.
78+
r += Distributions.cdf(C,eval_pt) # the sign is always 0.
7979
for s = 1:(1<<d)-1
8080
graycode′ = s (s >> 1)
8181
graycomp = trailing_zeros(graycode graycode′) + 1

src/Copulas.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ module Copulas
1010
import StatsFuns
1111
import TaylorSeries
1212
import ForwardDiff
13-
import Cubature
13+
import HCubature
1414
import MvNormalCDF
1515
import WilliamsonTransforms
1616
import Combinatorics
1717
import LogExpFunctions
1818
import QuadGK
1919
import LinearAlgebra
2020

21-
# Standard copulas and stuff.
21+
# Standard copulas and stuff.
2222
include("utils.jl")
2323
include("Copula.jl")
2424
include("SklarDist.jl")
2525
export pseudos,
2626
SklarDist
2727

28-
# Others.
28+
# Others.
2929
include("MiscellaneousCopulas/SurvivalCopula.jl")
3030
include("MiscellaneousCopulas/PlackettCopula.jl")
3131
include("MiscellaneousCopulas/EmpiricalCopula.jl")
@@ -41,10 +41,10 @@ module Copulas
4141
include("EllipticalCopula.jl")
4242
include("EllipticalCopulas/GaussianCopula.jl")
4343
include("EllipticalCopulas/TCopula.jl")
44-
export GaussianCopula,
44+
export GaussianCopula,
4545
TCopula
4646

47-
# These three distributions might be merged in Distrbutions.jl one day.
47+
# These three distributions might be merged in Distrbutions.jl one day.
4848
include("UnivariateDistribution/Sibuya.jl")
4949
include("UnivariateDistribution/Logarithmic.jl")
5050
include("UnivariateDistribution/AlphaStable.jl")
@@ -67,7 +67,7 @@ module Copulas
6767
include("Generator/UnivariateGenerator/GumbelGenerator.jl")
6868
include("Generator/UnivariateGenerator/InvGaussianGenerator.jl")
6969
include("Generator/UnivariateGenerator/JoeGenerator.jl")
70-
70+
7171
# Archimedean copulas
7272
include("ArchimedeanCopula.jl")
7373
include("BivariateArchimedeanMethods.jl")
@@ -94,9 +94,9 @@ module Copulas
9494
include("ExtremeValueCopulas/HuslerReissCopula.jl")
9595
include("ExtremeValueCopulas/LogCopula.jl")
9696
include("ExtremeValueCopulas/MixedCopula.jl")
97-
include("ExtremeValueCopulas/MOCopula.jl")
97+
include("ExtremeValueCopulas/MOCopula.jl")
9898
include("ExtremeValueCopulas/tEVCopula.jl")
99-
99+
100100
export AsymGalambosCopula,
101101
AsymLogCopula,
102102
AsymMixedCopula,
@@ -106,12 +106,12 @@ module Copulas
106106
HuslerReissCopula,
107107
LogCopula,
108108
MixedCopula,
109-
MOCopula,
109+
MOCopula,
110110
tEVCopula
111111

112112

113113
# Subsetting
114-
include("SubsetCopula.jl") # not exported yet.
114+
include("SubsetCopula.jl") # not exported yet.
115115

116116
using PrecompileTools
117117
@setup_workload begin
@@ -143,8 +143,8 @@ module Copulas
143143
# WCopula(2), ################ <<<<<<<<<-------------- Does not work and I cannot explain why !
144144
# RafteryCopula(2, 0.2), ################ <<<<<<<<<<------------- BUGGY
145145
# RafteryCopula(3, 0.5), ################ <<<<<<<<<<------------- BUGGY
146-
# We should probably add others to speed up again.
147-
)
146+
# We should probably add others to speed up again.
147+
)
148148
u1 = rand(C)
149149
u = rand(C,2)
150150
if applicable(Distributions.pdf,C,u1) && !(typeof(C)<:EmpiricalCopula)

0 commit comments

Comments
 (0)