Skip to content

Commit

Permalink
Merge pull request #46 from JuliaGaussianProcesses/tgf/add_abstract_l…
Browse files Browse the repository at this point in the history
…ikelihood

Add AbstractLikelihood type and use operatorname for docstrings
  • Loading branch information
theogf authored Sep 29, 2021
2 parents 443510f + e4dd665 commit 9391858
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GPLikelihoods"
uuid = "6031954c-0455-49d7-b3b9-3e1c99afaf40"
authors = ["JuliaGaussianProcesses Team"]
version = "0.2.1"
version = "0.2.2"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
1 change: 1 addition & 0 deletions src/GPLikelihoods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export Link,
include("links.jl")

# Likelihoods
abstract type AbstractLikelihood end
include("likelihoods/bernoulli.jl")
include("likelihoods/categorical.jl")
include("likelihoods/gaussian.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/likelihoods/bernoulli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ uncertainity associated with the data follows a Bernoulli distribution.
The link `l` needs to transform the input `f` to the domain [0, 1]
```math
p(y|f) = Bernoulli(y | l(f))
p(y|f) = \\operatorname{Bernoulli}(y | l(f))
```
On calling, this would return a Bernoulli distribution with `l(f)` probability of `true`.
"""
struct BernoulliLikelihood{Tl<:AbstractLink}
struct BernoulliLikelihood{Tl<:AbstractLink} <: AbstractLikelihood
invlink::Tl
end

Expand Down
8 changes: 4 additions & 4 deletions src/likelihoods/categorical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
Categorical likelihood is to be used if we assume that the
uncertainity associated with the data follows a Categorical distribution.
```math
p(y|f_1, f_2, \\dots, f_{n-1}) = Categorical(y | l(f_1, f_2, \\dots, f_{n-1}, 0))
p(y|f_1, f_2, \\dots, f_{n-1}) = \\operatorname{Categorical}(y | l(f_1, f_2, \\dots, f_{n-1}, 0))
```
Given an `AbstractVector` [f_1, f_2, ..., f_{n-1}], returns a `Categorical` distribution,
with probabilities given by `l(f_1, f_2, ..., f_{n-1}, 0)`.
Given an `AbstractVector` ``[f_1, f_2, ..., f_{n-1}]``, returns a `Categorical` distribution,
with probabilities given by ``l(f_1, f_2, ..., f_{n-1}, 0)``.
"""
struct CategoricalLikelihood{Tl<:AbstractLink}
struct CategoricalLikelihood{Tl<:AbstractLink} <: AbstractLikelihood
invlink::Tl
end

Expand Down
4 changes: 2 additions & 2 deletions src/likelihoods/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
Exponential likelihood with scale given by `l(f)`.
```math
p(y|f) = Exponential(y | l(f))
p(y|f) = \\operatorname{Exponential}(y | l(f))
```
"""
struct ExponentialLikelihood{Tl<:AbstractLink}
struct ExponentialLikelihood{Tl<:AbstractLink} <: AbstractLikelihood
invlink::Tl
end

Expand Down
4 changes: 2 additions & 2 deletions src/likelihoods/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
Gamma likelihood with fixed shape `α`.
```math
p(y|f) = Gamma(y | α, l(f))
p(y|f) = \\operatorname{Gamma}(y | α, l(f))
```
On calling, this would return a gamma distribution with shape `α` and scale `l(f)`.
"""
struct GammaLikelihood{T<:Real,Tl<:AbstractLink}
struct GammaLikelihood{T<:Real,Tl<:AbstractLink} <: AbstractLikelihood
α::T # shape parameter
invlink::Tl
end
Expand Down
8 changes: 4 additions & 4 deletions src/likelihoods/gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Gaussian likelihood with `σ²` variance. This is to be used if we assume that t
uncertainity associated with the data follows a Gaussian distribution.
```math
p(y|f) = Normal(y | f, σ²)
p(y|f) = \\operatorname{Normal}(y | f, σ²)
```
On calling, this would return a normal distribution with mean `f` and variance σ².
"""
struct GaussianLikelihood{T<:Real}
struct GaussianLikelihood{T<:Real} <: AbstractLikelihood
σ²::Vector{T}
end

Expand All @@ -31,12 +31,12 @@ This is a Gaussian likelihood whose mean and variance are functions of
latent processes.
```math
p(y|[f, g]) = Normal(y | f, sqrt(l(g)))
p(y|[f, g]) = \\operatorname{Normal}(y | f, sqrt(l(g)))
```
On calling, this would return a normal distribution with mean `f` and variance `l(g)`.
Where `l` is link going from R to R^+
"""
struct HeteroscedasticGaussianLikelihood{Tl<:AbstractLink}
struct HeteroscedasticGaussianLikelihood{Tl<:AbstractLink} <: AbstractLikelihood
invlink::Tl
end

Expand Down
4 changes: 2 additions & 2 deletions src/likelihoods/poisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
Poisson likelihood with rate defined as `l(f)`.
```math
p(y|f) = Poisson(y | θ=l(f))
p(y|f) = \\operatorname{Poisson}(y | θ=l(f))
```
This is to be used if we assume that the uncertainity associated
with the data follows a Poisson distribution.
"""
struct PoissonLikelihood{L<:AbstractLink}
struct PoissonLikelihood{L<:AbstractLink} <: AbstractLikelihood
invlink::L
end

Expand Down
2 changes: 1 addition & 1 deletion src/links.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Base.inv(::LogitLink) = LogisticLink()
"""
LogisticLink()
`exp(x)/(1+exp(-x))` link. f:ℝ->[0,1]. Its inverse is the [`Logit`](@ref).
`exp(x)/(1+exp(-x))` link. f:ℝ->[0,1]. Its inverse is the [`LogitLink`](@ref).
"""
struct LogisticLink <: AbstractLink end

Expand Down

2 comments on commit 9391858

@theogf
Copy link
Member Author

@theogf theogf commented on 9391858 Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/45766

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.2 -m "<description of version>" 939185885f1588211842c58e9382ae192ec913fe
git push origin v0.2.2

Please sign in to comment.