14class NonlinearClusterTree :
public ClusterTree<NonlinearFactorGraph> {
16 NonlinearClusterTree() {}
18 struct NonlinearCluster : Cluster {
24 for (
const Key key : keys) {
25 std::vector<NonlinearFactor::shared_ptr>
factors;
26 for (
auto i : variableIndex[key])
31 Cluster::addFactors(key,
factors);
36 return factors.linearize(values);
39 static NonlinearCluster* DownCast(
const std::shared_ptr<Cluster>& cluster) {
40 auto nonlinearCluster =
41 std::dynamic_pointer_cast<NonlinearCluster>(cluster);
42 if (!nonlinearCluster)
43 throw std::runtime_error(
"Expected NonlinearCluster");
44 return nonlinearCluster.get();
54 return factors.linearizeToHessianFactor(values, ordering, dampen);
62 return factors.linearizeToHessianFactor(values, ordering, dampen);
67 std::pair<GaussianBayesNet, HessianFactor::shared_ptr> linearizeAndEliminate(
73 auto message = DownCast(child)->linearizeAndEliminate(values, &bayesNet);
74 message->updateHessian(localFactor.get());
77 bayesNet.
add(gaussianConditional);
78 return {bayesNet, localFactor};
83 std::pair<GaussianBayesNet, HessianFactor::shared_ptr> linearizeAndEliminate(
88 return linearizeAndEliminate(values, localFactor);
93 std::pair<GaussianBayesNet, HessianFactor::shared_ptr> linearizeAndEliminate(
98 return linearizeAndEliminate(values, localFactor);
107 auto bayesNet_newFactor_pair = linearizeAndEliminate(values, dampen);
109 bayesNet->
push_back(bayesNet_newFactor_pair.first);
111 return bayesNet_newFactor_pair.second;
121 auto bayesNet_newFactor_pair = linearizeAndEliminate(values, ordering, dampen);
123 bayesNet->
push_back(bayesNet_newFactor_pair.first);
125 return bayesNet_newFactor_pair.second;
132 for (
const auto& root :
roots_) {
133 auto result = NonlinearCluster::DownCast(root)->linearizeAndEliminate(values);
Collects factorgraph fragments defined on variable clusters, arranged in a tree.
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:91
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition FactorGraph.h:147
void remove(size_t i)
delete factor without re-arranging indexes by inserting a nullptr pointer
Definition FactorGraph.h:371
const sharedFactor at(size_t i) const
Get a specific factor by index (this checks array bounds and may throw an exception,...
Definition FactorGraph.h:306
IsDerived< DERIVEDFACTOR > add(std::shared_ptr< DERIVEDFACTOR > factor)
add is a synonym for push_back.
Definition FactorGraph.h:171
FastVector< sharedNode > roots_
Definition ClusterTree.h:135
ClusterTree(const This &other)
Definition ClusterTree.h:142
Children children
Definition ClusterTree.h:40
Keys orderedFrontalKeys
Definition ClusterTree.h:43
FactorGraphType factors
Definition ClusterTree.h:45
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:139
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:41
GaussianBayesNet is a Bayes net made from linear-Gaussian conditionals.
Definition GaussianBayesNet.h:36
VectorValues optimize() const
Solve the GaussianBayesNet, i.e.
Definition GaussianBayesNet.cpp:40
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition GaussianFactorGraph.h:83
std::shared_ptr< This > shared_ptr
A shared_ptr to this class.
Definition HessianFactor.h:110
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73
Definition NonlinearFactorGraph.h:57
std::function< void(const std::shared_ptr< HessianFactor > &hessianFactor)> Dampen
typdef for dampen functions used below
Definition NonlinearFactorGraph.h:141
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
Values retract(const VectorValues &delta) const
Add a delta config to current config and returns a new config.
Definition Values.cpp:100