Backpropagation is a fundamental algorithm used for training artificial neural networks. It computes the gradient of the loss function with respect to each weight by the chain rule, efficiently propagating errors backward through the network. This allows for the adjustment of weights to minimize the loss function, ultimately improving the performance of the neural network.
- Input Layer: The input data is fed into the network.
- Hidden Layers: Each layer performs computations using weights and biases to transform the input data.
- Output Layer: The final transformation produces the output, which is compared to the actual target to calculate the loss.
where f is the activation function, zᵢˡ is the net input of neuron i in layer l, wᵢⱼˡ is the connection weight between neuron j in layer l — 1 and neuron i in layer l, and bᵢˡ is the bias of neuron i in layer l.
- Compute Loss: Calculate the error (loss) using a loss function (e.g., Mean Squared Error, Cross-Entropy Loss).
- Error Propagation: Propagate the error backward through the network, layer by layer.
- Gradient Calculation: Compute the gradient of the loss with respect to each weight using the chain rule.
- Weight Update: Adjust the weights by subtracting the gradient multiplied by the learning rate.
- The loss function measures how well the neural network's output matches the target values. Common loss functions include:
- Mean Squared Error (MSE):
- Cross-Entropy Loss:
- For each weight 𝑤 in the network, the gradient of the loss L with respect to w is computed as:
- Weights are updated using the gradient descent algorithm:
git clone https://github.com/recodehive/machine-learning-repos/Backpropogation from scratch.git
pip install -r requirements.txt