RainerKuemmerle / g2o

g2o: A General Framework for Graph Optimization
3.1k stars 1.11k forks source link

Extracting Jacobian Matrix #340

Open B0Bftl opened 5 years ago

B0Bftl commented 5 years ago

Hello,

I am implementing a Conjugate Gradient linear solver with a special preconditioning. To use it, I need the Jacobian of the error vector, instead of the Hessian, which g2o passes to the solver. Right now I'm trying to work my way through g2o internals, to understand how to extract the jacobian.

My current idea is to adjust constructQuadraticForm() and write the current Jacobian block into the jacobian of the complete problem. Is is advisable, or is there an easier way to accomplish getting the jacobian to a linear solver? Has anyone done this before, or knows what adjustments are needed?

Thanks for your help

billamiable commented 3 years ago

Hi, I am also interested in this question. Have you ever succeeded in extracting the jacobian matrix from g2o? Thanks! Appreciate your help!

sjulier commented 3 years ago

I haven't done it myself. However, I'd hazard a guess you could build it up by iterating over all the edges, extracting all the Jacobians and using them to populate a sparse block matrix (or another sparse matrix type of your own choosing) whose number of rows and columns is that of the overall system. You'd need to use the Hessian indices from the vertices to specify the block coordinates in the sparse matrix. I think the buildSystem method does a similar kind of thing to construct both the Hessian and the Jacobian times the system information matrix.

B0Bftl commented 3 years ago

Hello, I made an implementation a couple of years ago. My Implementation of extraction of the jacobian is NOT efficient, but it worked good enough for me. I focused on the linear solver, so the jacobian was just a requirement i needed. You can take a look at my fork https://github.com/B0Bftl/g2o Maybe it's useful to you :)