当前位置:   article > 正文

GTSAM中ISAM2和IncrementalFixedLagSmoother说明

incrementalfixedlagsmoother

1. 参数

1.1. 配置参数ISAM2Params

  1. struct ISAM2Params {
  2. typedef boost::variant<ISAM2GaussNewtonParams, ISAM2DoglegParams>
  3. OptimizationParams; ///< Either ISAM2GaussNewtonParams or
  4. ///< ISAM2DoglegParams
  5. typedef boost::variant<double, FastMap<char, Vector> >
  6. RelinearizationThreshold; ///< Either a constant relinearization
  7. ///< threshold or a per-variable-type set of
  8. ///< thresholds
  9. /** Optimization parameters, this both selects the nonlinear optimization
  10. * method and specifies its parameters, either ISAM2GaussNewtonParams or
  11. * ISAM2DoglegParams. In the former, Gauss-Newton optimization will be used
  12. * with the specified parameters, and in the latter Powell's dog-leg
  13. * algorithm will be used with the specified parameters.
  14. */
  15. OptimizationParams optimizationParams;
  16. /** Only relinearize variables whose linear delta magnitude is greater than
  17. * this threshold (default: 0.1). If this is a FastMap<char,Vector> instead
  18. * of a double, then the threshold is specified for each dimension of each
  19. * variable type. This parameter then maps from a character indicating the
  20. * variable type to a Vector of thresholds for each dimension of that
  21. * variable. For example, if Pose keys are of type TypedSymbol<'x',Pose3>,
  22. * and landmark keys are of type TypedSymbol<'l',Point3>, then appropriate
  23. * entries would be added with:
  24. * \code
  25. FastMap<char,Vector> thresholds;
  26. thresholds['x'] = (Vector(6) << 0.1, 0.1, 0.1, 0.5, 0.5, 0.5).finished();
  27. // 0.1 rad rotation threshold, 0.5 m translation threshold thresholds['l'] =
  28. Vector3(1.0, 1.0, 1.0); // 1.0 m landmark position threshold
  29. params.relinearizeThreshold = thresholds;
  30. \endcode
  31. */
  32. RelinearizationThreshold relinearizeThreshold;
  33. int relinearizeSkip; ///< Only relinearize any variables every
  34. ///< relinearizeSkip calls to ISAM2::update (default:
  35. ///< 10)
  36. bool enableRelinearization; ///< Controls whether ISAM2 will ever relinearize
  37. ///< any variables (default: true)
  38. bool evaluateNonlinearError; ///< Whether to evaluate the nonlinear error
  39. ///< before and after the update, to return in
  40. ///< ISAM2Result from update()
  41. enum Factorization { CHOLESKY, QR };
  42. /** Specifies whether to use QR or CHOESKY numerical factorization (default:
  43. * CHOLESKY). Cholesky is faster but potentially numerically unstable for
  44. * poorly-conditioned problems, which can occur when uncertainty is very low
  45. * in some variables (or dimensions of variables) and very high in others. QR
  46. * is slower but more numerically stable in poorly-conditioned problems. We
  47. * suggest using the default of Cholesky unless gtsam sometimes throws
  48. * IndefiniteLinearSystemException when your problem's Hessian is actually
  49. * positive definite. For positive definite problems, numerical error
  50. * accumulation can cause the problem to become numerically negative or
  51. * indefinite as solving proceeds, especially when using Cholesky.
  52. */
  53. Factorization factorization;
  54. /** Whether to cache linear factors (default: true).
  55. * This can improve performance if linearization is expensive, but can hurt
  56. * performance if linearization is very cleap due to computation to look up
  57. * additional keys.
  58. */
  59. bool cacheLinearizedFactors;
  60. KeyFormatter
  61. keyFormatter; ///< A KeyFormatter for when keys are printed during
  62. ///< debugging (default: DefaultKeyFormatter)
  63. bool enableDetailedResults; ///< Whether to compute and return
  64. ///< ISAM2Result::detailedResults, this can
  65. ///< increase running time (default: false)
  66. /** Check variables for relinearization in tree-order, stopping the check once
  67. * a variable does not need to be relinearized (default: false). This can
  68. * improve speed by only checking a small part of the top of the tree.
  69. * However, variables below the check cut-off can accumulate significant
  70. * deltas without triggering relinearization. This is particularly useful in
  71. * exploration scenarios where real-time performance is desired over
  72. * correctness. Use with caution.
  73. */
  74. bool enablePartialRelinearizationCheck;
  75. /// When you will be removing many factors, e.g. when using ISAM2 as a
  76. /// fixed-lag smoother, enable this option to add factors in the first
  77. /// available factor slots, to avoid accumulating nullptr factor slots, at the
  78. /// cost of having to search for slots every time a factor is added.
  79. bool findUnusedFactorSlots;
  80. };

1.2. 更新参数ISAM2UpdateParams

  1. struct ISAM2UpdateParams {
  2. ISAM2UpdateParams() = default;
  3. /** Indices of factors to remove from system (default: empty) */
  4. FactorIndices removeFactorIndices;
  5. /** An optional map of keys to group labels, such that a variable can be
  6. * constrained to a particular grouping in the BayesTree */
  7. boost::optional<FastMap<Key, int>> constrainedKeys{boost::none};
  8. /** An optional set of nonlinear keys that iSAM2 will hold at a constant
  9. * linearization point, regardless of the size of the linear delta */
  10. boost::optional<FastList<Key>> noRelinKeys{boost::none};
  11. /** An optional set of nonlinear keys that iSAM2 will re-eliminate, regardless
  12. * of the size of the linear delta. This allows the provided keys to be
  13. * reordered. */
  14. boost::optional<FastList<Key>> extraReelimKeys{boost::none};
  15. /** Relinearize any variables whose delta magnitude is sufficiently large
  16. * (Params::relinearizeThreshold), regardless of the relinearization
  17. * interval (Params::relinearizeSkip). */
  18. bool force_relinearize{false};
  19. /** An optional set of new Keys that are now affected by factors,
  20. * indexed by factor indices (as returned by ISAM2::update()).
  21. * Use when working with smart factors. For example:
  22. * - Timestamp `i`: ISAM2::update() called with a new smart factor depending
  23. * on Keys `X(0)` and `X(1)`. It returns that the factor index for the new
  24. * smart factor (inside ISAM2) is `13`.
  25. * - Timestamp `i+1`: The same smart factor has been augmented to now also
  26. * depend on Keys `X(2)`, `X(3)`. Next call to ISAM2::update() must include
  27. * its `newAffectedKeys` field with the map `13 -> {X(2), X(3)}`.
  28. */
  29. boost::optional<FastMap<FactorIndex, KeySet>> newAffectedKeys{boost::none};
  30. /** By default, iSAM2 uses a wildfire update scheme that stops updating when
  31. * the deltas become too small down in the tree. This flagg forces a full
  32. * solve instead. */
  33. bool forceFullSolve{false};
  34. };

1.3. 返回参数ISAM2Result

  1. /**
  2. * @addtogroup ISAM2
  3. * This struct is returned from ISAM2::update() and contains information about
  4. * the update that is useful for determining whether the solution is
  5. * converging, and about how much work was required for the update. See member
  6. * variables for details and information about each entry.
  7. */
  8. struct ISAM2Result {
  9. /** The nonlinear error of all of the factors, \a including new factors and
  10. * variables added during the current call to ISAM2::update(). This error is
  11. * calculated using the following variable values:
  12. * \li Pre-existing variables will be evaluated by combining their
  13. * linearization point before this call to update, with their partial linear
  14. * delta, as computed by ISAM2::calculateEstimate().
  15. * \li New variables will be evaluated at their initialization points passed
  16. * into the current call to update.
  17. * \par Note: This will only be computed if
  18. * ISAM2Params::evaluateNonlinearError is set to \c true, because there is
  19. * some cost to this computation.
  20. */
  21. boost::optional<double> errorBefore;
  22. /** The nonlinear error of all of the factors computed after the current
  23. * update, meaning that variables above the relinearization threshold
  24. * (ISAM2Params::relinearizeThreshold) have been relinearized and new
  25. * variables have undergone one linear update. Variable values are
  26. * again computed by combining their linearization points with their
  27. * partial linear deltas, by ISAM2::calculateEstimate().
  28. * \par Note: This will only be computed if
  29. * ISAM2Params::evaluateNonlinearError is set to \c true, because there is
  30. * some cost to this computation.
  31. */
  32. boost::optional<double> errorAfter;
  33. /** The number of variables that were relinearized because their linear
  34. * deltas exceeded the reslinearization threshold
  35. * (ISAM2Params::relinearizeThreshold), combined with any additional
  36. * variables that had to be relinearized because they were involved in
  37. * the same factor as a variable above the relinearization threshold.
  38. * On steps where no relinearization is considered
  39. * (see ISAM2Params::relinearizeSkip), this count will be zero.
  40. */
  41. size_t variablesRelinearized;
  42. /** The number of variables that were reeliminated as parts of the Bayes'
  43. * Tree were recalculated, due to new factors. When loop closures occur,
  44. * this count will be large as the new loop-closing factors will tend to
  45. * involve variables far away from the root, and everything up to the root
  46. * will be reeliminated.
  47. */
  48. size_t variablesReeliminated;
  49. /** The number of factors that were included in reelimination of the Bayes'
  50. * tree. */
  51. size_t factorsRecalculated;
  52. /** The number of cliques in the Bayes' Tree */
  53. size_t cliques;
  54. /** The indices of the newly-added factors, in 1-to-1 correspondence with the
  55. * factors passed as \c newFactors to ISAM2::update(). These indices may be
  56. * used later to refer to the factors in order to remove them.
  57. */
  58. FactorIndices newFactorsIndices;
  59. /** Unused keys, and indices for unused keys,
  60. * i.e., keys that are empty now and do not appear in the new factors.
  61. */
  62. KeySet unusedKeys;
  63. /** keys for variables that were observed, i.e., not unused. */
  64. KeyVector observedKeys;
  65. /** Keys of variables that had factors removed. */
  66. KeySet keysWithRemovedFactors;
  67. /** All keys that were marked during the update process. */
  68. KeySet markedKeys;
  69. }

2. 函数说明

2.1. ISAM2::marginalizeLeaves

Marginalize out variables listed in leafKeys. These keys must be leaves in the BayesTree. Throws MarginalizeNonleaf Exception if non-leaves are requested to be marginalized. Marginalization leaves a linear approximation of the marginal in the system, and the linearization points of any variables involved in this linear marginal become fixed. The set fixed variables will include any key involved with the marginalized variables in the original factors, and possibly additional ones due to fill-in.

If provided, 'marginalFactorsIndices' will be augmented with the factor graph indices of the marginal factors added during the 'marginalizeLeaves' call

If provided, 'deletedFactorsIndices' will be augmented with the factor graph indices of any factor that was removed during the 'marginalizeLeaves'

2.2. ISAM2::recalculateIncremental

2.3. ISAM2::recalculateBatch

2.4. recursiveMarkAffectedKeys

在IncrementalFixedLagSmoother.cpp这个文件中,但并不是成员函数。

用于标记一个key的子树

2.5. IncrementalFixedLagSmoother::update

2.6. ISAM2::update

2.7. BayesTree::removeSubtree

如果入参是根团,删除该团及其所有子孙团,在node_中也有删除

如果入参不是根节点,先把其父团与其的边删除

返回所有被删除的团

3. 成员变量说明

Values ISAM2::theta_

VectorValues ISAM2::delta_

VariableIndex ISAM2::variableIndex_

4. 辅助类

4.1. treeTraversalNode-inst.h

  1. // Internal node used in DFS preorder stack
  2. template<typename NODE, typename DATA>
  3. struct TraversalNode {
  4. bool expanded;
  5. const boost::shared_ptr<NODE>& treeNode;
  6. DATA& parentData;
  7. typename FastList<DATA>::iterator dataPointer;
  8. TraversalNode(const boost::shared_ptr<NODE>& _treeNode, DATA& _parentData) :
  9. expanded(false), treeNode(_treeNode), parentData(_parentData) {
  10. }
  11. };

4.2. EliminationTree.h

  1. struct EliminationTree::Node {
  2. typedef FastVector<sharedFactor> Factors;
  3. typedef FastVector<boost::shared_ptr<Node> > Children;
  4. Key key; ///< key associated with root
  5. Factors factors; ///< factors associated with root
  6. Children children; ///< sub-trees
  7. sharedFactor eliminate(const boost::shared_ptr<BayesNetType>& output,
  8. const Eliminate& function,
  9. const FastVector<sharedFactor>& childrenFactors) const;
  10. void print(const std::string& str, const KeyFormatter& keyFormatter) const;
  11. };

4.3. ClusterTree-inst.h

  1. struct EliminationData {
  2. // Typedefs
  3. typedef typename CLUSTERTREE::sharedFactor sharedFactor;
  4. typedef typename CLUSTERTREE::FactorType FactorType;
  5. typedef typename CLUSTERTREE::FactorGraphType FactorGraphType;
  6. typedef typename CLUSTERTREE::ConditionalType ConditionalType;
  7. typedef typename CLUSTERTREE::BayesTreeType::Node BTNode;
  8. // member variables
  9. EliminationData* const parentData;
  10. size_t myIndexInParent;
  11. FastVector<sharedFactor> childFactors;
  12. boost::shared_ptr<BTNode> bayesTreeNode;
  13. // member functions
  14. // Elimination pre-order visitor - creates the EliminationData structure for the visited node.
  15. static EliminationData EliminationPreOrderVisitor(const typename CLUSTERTREE::sharedNode& node,
  16. EliminationData& parentData) {
  17. assert(node);
  18. EliminationData myData(&parentData, node->nrChildren());
  19. myData.bayesTreeNode->problemSize_ = node->problemSize();
  20. return myData;
  21. }
  22. // ........
  23. }

4.4. VariableIndex

  1. The VariableIndex class computes and stores the block column structure of a factor graph. The factor graph stores a collection of factors, each of which involves a set of variables. In contrast, the VariableIndex is built from a factor graph prior to elimination, and stores the list of factors that involve each variable. This information is stored as a deque of lists of factor indices.
  2. 最主要的成变量是FastMap<Key, FactorIndices> index_,用于存储key和因子的索引的对应关系
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/116699
推荐阅读
相关标签
  

闽ICP备14008679号