From 40399cf405c30c7dde49042c581b654d04fa72f3 Mon Sep 17 00:00:00 2001 From: Santymax98 <132070198+Santymax98@users.noreply.github.com> Date: Sun, 19 Nov 2023 12:16:29 -0300 Subject: [PATCH 1/3] adding calculation of the quantile function I added the quantile function for the purpose of determining the natural marginals of the Archimedean copulas. --- src/WilliamsonTransforms.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/WilliamsonTransforms.jl b/src/WilliamsonTransforms.jl index 9b0c116..8d510e1 100644 --- a/src/WilliamsonTransforms.jl +++ b/src/WilliamsonTransforms.jl @@ -121,4 +121,12 @@ function Distributions.rand(rng::Distributions.AbstractRNG, d::𝒲₋₁) end Base.minimum(::𝒲₋₁) = 0.0 Base.maximum(::𝒲₋₁) = Inf +end #This end was here before increasing the following function + +function Distributions.quantile(d::𝒲₋₁, p::Real) + # Validate that p is in the range [0, 1] + @assert 0 <= p <= 1 + + # Finding the root of the equation F(x) - p = 0 using the root function + return Roots.find_zero(x -> (Distributions.cdf(d, x) - p), (0.0, Inf)) end From a296b78ea5351958d890c390ede23487251d624a Mon Sep 17 00:00:00 2001 From: Santymax98 <132070198+Santymax98@users.noreply.github.com> Date: Sun, 19 Nov 2023 12:29:03 -0300 Subject: [PATCH 2/3] adding test I added a test with the unknown distribution, in this case the calculated quantile is expected to be equal to the quantile of the Earlang distribution --- test/testing_the_paper.jl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/testing_the_paper.jl b/test/testing_the_paper.jl index 8957114..5edf592 100644 --- a/test/testing_the_paper.jl +++ b/test/testing_the_paper.jl @@ -82,4 +82,23 @@ end X = 𝒲₋₁(ϕ,d) rand(X,100) @test true -end \ No newline at end of file +end + +@testitem "Quantile test - IndependantCopula, dimension 10" begin + using Distributions + for d in 3:20 + X = Erlang(d) + ϕ(x) = exp(-x) + Xhat = 𝒲₋₁(ϕ, d) + + # Perform 10 tests of the quantile function + for _ in 1:10 + p = rand() + x = quantile(X, p) + xhat = quantile(Xhat, p) + + # Verify that the difference between the quantiles is small + @test abs(x - xhat) <= sqrt(eps(Float64)) + end + end +end From 75356314d12ea791b82cb406dd6c83623ba07abc Mon Sep 17 00:00:00 2001 From: Santymax98 <132070198+Santymax98@users.noreply.github.com> Date: Sun, 19 Nov 2023 14:05:06 -0300 Subject: [PATCH 3/3] moving function --- src/WilliamsonTransforms.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/WilliamsonTransforms.jl b/src/WilliamsonTransforms.jl index 8d510e1..fcb8976 100644 --- a/src/WilliamsonTransforms.jl +++ b/src/WilliamsonTransforms.jl @@ -121,8 +121,6 @@ function Distributions.rand(rng::Distributions.AbstractRNG, d::𝒲₋₁) end Base.minimum(::𝒲₋₁) = 0.0 Base.maximum(::𝒲₋₁) = Inf -end #This end was here before increasing the following function - function Distributions.quantile(d::𝒲₋₁, p::Real) # Validate that p is in the range [0, 1] @assert 0 <= p <= 1 @@ -130,3 +128,6 @@ function Distributions.quantile(d::𝒲₋₁, p::Real) # Finding the root of the equation F(x) - p = 0 using the root function return Roots.find_zero(x -> (Distributions.cdf(d, x) - p), (0.0, Inf)) end +end + +