All problems
BatchNorm Forward
Problem
Normalize vector x to zero mean and unit variance, then scale and shift:
y[i] = gamma * (x[i] - mean) / sqrt(var + eps) + beta
where var is the biased (population) variance. If var + eps is 0, treat the normalized value as 0.
Hint
The epsilon inside the square root keeps the division safe when variance is small.
Test cases
case 1
in: [[1,2,3],1,0,0]
expected: [-1.224744871391589,0,1.224744871391589]
case 2
in: [[1,1],1,0,0]
expected: [0,0]
case 3
in: [[1,2,3],2,1,0]
expected: [-1.4494897427831779,1,3.449489742783178]
case 4
in: [[0,2],1,1,1]
expected: [0.29289321881345254,1.7071067811865475]
Starter codePython
def batchnorm_forward(x, gamma, beta, eps):
# Your code here
pass4 test cases · run your code against them in the editor