Backpropagation is an algorithm used to train neural networks, based on the gradient of the loss function. It is used to compute the gradient of the loss with respect to the weights of the network w, which are then used to update the weights in the direction that minimizes the loss.
- Forward Propagation:
First, the output y of the network is computed for a given input x using forward propagation. This is done by multiplying the input x by the weight matrix w and passing the result through an activation function.
If f is the activation function, y=f(w⋅x).
- Loss Calculation:
The difference between the network's output y and the expected target t is determined by a loss function L. For example, in regression problems, the mean squared error is often used as the loss function.
The loss can be represented as L=L(t,y).
- Backward Propagation:
The gradient of the loss L with respect to the weights w is then computed using the chain rule of calculus. This is the backpropagation step.
The gradient can be represented as ∂w∂L=∂y.
- Weights update:
Finally, the weights w are updated by taking a step in the direction of the negative gradient. If η is the learning rate, the weights are updated as follows:
w=w−η⋅∂w∂L.
This process is repeated for several epochs or until the loss L is below a certain threshold.