Created
June 16, 2016 16:30
-
-
Save DominicBreuker/c1082d02456c4186c1a5f77e12972b85 to your computer and use it in GitHub Desktop.
Simple example of gradient descent in 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
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
Anyone have this for tensorflow 2.0?