-
Notifications
You must be signed in to change notification settings - Fork 166
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
Eigenvalues derivatives and status of the project #191
Comments
Hi @giacomo-b , This should be possible. I've started creating an example here, but noticed that some things will need to be implemented (e.g., Eigen uses Please try the idea below (it does not compile, but I think you should be able to implement missing parts to get it working): // C++ includes
#include <iostream>
#include <complex>
using namespace std;
// Eigen includes
#include <Eigen/Eigenvalues>
// autodiff include
#include <autodiff/forward/dual.hpp>
#include <autodiff/forward/dual/eigen.hpp>
using namespace autodiff;
using cxdual = complex<dual>;
MatrixXdual assembleMatrix(dual p, dual q)
{
return MatrixXdual({
{ 2.0*p, p*q },
{ 4.0*q, p*q }
});
}
int main()
{
dual p = 1.0;
dual q = 1.0;
MatrixXdual M;
seed(p);
M = assembleMatrix(p, q);
unseed(p);
auto lambdas_p = M.eigenvalues(); // for each complex a + ib in lambdas_p, a.grad and b.grad are ∂a/∂p and ∂b/∂p
seed(q);
M = assembleMatrix(p, q);
unseed(q);
auto lambdas_q = M.eigenvalues(); // for each complex a + ib in lambdas_q, a.grad and b.grad are ∂a/∂q and ∂b/∂q
} As to v1.0, this should be happening soon! |
Hi @allanleal, Thanks a lot for the detailed answer, I will try to implement this asap and will get back to you! |
Great, keep me posted!
…On Fri, Oct 29, 2021 at 6:14 PM giacomo-b ***@***.***> wrote:
Hi @allanleal <https://github.com/allanleal>,
Thanks a lot for the detailed answer, I will try to implement this asap
and will get back to you!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#191 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABMOING3AFJGCVN3KBIMHZ3UJLB7TANCNFSM5G6LLNJA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Hi @allanleal, thumbs up for autodiff, great piece of software!
I added a T cast operator (acting as a double cast usually) to the Edit: sorry, forgot to push the latest version |
Hi @mattarroz , a PR for this would be great! Thanks a lot for this. Does the same change you did for |
For the
It compiles and runs, however I didn't do any checks if the numbers are correct. For the Edit: Pushed the commit instead of just writing about it. |
Hey @mattarroz, I cloned your fork but this is still not working for me, even using The following doesn't compile: #include <Eigen/Eigenvalues>
#include <autodiff/forward/real.hpp>
#include <autodiff/forward/real/eigen.hpp>
using namespace autodiff;
MatrixXreal assembleMatrix(real p) {
return MatrixXreal({{2.0 * p, p * p},
{4.0 * p, p}});
}
int main() {
real p = 1.0;
MatrixXreal M;
seed(p);
M = assembleMatrix(p);
unseed(p);
auto lambdas_p = M.eigenvalues();
} The error is due to the eigensolver: Am I missing something? Thanks! |
Upon adding the cast operator and changing the Here is the full program I compiled for
Output:
Edit: Cleaned up the lambda expression a little |
@mattarroz thank you for taking the time, this is very helpful! It is now working, I am not sure what was going on before (did you change anything on the new branch?) You mentioned that you haven't validated the results, right? If so, I can proceed and do that. |
No big deal, you're welcome! I didn't change anything except for removing the
That would be great! |
Awesome, I'll post an update here as soon as I get that done. Thanks again! |
First of all, keep up the great work! I think this library is awesome and I'd like to contribute one day.
I have a matrix
M
whose entries depend on one or more input parameters, and I am computing the eigenvalues ofM
using spectra. What I would like to achieve using autodiff is the computation of the derivatives of these eigenvalues w.r.t. the input parameters (basically, their sensitivities). Since spectra supports custom types I thought it might be possible to have it work seamlessly with autodiff.The problem I am facing is that I don't know:
I went through the tutorials but didn't find anything similar.
The steps are:
p
M
as a function ofp
eigs
ofM
(done using spectra)eigs
w.r.t.p
(which of course go through the computation ofM
and the eigensolver)Simple example for one input parameter and a 2x2 matrix:
Do you think this is possible? If so, could you please show me how or point me to some related examples?
Also, quick question: what is the current status of the project? I noticed that the release version is not 1.0 yet, so I was wondering if there are any specific features in the pipeline that are currently not supported but you think are worth mentioning.
Thanks!
The text was updated successfully, but these errors were encountered: