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
Add LKJ bijector #125
Add LKJ bijector #125
Changes from 5 commits
a8c32a2
ba1ab40
a98ce04
74c902b
9c1742c
a1f8ec7
1c9b4ea
a52bdce
ead7e71
32cab00
1859672
1ef50b0
5ecaaee
bf41efc
52e74e4
be3dddf
476ca0f
bfd8d4f
dd0fade
38785f5
463acdc
5bdea37
131c502
4bbe656
8d2fc60
1120763
eec4de0
d9e0abf
1f24e65
09297e9
388fee0
72a16a8
d2908d5
8eb0686
9260c61
02a7d7e
d0984a4
10c2aed
fc6af4f
5ee5826
917605f
32497a1
c82e57c
c13d8a2
01250ce
de86456
5238efe
3a01d90
c86bcdf
79cbc5e
01db0f4
8cfc22d
9c9846b
9746499
7fb2675
bad759b
7710187
5228310
ea71cd7
a577b05
50b837d
b04252b
6c525a7
7e46a09
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.
Can we make use of
UpperTriangular
(which uses a view) instead of copying the matrix?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.
PDBijector
use a similar copy based implementation https://github.com/TuringLang/Bijectors.jl/blob/master/src/bijectors/pd.jl#L16 https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/triangular.jl#L164. Besides, I think I can just remove this function if https://github.com/TuringLang/Bijectors.jl/blob/master/test/transform.jl#L67 is not required.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 guess this should just be
and return
w' * w
instead. All these different functions with (IMO) not really descriptive names should be avoided if possible.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 guessing the reason why @yiyuezhuo has done this is to be able to define custom adjoints. Not possible to do so if we use
(b::Bijector)(x)
.So I think leaving the
(inv_)link_w_lkj
is fine, but redefine(inv_)link_lkj
to their correspondingb::Bijector
definitions.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.
For Zygote (or rather ChainRules nowadays) it's definitely possible to define adjoints for
(::Bijector)(...)
(see e.g. the support of Distances in Zygote). Does it not work for other AD backends?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 defined custom adjoint on
link_w_lkj
but not onlink_lkj
, solink_w_lkj
is just an "anonymous" code block requiring a custom gradient. A name is required, though not that descriptive.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.
Hmm I'm not sure how that relates to my comment? I just wanted to point out that in Zygote and ChainRules you can also define adjoints for functions such as
(ib::Inverse{<:CorrBijector})(y::AbstractMatrix{<:Real}) = ...
if needed - there is no need to introduce some functioninv_link_lkj
for this purpose.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.
Woah, really? If so I guess there's no need. Back when we started this overhaul of Bijectors, it was not possible to define adjoints for those kind of signatures. If that's not the case anymore, then I agree with your comments @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.
In Zygote you can write something like https://github.com/FluxML/Zygote.jl/blob/956575ee2c732dee25324b59ba43fbb471a52d9a/src/lib/distances.jl#L3-L10. However, we should definitely use ChainRules (https://www.juliadiff.org/ChainRulesCore.jl/dev/index.html#frule-and-rrule) which supports this as well.
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 mean, let's say these is a function
f
which needs AD:where
f1
is AD-friendly andf2
needs a custom adjoint. So I wrote an adjoint forf2
only. Are you suggesting to write an adjoint forf
and callpullback
forf1
in there to avoid adjoint forf2
? It's not clear to me.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.
It would be good to avoid this loop and the allocation of
z
if possible (haven't thought through if it is possible).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.
Are you suggesting
w = w .* z
? It's wrong since diagonal elements are not zeros. And z is used in 3 Reverse AD backends.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.
Probably this should just be
with the additional code from
link_lkj
below.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.
See above comments.
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 mean because of the adjoint? At least for Zygote that should work in exactly the same way, regardless of how you define the function.