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 }
gtsam::EliminateableFactorGraph::eliminatePartialMultifrontal
std::pair< std::shared_ptr< BayesTreeType >, std::shared_ptr< FactorGraphType > > eliminatePartialMultifrontal(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Definition: EliminateableFactorGraph-inst.h:190
gtsam::ConcurrentFilter::postsync
virtual void postsync()
Definition: ConcurrentFilteringAndSmoothing.h:94
LinearContainerFactor.h
Wrap Jacobian and Hessian linear factors to allow simple injection into a nonlinear graph.
gtsam::synchronize
void synchronize(ConcurrentFilter &filter, ConcurrentSmoother &smoother)
Definition: ConcurrentFilteringAndSmoothing.cpp:28
gtsam::ConcurrentFilter::synchronize
virtual void synchronize(const NonlinearFactorGraph &summarizedFactors, const Values &separatorValues)=0
gtsam::FastSet< Key >
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::ConcurrentSmoother::postsync
virtual void postsync()
Definition: ConcurrentFilteringAndSmoothing.h:150
gtsam::ConcurrentFilter
Definition: ConcurrentFilteringAndSmoothing.h:39
gtsam::ConcurrentSmoother::synchronize
virtual void synchronize(const NonlinearFactorGraph &smootherFactors, const Values &smootherValues, const NonlinearFactorGraph &summarizedFactors, const Values &rootValues)=0
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
gtsam::ConcurrentFilter::getSmootherFactors
virtual void getSmootherFactors(NonlinearFactorGraph &smootherFactors, Values &smootherValues)=0
gtsam::ConcurrentFilter::presync
virtual void presync()
Definition: ConcurrentFilteringAndSmoothing.h:61
gtsam::internal::calculateMarginalFactors
NonlinearFactorGraph calculateMarginalFactors(const NonlinearFactorGraph &graph, const Values &theta, const KeySet &remainingKeys, const GaussianFactorGraph::Eliminate &eliminateFunction)
Definition: ConcurrentFilteringAndSmoothing.cpp:54
gtsam::ConcurrentFilter::getSummarizedFactors
virtual void getSummarizedFactors(NonlinearFactorGraph &summarizedFactors, Values &separatorValues)=0
gtsam::ConcurrentSmoother
Definition: ConcurrentFilteringAndSmoothing.h:101
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::GaussianFactor::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
gtsam::FactorGraph::size
size_t size() const
Definition: FactorGraph.h:297
gtsam
traits
Definition: SFMdata.h:40
gtsam::Values
Definition: Values.h:65
ConcurrentFilteringAndSmoothing.h
Base classes for the 'filter' and 'smoother' portion of the Concurrent Filtering and Smoothing archit...
gtsam::EliminateableFactorGraph< GaussianFactorGraph >::Eliminate
std::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
Definition: EliminateableFactorGraph.h:88
gtsam::ConcurrentSmoother::presync
virtual void presync()
Definition: ConcurrentFilteringAndSmoothing.h:123
gtsam::FactorGraph::reserve
void reserve(size_t size)
Definition: FactorGraph.h:143
internal
Definition: BandTriangularSolver.h:13
gtsam::LinearContainerFactor
Definition: LinearContainerFactor.h:29
gtsam::ConcurrentSmoother::getSummarizedFactors
virtual void getSummarizedFactors(NonlinearFactorGraph &summarizedFactors, Values &separatorValues)=0
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gtsam::FactorGraph::emplace_shared
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition: FactorGraph.h:153


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:01