symforce.jacobian_helpers module#

tangent_jacobians(expr, args)[source]#

Compute jacobians of expr, a Lie Group element which is a function of the Lie Group elements in args. Jacobians are derivatives in the tangent space of expr with respect to changes in the tangent space of the arg, as opposed to jacobians of the storage of either which could be trivially computed with sf.Matrix.jacobian or sf.Expr.diff.

This uses tangent_jacobians_first_order() internally.

Parameters:
  • expr (Any) – The final expression that should be differentiated

  • args (Sequence[Any]) – Sequence of variables (can be Lie Group elements) to differentiate with respect to

Returns:

The jacobian ``expr_D_arg`` for each arg in ``args``, where each ``expr_D_arg`` is of shapeMxN, with M the tangent space dimension of expr and N the tangent space dimension of arg

Return type:

List[Matrix]

tangent_jacobians_first_order(expr, args)[source]#

An implementation of tangent_jacobians() using first-order simplifications of retract and local_coordinates.

The interface is the same as for tangent_jacobians().

This is the method described in Section V.B.2 of the SymForce paper.

If expr = f(arg), then the jacobian we want to return is the derivative of local_coordinates(f(arg), f(retract(arg), t) with respect to tangent vector t at t = 0.

local_coordinates and retract, however, are often complicated functions which are hard to symbolically differentiate when composed with f. To avoid this issue, we replace them with first order approximations. The result is something which we can easily symbolically differentiate.

This works because the approximations become exact in the limit as t -> 0.

While the output returned is different than that returned by tangent_jacobians_chain_rule(), they are the same when evaluated numerically. tangent_jacobians_first_order (almost?) always returns expressions which require fewer ops after cse.

Parameters:
Return type:

List[Matrix]

tangent_jacobians_chain_rule(expr, args)[source]#

An implementation of tangent_jacobians() using the symbolic chain rule with tangent_D_storage and storage_D_tangent.

The interface is the same as for tangent_jacobians().

This is the method described in Section V.B.1 of the SymForce paper.

If expr = f(arg), then the jacobian we want to return is the derivative of local_coordinates(f(arg), f(retract(arg), t) with respect to tangent vector t at t = 0.

local_coordinates and retract, however, are often complicated functions which are hard to symbolically differentiate. To avoid this issue, we compute their derivatives ahead of time, then use the chain rule.

While the output returned is different than that returned by tangent_jacobians_first_order(), they are the same when evaluated numerically. tangent_jacobians_first_order() (almost?) always returns expressions which require fewer ops after cse.

Parameters:
Return type:

List[Matrix]