Created
December 31, 2019 07:07
-
-
Save SuvroBaner/a9273ef0c73f959ad795d1776c389737 to your computer and use it in GitHub Desktop.
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 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