From 5570e9513f6bc14dd6b837c8997797de94e874ea Mon Sep 17 00:00:00 2001 From: Oskar Laverny Date: Wed, 22 Nov 2023 15:24:42 +0100 Subject: [PATCH 1/4] First sketch --- src/Generator.jl | 3 +- .../DistordedGenerator/PowerGenerator.jl | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/Generator/DistordedGenerator/PowerGenerator.jl diff --git a/src/Generator.jl b/src/Generator.jl index 790eda41f..f34643c6c 100644 --- a/src/Generator.jl +++ b/src/Generator.jl @@ -51,4 +51,5 @@ williamson_dist(G::Generator, d) = WilliamsonTransforms.𝒲₋₁(t -> ϕ(G,t), abstract type UnivariateGenerator <: Generator end -abstract type ZeroVariateGenerator <: Generator end \ No newline at end of file +abstract type ZeroVariateGenerator <: Generator end +abstract type DistordedGenerator <: Generator end \ No newline at end of file diff --git a/src/Generator/DistordedGenerator/PowerGenerator.jl b/src/Generator/DistordedGenerator/PowerGenerator.jl new file mode 100644 index 000000000..1559ba83b --- /dev/null +++ b/src/Generator/DistordedGenerator/PowerGenerator.jl @@ -0,0 +1,45 @@ +""" + PowerGenerator{T, TG} + +Fields: + - G::Generator - another generator + - α::Real - parameter, the inner power, positive + - β::Real - parameter, the outer power, positive + +Constructor + + PowerGenerator(G, α, β) + + The inner/outer power generator based on the generator ϕ given by + +```math +\\phi_{\\alpha,\\beta}(t) = \\phi(t^\\alpha)^\\beta +``` + +It keeps the monotony of ϕ. + +It has a few special cases: + - When α = 1 and β = 1, it returns G. + +References : + Nelsen, R. B. (2006). An introduction to copulas. Springer, theorem 4.5.1 p141 +""" +struct PowerGenerator{TG,T} <: DistordedGenerator + G::TG + α::T + β::T + function PowerGenerator(G, α, β) + @assert α > 0 + @assert β > 0 + if α == 1 && β == 1 + return G + end + α,β = promote(α,β) + return new{typeof(G),typeof(β)}(G, α, β) + end +end +max_monotony(G::PowerGenerator) = max_monotony(G.G) +ϕ( G::PowerGenerator, t) = ϕ(G.G,t^G.α)^G.β +ϕ⁻¹(G::PowerGenerator, t) = ϕ⁻¹(G.G, t^(1/G.β))^(1/G.α) + + From 22a4baea324581d559873d50025ddfcb134c7611 Mon Sep 17 00:00:00 2001 From: Oskar Laverny Date: Thu, 23 Nov 2023 17:50:51 +0100 Subject: [PATCH 2/4] add the PowerGenerator to the docs --- docs/src/archimedean/available_models.md | 6 ++++++ src/Generator/DistordedGenerator/PowerGenerator.jl | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/src/archimedean/available_models.md b/docs/src/archimedean/available_models.md index 473ee44a2..4098fb4a6 100644 --- a/docs/src/archimedean/available_models.md +++ b/docs/src/archimedean/available_models.md @@ -8,6 +8,12 @@ CurrentModule = Copulas ```@docs; canonical=false WilliamsonGenerator ``` + +## `PowerGenerator` +```@docs +PowerGenerator +``` + ## `IndependentGenerator` ```@docs IndependentGenerator diff --git a/src/Generator/DistordedGenerator/PowerGenerator.jl b/src/Generator/DistordedGenerator/PowerGenerator.jl index 1559ba83b..c83be1edd 100644 --- a/src/Generator/DistordedGenerator/PowerGenerator.jl +++ b/src/Generator/DistordedGenerator/PowerGenerator.jl @@ -22,7 +22,7 @@ It has a few special cases: - When α = 1 and β = 1, it returns G. References : - Nelsen, R. B. (2006). An introduction to copulas. Springer, theorem 4.5.1 p141 +* [nelsen2006](@cite) Nelsen, R. B. (2006). An introduction to copulas. Springer, theorem 4.5.1 p141 """ struct PowerGenerator{TG,T} <: DistordedGenerator G::TG From 2fc01914f217a664960e3990571caace004006de Mon Sep 17 00:00:00 2001 From: Oskar Laverny Date: Thu, 23 Nov 2023 18:12:48 +0100 Subject: [PATCH 3/4] add the file --- src/Copulas.jl | 1 + src/Generator/DistordedGenerator/PowerGenerator.jl | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Copulas.jl b/src/Copulas.jl index a53487215..bf26dc534 100644 --- a/src/Copulas.jl +++ b/src/Copulas.jl @@ -64,6 +64,7 @@ module Copulas include("Generator/UnivariateGenerator/GumbelGenerator.jl") include("Generator/UnivariateGenerator/InvGaussianGenerator.jl") include("Generator/UnivariateGenerator/JoeGenerator.jl") + include("Generator/DistordedGenerator/PowerGenerator.jl") # Archimedean copulas include("ArchimedeanCopula.jl") diff --git a/src/Generator/DistordedGenerator/PowerGenerator.jl b/src/Generator/DistordedGenerator/PowerGenerator.jl index c83be1edd..73db54c7b 100644 --- a/src/Generator/DistordedGenerator/PowerGenerator.jl +++ b/src/Generator/DistordedGenerator/PowerGenerator.jl @@ -2,9 +2,9 @@ PowerGenerator{T, TG} Fields: - - G::Generator - another generator - - α::Real - parameter, the inner power, positive - - β::Real - parameter, the outer power, positive +* `G::Generator` - another generator +* `α::Real` - parameter, the inner power, positive +* `β::Real` - parameter, the outer power, positive Constructor From e4980f34b04fdf5a61700d94a24c49173166e59e Mon Sep 17 00:00:00 2001 From: Oskar Laverny Date: Thu, 30 Nov 2023 10:39:46 +0100 Subject: [PATCH 4/4] first shot at a test, not working --- test/archimedean_tests.jl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/archimedean_tests.jl b/test/archimedean_tests.jl index e1f6b8f83..7de0e69ea 100644 --- a/test/archimedean_tests.jl +++ b/test/archimedean_tests.jl @@ -286,6 +286,27 @@ end @test true end +@testitem "PowerGenerator - sampling,pdf,cdf,fit" begin + using StableRNGs + using Distributions + rng = StableRNG(123) + for d in 2:10 + for G ∈ ( + Copulas.GumbelGenerator(1.7), + Copulas.ClaytonGenerator(1.8), + # others ? + ) + C = ArchimedeanCopula(d,Copulas.PowerGenerator(G,1,2)) + # C = InvGaussianCopula(d,θ) + data = rand(rng,C,100) + # @test all(pdf(C,data) .>= 0) + # @test all(0 .<= cdf(C,data) .<= 1) + # fit(GumbelCopula,data) + end + end + @test true +end + @testitem "Testing empirical tail values of certain copula samples" begin using StableRNGs using Distributions