Skip to content

Instantly share code, notes, and snippets.

@SuvroBaner
Created December 31, 2019 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SuvroBaner/a9273ef0c73f959ad795d1776c389737 to your computer and use it in GitHub Desktop.
Save SuvroBaner/a9273ef0c73f959ad795d1776c389737 to your computer and use it in GitHub Desktop.
import numpy as np
import tensorflow as tf
coefficients = np.array([[1.], [-10.], [25.]])
w = tf.Variable(0, dtype = tf.float32) # initializing the parameter as 0.
x = tf.placeholder(tf.float32, [3, 1]) # defining x as a 3x1 column vector
cost = x[0][0]*w**2 + x[1][0]*w + x[2][0]
train = tf.train.GradientDescentOptimizer(0.01).minimize(cost)
init = tf.global_variables_initializer()
session = tf.Session()
session.run(init)
for i in range(1000):
session.run(train, feed_dict = {x : coefficients})
print(session.run(w))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment