Created
November 12, 2018 04:19
-
-
Save ahmadyan/27c1195c7769fb5792f0d650680a3f79 to your computer and use it in GitHub Desktop.
Autodifferentiation of Rosenbrock function using Tensorflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = tf.Variable([1., 3.], tf.float32) | |
# Rosenbrock function | |
y = tf.add(tf.pow(tf.subtract(1.0, x[0]), 2.0), | |
tf.multiply(100.0, tf.pow(tf.subtract(x[1],tf.pow(x[0], 2.0)), 2.0)), 'y') | |
dx = tf.gradients(y, x)[0] | |
val = np.array([1, 3], dtype=np.float32) | |
with tf.Session() as sess: | |
sess.run(tf.global_variables_initializer()) | |
print (sess.run(y, {x: val}), sess.run(dx, {x: val})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment