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) :
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 }
parentData
EliminationData *const parentData
Definition: inference-inst.h:34
treeTraversal-inst.h
FastVector.h
A thin wrapper around std::vector that uses a custom allocator.
tree
Definition: testExpression.cpp:212
operator()
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
Definition: IndexedViewMethods.h:73
gtsam::treeTraversal::DepthFirstForest
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
Definition: treeTraversal-inst.h:77
eliminationFunction
const TREE::Eliminate & eliminationFunction
Definition: inference-inst.h:55
gtsam::inference::EliminateTree
FastVector< typename TREE::sharedFactor > EliminateTree(RESULT &result, const TREE &tree, const typename TREE::Eliminate &function)
Definition: inference-inst.h:74
gtsam
traits
Definition: SFMdata.h:40
childFactors
FastVector< typename TREE::sharedFactor > childFactors
Definition: inference-inst.h:35
result
RESULT & result
Definition: inference-inst.h:54
sharedNode
SymbolicEliminationTree::sharedNode sharedNode
Definition: testSymbolicEliminationTree.cpp:31


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:46