-
-
Notifications
You must be signed in to change notification settings - Fork 216
Add jacobian function #747
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
Conversation
|
needs a test and a mention in the docs |
Co-authored-by: Carlo Lucibello <carlo.lucibello@gmail.com>
mcabbott
left a comment
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.
This would be good to have, but shouldn't it behave like gradient and return a 1-tuple for one argument? Then the extension to several arguments need not break anything.
|
Bump? Would be nice to have. |
|
If we split out using Flux: OneHotVector
"""
jacobian(f,x)
Construct the Jacobian of `f` where `x` is a real-valued array
and `f(x)` is also a real-valued array.
"""
function jacobian(f, x)
y, ∂f = Zygote.pullback(f,x)
n, m = length(x), length(y)
mapreduce(i -> ∂f(OneHotVector(i, m)), hcat, 1:m)
end |
Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
DhairyaLGandhi
left a comment
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 good, but needs tests
|
Also probably something that should hook into the forward mode |
|
Forward mode Jacobian should be kept as a separate call: which one is better depends on the application so both are required. What this should really connect to is SparseDiffTools for sparse Jacobians, but what will happen there is that SparseDiffTools will have a... more intense version that handles all of that extra machinery. |
|
This is due to it detecting sparsity patterns I assume? |
Co-authored-by: Mason Protter <mason.protter@icloud.com>
Well this could be made to accept a color vector even without SparseDiffTools. |
Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
Fixes #98