31 const Vector& delta =
getDelta()[key];
37 template<
class CLIQUE>
46 bool cliqueReplaced = replaced.
exists((*clique)->frontals().front());
47 #ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS 48 for(
Key frontal: clique->conditional()->frontals()) {
49 assert(cliqueReplaced == replaced.
exists(frontal));
54 bool recalculate = cliqueReplaced;
56 for(
Key parent: clique->conditional()->parents()) {
57 if(changed.
exists(parent)) {
71 for(it = clique->conditional()->beginFrontals(); it!=clique->conditional()->endFrontals(); it++) {
72 originalValues[it - clique->conditional()->beginFrontals()] = delta[*it];
76 delta.
update(clique->conditional()->solve(delta));
77 count += clique->conditional()->nrFrontals();
81 bool valuesChanged = cliqueReplaced;
82 for(it = clique->conditional()->beginFrontals(); it != clique->conditional()->endFrontals(); it++) {
84 const Vector& oldValue(originalValues[it - clique->conditional()->beginFrontals()]);
85 const Vector& newValue(delta[*it]);
86 if((oldValue - newValue).lpNorm<Eigen::Infinity>() >= threshold) {
97 for(
Key frontal: clique->conditional()->frontals()) {
98 changed.insert(frontal);
102 for(it = clique->conditional()->beginFrontals(); it != clique->conditional()->endFrontals(); it++) {
103 delta[*it] = originalValues[it - clique->conditional()->beginFrontals()];
108 for(
const typename CLIQUE::shared_ptr& child: clique->children) {
114 template<
class CLIQUE>
115 bool optimizeWildfireNode(
const boost::shared_ptr<CLIQUE>& clique,
double threshold,
123 bool cliqueReplaced = replaced.
exists(clique->conditional()->frontals().front());
124 #ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS 125 for(
Key frontal: clique->conditional()->frontals()) {
126 assert(cliqueReplaced == replaced.
exists(frontal));
131 bool recalculate = cliqueReplaced;
133 for(
Key parent: clique->conditional()->parents()) {
134 if(changed.
exists(parent)) {
149 for(it = clique->conditional()->beginFrontals(); it != clique->conditional()->endFrontals(); it++) {
150 originalValues[it - clique->conditional()->beginFrontals()] = delta[*it];
157 boost::shared_ptr<CLIQUE> parent = clique->parent_.lock();
158 if(clique->solnPointers_.empty() && (clique->isRoot() || !parent->solnPointers_.empty()))
160 for(
Key key: clique->conditional()->frontals())
161 clique->solnPointers_.
insert(std::make_pair(key, delta.
find(key)));
162 for(
Key key: clique->conditional()->parents())
163 clique->solnPointers_.insert(std::make_pair(key, parent->solnPointers_.at(key)));
168 if(!clique->solnPointers_.empty())
177 parentPointers.reserve(clique->conditional()->nrParents());
178 for(
Key parent: clique->conditional()->parents()) {
179 parentPointers.push_back(clique->solnPointers_.at(parent));
180 dim += parentPointers.back()->second.size();
187 const Vector& parentVector = parentPointer->second;
188 xS.block(vectorPos,0,parentVector.size(),1) = parentVector.block(0,0,parentVector.size(),1);
189 vectorPos += parentVector.size();
197 const Vector rhs = c.
getb() - c.
get_S() * xS;
198 const Vector solution = c.
get_R().triangularView<Eigen::Upper>().solve(rhs);
206 clique->solnPointers_.at(*frontal)->second = solution.segment(vectorPosition, c.
getDim(frontal));
207 vectorPosition += c.
getDim(frontal);
213 delta.
update(clique->conditional()->solve(delta));
216 count += clique->conditional()->nrFrontals();
220 bool valuesChanged = cliqueReplaced;
221 for(it = clique->conditional()->beginFrontals(); it != clique->conditional()->endFrontals(); it++) {
223 const Vector& oldValue(originalValues[it - clique->conditional()->beginFrontals()]);
224 const Vector& newValue(delta[*it]);
225 if((oldValue - newValue).lpNorm<Eigen::Infinity>() >= threshold) {
226 valuesChanged =
true;
236 for(
Key frontal: clique->conditional()->frontals()) {
237 changed.insert(frontal);
241 for(it = clique->conditional()->beginFrontals(); it != clique->conditional()->endFrontals(); it++) {
242 delta[*it] = originalValues[it - clique->conditional()->beginFrontals()];
253 template<
class CLIQUE>
264 template<
class CLIQUE>
265 size_t optimizeWildfireNonRecursive(
const boost::shared_ptr<CLIQUE>& root,
double threshold,
const KeySet& keys,
VectorValues& delta)
271 std::stack<boost::shared_ptr<CLIQUE> > travStack;
272 travStack.push(root);
273 boost::shared_ptr<CLIQUE> currentNode = root;
274 while (!travStack.empty()) {
275 currentNode = travStack.top();
277 bool recalculate = internal::optimizeWildfireNode(currentNode, threshold, changed, keys, delta, count);
279 for(
const typename CLIQUE::shared_ptr& child: currentNode->children) {
280 travStack.push(child);
290 template<
class CLIQUE>
291 void nnz_internal(
const boost::shared_ptr<CLIQUE>&
clique,
int& result) {
292 int dimR = (int)clique->conditional()->rows();
293 int dimSep = (int)clique->conditional()->get_S().cols();
294 result += ((dimR+1)*dimR)/2 + dimSep*dimR;
296 for(
const typename CLIQUE::shared_ptr& child: clique->children) {
297 nnz_internal(child, result);
302 template<
class CLIQUE>
306 nnz_internal(clique, result);
bool exists(const VALUE &e) const
Handy 'exists' function.
Definition: FastSet.h:98
Values::const_iterator const_iterator
Const iterator over vector values.
Definition: VectorValues.h:98
int calculate_nnz(const boost::shared_ptr< CLIQUE > &clique)
calculate the number of non-zero entries for the tree starting at clique (use root for complete matri...
Definition: ISAM2-inl.h:303
FACTOR::const_iterator beginFrontals() const
Iterator pointing to first frontal key.
Definition: Conditional.h:104
const VectorValues & getDelta() const
Access the current delta, computed during the last call to update.
Definition: ISAM2.cpp:1040
Values theta_
The current linearization point.
Definition: ISAM2.h:440
A conditional Gaussian functions as the node in a Bayes network It has a set of parents y...
Definition: GaussianConditional.h:36
Thrown when a linear system is ill-posed.
Definition: linearExceptions.h:94
iterator find(Key j)
Return the iterator corresponding to the requested key, or end() if no variable is present with this ...
Definition: VectorValues.h:227
const constBVector getb() const
Get a view of the r.h.s.
Definition: JacobianFactor.h:264
FACTOR::const_iterator endFrontals() const
Iterator pointing past the last frontal key.
Definition: Conditional.h:107
Definition: FastVector.h:36
void update(const VectorValues &values)
For all key/value pairs in values, replace values with corresponding keys in this class with those in...
Definition: VectorValues.cpp:90
constABlock get_S() const
Get a view of the parent blocks.
Definition: GaussianConditional.h:100
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:60
Values calculateEstimate() const
Compute an estimate from the incomplete linear delta computed during the last update.
Definition: ISAM2.cpp:1014
ValueType at(Key j) const
Retrieve a variable by key j.
Definition: Values-inl.h:343
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:90
FastVector< Key >::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:64
size_t optimizeWildfire(const boost::shared_ptr< CLIQUE > &root, double threshold, const KeySet &keys, VectorValues &delta)
Optimize the BayesTree, starting from the root.
Definition: ISAM2-inl.h:254
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
const FastVector< Key > & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:115
virtual DenseIndex getDim(const_iterator variable) const
Return the dimension of the variable pointed to by the given key iterator todo: Remove this in favor ...
Definition: JacobianFactor.h:245
constABlock get_R() const
Return a view of the upper-triangular R block of the conditional.
Definition: GaussianConditional.h:97
const sharedClique & clique(Key j) const
alternate syntax for matlab: find the clique that contains the variable with Key j ...
Definition: BayesTree.h:150
iterator insert(Key j, const Vector &value)
Insert a vector value with key j.
Definition: VectorValues.h:187
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Global functions in a separate testing namespace.
Definition: chartTesting.h:28