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();
53 return factors.linearizeToHessianFactor(values, ordering, dampen);
61 return factors.linearizeToHessianFactor(values, ordering, dampen);
66 std::pair<GaussianBayesNet, HessianFactor::shared_ptr> linearizeAndEliminate(
71 for (
const auto& child : children) {
72 auto message = DownCast(child)->linearizeAndEliminate(values, &bayesNet);
73 message->updateHessian(localFactor.get());
75 auto gaussianConditional = localFactor->eliminateCholesky(orderedFrontalKeys);
76 bayesNet.
add(gaussianConditional);
77 return {bayesNet, localFactor};
82 std::pair<GaussianBayesNet, HessianFactor::shared_ptr> linearizeAndEliminate(
87 return linearizeAndEliminate(values, localFactor);
92 std::pair<GaussianBayesNet, HessianFactor::shared_ptr> linearizeAndEliminate(
97 return linearizeAndEliminate(values, localFactor);
106 auto bayesNet_newFactor_pair = linearizeAndEliminate(values, dampen);
108 bayesNet->
push_back(bayesNet_newFactor_pair.first);
110 return bayesNet_newFactor_pair.second;
120 auto bayesNet_newFactor_pair = linearizeAndEliminate(values, ordering, dampen);
122 bayesNet->
push_back(bayesNet_newFactor_pair.first);
124 return bayesNet_newFactor_pair.second;
131 for (
const auto& root :
roots_) {
132 auto result = NonlinearCluster::DownCast(root)->linearizeAndEliminate(values);
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
Factor Graph consisting of non-linear factors.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:165
IsDerived< DERIVEDFACTOR > add(boost::shared_ptr< DERIVEDFACTOR > factor)
add is a synonym for push_back.
Definition: FactorGraph.h:189
A cluster-tree is associated with a factor graph and is defined as in Koller-Friedman: each node k re...
Definition: ClusterTree.h:25
FastVector< sharedNode > roots_
concept check
Definition: ClusterTree.h:116
Definition: Ordering.h:34
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
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition: VariableIndex.h:43
A Bayes net made from linear-Gaussian densities.
Definition: GaussianBayesNet.h:31
VectorValues optimize() const
Solve the GaussianBayesNet, i.e. return , by back-substitution.
Definition: GaussianBayesNet.cpp:41
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactorGraph.h:75
boost::shared_ptr< This > shared_ptr
A shared_ptr to this class.
Definition: HessianFactor.h:110
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:74
A non-linear factor graph is a graph of non-Gaussian, i.e.
Definition: NonlinearFactorGraph.h:78
std::function< void(const boost::shared_ptr< HessianFactor > &hessianFactor)> Dampen
typdef for dampen functions used below
Definition: NonlinearFactorGraph.h:163
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:63
Values retract(const VectorValues &delta) const
Add a delta config to current config and returns a new config.
Definition: Values.cpp:101
Definition: NonlinearClusterTree.h:14
Definition: NonlinearClusterTree.h:18