深度学习基本模块
Optimization
SGD
公式
while True:
dx = compute_gradient(x)
x -= learning_rate * dx
SGD+Momentum
公式:
vx = 0
while True:
dx = compute_gradient(x)
vx = rho*vx+dx
x -= learning_rate * vx
AdaGrad
AdaGrad就是在sgd的基础上除以一个项,使得在梯度变化快的地方减慢速度,在梯度变化慢的地方加快速度。但是随着梯度累加,速度会越来越慢,因此RMSProp被提出
grad_squared = 0
while True:
dx = compute_gradient(x)
grad_squared += dx*dx
x -= learning_rate * dx / (np.sqrt(grad_squared) + 1e-7)
RMSProp
grad_squared = 0
while True:
dx = compute_gradient(x)
grad_squared = decay_rate * grad_squared + (1 - decay_rate)*dx*dx
x -= learning_rate * dx/(np.sqrt(grad_squared)+1e-7)
Adam:Momentum+RMSProp
first_moment = 0
second_moment = 0
while True:
dx = compute_gradient(x)
first_moment = beta1 * first_moment + (1-beta1)*dx
second_moment = beta2 * second_moment + (1-beta2)*dx*dx
x -= learning_rate*first_moment /(np.sqrt(second_moment)+1e-7)
Batchnorm