As a network trains, every layer's weights shift — so the distribution each layer receives keeps moving under it. Batch norm pins that distribution in place: standardize each feature across the batch, then let the network learn its own scale and shift back.
For each feature j, across the batch:
1normalized = (x - mean[j]) / sqrt(variance[j] + epsilon)2output = gamma[j] * normalized + beta[j]
Task: write batch_norm(batch, gamma, beta, epsilon) where batch is a list of samples (each a list of features). Return the same shape, rounded to 4 decimal places.
n).epsilon goes inside the square root.
gammaandbetaexist because forcing every layer to zero mean and unit variance would be a real loss of expressiveness. Learning them back means the network can undo the normalization exactly when that helps — it just no longer has to.