Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
linesd committed Sep 12, 2019
2 parents 5fb81a5 + 6f1db66 commit 6eddb54
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion check_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def check_grad(f, X, e, args=()):
d : the norm of the difference divided by the norm of
the sum.
"""

y, dy = eval('f')(X, *list(args))
dy = dy.reshape(-1,1)
dh = np.zeros_like(X)
Expand All @@ -45,4 +46,4 @@ def check_grad(f, X, e, args=()):
print("Gradients vs finite difference:")
print(vec)

return np.linalg.norm(dh-dy)/np.linalg.norm(dh+dy)
return np.linalg.norm(dh-dy)/np.linalg.norm(dh+dy)
1 change: 1 addition & 0 deletions minimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def minimize(f, X, length, args=(), reduction=None, verbose=True):
x3 = max(min(x3, x4-INT*(x4-x2)), x2+INT*(x4-x2)) # don't accept too close
f3, df3 = eval('f')(X + x3 * s, *list(args))
df3 = df3.reshape(-1,1)

if f3 < F0:
X0 = X+x3*s; F0 = f3; dF0 = df3 # keep best values

Expand Down

0 comments on commit 6eddb54

Please sign in to comment.