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

Gamma measure #153

Open
wants to merge 2 commits into
base: master
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
1 change: 1 addition & 0 deletions src/MeasureTheory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ include("parameterized/laplace.jl")
include("parameterized/uniform.jl")
include("parameterized/beta.jl")
include("parameterized/dirichlet.jl")
include("parameterized/gamma.jl")
include("parameterized/gumbel.jl")
include("parameterized/exponential.jl")
include("parameterized/mvnormal.jl")
Expand Down
41 changes: 41 additions & 0 deletions src/parameterized/gamma.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Gamma distribution

# REFERENCES
# https://mc-stan.org/docs/2_27/functions-reference/gamma-distribution.html
# https://en.wikipedia.org/wiki/Gamma_distribution
# https://juliastats.org/Distributions.jl/stable/univariate/#Distributions.Gamma

export Gamma

@parameterized Gamma(α, θ) ≪ Lebesgue(ℝ₊)

@kwstruct Gamma(α, θ)
@kwstruct Gamma(α, β)

@kwalias Gamma [
a => α
alpha => α
shape => α
b => β
beta => β
rate => β
theta => θ
scale => θ
]

TV.as(::Gamma) = asℝ₊

function logdensity(d::Gamma{(:α, :θ)}, x)
return (d.α - 1) * log(x) - x / d.θ - d.α * log(d.θ) - loggamma(d.α)
end

function logdensity(d::Gamma{(:α, :β)}, x)
return (d.α - 1) * log(x) - x * d.β + d.α * log(d.β) - loggamma(d.α)
end

distproxy(d::Gamma{(:α, :θ)}) = Dists.Gamma(d.α, d.θ)
distproxy(d::Gamma{(:α, :β)}) = Dists.Gamma(d.α, 1/d.β)

asparams(::Type{<:Gamma}, ::Val{:α}) = asℝ₊
asparams(::Type{<:Gamma}, ::Val{:β}) = asℝ₊
asparams(::Type{<:Gamma}, ::Val{:θ}) = asℝ₊