-
-
Save anujonthemove/616200dca9046625630e6c8b40f1e24c to your computer and use it in GitHub Desktop.
Simple example of gradient descent in tensorflow
This file contains hidden or 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
import tensorflow as tf | |
x = tf.Variable(2, name='x', dtype=tf.float32) | |
log_x = tf.log(x) | |
log_x_squared = tf.square(log_x) | |
optimizer = tf.train.GradientDescentOptimizer(0.5) | |
train = optimizer.minimize(log_x_squared) | |
init = tf.initialize_all_variables() | |
def optimize(): | |
with tf.Session() as session: | |
session.run(init) | |
print("starting at", "x:", session.run(x), "log(x)^2:", session.run(log_x_squared)) | |
for step in range(10): | |
session.run(train) | |
print("step", step, "x:", session.run(x), "log(x)^2:", session.run(log_x_squared)) | |
optimize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment