-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
There was a problem hiding this 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.
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 |
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? |
Hm, for |
function (l::CategoricalLikelihood)(fs::AbstractVector) | ||
return Product(Categorical.(l.invlink.(fs))) | ||
end |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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))
?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Less chance for mistakes / less work when changing anything later on.:)