Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import numpy as np
  2. import tensorflow as tf
  3.  
  4. coefficients = np.array([[1.], [-10.], [25.]])
  5.  
  6. w = tf.Variable(0,dtype=tf.float32)
  7. x = tf.placeholder(tf.float32, [3,1])
  8. # cost = tf.add(tf.add(w**2,tf.multiply(-10.,w)),25)
  9. # cost = w**2 - 10*w + 25
  10. cost = x[0][0]*w**2 + x[1][0]*w + x[2][0]
  11. train = tf.train.GradientDescentOptimizer(0.01).minimize(cost)
  12.  
  13. init = tf.global_variables_initializer()
  14. session = tf.Session()
  15. session.run(init)
  16. print(session.run(w))
  17. #output: 0
  18.  
  19. session.run(train,feed_dict={x:coefficients})
  20. print(session.run(w))
  21. #output: 0.1
  22.  
  23. for i in range(1000):
  24. session.run(train,feed_dict={x:coefficients})
  25. print(session.run(w))
  26. #output: 4.99999
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement