# 计算图

### 什么是计算图

$$p = x + y$$

$$g = \ left(x + y \right)\ast z$$

## 计算图和反向传播

### 前向传递

$$x = 1，y = 3，z = -3$$

## 向后传递的目标

### 所需渐变

$$\frac {\ partial x} {\ partial f}，\ frac {\ partial y} {\ partial f}，\ frac { \ partial z} {\ partial f}$$

### 向后传球(反向传播)

$$\frac {\partial g} {\ partial g} = 1$$

$$\frac {\ partial g} {\ partial z} = p$$

$$\frac {\ partial g} {\ partial p} = z$$

$$\frac {\partial g} {\ partial z} = p = 4$$

$$\frac {\ partial g} {\ partial p} = z = -3$$

$$\ frac {\ partial g} {\partial x}，\ frac {\ partial g} {\ partial y}$$

$$\frac {\ partial g} {\ partial x} = \frac {\ partial g } {\ partial p} \ast \frac {\ partial p} {\partial x}$$

$$\frac {\ partial g} {\ partial y} = \frac {\ partial g} {\ partial p} \ast \frac {\ partial p} {\ partial y}$$

$$p = x + y\Rightarrow \frac {\ partial x} {\ partial p} = 1，\ frac {\ partial y} {\ partial p} = 1$$

$$\frac {\ partial g} {\ partial f} = \ frac {\ partial g} {\ partial p} \ast \frac {\ partial p} {\ partial x } = \ left(-3 \ right).1 = -3$$

$$\frac {\partial g} {\ partial y} = \frac {\ partial g} {\ partial p} \ast \frac {\ partial p} {\partial y} = \ left(-3 \ right).1 = -3$$

### 训练神经网络的步骤

• 对于数据集中的数据点x，我们使用x作为输入进行正向传递，并将成本c计算为输出.

• 我们从c开始向后传递，并计算图中所有节点的渐变.这包括代表神经网络权重的节点.

• 然后我们通过W = W  - 学习率*渐变来更新权重.

• 我们重复此过程，直到达到停止标准.