梯度检验用于检验后向传播正常工作
一维数组模型梯度检验
前向传播,计算损失函数:
J = theta * x
后向传播:
dtheta = x
梯度检验:
首先计算gradapprox:
thetaplus = theta + epsilon
thetaminus = theta - epsilon
J_plus = forward_propagation(x, thetaplus)
J_minus = forward_propagation(x, thetaminus)
gradapprox = (J_plus - J_minus)/(2*epsilon)
然后计算grad:
grad = b