22#include <boost/optional.hpp>
23#include <boost/shared_ptr.hpp>
29 namespace linearAlgorithms
33 boost::optional<OptimizeData&> parentData;
46 template<
class CLIQUE>
52 const boost::shared_ptr<CLIQUE>& clique,
56 myData.parentData = parentData;
58 for(
Key parent: clique->conditional_->parents())
59 myData.cliqueResults.emplace(parent, myData.parentData->cliqueResults.at(parent));
69 FastVector<VectorValues::const_iterator> parentPointers;
70 parentPointers.reserve(clique->conditional()->nrParents());
71 for(
Key parent: clique->conditional()->parents()) {
72 parentPointers.push_back(myData.cliqueResults.at(parent));
73 dim += parentPointers.
back()->second.size();
80 const Vector& parentVector = parentPointer->second;
81 xS.block(vectorPos,0,parentVector.size(),1) = parentVector.block(0,0,parentVector.size(),1);
82 vectorPos += parentVector.size();
90 const Vector rhs = c.
getb() - c.
S() * xS;
93 const Vector solution = c.
R().triangularView<Eigen::Upper>().solve(rhs);
101 auto result = collectedResult.
emplace(*frontal, solution.segment(vectorPosition, c.
getDim(frontal)));
103 throw std::runtime_error(
104 "Internal error while optimizing clique. Trying to insert key '" + DefaultKeyFormatter(*frontal)
108 myData.cliqueResults.emplace(r->first, r);
109 vectorPosition += c.
getDim(frontal);
139 template<
class BAYESTREE>
140 VectorValues optimizeBayesTree(
const BAYESTREE& bayesTree)
142 gttic(linear_optimizeBayesTree);
148 treeTraversal::no_op postVisitor;
151 return preVisitor.collectedResult;
Conditional Gaussian Base class.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:75
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
void DepthFirstForestParallel(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost, int problemSizeThreshold=10)
Traverse a forest depth-first with pre-order and post-order visits.
Definition: treeTraversal-inst.h:154
An object whose scope defines a block where TBB and OpenMP parallelism are mixed.
Definition: types.h:161
FACTOR::const_iterator endFrontals() const
Iterator pointing past the last frontal key.
Definition: Conditional.h:108
FACTOR::const_iterator beginFrontals() const
Iterator pointing to first frontal key.
Definition: Conditional.h:105
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:125
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:68
Key back() const
Last key.
Definition: Factor.h:119
A conditional Gaussian functions as the node in a Bayes network It has a set of parents y,...
Definition: GaussianConditional.h:39
constABlock R() const
Return a view of the upper-triangular R block of the conditional.
Definition: GaussianConditional.h:97
constABlock S() const
Get a view of the parent blocks.
Definition: GaussianConditional.h:100
const constBVector getb() const
Get a view of the r.h.s.
Definition: JacobianFactor.h:295
DenseIndex getDim(const_iterator variable) const override
Return the dimension of the variable pointed to by the given key iterator todo: Remove this in favor ...
Definition: JacobianFactor.h:274
Definition: linearAlgorithms-inst.h:32
Pre-order visitor for back-substitution in a Bayes tree.
Definition: linearAlgorithms-inst.h:48
Thrown when a linear system is ill-posed.
Definition: linearExceptions.h:94
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:74
Values::const_iterator const_iterator
Const iterator over vector values.
Definition: VectorValues.h:82
std::pair< VectorValues::iterator, bool > emplace(Key j, Args &&... args)
Emplace a vector value with key j.
Definition: VectorValues.h:183