11 #include <gtsam/inference/ClusterTree.h> 24 for (
const Key key : keys) {
25 std::vector<NonlinearFactor::shared_ptr> factors;
26 for (
auto i : variableIndex[key])
28 factors.push_back(graph->at(i));
31 Cluster::addFactors(key, factors);
36 return factors.linearize(values);
39 static NonlinearCluster* DownCast(
const boost::shared_ptr<Cluster>& cluster) {
40 auto nonlinearCluster = boost::dynamic_pointer_cast<NonlinearCluster>(cluster);
41 if (!nonlinearCluster)
42 throw std::runtime_error(
"Expected NonlinearCluster");
43 return nonlinearCluster.get();
49 const Values& values, boost::optional<Ordering> ordering = boost::none,
53 return factors.linearizeToHessianFactor(values, *ordering, dampen);
58 std::pair<GaussianBayesNet, HessianFactor::shared_ptr> linearizeAndEliminate(
59 const Values& values, boost::optional<Ordering> ordering = boost::none,
66 for (
const auto& child : children) {
67 auto message = DownCast(child)->linearizeAndEliminate(values, &bayesNet);
68 message->updateHessian(localFactor.get());
70 auto gaussianConditional = localFactor->eliminateCholesky(orderedFrontalKeys);
71 bayesNet.
add(gaussianConditional);
72 return {bayesNet, localFactor};
80 boost::optional<Ordering> ordering = boost::none,
82 auto bayesNet_newFactor_pair = linearizeAndEliminate(values, ordering, dampen);
84 bayesNet->
push_back(bayesNet_newFactor_pair.first);
86 return bayesNet_newFactor_pair.second;
93 for (
const auto& root : roots_) {
94 auto result = NonlinearCluster::DownCast(root)->linearizeAndEliminate(values);
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
Definition: NonlinearClusterTree.h:18
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactorGraph.h:74
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition: VariableIndex.h:43
A cluster-tree is associated with a factor graph and is defined as in Koller-Friedman: each node k re...
Definition: ClusterTree.h:25
boost::shared_ptr< This > shared_ptr
A shared_ptr to this class.
Definition: HessianFactor.h:110
Definition: NonlinearClusterTree.h:14
Factor Graph Constsiting of non-linear factors.
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:73
A Bayes net made from linear-Gaussian densities.
Definition: GaussianBayesNet.h:30
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:56
static Ordering ColamdConstrainedFirst(const FACTOR_GRAPH &graph, const KeyVector &constrainFirst, bool forceOrder=false)
Compute a fill-reducing ordering using constrained COLAMD from a factor graph (see details for note o...
Definition: Ordering.h:128
std::function< void(const boost::shared_ptr< HessianFactor > &hessianFactor)> Dampen
typdef for dampen functions used below
Definition: NonlinearFactorGraph.h:146
VectorValues optimize() const
Solve the GaussianBayesNet, i.e. return , by back-substitution.
Definition: GaussianBayesNet.cpp:40
Values retract(const VectorValues &delta) const
Add a delta config to current config and returns a new config.
Definition: Values.cpp:102
A non-linear factor graph is a graph of non-Gaussian, i.e.
Definition: NonlinearFactorGraph.h:77
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
std::enable_if< std::is_base_of< FactorType, DERIVEDFACTOR >::value >::type add(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:243
std::enable_if< std::is_base_of< FactorType, DERIVEDFACTOR >::value >::type push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:159