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

less code duplication #72

merged 3 commits into from
Mar 28, 2022

Conversation

st--
Copy link
Member

@st-- st-- commented Mar 25, 2022

Less chance for mistakes / less work when changing anything later on.:)

@codecov
Copy link

codecov bot commented Mar 25, 2022

Codecov Report

Merging #72 (8df1113) into master (21aa15f) will decrease coverage by 0.18%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #72      +/-   ##
==========================================
- Coverage   95.06%   94.87%   -0.19%     
==========================================
  Files           9        9              
  Lines          81       78       -3     
==========================================
- Hits           77       74       -3     
  Misses          4        4              
Impacted Files Coverage Δ
src/likelihoods/bernoulli.jl 100.00% <100.00%> (ø)
src/likelihoods/categorical.jl 100.00% <100.00%> (ø)
src/likelihoods/exponential.jl 100.00% <100.00%> (ø)
src/likelihoods/gamma.jl 100.00% <100.00%> (ø)
src/likelihoods/negativebinomial.jl 100.00% <100.00%> (ø)
src/likelihoods/poisson.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21aa15f...8df1113. Read the comment docs.

src/likelihoods/bernoulli.jl Outdated Show resolved Hide resolved
src/likelihoods/categorical.jl Outdated Show resolved Hide resolved
src/likelihoods/exponential.jl Outdated Show resolved Hide resolved
src/likelihoods/gamma.jl Outdated Show resolved Hide resolved
src/likelihoods/negativebinomial.jl Outdated Show resolved Hide resolved
src/likelihoods/poisson.jl Outdated Show resolved Hide resolved
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Copy link
Member

@theogf theogf left a comment

Choose a reason for hiding this comment

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

Can't we have a unique

(l::AbstractLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs))

I think we need 1.6 for this feature but we are already bounding to this version so that seems like a valid thing.

@devmotion
Copy link
Member

Can't we have a unique

That's not always correct though so I'm not sure if it's good to define it automatically. Eg, it's incorrect for the CategoricalLikelihood.

@st--
Copy link
Member Author

st-- commented Mar 27, 2022

I agree it's not going to be valid for all likelihoods, but we could define an AbstractScalarLikelihood (or something like that) for which

(l::AbstractScalarLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs))

would be valid and define it thus?

@st--
Copy link
Member Author

st-- commented Mar 28, 2022

That's not always correct though so I'm not sure if it's good to define it automatically. Eg, it's incorrect for the CategoricalLikelihood.

Hm, for CategoricalLikelihood it's currently defined the same way as for all the others. Is this a bug in the code then ?

Comment on lines -39 to -41
function (l::CategoricalLikelihood)(fs::AbstractVector)
return Product(Categorical.(l.invlink.(fs)))
end
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.

Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

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

I'm happy that this is an improvement over the existing implementations, so I'm happy for it to be merged.

@st-- I'm also happy for this to be rolled in with the 0.4 release associated with #70 as discussed offline, but please only merge this when you're about to merge that PR also, so that we don't leave master hanging with unreleased changes.

@st-- st-- merged commit 932f516 into master Mar 28, 2022
@st-- st-- deleted the st/less-code-duplication branch March 28, 2022 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants