Skip to content

Commit

Permalink
Merge pull request #65 from JuliaGaussianProcesses/tgf/unify_link
Browse files Browse the repository at this point in the history
Use smart `link` constructor
  • Loading branch information
theogf authored Jan 28, 2022
2 parents d254543 + c5f7387 commit 40d2790
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 8 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.6"
version = "0.2.7"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods/bernoulli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct BernoulliLikelihood{Tl<:AbstractLink} <: AbstractLikelihood
invlink::Tl
end

BernoulliLikelihood(l=logistic) = BernoulliLikelihood(Link(l))
BernoulliLikelihood(l=logistic) = BernoulliLikelihood(link(l))

(l::BernoulliLikelihood)(f::Real) = Bernoulli(l.invlink(f))

Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods/categorical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct CategoricalLikelihood{Tl<:AbstractLink} <: AbstractLikelihood
invlink::Tl
end

CategoricalLikelihood(l=softmax) = CategoricalLikelihood(Link(l))
CategoricalLikelihood(l=softmax) = CategoricalLikelihood(link(l))

(l::CategoricalLikelihood)(f::AbstractVector{<:Real}) = Categorical(l.invlink(vcat(f, 0)))

Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct ExponentialLikelihood{Tl<:AbstractLink} <: AbstractLikelihood
invlink::Tl
end

ExponentialLikelihood(l=exp) = ExponentialLikelihood(Link(l))
ExponentialLikelihood(l=exp) = ExponentialLikelihood(link(l))

(l::ExponentialLikelihood)(f::Real) = Exponential(l.invlink(f))

Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct GammaLikelihood{T<:Real,Tl<:AbstractLink} <: AbstractLikelihood
end

GammaLikelihood(l) = GammaLikelihood(1.0, l)
GammaLikelihood::Real=1.0, l=exp) = GammaLikelihood(α, Link(l))
GammaLikelihood::Real=1.0, l=exp) = GammaLikelihood(α, link(l))

@functor GammaLikelihood

Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods/gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct HeteroscedasticGaussianLikelihood{Tl<:AbstractLink} <: AbstractLikelihood
invlink::Tl
end

HeteroscedasticGaussianLikelihood(l=exp) = HeteroscedasticGaussianLikelihood(Link(l))
HeteroscedasticGaussianLikelihood(l=exp) = HeteroscedasticGaussianLikelihood(link(l))

function (l::HeteroscedasticGaussianLikelihood)(f::AbstractVector{<:Real})
return Normal(f[1], sqrt(l.invlink(f[2])))
Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods/poisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct PoissonLikelihood{L<:AbstractLink} <: AbstractLikelihood
invlink::L
end

PoissonLikelihood(l=exp) = PoissonLikelihood(Link(l))
PoissonLikelihood(l=exp) = PoissonLikelihood(link(l))

(l::PoissonLikelihood)(f::Real) = Poisson(l.invlink(f))

Expand Down
3 changes: 3 additions & 0 deletions src/links.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct Link{F} <: AbstractLink
f::F
end

link(f) = Link(f)
link(l::AbstractLink) = l

(l::Link)(x) = l.f(x)

Base.inv(l::Link) = Link(InverseFunctions.inverse(l.f))
Expand Down
5 changes: 4 additions & 1 deletion test/links.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

# Generic link
f = sin
l = Link(f)
l = GPLikelihoods.link(f)
@test l == Link(f)
@test l(x) == f(x)
l = GPLikelihoods.link(ExpLink())
@test l == ExpLink()

# Log
l = LogLink()
Expand Down

2 comments on commit 40d2790

@theogf
Copy link
Member Author

@theogf theogf commented on 40d2790 Jan 28, 2022

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/53376

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.7 -m "<description of version>" 40d279036a6ff79585cbf6ff7ad40e85022d492e
git push origin v0.2.7

Please sign in to comment.