Skip to content

Instantly share code, notes, and snippets.

@msaroufim
Last active February 25, 2020 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msaroufim/434523a594b7fac9794e6316a4e91cca to your computer and use it in GitHub Desktop.
Save msaroufim/434523a594b7fac9794e6316a4e91cca to your computer and use it in GitHub Desktop.
def step(v, direction, step_size):
return [v_i + step_size * direction_i for v_i, direction_i in zip(v, direction)]
def sum_of_squares_gradient(v):
return [2 * v_i for v_i in v]
v = random point
tolerance = 0.00001
while True:
gradient = sum_of_squares_gradient(v)
next_v = step(v, gradient, -0.01)
if distance(next_v, v) < tolerance:
break
v = next_v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment