Last active
February 25, 2020 20:01
-
-
Save msaroufim/434523a594b7fac9794e6316a4e91cca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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