Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 10 additions & 9 deletions src/Generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ end


"""
TiltedGenerator(G, p, sJ) <: Generator
TiltedGenerator(G, p, sJ)

Archimedean generator tilted by conditioning on `p` components fixed at values
with cumulative generator sum `sJ = ∑ ϕ⁻¹(u_j)`. It defines
Expand All @@ -495,19 +495,20 @@ which yields the conditional copula within the Archimedean family for the
remaining d-p variables.
You will get a TiltedGenerator if you condition() an archimedean copula.
"""
struct TiltedGenerator{TG, T, p} <: Generator
struct TiltedGenerator{TG, T} <: Generator
G::TG
p::Int
sJ::T
den::T
function TiltedGenerator(G::Generator, p::Int, sJ::T) where {T<:Real}
den = ϕ⁽ᵏ⁾(G, p, sJ)
return new{typeof(G), T, p}(G, sJ, den)
return new{typeof(G), T}(G, p, sJ, den)
end
end
max_monotony(G::TiltedGenerator{TG, T, p}) where {TG, T, p} = max(0, max_monotony(G.G) - p)
ϕ(G::TiltedGenerator{TG, T, p}, t) where {TG, T, p} = ϕ⁽ᵏ⁾(G.G, p, G.sJ + t) / G.den
ϕ⁻¹(G::TiltedGenerator{TG, T, p}, x) where {TG, T, p} = ϕ⁽ᵏ⁾⁻¹(G.G, p, x * G.den; start_at = G.sJ) - G.sJ
ϕ⁽ᵏ⁾(G::TiltedGenerator{TG, T, p}, k::Int, t) where {TG, T, p} = ϕ⁽ᵏ⁾(G.G, k + p, G.sJ + t) / G.den
ϕ⁽ᵏ⁾⁻¹(G::TiltedGenerator{TG, T, p}, k::Int, y; start_at = G.sJ) where {TG, T, p} = ϕ⁽ᵏ⁾⁻¹(G.G, k + p, y * G.den; start_at = start_at+G.sJ) - G.sJ
ϕ⁽¹⁾(G::TiltedGenerator{TG, T, p}, t) where {TG, T, p} = ϕ⁽ᵏ⁾(G, 1, t)
max_monotony(G::TiltedGenerator{TG, T}) where {TG, T} = max(0, max_monotony(G.G) - G.p)
ϕ(G::TiltedGenerator{TG, T}, t) where {TG, T} = ϕ⁽ᵏ⁾(G.G, G.p, G.sJ + t) / G.den
ϕ⁻¹(G::TiltedGenerator{TG, T}, x) where {TG, T} = ϕ⁽ᵏ⁾⁻¹(G.G, G.p, x * G.den; start_at = G.sJ) - G.sJ
ϕ⁽ᵏ⁾(G::TiltedGenerator{TG, T}, k::Int, t) where {TG, T} = ϕ⁽ᵏ⁾(G.G, k + G.p, G.sJ + t) / G.den
ϕ⁽ᵏ⁾⁻¹(G::TiltedGenerator{TG, T}, k::Int, y; start_at = G.sJ) where {TG, T} = ϕ⁽ᵏ⁾⁻¹(G.G, k + G.p, y * G.den; start_at = start_at+G.sJ) - G.sJ
ϕ⁽¹⁾(G::TiltedGenerator{TG, T}, t) where {TG, T} = ϕ⁽ᵏ⁾(G, 1, t)
Distributions.params(G::TiltedGenerator) = (Distributions.params(G.G)..., sJ = G.sJ)
13 changes: 7 additions & 6 deletions src/UnivariateDistribution/Distortions/ArchimedeanDistortion.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
###########################################################################
##### ArchimedeanCopula fast-paths
###########################################################################
struct ArchimedeanDistortion{TG, T, p} <: Distortion
struct ArchimedeanDistortion{TG, T} <: Distortion
G::TG
p::Int
sJ::T
den::T
ArchimedeanDistortion(G::TG, p::Int, sJ::T, den::T) where {T<:Real, TG} = new{TG, T, p}(G, sJ, den)
ArchimedeanDistortion(G::TG, p::Int, sJ::T, den::T) where {T<:Real, TG} = new{TG, T}(G, p, sJ, den)
end
function Distributions.cdf(D::ArchimedeanDistortion{TG, T, p}, u::Real) where {TG, T, p}
return ϕ⁽ᵏ⁾(D.G, p, D.sJ + ϕ⁻¹(D.G, float(u))) / D.den
function Distributions.cdf(D::ArchimedeanDistortion{TG, T}, u::Real) where {TG, T}
return ϕ⁽ᵏ⁾(D.G, D.p, D.sJ + ϕ⁻¹(D.G, float(u))) / D.den
end
function Distributions.quantile(D::ArchimedeanDistortion{TG, T, p}, α::Real) where {TG, T, p}
y = ϕ⁽ᵏ⁾⁻¹(D.G, p, α * D.den; start_at = D.sJ)
function Distributions.quantile(D::ArchimedeanDistortion{TG, T}, α::Real) where {TG, T}
y = ϕ⁽ᵏ⁾⁻¹(D.G, D.p, α * D.den; start_at = D.sJ)
return ϕ(D.G, y - D.sJ)
end
## ConditionalCopula moved next to ArchimedeanCopula definition
Loading