Skip to content

Instantly share code, notes, and snippets.

@timothyjlaurent
Last active June 20, 2016 19:46
Show Gist options
  • Save timothyjlaurent/9cb620c090a23841b08eb003bc9d4058 to your computer and use it in GitHub Desktop.
Save timothyjlaurent/9cb620c090a23841b08eb003bc9d4058 to your computer and use it in GitHub Desktop.
def twiddle(run, p, tol = 0.2): #Make this tolerance bigger if you are timing out!
############## ADD CODE BELOW ####################
dp = [1.0 for i in p]
best_err = run(p)
while sum(dp) > tol:
for i in range(len(p)):
p[i] += dp[i]
err = run(p)
if err < best_err:
best_err = err
dp[i] *= 1.1
else:
p[i] -= 2 * dp[i]
err = run(p)
if err < best_err:
best_err = err
dp[i] *= 1.1
else:
p[i] += dp[i]
dp[i] *= 0.9
# -------------
# Add code here
# -------------
return p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment