|
g2o
|
Implementation of Automatic Differentiation for edges in g2o. More...
#include <auto_differentiation.h>
Public Types | |
| template<int EdgeDimension, int VertexDimension> | |
| using | ADJacobianType = typename Eigen::Matrix< double, EdgeDimension, VertexDimension, Eigen::RowMajor > |
| type for the Jacobians during AD | |
Static Public Member Functions | |
| static void | computeError (Edge *that) |
| helper for computing the error based on the functor in the edge | |
| static void | linearize (Edge *that) |
Static Protected Member Functions | |
| template<std::size_t... Ints> | |
| static void | computeErrorNs (Edge *that, std::index_sequence< Ints... >) |
| packed version to call the functor that evaluates the error function | |
| template<std::size_t... Ints> | |
| static void | linearizeOplusNs (Edge *that, std::index_sequence< Ints... >) |
| template<typename A , typename B > | |
| static EIGEN_STRONG_INLINE void | assign (const Eigen::MatrixBase< A > &a, const Eigen::MatrixBase< B > &b) |
| helper function to perform a = b | |
Implementation of Automatic Differentiation for edges in g2o.
This class implements an interface to Automatic Differentiation, see, for example, https://en.wikipedia.org/wiki/Automatic_differentiation for the idea behind it.
Pre-condition: Your estimate type in your vertices provides a method called data() which returns a raw pointer to the data representing the estimate. This can, for example, be achieved by using Eigen's vector underneath as the container for the data. An SE2 vertex might look as follows
class VertexFlatSE2 : public g2o::BaseVertex<3, g2o::Vector3> { public: virtual void setToOriginImpl() { _estimate.setZero(); } virtual void oplusImpl(const double* update) { _estimate += Eigen::Map<const g2o::Vector3>(update); _estimate(2) = g2o::normalize_theta(_estimate(2)); } virtual bool read(std::istream&) { return false; } virtual bool write(std::ostream&) const { return false; } };
If this is not the case for your edge, then you can provide a functor object as second template argument which does this conversion for you. See EstimateAccessor above. Such a functor has to provide a templatized function data(Edge*) that returns the raw-pointer to the underlying data. The raw-pointer should point to memory that is either owned by the functor itself or is owned by the edge, the vertex, or sth else. It has to to be valid throughout the lifetime of the functor object. See, for example, the functor EstimateAccessorGet which uses the potentially implemented method getEstimateData() on vertices to obtain the estimate in a raw array. This array is then buffered and passed on to compute the error or its Jacobian.
To use automatic differentiation on your own edge you need to implement the following steps:
Example integration: g2o/examples/bal/bal_example.cpp This provides a self-contained example for integration of AD into an optimization problem.
Further documentation on the underlying implementation: Jet: EXTERNAL/ceres/jet.h AutoDiff: EXTERNAL/ceres/autodiff.h
Definition at line 155 of file auto_differentiation.h.
| using g2o::AutoDifferentiation< Edge, EstimateAccess >::ADJacobianType = typename Eigen::Matrix<double, EdgeDimension, VertexDimension, Eigen::RowMajor> |
type for the Jacobians during AD
Definition at line 159 of file auto_differentiation.h.
|
inlinestaticprotected |
helper function to perform a = b
Definition at line 253 of file auto_differentiation.h.
Referenced by g2o::AutoDifferentiation< Edge, EstimateAccess >::linearizeOplusNs().
|
inlinestatic |
helper for computing the error based on the functor in the edge
Definition at line 164 of file auto_differentiation.h.
References g2o::AutoDifferentiation< Edge, EstimateAccess >::computeErrorNs().
|
inlinestaticprotected |
packed version to call the functor that evaluates the error function
Definition at line 186 of file auto_differentiation.h.
Referenced by g2o::AutoDifferentiation< Edge, EstimateAccess >::computeError().
|
inlinestatic |
Linearize (compute the Jacobians) for the given edge. Stores the Jacobians in the members of the edge. A vertex that is fixed will obtain a Jacobian with all elements set to zero. In the particular case that all vertices are fixed, we terminate early and do not start evaluation of the Jacobian.
Definition at line 177 of file auto_differentiation.h.
References g2o::AutoDifferentiation< Edge, EstimateAccess >::linearizeOplusNs().
|
inlinestaticprotected |
packed version of the code to linearize using AD
Definition at line 198 of file auto_differentiation.h.
References g2o::AutoDifferentiation< Edge, EstimateAccess >::assign(), and g2o::ceres::internal::AutoDifferentiate().
Referenced by g2o::AutoDifferentiation< Edge, EstimateAccess >::linearize().