Advertisement
Guest User

Untitled

a guest
May 25th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. def do_nesterov_accelerated_gradient_descent():
  2. w, b, eta = init_w, init_b, 1.0
  3. prev_v_w, prev_v_b, gamma = 0, 0, 0.9
  4. for i in range(max_epochs):
  5. dw, db = 0, 0
  6. # do partial update
  7. v_w = gamma * prev_v_w
  8. v_b = gamma * prev_v_b
  9. for x,y in zip(X,Y):
  10. # calculate gradients after partial update
  11. dw += grad_w(w, b, x, y)
  12. db += grad_b(w, b, x, y)
  13. # now do the full update
  14. v_w = gamma * prev_v_w + eta*dw
  15. v_b = gamma * prev_v_b + eta*db
  16. w = w - v_w
  17. b = b - v-b
  18. prev_v_w = v_w
  19. prev_v_b = v_b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement