diff --git a/src/MeasureTheory.jl b/src/MeasureTheory.jl index 4cfcc92c..3d576116 100644 --- a/src/MeasureTheory.jl +++ b/src/MeasureTheory.jl @@ -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") diff --git a/src/parameterized/gamma.jl b/src/parameterized/gamma.jl new file mode 100644 index 00000000..820711bc --- /dev/null +++ b/src/parameterized/gamma.jl @@ -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ℝ₊