Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

less code duplication #72

Merged
merged 3 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(l.(fs))
st-- marked this conversation as resolved.
Show resolved Hide resolved
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
Comment on lines -39 to -41
Copy link
Member Author

Choose a reason for hiding this comment

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

is this a bug then @devmotion ?

Copy link
Member Author

Choose a reason for hiding this comment

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

looks like this is assuming vectors of vectors (or vectors of tuples)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could the following work then:

(l::AbstractLikelihood)(fs::AbstractVector) = Product(map(l, fs))
(l::CategoricalLikelihood)(f::AbstractVector{<:Real}) = Categorical(l.invlink(f))

?

Copy link
Member

Choose a reason for hiding this comment

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

No, I don't think this is a bug. It is just the usual dispatch we also use in KernelFunctions - multiple samples form a vector, e.g., ColVecs, RowVecs or a vector of vectors. The single sample case is handled by the definition for AbstractVector{<:Real} above.

(l::CategoricalLikelihood)(fs::AbstractVector) = Product(l.(fs))
st-- marked this conversation as resolved.
Show resolved Hide resolved
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(l.(fs))
st-- marked this conversation as resolved.
Show resolved Hide resolved
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(l.(fs))
st-- marked this conversation as resolved.
Show resolved Hide resolved
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(l.(fs))
st-- marked this conversation as resolved.
Show resolved Hide resolved
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(l.(fs))
st-- marked this conversation as resolved.
Show resolved Hide resolved