artivis / manif

A small C++11 header-only library for Lie theory.
https://artivis.github.io/manif
MIT License
1.46k stars 239 forks source link

Confused by Ceres Jacobian Explanation #283

Closed willat343 closed 8 months ago

willat343 commented 8 months ago

Hi guys. I've been working with manif and ceres together, and am trying to understand how Ceres composes its Jacobians as described on this page of the documentation https://artivis.github.io/manif/cpp/md_pages_cpp__on_the_use_with__ceres.html

In particular, I'm working towards implementing analytic jacobians, and am first trying to understand how this works with Lie groups/manifolds.

The key confusion for me comes from the Jacobian defined in Equation (3). From the notation used there, it appears that it should be equal to the right Jacobian, using equation (81) from your paper. However instead it is a matrix of size RepresentationSize * TangentSize (consistent with http://ceres-solver.org/nnls_modeling.html#manifold where they use "AmbientSize" for RepresentationSize, e.g. 4 x 3 for a quaternion manifold).

Equation (1) also looks strange, as J_w^e = De/Dx differs from how you defined the notation in the paper.

In new Ceres residuals, we have to implement the Jacobian of Equation (2). However what exactly is J_{x oplus w}^e? Is e f(x oplus w) and hence this just simplifies to Jx^{f(x)}? Or is e = f(x), in which case I'm lost at how to compute J{x oplus w}^{f(x)}. From the Ceres documentation, and the way the chain rule is written in Equation (4), would the dimensions be ResidualSize * RepresentationSize. So we must compute the Jacobian with respect to the parameters of the underlying representation?

Any clarification of this documentation would be greatly appreciated.

artivis commented 8 months ago

Hi @willat343,

Sorry for the ceres-related doc page, it isn't great, the notation isn't methodical and it should be revamped.

The tldr is that manif analytic jacobians aren't compatible with ceres.

Altho I'm not familiar with ceres 2.+, a quick look seems to indicate that nothing change from 1.x in the sense that ceres expects Jacobians to be expressed with respect to the underlying representation vector (AmbientSize) while manif express them w.r.t a perturbation on the tangent space (TangentSize). If I re-use the notation from the ceres-related doc page,

J_w^e = J_{x+w}^e x J_w^{x+w}
(ResidualSize,TangentSize) = (ResidualSize,AmbientSize) x (AmbientSize,TangentSize)

This notation is bad as it suggests that all Jacobians are w.r.t the tangent space which is not the case as you can see from the matrix dimensions.

This being said, manif supports ceres autodiff. If you're looking for analytic Jacobians to be used with ceres, you could consider using Sophus.

You may be interested in having a look at the following issues for further reading: https://github.com/ceres-solver/ceres-solver/issues/387 & https://github.com/ceres-solver/ceres-solver/issues/615.

willat343 commented 8 months ago

Thank you for your explanation @artivis, and for those links, that actually does help a bit. Happy to close this for now.