ConcurrentFilteringAndSmoothing.cpp
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 // \callgraph
21 
24 
25 namespace gtsam {
26 
27 /* ************************************************************************* */
29 
30  NonlinearFactorGraph smootherFactors, filterSumarization, smootherSummarization;
31  Values smootherValues, filterSeparatorValues, smootherSeparatorValues;
32 
33  // Call the pre-sync functions of the filter and smoother
34  filter.presync();
35  smoother.presync();
36 
37  // Get the updates from the smoother and apply them to the filter
38  smoother.getSummarizedFactors(smootherSummarization, smootherSeparatorValues);
39  filter.synchronize(smootherSummarization, smootherSeparatorValues);
40 
41  // Get the updates from the filter and apply them to the smoother
42  filter.getSmootherFactors(smootherFactors, smootherValues);
43  filter.getSummarizedFactors(filterSumarization, filterSeparatorValues);
44  smoother.synchronize(smootherFactors, smootherValues, filterSumarization, filterSeparatorValues);
45 
46  // Call the post-sync functions of the filter and smoother
47  filter.postsync();
48  smoother.postsync();
49 }
50 
51 namespace internal {
52 
53 /* ************************************************************************* */
55  const KeySet& remainingKeys, const GaussianFactorGraph::Eliminate& eliminateFunction) {
56 
57 
58  // Calculate the set of RootKeys = AllKeys \Intersect RemainingKeys
59  KeySet rootKeys;
60  KeySet allKeys(graph.keys());
61  std::set_intersection(allKeys.begin(), allKeys.end(), remainingKeys.begin(), remainingKeys.end(), std::inserter(rootKeys, rootKeys.end()));
62 
63  // Calculate the set of MarginalizeKeys = AllKeys - RemainingKeys
64  KeySet marginalizeKeys;
65  std::set_difference(allKeys.begin(), allKeys.end(), remainingKeys.begin(), remainingKeys.end(), std::inserter(marginalizeKeys, marginalizeKeys.end()));
66 
67  if(marginalizeKeys.size() == 0) {
68  // There are no keys to marginalize. Simply return the input factors
69  return graph;
70  } else {
71  // Create the linear factor graph
72  GaussianFactorGraph linearFactorGraph = *graph.linearize(theta);
73  // .first is the eliminated Bayes tree, while .second is the remaining factor graph
74  GaussianFactorGraph marginalLinearFactors = *linearFactorGraph.eliminatePartialMultifrontal(
75  KeyVector(marginalizeKeys.begin(), marginalizeKeys.end()), eliminateFunction).second;
76 
77  // Wrap in nonlinear container factors
78  NonlinearFactorGraph marginalFactors;
79  marginalFactors.reserve(marginalLinearFactors.size());
80  for(const GaussianFactor::shared_ptr& gaussianFactor: marginalLinearFactors) {
81  marginalFactors.emplace_shared<LinearContainerFactor>(gaussianFactor, theta);
82  }
83 
84  return marginalFactors;
85  }
86 }
87 
88 /* ************************************************************************* */
89 }
90 
91 /* ************************************************************************* */
92 }
std::pair< std::shared_ptr< BayesTreeType >, std::shared_ptr< FactorGraphType > > eliminatePartialMultifrontal(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
KeySet keys() const
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition: FactorGraph.h:196
Wrap Jacobian and Hessian linear factors to allow simple injection into a nonlinear graph...
NonlinearFactorGraph graph
std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
size_t size() const
Definition: FactorGraph.h:334
virtual void getSummarizedFactors(NonlinearFactorGraph &summarizedFactors, Values &separatorValues)=0
virtual void getSummarizedFactors(NonlinearFactorGraph &summarizedFactors, Values &separatorValues)=0
std::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
NonlinearFactorGraph calculateMarginalFactors(const NonlinearFactorGraph &graph, const Values &theta, const KeySet &remainingKeys, const GaussianFactorGraph::Eliminate &eliminateFunction)
virtual void synchronize(const NonlinearFactorGraph &summarizedFactors, const Values &separatorValues)=0
std::shared_ptr< This > shared_ptr
shared_ptr to this class
traits
Definition: chartTesting.h:28
void synchronize(ConcurrentFilter &filter, ConcurrentSmoother &smoother)
virtual void synchronize(const NonlinearFactorGraph &smootherFactors, const Values &smootherValues, const NonlinearFactorGraph &summarizedFactors, const Values &rootValues)=0
void reserve(size_t size)
Definition: FactorGraph.h:186
Base classes for the &#39;filter&#39; and &#39;smoother&#39; portion of the Concurrent Filtering and Smoothing archit...
virtual void getSmootherFactors(NonlinearFactorGraph &smootherFactors, Values &smootherValues)=0
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86


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