A Python implementation showing one complete step of gradient descent with backpropagation. This code demonstrates how neural networks learn by computing gradients and updating parameters.
- Forward propagation through two layers
- Computation of gradients using backpropagation
- One step of gradient descent parameter updates
-
Forward Pass:
- Input → Hidden Layer (with sigmoid activation)
- Hidden Layer → Output
- Loss Calculation
-
Backward Pass (Backpropagation):
- Computing gradients using chain rule
- Starting from loss and working backwards
- Computing gradients for all weights and biases
-
Parameter Updates:
- Using gradient descent: θ_new = θ - α∇θ
- Where α is learning rate and ∇θ is the gradient
- Forward: z = wx + b
- Activation: sigmoid(z) = 1/(1 + e^(-z))
- Loss: L = (y - ŷ)²
- Gradients: Computed using chain rule
- Additional notes behind the mathematics can be found in Math.pdf
import numpy as np