Skip to content

Instantly share code, notes, and snippets.

@acl21
Created September 26, 2019 19:29
Show Gist options
  • Save acl21/324e9f2b0b749702433c566aeeeb38b8 to your computer and use it in GitHub Desktop.
Save acl21/324e9f2b0b749702433c566aeeeb38b8 to your computer and use it in GitHub Desktop.
Line Search Gradient Descent
def do_line_search_gradient_descent():
w, b, etas, max_epochs = init_w, init_b, [0.1, 0.5, 1.0, 5.0, 10.0], 100
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)
min_error = 100000 #some large value
best_w, best_b = w, b
for eta in etas:
w = w - eta * dw
b = b - eta * db
if error(tmp_w, tmp_b) < min_error:
best_w = tmp_w
best_b = tmp_b
min_error = error(tmp_w, tmp_b)
w, b = best_w, best_b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment