Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix
logpdf_grad
for BroadcastedNormal. #433Fix
logpdf_grad
for BroadcastedNormal. #433Changes from 3 commits
56cdef4
76e7f98
a7ff2d7
8bc4d89
8d79f46
0d37660
e712c71
b35f326
6dc4492
127e07c
677282a
36e8c1f
8e50e66
f7cc6d9
ab66a2b
7159b11
f9ac944
e08dd07
c4573fc
5d3f192
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Why this change?
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 actually a little unsure how to fix these tests. It seems that the first argument of
isapprox
is a zero-dimensional array (which I believe is the expected behavior) but the second argument is aFloat64
, which causes Julia to complain that no method ofisapprox
matches the given argument types. Any suggestions on how to fix this?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.
After investigating this a bit, I think it boils down to JuliaLang/julia#28866, which I consider to be a bug in Julia. Yes -- in the version of the code before this PR, both the LHS and the RHS should be 0-dimensional arrays. For the RHS, the issue appears to be that these lines
Gen.jl/test/runtests.jl
Lines 22 to 23 in d79aded
do
::Aray{T,0} .+ ::T
and::Aray{T,0} .- ::T
, which should give an::Array{T,0}
but due to JuliaLang/julia#28866 gives a scalar. So the LHS of the./
on the following line should have anArray{T,0}
as thei
th argument tof
, thus (sincebroadcast = true
) should output anArray{T,0}
, and consequently the division operation should be::Array{T,0} ./ ::T
which should output anArray{T,0}
, but that is not what happens.I think the cleanest way to fix this is to add a workaround to the (test-only) function
finite_diff
so that it handles zero-dimensional array valued arguments correctly.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 currently drafting this.)
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.
Aha, in addition to the above, the function
f
being supplied tofinite_diff
does not satisfy the requirements in its docstring: it takes array-valued arguments, but is not the broadcast of a function that takes scalar-valued arguments (i.e.logpdf_grad(vector-valued distribution parameters)
is not a broadcast of a bunch oflogpdf_grad(scalar-valued distribution parameters)
's). So I guess we should add a variant offinite_diff
that has the semantics we need.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.
Yeah, I think to properly test this, we will need a more general
finite_diff
function or use an autodiff library implementation as a reference.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.
you clearly trust autodiff more than I do 🙂