Registered Member
|
Hi all,
I have been testing the AutoDiffScalar (and AutoDiffJacobian) for future use and have been trying to see how well it optimizes. As I understand Eigen uses expression templates to get nicely optimized expressions, but I am wondering if this will happen for AutoDiffXX as well? The sub-expression that calculates the derivative seems to be hidden from Eigen within the AutoDiffScalar (expression templates should still operate on the AutoDiffScalar, but what about the internal calculations?). On another note, which is mostly my curiosity, is the team behind Eigen planning to officially support (basic) Automatic Differentiation? Eigen as it is is wonderful to use and if the AD module was supported (perhaps with reverse mode?) and had acceptable documentation, it would make Eigen even more complete. Or is the recommendation to mix Eigen and another AD library (though this seems dangerous from a performance POV, as mixing 2 libraries using expression templates usually does not mix well)? Thank you for your time! |
Moderator
|
Eigen::AutoDiffScalar (ADS) uses expressions templates to compute the derivatives. However, if you put an ADS inside an Eigen's Matrix or Vector, then expression template will operate at the level of Eigen's matrices only.
Then, Eigen::ADS performs pure forward differentiation without specific optimization except that all derivatives are computed taking advantage of Eigen's explicit unrolling and vectorizations. On the longer term, I'd like to redesign it so that fast matrix (and more generally tensor) algebra can be carried out for second (and higher) order derivatives. I'd also like that it better integrate within Eigen's vectors and matrices by leveraging matrix-level differential operators (e.g, for products, matrix inversion, eigenvalues, etc.). But that's unlikely to come soon as nobody has been working on it for several years.... |
Registered Member
|
Thank you for the update and your time!
Just out of curiosity, is there a reason for no one working on the AD part? Or perhaps it has just not been a priority? Sadly I am not able to gauge the scope, in terms of the work needed, of the changes you would like to do. |
Registered Member
|
I have a question about AutoDiffJacobian, while on the subject.
It seems to me that the types and definitions needed by AutoDiffJacobian are redundant to some degree, please look at the following example:
The part;
This should all be in the AutoDiffJacobian class. Is there a reason for it being this way, or is the code perhaps outdated? Thank you for your time! Edit - Possible change to AutoDiffJacobian.h Should play safe with old code as well, unless I missed something.
|
Moderator
|
You're probably right. I believe there are lot of other opportunities for API simplifications/clarifications.
Actually, the major concern is regarding expression template and non-initialized derivatives of arbitrary sizes. See this bug: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1281 |
Registered Member
|
Oh, that was an interesting problem.
To me it seems that the user should define the cost function properly, instead of setting a parameter as a constant. But I can see the usage case when it would be nice to just have the AD variable as a constant as well. I realized one thing with my update to the AutoDiffJacobian.h, I assume that the vectors are Nx1 which might not be desired. Anyways, is this update something that would be considered useful? I could submit a patch for this, to make it easier (less verbose) to use. |
Registered Member
|
I tested the AutoDiffJacobian with some different cases and found a few things missing when testing optimization and a generic Extended Kalman Filter implementation where you want the Jacobians automatically
I copied your file and updated it as per here: https://gitlab.com/korken89/autodiff-te ... Jacobian.h Maybe there is something there you would like to include? The changes I made should not affect old code. The changes are: * Removed unnecessary types from the Functor by inferring from its types * Removed the inputs() function reference, replaced with .rows() * Updated the forward constructor to use variadic templates * Added optional parameters to pass extra arguments to the Functor (parameters, control signals, etc) Thanks for a great tool! |
Moderator
|
This sounds nice. At this stage the best is probably that you clone Eigen in bitbucket, submit your changes in your repo, and send a pull-request. This will make easier to discuss the details.
A first issue is that "variadic templates" are c++11 only, so we should provide both: #if EIGEN_HAS_VARIADIC_TEMPLATES .. #else // old code #endif |
Registered Member
|
Okey!
I will make a pull-request tomorrow with the additional check for the templates. |
Registered Member
|
Hi, I have created the pull request:
https://bitbucket.org/eigen/eigen/pull- ... ve-to/diff |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]