jacobians and hessians for an application involving complex numbers
See original GitHub issueThe imaginary components of the derivatives of the following complex-valued functions are always zero in jax. In contrast, tensorflow returns a non zero imaginary component. I think this is a bug on the JAX side of things.
from jax.config import config; config.update("jax_enable_x64", True)
import jax
import jax.numpy as np
import numpy as onp
import tensorflow as tf
zs = 0.5j * np.arange(5) + np.arange(5)
print("input", zs)
def fn(z):
return np.cos(np.linalg.norm(z*2))
grad = jax.jacfwd(fn)
print("jax", fn(zs), grad(zs))
def tf_fn(z):
return tf.cos(tf.norm(z*2))
tf_zs = tf.convert_to_tensor(0.5j * onp.arange(5) + onp.arange(5))
tf_res = tf_fn(tf_zs)
sess = tf.Session()
grad_ys = tf.ones_like(tf_res)
grad_op = tf.gradients(tf_res, tf_zs, grad_ys=grad_ys)
print("tf", sess.run([tf_res, grad_op, grad_ys]))
input [0.+0.j 1.+0.5j 2.+1.j 3.+1.5j 4.+2.j ]
jax 0.9495740004388323 [0. +0.j 0.10240272+0.j 0.20480544+0.j 0.30720815+0.j
0.40961087+0.j]
tf [(0.9495740004388323+0j), [array([0. +0.j , 0.10240272+0.05120136j,
0.20480544+0.10240272j, 0.30720815+0.15360408j,
0.40961087+0.20480544j])], (1+0j)]
Issue Analytics
- State:
- Created 4 years ago
- Comments:29 (29 by maintainers)
Top Results From Across the Web
The Autodiff Cookbook - JAX documentation
A Hessian-vector product function can be useful in a truncated Newton Conjugate-Gradient algorithm ... JAX is great at complex numbers and differentiation.
Read more >Complexity of Gradients, Jacobians, and Hessians
This is far from true for Jacobians and Hessians, whose cost is very hard to ... This process which typically involves rational numbers...
Read more >Some Bounds on the Complexity of Gradients ... - CiteSeerX
Fortunately, much of the excellent research that has been conducted regarding the estimation of sparse Jacobians and Hessians by di erencing (see, e.g., ......
Read more >Some Bounds on the Complexity of Gradients, Jacobians, and ...
The new separability concepts facilitate the reduction of chromatic numbers and maximal row lengths, which determine the complexity of the ...
Read more >Jacobians and Hessians of Mean Value Coordinates for ...
In several applications though, it is desirable to enforce additional constraints involving the partial derivatives of the interpolated function, as done.
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
Again, thanks for all the help on this issue!
Confirmed bug in tensorflow: