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

Incorrect gradient with cascaded reshape, linear equation solver operations #506

Closed
semihakbayrak opened this issue Feb 17, 2021 · 2 comments · Fixed by #481
Closed

Incorrect gradient with cascaded reshape, linear equation solver operations #506

semihakbayrak opened this issue Feb 17, 2021 · 2 comments · Fixed by #481

Comments

@semihakbayrak
Copy link

For the following function A(η::Array) = η[1:2]'*(reshape(η[2+1:end],(2,2))\η[1:2]), I observed a weird behaviour with ForwardDiff. Suppose that we want to evaluate the gradient at x = [2.0, 2.0, 1.0, 0.0, 0.0, 1.0]. Then ForwardDiff.gradient(A,x) returns the output [4.0, 4.0, -4.0, 0.0, -4.0, -4.0]. However, I would expect 4th element of the gradient to be -4.0. If I change the vector x slightly as [2.0, 2.0, 1.0, 0.00001, 0.00001, 1.0], then the gradient turns out to be correct and I get the output [3.999960000399996, 3.999960000399996, -3.9999200011999845, -3.9999200011999845, -3.9999200011999845, -3.9999200011999845].

@mcabbott
Copy link
Member

mcabbott commented Mar 1, 2021

I think this should be fixed by #481, can you confirm?

@semihakbayrak
Copy link
Author

Yes, indeed it resolves the issue. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants