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

[New Generator] PowerGenerator from any other generator #84

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions docs/src/archimedean/available_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ CurrentModule = Copulas
```@docs; canonical=false
WilliamsonGenerator
```

## `PowerGenerator`
```@docs
PowerGenerator
```

## `IndependentGenerator`
```@docs
IndependentGenerator
Expand Down
1 change: 1 addition & 0 deletions src/Copulas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion src/Generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ williamson_dist(G::Generator, d) = WilliamsonTransforms.𝒲₋₁(t -> ϕ(G,t),


abstract type UnivariateGenerator <: Generator end
abstract type ZeroVariateGenerator <: Generator end
abstract type ZeroVariateGenerator <: Generator end
abstract type DistordedGenerator <: Generator end
45 changes: 45 additions & 0 deletions src/Generator/DistordedGenerator/PowerGenerator.jl
Original file line number Diff line number Diff line change
@@ -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 :
* [nelsen2006](@cite) 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.α)


21 changes: 21 additions & 0 deletions test/archimedean_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading