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

Quantile function #6

Merged
merged 3 commits into from
Nov 20, 2023
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
9 changes: 9 additions & 0 deletions src/WilliamsonTransforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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


21 changes: 20 additions & 1 deletion test/testing_the_paper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,23 @@ end
X = 𝒲₋₁(ϕ,d)
rand(X,100)
@test true
end
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
Loading