Skip to content

Commit

Permalink
Merge pull request #30 from rossviljoen/master
Browse files Browse the repository at this point in the history
Add Gamma and Exponential likelihoods
  • Loading branch information
rossviljoen authored Jul 21, 2021
2 parents dd28057 + ff89e7f commit c46ad70
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/GPLikelihoods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ export BernoulliLikelihood,
CategoricalLikelihood,
GaussianLikelihood,
HeteroscedasticGaussianLikelihood,
PoissonLikelihood
PoissonLikelihood,
ExponentialLikelihood,
GammaLikelihood

# Likelihoods
include("likelihoods/bernoulli.jl")
include("likelihoods/categorical.jl")
include("likelihoods/gaussian.jl")
include("likelihoods/poisson.jl")
include(joinpath("likelihoods", "bernoulli.jl"))
include(joinpath("likelihoods", "categorical.jl"))
include(joinpath("likelihoods", "gaussian.jl"))
include(joinpath("likelihoods", "poisson.jl"))
include(joinpath("likelihoods", "gamma.jl"))
include(joinpath("likelihoods", "exponential.jl"))

end # module
14 changes: 14 additions & 0 deletions src/likelihoods/exponential.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
ExponentialLikelihood()
Exponential likelihood with scale given by `exp(f)`.
```math
p(y|f) = Exponential(y | exp(f))
```
"""
struct ExponentialLikelihood end

(l::ExponentialLikelihood)(f::Real) = Exponential(exp(f))

(l::ExponentialLikelihood)(fs::AbstractVector{<:Real}) = Product(Exponential.(exp.(fs)))
21 changes: 21 additions & 0 deletions src/likelihoods/gamma.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
GammaLikelihood(α)
Gamma likelihood with fixed shape `α`.
```math
p(y|f) = Gamma(y | α, θ=exp(f))
```
On calling, this would return a gamma distribution with shape `α` and scale `exp(f)`.
"""
struct GammaLikelihood{T<:Real}
α::T # shape parameter
end

GammaLikelihood() = GammaLikelihood(1.)

@functor GammaLikelihood

(l::GammaLikelihood)(f::Real) = Gamma(l.α, exp(f))

(l::GammaLikelihood)(fs::AbstractVector{<:Real}) = Product(Gamma.(l.α, exp.(fs)))
4 changes: 4 additions & 0 deletions test/likelihoods/exponential.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@testset "ExponentialLikelihood" begin
lik = ExponentialLikelihood()
test_interface(lik, SqExponentialKernel(), rand(10))
end
4 changes: 4 additions & 0 deletions test/likelihoods/gamma.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@testset "GammaLikelihood" begin
lik = GammaLikelihood(1.)
test_interface(lik, SqExponentialKernel(), rand(10); functor_args=(,))
end
10 changes: 6 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ using Distributions
include("test_utils.jl")

@testset "likelihoods" begin
include("likelihoods/bernoulli.jl")
include("likelihoods/categorical.jl")
include("likelihoods/gaussian.jl")
include("likelihoods/poisson.jl")
include(joinpath("likelihoods", "bernoulli.jl"))
include(joinpath("likelihoods", "categorical.jl"))
include(joinpath("likelihoods", "gaussian.jl"))
include(joinpath("likelihoods", "poisson.jl"))
include(joinpath("likelihoods", "gamma.jl"))
include(joinpath("likelihoods", "exponential.jl"))
end

end

0 comments on commit c46ad70

Please sign in to comment.