Skip to content

What is the best way to get both the Jacobian and Hessian of a function? #14140

Answered by jakevdp
newalexander asked this question in Q&A
Discussion options

You must be logged in to vote

Sometimes the simplest approach is the best:

@jit
def jac_and_hess(x):
  return jax.jacfwd(f)(x), jax.hessian(f)(x)

The compiler in most cases is able to de-duplicate operations within a JIT-compiled function.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by newalexander
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants