Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when using powers? #116

Closed
jcockayne opened this issue Jun 3, 2016 · 1 comment
Closed

Bug when using powers? #116

jcockayne opened this issue Jun 3, 2016 · 1 comment

Comments

@jcockayne
Copy link

Hi guys,

I'm seeing a strange error when I use x**2 vs. x*x in a function I'm differentiating with autograd. I'm on v1.1.4. Reproducing code is below:

def fun(x):
    return np.exp(-(x*x))
d1 = autograd.grad(fun)
d2 = autograd.grad(d1)
d3 = autograd.grad(d2)
d4 = autograd.grad(d3)
# prints -0.0, -2.0, 0.0, 12.0
print d1(0.), d2(0.), d3(0.), d4(0.)

def fun(x):
    return np.exp(-(x**2))
d1 = autograd.grad(fun)
d2 = autograd.grad(d1)
d3 = autograd.grad(d2)
d4 = autograd.grad(d3)
# prints -0.0, -2.0, nan, nan
print d1(0.), d2(0.), d3(0.), d4(0.)

Any idea why this could be happening?

Cheers!
Jon

@mattjj
Copy link
Contributor

mattjj commented Jun 3, 2016

Good catch. I think it's because the formula used the call to anp.power.defgrad is not valid at zero, but I am afk and can't check right now. If that's the case then the fix would be to test if y is 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants