
















一. 前向传播
- 输入层->隐含层
的输入: 
的输出: 
的输入: 
的输出: 
2. 隐含层->输出层
的输入: 
的输出: 
的输入: 
的输出: 
二. 反向传播
- 损失函数(均方误差):

- 隐含层->输出层的权值
更新
以 为例, 用整体误差对
求偏导


3. 输入层->隐含层的权值
更新
以 为例, 用整体误差对
求偏导





三. TensorFlow代码实现
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
import numpy as np
import tensorflow as tf
sess = tf.InteractiveSession()
x_input = tf.constant([[0.05, 0.10]], dtype=tf.float32)
y_input = tf.constant([[0.01, 0.99]], dtype=tf.float32)
biases1 = tf.Variable(tf.constant([[0.35, 0.35]], dtype=tf.float32))
weights1 = tf.Variable(tf.constant([[0.15, 0.25], [0.20, 0.30]], dtype=tf.float32))
biases2 = tf.Variable(tf.constant([[0.60, 0.60]], dtype=tf.float32))
weights2 = tf.Variable(tf.constant([[0.40, 0.50], [0.45, 0.55]], dtype=tf.float32))
h_layer1 = tf.nn.sigmoid(tf.matmul(x_input, weights1) + biases1)
y_output = tf.nn.sigmoid(tf.matmul(h_layer1, weights2) + biases2)
loss_mse = tf.reduce_mean(tf.square(y_input - y_output))
tf.global_variables_initializer().run()
for step in range(401):
tf.train.GradientDescentOptimizer(0.50).minimize(loss_mse).run()
if step % 20 == 0:
print(step, y_output.eval())
sess.close()
本文介绍了神经网络的前向传播过程,从输入层到隐含层再到输出层的计算步骤。接着详细阐述了反向传播中的损失函数和权重更新,特别是针对隐含层到输出层以及输入层到隐含层的权值更新策略。最后,文章通过TensorFlow展示了神经网络的代码实现。
12万+

被折叠的 条评论
为什么被折叠?



