Skip to content

Tip: debugging Jacobians

Tim McGrath edited this page Jan 8, 2021 · 3 revisions

This is still a work in progress. Things I wanted to add:

  • What is a Jacobian? What do its rows and columns represent?
  • How can we pull out the Jacobian from our factor graphs? Discuss sparse vs. dense form.
  • How can we test and debug that Jacobian? e.g., test rank.

A Jacobian is the matrix of partial derivatives to your optimization problem. In GTSAM (and, by virtue, bioslam), these Jacobians are properties of the factor graphs which represent the optimization problem--the constraints of the graph ("factors") are functions whose derivatives you need to know the guide the problem as it searches for a global minimum.

Inspecting your problem Jacobian can tell you a lot about its conditioning. This page details a few tips on how you can construct a Jacobian and inspect it.

Jacobian representation

In reduced linear form (as is commonly computed in GTSAM optimization routines), the Jacobian is an NxM matrix where N represents the dimensions of XXXX and M represents the dimensions of XXXX. Note that variable dimensionality is defined on the manifold, e.g., a gtsam:::Rot3 represents an SO(3) value whose dimensionality is (by definition) 3.

Debugging approach

In C++, say you have a gtsam::NonlinearFactorGraph called graph and a current state of gtsam::Values called vals. The following code will print the sparse version of the Jacobian to a .csv file for reading in MATLAB.

boost::shared_ptr<gtsam::GaussianFactorGraph> gfg=mygraph.linearize(myVals);
gtsam::Matrix m=gfg->sparseJacobian_();
gtsamutils::writeEigenMatrixToCsvFile("jacobian.csv",m);

This matrix is in sparse form.

Clone this wiki locally