Skip to content

Instantly share code, notes, and snippets.

@acl21
Last active May 15, 2019 19:04
Show Gist options
  • Save acl21/686a9bc9ed34455c6fe618adb912e439 to your computer and use it in GitHub Desktop.
Save acl21/686a9bc9ed34455c6fe618adb912e439 to your computer and use it in GitHub Desktop.
Momentum-Based Gradient Descent
def do_momentum_gradient_descent():
w, b, eta = init_w, init_b, 1.0
prev_v_w, prev_v_b, gamma = 0, 0, 0.9
for i in range(max_epochs):
dw, db = 0, 0
for x,y in zip(X,Y):
dw += grad_w(w, b, x, y)
db += grad_b(w, b, x, y)
v_w = gamma * prev_v_w + eta*dw
v_b = gamma * prev_v_b + eta*db
w = w - v_w
b = b - v-b
prev_v_w = v_w
prev_v_b = v_b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment