Created
June 22, 2012 19:34
-
-
Save amueller/2974649 to your computer and use it in GitHub Desktop.
check_grad
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 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