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 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(
72 auto message = DownCast(child)->linearizeAndEliminate(values, &bayesNet);
73 message->updateHessian(localFactor.get());
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);
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:86
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition FactorGraph.h:186
void remove(size_t i)
delete factor without re-arranging indexes by inserting a nullptr pointer
Definition FactorGraph.h:385
IsDerived< DERIVEDFACTOR > add(boost::shared_ptr< DERIVEDFACTOR > factor)
add is a synonym for push_back.
Definition FactorGraph.h:210
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:335
FastVector< sharedNode > roots_
Definition ClusterTree.h:116
ClusterTree(const This &other)
Definition ClusterTree.h:123
Children children
Definition ClusterTree.h:38
Keys orderedFrontalKeys
Definition ClusterTree.h:41
FactorGraphType factors
Definition ClusterTree.h:43
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:141
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:43
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:44
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition GaussianFactorGraph.h:81
boost::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:74
Definition NonlinearFactorGraph.h:55
std::function< void(const boost::shared_ptr< HessianFactor > &hessianFactor)> Dampen
typdef for dampen functions used below
Definition NonlinearFactorGraph.h:136
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:99