-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
[WIP] initial implementation of sqrt_spd and inv_sqrt_spd #1145
Conversation
adj_jac_apply() and jacobian() seem to not work together
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.
Is there an assert happening in the sqrt_spd_tests that are causing this to puke? Is that why they're commented out?
There's a specialization for sqrt_spd, but is there a specialization for inv_sqrt_spd?
I reread the commit, looks like the answer is yes. I'll check this out in the afternoooooon. |
Yeah, I used to be doing the sqrt_spd test like the inv_sqrt_spd test,
which seemed fine. And then I added the adj_jac_apply stuff to rev mode
sqrt_spd and jacobian() would not cooperate anymore.
…On Thu, Mar 7, 2019 at 11:38 AM Ben Bales ***@***.***> wrote:
I reread the commit, looks like the answer is yes. I'll check this out in
the afternoooooon.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1145 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqr1LtC1jVjK0TwuFBz2IS1WqZksDks5vUUCagaJpZM4bjg9y>
.
|
Someone can kill the continuous integration tests for this. It is not ready to be merged and isn't necessary for 2.19.0. |
#1144) Rearranged some includes in stan/math/rev/mat.hpp to get rid of some type traits errors. Not sure why these were moved around. Might need moved back.
…stable/2017-11-14)
I wiggled around the types on the multiply_adjoint_jacobian. I dunno if I got the Kronecker stuff right. The sqrt_spd tests run now. There was also some includes that got shuffled in stan/math/rev/mat.hpp. I moved them back. I was getting weird type traits errors. |
The type of the thing passed to multiply_adjoint_jacobian in one of these functors matches the output type of operator(). The return type of multiply_adjoint_jacobian is a tuple of the input types to operator() (excluding is_var), so that's where the type stuff came from. |
stan/math/rev/mat/fun/sqrt_spd.hpp
Outdated
using Eigen::kroneckerProduct; | ||
using Eigen::MatrixXd; | ||
Eigen::MatrixXd output(K_, K_); | ||
Eigen::Map<const Eigen::VectorXd> map_input(adj.data(), adj.size()); |
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.
And if adj
is a MatrixXd
, how can it be mapped to a VectorXd
?
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.
That mapping is doing this (https://en.wikipedia.org/wiki/Vectorization_(mathematics)). I was just pattern-matching the eqs in the Stackoverflow link. I'm not really familiar with that. I was just double checking myself and Abhishek makes a note at the end of his post that the Jacobian he wrote is in terms of the vectorization, which I assume is the Wikipedia definition.
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.
Oh yeah fair warning, I was just kinda guessing on the math stuff to make things compile. Maybe add in a diagonal matrix test (with things that aren't 1 on the diagonal) so we know the answer and gradients and all just to make sure things are in the right direction.
stan/math/rev/mat/fun/sqrt_spd.hpp
Outdated
using Eigen::kroneckerProduct; | ||
using Eigen::MatrixXd; | ||
Eigen::MatrixXd output(K_, K_); | ||
Eigen::Map<const Eigen::VectorXd> map_input(adj.data(), adj.size()); | ||
Eigen::Map<Eigen::VectorXd> map_output(output.data(), output.size()); |
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.
Similar, how can map_output
be a Map<VectorXd>
but output
be a square MatrixXd
?
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.
And why is map_output
necessary? Can we just do the linear algebra to form output
and do std::make_tuple(output)
?
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.
The maps are just an eigen thing for mapping one data structure onto another. So the math happens in terms of the vectors like Abhishek had it but it just ends up in the right place in the matrices. I think it should be okay in terms of efficiency?
[CI skip]
…stable/2017-11-14)
Ah, OK. I had to print a bunch of stuff out but now I think I understand
what it is doing.
…On Thu, Mar 7, 2019 at 11:47 PM Ben Bales ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In stan/math/rev/mat/fun/sqrt_spd.hpp
<#1145 (comment)>:
> multiply_adjoint_jacobian(const std::array<bool, size> &needs_adj,
- const Eigen::VectorXd &adj) const {
+ const Eigen::MatrixXd &adj) const {
adj was getting vectorized to be K^2 x 1.
This is what the Map is doing. It's taking the KxK adj and then looking at
it likes it's a K^2x1 vector.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1145 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqg3bsdUbPX2_FejlIbZXbdH-QUHQks5vUetzgaJpZM4bjg9y>
.
|
@bbbales2 Is there a way to automate the "second check" mentioned before the conclusions section of https://people.maths.ox.ac.uk/gilesm/files/NA-08-01.pdf when utilizing |
Yeah, looks like it'd work (in a hand-wavy I didn't actually think through the code kinda way). Looks like something that would be handy in other places too. @bob-carpenter, you seen this? |
Would also be good in mix/
…On Fri, Mar 8, 2019 at 9:23 PM Ben Bales ***@***.***> wrote:
Is there a way to automate the "second check" mentioned before the
conclusions section of
https://people.maths.ox.ac.uk/gilesm/files/NA-08-01.pdf when utilizing
adj_jac_apply?
Yeah, looks like it'd work (in a hand-wavy I didn't actually think through
the code kinda way). Looks like something that would be handy in other
places too. @bob-carpenter <https://github.com/bob-carpenter>, you seen
this?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1145 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqjU4tjOulUffxCISSOFrCKL1ndCBks5vUxsJgaJpZM4bjg9y>
.
|
…into feature/matrix_sqrt
…gs/RELEASE_500/final)
I have not seen that. My matrix fu is weak. It says that if Tr(transpose(bar(C)) * dot(C) = Tr(transpose(bar(A)) * dot(A)) + Tr(transpose(bar(B)) * dot(B)) where I think the |
Closing due to inactivity. @bgoodri, I hope you get a chance to finish this. |
@bgoodri just pinging you in case you want to resurrect this. |
@bgoodri are you still working on this? |
I want to finish it, but haven't been able to deal with anything except R
packages and StanCon recently.
…On Thu, Jul 16, 2020 at 11:16 AM Steve Bronder ***@***.***> wrote:
@bgoodri <https://github.com/bgoodri> are you still working on this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1145 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZ2XKQFWENAOYW6QXVPBSTR34KWBANCNFSM4G4OB5ZA>
.
|
Thanks, @bgoodri. I'm going to convert it to a draft so we know it's not ready yet. |
@bgoodri, I'm going to close this with a |
Summary
This implements the symmetric square root of a positive definite matrix (
sqrt_spd
) and its inverse (inv_sqrt_spd
) and fixes #1144 .These call the
operatorSqrt
andoperatorInverseSqrt
methods of Eigen's self-adjoint eigensolver http://eigen.tuxfamily.org/dox/classEigen_1_1SelfAdjointEigenSolver.html .Tests
There are tests that the difference between an arbitrary positive definite matrix and its
sqrt_spd
multiplied by itself are zero, but there is an assert when evaluatingadj_jac_apply
that I am hoping @bbbales2 knows about. Same thing for the inverse square root.Side Effects
No
Checklist
Math issue Math does not have the matrix (inverse) square root #1144
Copyright holder: Trustees of Columbia University
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing (Not for the new tests)
./runTests.py test/unit
)make test-headers
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested