Skip to content

Instantly share code, notes, and snippets.

@amueller
Created June 22, 2012 19:34
Show Gist options
  • Save amueller/2974649 to your computer and use it in GitHub Desktop.
Save amueller/2974649 to your computer and use it in GitHub Desktop.
check_grad
def check_grad(f, fprime, x0):
eps = 1e-5
approx = np.zeros(len(x0))
for i in xrange(len(x0)):
x0_ = x0.copy()
x0_[i] += eps
approx[i] = (f(x0_) - f(x0)) / eps
return np.linalg.norm(approx.ravel() - fprime(x0).ravel())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment