# TensorFlow中的梯度下降函数的疑问

``````import tensorflow as tf
sess = tf.Session()

a = tf.Variable(tf.constant(0.))
x_val = 5.
x_data = tf.placeholder(dtype=tf.float32)
multiplication = tf.multiply(a, x_data)
loss = tf.square(tf.subtract(multiplication, 50.))
init = tf.global_variables_initializer()
sess.run(init)
train_step = my_opt.minimize(loss)
print('Optimizing a Multiplication Gate Output to 50.')
for i in range(10):
sess.run(train_step, feed_dict={x_data: x_val})
a_val = sess.run(a)
mult_output = sess.run(multiplication, feed_dict={x_data: x_val})
print(str(a_val) + ' * ' + str(x_val) + ' = ' + str(mult_output))

``````

Optimizing a Multiplication Gate Output to 50.
5.0 * 5.0 = 25.0
7.5 * 5.0 = 37.5
8.75 * 5.0 = 43.75
9.375 * 5.0 = 46.875
9.6875 * 5.0 = 48.4375
9.84375 * 5.0 = 49.2188
9.92188 * 5.0 = 49.6094
9.96094 * 5.0 = 49.8047
9.98047 * 5.0 = 49.9023
9.99023 * 5.0 = 49.9512

a := a + alpha (y - a*x)x
= 0 + 0.01 ( 50 - 0 * 5) 5 = 2.5

a := a + 2 * alpha (y -a*x)x， 这样第二步a才会变成7.5

• 写回答

#### 2条回答默认 最新

• silent56_th 2017-12-23 15:11
关注

对平方差求导，指数项下来就是那个2

本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

#### 悬赏问题

• ¥15 磁盘分区错误出现压缩包怎么找回损失空间
• ¥15 Dijkstra 算法的堆优化方法
• ¥15 师哥师姐们，如何帮我下载一下python？
• ¥15 Office版本升级，Oracle连接报错
• ¥20 利用python搜索PDF文件中是否存在1
• ¥15 ImportPathMismatchError
• ¥15 滤波器这个效果是对的么
• ¥15 c++静态函数的静态函数参数问题
• ¥15 51单片机数码管显示有问题
• ¥30 delphi 10 seattle 调https