Skip to content

Commit

Permalink
[Bug] Force elliptical cdf to behave by clamping them (#197)
Browse files Browse the repository at this point in the history
* Try to clamp the cdf's
Fixes #196

* last clamping
  • Loading branch information
lrnv authored Apr 20, 2024
1 parent 36f18b2 commit 382214c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/EllipticalCopula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ abstract type EllipticalCopula{d,MT} <: Copula{d} end
Base.eltype(C::CT) where CT<:EllipticalCopula = Base.eltype(N(CT)(C.Σ))
function Distributions._rand!(rng::Distributions.AbstractRNG, C::CT, x::AbstractVector{T}) where {T<:Real, CT <: EllipticalCopula}
Random.rand!(rng,N(CT)(C.Σ),x)
x .= Distributions.cdf.(U(CT),x)
x .= clamp.(Distributions.cdf.(U(CT),x),0,1)
return x
end
function Distributions._rand!(rng::Distributions.AbstractRNG, C::CT, A::DenseMatrix{T}) where {T<:Real, CT<:EllipticalCopula}
# More efficient version that precomputes stuff:
n = N(CT)(C.Σ)
u = U(CT)
Random.rand!(rng,n,A)
A .= Distributions.cdf.(u,A)
A .= clamp.(Distributions.cdf.(u,A),0,1)
return A
end
function Distributions._logpdf(C::CT, u) where {CT <: EllipticalCopula}
Expand Down
2 changes: 1 addition & 1 deletion src/SklarDist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Distributions._rand!(rng::Distributions.AbstractRNG, S::SklarDist{CT,Tp
x .= Distributions.quantile.(S.m,x)
end
function Distributions._logpdf(S::SklarDist{CT,TplMargins},u) where {CT,TplMargins}
sum(Distributions.logpdf(S.m[i],u[i]) for i in 1:length(u)) + Distributions.logpdf(S.C,Distributions.cdf.(S.m,u))
sum(Distributions.logpdf(S.m[i],u[i]) for i in 1:length(u)) + Distributions.logpdf(S.C,clamp.(Distributions.cdf.(S.m,u),0,1))
end


Expand Down

0 comments on commit 382214c

Please sign in to comment.