diff --git a/src/WilliamsonTransforms.jl b/src/WilliamsonTransforms.jl index 9b0c116..fcb8976 100644 --- a/src/WilliamsonTransforms.jl +++ b/src/WilliamsonTransforms.jl @@ -121,4 +121,13 @@ function Distributions.rand(rng::Distributions.AbstractRNG, d::𝒲₋₁) end Base.minimum(::𝒲₋₁) = 0.0 Base.maximum(::𝒲₋₁) = Inf +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 end + + 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