Skip to content

Commit

Permalink
less code duplication (#72)
Browse files Browse the repository at this point in the history
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
  • Loading branch information
st-- and devmotion authored Mar 28, 2022
1 parent 21aa15f commit 932f516
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)

GPLikelihoods.jl provides a collection of likelihoods to be used as building blocks for defining non-Gaussian problems.
It is intended to be mainly consumed by other packages within the JuliaGaussianProcesses ecosystem (such as [ApproximateGPs.jl](https://github.com/JuliaGaussianProcesses/ApproximateGPs.jl)) for approximate Gaussian process regression, classification, event counting, etc.
GPLikelihoods.jl provides a collection of likelihoods to be used as building
blocks for defining non-Gaussian problems. It is intended to be mainly
consumed by other packages within the JuliaGaussianProcesses ecosystem (such as
[ApproximateGPs.jl](https://github.com/JuliaGaussianProcesses/ApproximateGPs.jl))
for approximate Gaussian process regression, classification, event counting,
etc.
2 changes: 1 addition & 1 deletion src/likelihoods/bernoulli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ BernoulliLikelihood(l=logistic) = BernoulliLikelihood(link(l))

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

(l::BernoulliLikelihood)(fs::AbstractVector{<:Real}) = Product(Bernoulli.(l.invlink.(fs)))
(l::BernoulliLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs))
4 changes: 1 addition & 3 deletions src/likelihoods/categorical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,4 @@ function (l::CategoricalLikelihood)(f::AbstractVector{<:Real})
return Categorical(l.invlink(f))
end

function (l::CategoricalLikelihood)(fs::AbstractVector)
return Product(Categorical.(l.invlink.(fs)))
end
(l::CategoricalLikelihood)(fs::AbstractVector) = Product(map(l, fs))
4 changes: 1 addition & 3 deletions src/likelihoods/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ ExponentialLikelihood(l=exp) = ExponentialLikelihood(link(l))

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

function (l::ExponentialLikelihood)(fs::AbstractVector{<:Real})
return Product(Exponential.(l.invlink.(fs)))
end
(l::ExponentialLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs))
2 changes: 1 addition & 1 deletion src/likelihoods/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ GammaLikelihood(α::Real=1.0, l=exp) = GammaLikelihood(α, link(l))

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

(l::GammaLikelihood)(fs::AbstractVector{<:Real}) = Product(Gamma.(l.α, l.invlink.(fs)))
(l::GammaLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs))
4 changes: 1 addition & 3 deletions src/likelihoods/negativebinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ end

(l::NegativeBinomialLikelihood)(f::Real) = NegativeBinomial(l.successes, l.invlink(f))

function (l::NegativeBinomialLikelihood)(fs::AbstractVector{<:Real})
return Product(NegativeBinomial.(l.successes, l.invlink.(fs)))
end
(l::NegativeBinomialLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs))
2 changes: 1 addition & 1 deletion src/likelihoods/poisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ PoissonLikelihood(l=exp) = PoissonLikelihood(link(l))

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

(l::PoissonLikelihood)(fs::AbstractVector{<:Real}) = Product(Poisson.(l.invlink.(fs)))
(l::PoissonLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs))

0 comments on commit 932f516

Please sign in to comment.