inference-inst.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8 * See LICENSE for the license information
9 
10 * -------------------------------------------------------------------------- */
11 
20 #pragma once
21 
22 #include <utility>
23 
25 #include <gtsam/base/FastVector.h>
26 
27 namespace gtsam {
28  namespace inference {
29 
30  namespace {
31  /* ************************************************************************* */
32  template<class TREE>
33  struct EliminationData {
34  EliminationData* const parentData;
35  FastVector<typename TREE::sharedFactor> childFactors;
36  EliminationData(EliminationData* _parentData, size_t nChildren) :
37  parentData(_parentData) { childFactors.reserve(nChildren); }
38  };
39 
40  /* ************************************************************************* */
41  template<class TREE>
42  EliminationData<TREE> eliminationPreOrderVisitor(
43  const typename TREE::sharedNode& node, EliminationData<TREE>& parentData)
44  {
45  // This function is called before visiting the children. Here, we create this node's data,
46  // which includes a pointer to the parent data and space for the factors of the children.
47  return EliminationData<TREE>(&parentData, node->children.size());
48  }
49 
50  /* ************************************************************************* */
51  template<class TREE, class RESULT>
52  struct EliminationPostOrderVisitor
53  {
54  RESULT& result;
55  const typename TREE::Eliminate& eliminationFunction;
56  EliminationPostOrderVisitor(RESULT& result, const typename TREE::Eliminate& eliminationFunction) :
57  result(result), eliminationFunction(eliminationFunction) {}
58  void operator()(const typename TREE::sharedNode& node, EliminationData<TREE>& myData)
59  {
60  // Call eliminate on the node and add the result to the parent's gathered factors
61  typename TREE::sharedFactor childFactor = node->eliminate(result, eliminationFunction, myData.childFactors);
62  if(childFactor && !childFactor->empty())
63  myData.parentData->childFactors.push_back(childFactor);
64  }
65  };
66  }
67 
68  /* ************************************************************************* */
72  template<class TREE, class RESULT>
73  FastVector<typename TREE::sharedFactor>
74  EliminateTree(RESULT& result, const TREE& tree, const typename TREE::Eliminate& function)
75  {
76  // Do elimination using a depth-first traversal. During the pre-order visit (see
77  // eliminationPreOrderVisitor), we store a pointer to the parent data (where we'll put the
78  // remaining factor) and reserve a vector of factors to store the children elimination
79  // results. During the post-order visit (see eliminationPostOrderVisitor), we call dense
80  // elimination (using the gathered child factors) and store the result in the parent's
81  // gathered factors.
82  EliminationData<TREE> rootData(0, tree.roots().size());
83  EliminationPostOrderVisitor<TREE,RESULT> visitorPost(result, function);
84  treeTraversal::DepthFirstForest(tree, rootData, eliminationPreOrderVisitor<TREE>, visitorPost);
85 
86  // Return remaining factors
87  return rootData.childFactors;
88  }
89 
90  }
91 }
SymbolicEliminationTree::sharedNode sharedNode
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
FastVector< typename TREE::sharedFactor > EliminateTree(RESULT &result, const TREE &tree, const typename TREE::Eliminate &function)
EliminationData *const parentData
A thin wrapper around std::vector that uses a custom allocator.
traits
Definition: chartTesting.h:28
const TREE::Eliminate & eliminationFunction
RESULT & result
FastVector< typename TREE::sharedFactor > childFactors
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:22