Skip to content

Instantly share code, notes, and snippets.

@DominicBreuker
Last active April 16, 2018 20:01
Show Gist options
  • Save DominicBreuker/fb321f2e6aed834f5ec39ffbb8881d68 to your computer and use it in GitHub Desktop.
Save DominicBreuker/fb321f2e6aed834f5ec39ffbb8881d68 to your computer and use it in GitHub Desktop.
import tensorflow as tf
x_1 = tf.placeholder(tf.float32)
x_2 = tf.placeholder(tf.float32)
x_3 = tf.placeholder(tf.float32)
x = tf.Variable(2, name='x', dtype=tf.float32)
log_x = tf.log(x)
result = (x_1 + x_2 + x_3) * tf.square(log_x)
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(result)
init = tf.initialize_all_variables()
def optimize():
with tf.Session() as session:
session.run(init)
feed_dict = {
x_1: 1.0,
x_2: -1.0,
x_3: 1.0
}
print("starting at", "x:", session.run(x, feed_dict=feed_dict), "log(x)^2:", session.run(result, feed_dict=feed_dict))
for step in range(10):
session.run(train, feed_dict=feed_dict)
print(step, "x:", session.run(x, feed_dict=feed_dict), "log(x)^2:", session.run(result, feed_dict=feed_dict))
optimize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment