jithin pradeep Cognitive Research Scientist | AI and Mixed reality Enthusiast

Jacobian matrix

What is Jacobian matrix?

Significance

To be continued (…)

import tensorflow as tf
import numpy as np
N = 3

tf.reset_default_graph()

x = tf.placeholder(tf.float32, shape=[N])
y = x ** 2 / 2

y_list = tf.unstack(y)
jacobian_list = [tf.gradients(y_, x)[0] for y_ in y_list]  
# list [grad(y0, x), grad(y1, x), ...]
jacobian = tf.stack(jacobian_list)

sess = tf.Session()

x_val = np.random.randn(N)
jacobian_val = sess.run(jacobian, feed_dict={x:x_val})

print(x_val)
print(jacobian_val)

[ 0.31984693 -0.26663835 -0.14765843]
[[ 0.31984693 -0.         -0.        ]
 [ 0.         -0.26663837 -0.        ]
 [ 0.         -0.         -0.14765844]]