Elementwise Hessian
See original GitHub issueI’m super impressed with the progress you’ve been making! Autograd has the potential to save me and many others a lot of grief in terms of automatically differentiating scalar-valued functions while retaining broadcasting support. So right now I can do something like
from autograd import elementwise_grad
import numpy as np
def wrapper(args):
return energy(*args)
grad = elementwise_grad(wrapper)
inp = [1000*np.random.rand(10,1), np.random.rand(1,10), np.random.rand(1,10), np.random.rand(1,10), np.random.rand(1,10), np.random.rand(1,10)]
inp = np.broadcast_arrays(*inp)
%time gres = grad(inp)
print([i.shape for i in gres])
CPU times: user 301 ms, sys: 18 ms, total: 319 ms
Wall time: 300 ms
[(10, 10), (10, 10), (10, 10), (10, 10), (10, 10), (10, 10)]
And so each element of the returned list is the gradient of the objective function, with respect to the variable at that argument index, for all 100 combinations of input variables. So what I want now is the Hessian of my objective function, elementwise, meaning if my gradient is a (6, 10, 10) array, I want back a (6, 6, 10, 10) array with all the second derivatives including cross terms. Is this possible to do with Autograd?
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Online Newton Step Based on Pseudo-Inverse and ...
algorithms. Keywords Online learning · Elementwise multiplication · Pseudo inverse ·. Hessian matrix · Online convex optimization. 1 Introduction.
Read more >Modified online Newton step based on element wise ... - arXiv
The large data is a challenge in Newton method to store second order matrices as hessian. In this paper, we have proposed an...
Read more >Gradient and Hessian of - ( - 1 - 2 - x - T - Math Stack Exchange
This includes the Kronecker, Hadamard/elementwise, Frobenius/trace and dyadic/tensor products, as well as the Matrix/dot product. IFF the ...
Read more >Modified online Newton step based on elementwise ...
The large data are a challenge in the Newton method to store second-order matrices such as the hessian. In this article, we have...
Read more >Matrix Reference Manual: Matrix Calculus
... Differentials of Inverses, Trace and Determinant; Hessian matrices ... A • B the Hadamard or elementwise product; matrices and vectors A, B, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think it works. Here’s a cleaner
elementwise_hess
function for you, as well as a better test. (Of course, don’t trust me, please test it yourself!)It prints something like this (different every time due to the pseudorandom numbers generated):
Please reopen the issue if it’s not right!
Actually the above turned out not to be entirely true. There’s still a broadcasting hangup but it’s pretty easily solved. I’m working on a code writeup which I’ll share after I’ve kicked the tires a bit.