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

feat: Refactor SubsetCopula constructors for better readability and consistency #229

Merged
merged 2 commits into from
Sep 21, 2024
Merged
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
35 changes: 31 additions & 4 deletions src/SubsetCopula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,39 @@ function _cdf(C::SubsetCopula{d,CT},u) where {d,CT}
end

# A few specialized constructors:
SubsetCopula(C::GaussianCopula,dims) = length(dims) == 1 ? Distributions.Uniform() : GaussianCopula(C.Σ[collect(dims),collect(dims)])
SubsetCopula(C::TCopula{d,df,MT},dims) where {d,df,MT} = length(dims) == 1 ? Distributions.Uniform() : TCopula(df, C.Σ[collect(dims),collect(dims)])
SubsetCopula(C::ArchimedeanCopula{d,TG},dims) where {d,TG} = length(dims) == 1 ? Distributions.Uniform() : ArchimedeanCopula(length(dims), C.G) # in particular for the independence this will work.
function SubsetCopula(C::GaussianCopula, dims)
if length(dims) == 1
return Distributions.Uniform()
else
return GaussianCopula(C.Σ[collect(dims),collect(dims)])
end
end
function SubsetCopula(C::TCopula{d,df,MT}, dims) where {d,df,MT}
if length(dims) == 1
return Distributions.Uniform()
else
return TCopula(df, C.Σ[collect(dims),collect(dims)])
end
end
function SubsetCopula(C::ArchimedeanCopula{d,TG}, dims) where {d,TG}
if length(dims) == 1
return Distributions.Uniform()
else
return ArchimedeanCopula(length(dims), C.G)
end
end
function SubsetCopula(C::FGMCopula{d,Tθ}, dims::Tuple{Int64, Int64}) where {d,Tθ}
i = 1
for indices in Combinatorics.combinations(1:d, 2)
all(indices .∈ dims) && return FGMCopula(2,C.θ[i])
i = i+1
end
@error("Somethings wrong...")
end

# Kendall tau of bivariate subsets, when the underlying copula is bivariate, should just be kendall tau of the underlying copula.
# Kendall tau and spearman rho are symetric measures in bivaraite cases:
τ(C::SubsetCopula{2,CT}) where {CT<:Copula{2}} = τ(C.C)
ρ(C::SubsetCopula{2,CT}) where {CT<:Copula{2}} = ρ(C.C)

"""
subsetdims(C::Copula,dims)
Expand Down
Loading