-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
Implemented reverse mode for symmetric eigendecomposition #1878
Implemented reverse mode for symmetric eigendecomposition #1878
Conversation
…4.1 (tags/RELEASE_600/final)
…vanYashchuk/math into feature/issue-989-rev-mat-eig2
Thanks! The code for this looks beautiful and is well-documented and references. I don't quite feel up to reviewing the linear algebra here or the implications for matrix autodiff. I'm totally happy to sign off on the code, especially as we have generic autodiff tests in place already. |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! Looks good, just a couple simplifications. For the eigenvalues
function, you don't need to make eigenvector varis (there won't be any vars created for these eigenvectors). Same for the eigenvectors
function.
A little bit of math disappears from the chains as well (the adjoints of the eigenvectors for the eigenvalues
function will be zero).
@bbbales2, thank you for the review! I think I've addressed the comments. |
Thanks! Yeah the code looks great. I was just having a look at the original issue: #1803 I'm not convinced we want to do the full matrix of derivatives, if that makes sense. Can you take a look at what I posted over there? I kinda think the lower triangle is the way to go, as weird as that may seem. |
And by this argue back and tell me I'm wrong if I'm wrong I'm just trying to square it all in my head so I know what to do going forward. |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
I'm gonna just merge this once the tests pass. I didn't notice they were hung up. |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
@rok-cesnovar this is good to go. I made a change to how the tests are organized (just moved code from mix to rev in tests here), so I'm just leaving this to you to check I didn't do anything obviously silly and merge. |
That change look ok to me. The test tests rev so that is where it should be. Merging. |
Summary
This PR implements reverse mode differentiation for
stan::math::eigenvectors_sym
andstan::math::eigenvalues_sym
.Tests
There are already tests for AD with
eigenvalues_sym
andeigenvectors_sym
.I have added a test that checks the derivative of
sum(log(eigenvalues_sym(A)))
. The derivative should be equal to the inverse of A. This test fails on the currentdevelop
branch. See #1803.Side Effects
Currently, derivatives of
eigenvalues_sym
return lower triangular matrix.I think that the correct derivative matrix should be symmetric and not lower triangular. This also affects any other function involved in the computation and the calculated autodiff derivative is not correct anymore. See #1803.
Release notes
Reverse mode differentiation of
stan::math::eigenvectors_sym
andstan::math::eigenvalues_sym
now returns symmetric matrix (previously lower triangular).Checklist
Math issues Functions in prim/mat/fun that could use custom reverse mode autodiff implementations #989, Wrong derivatives for cholesky and symmetric eigen decomposition #1803
Copyright holder: Ivan Yashchuk
the basic tests are passing
./runTests.py test/unit
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested