tensorflow example1

用tensorflow实现J(w)=w**2-10*w+25的微分结果

import numpy as np
import tensorflow as tf

w=tf.Variable(0,dtype=tf.float32)
cost=tf.add(tf.add(w**2,tf.multiply(-10,w)),25)
train=tf.train.GradiantDescentOptimizer(0.01).minimize(cost)

init=tf.global_variables_initializer()
session=tf.Session()
session.run(init)
print(session.run(w))

session.run(train)
print(session.run(w))

for i in range(1000):
session.run(train)
print(session.run(w))

posted @ 2018-01-15 18:55  cecelia  阅读(145)  评论(0编辑  收藏  举报