32 return theta_.
at<VALUE>(key).retract(delta);
37 template<
class CLIQUE>
38 void optimizeWildfire(
const boost::shared_ptr<CLIQUE>& clique,
double threshold,
46 bool cliqueReplaced = replaced.
exists((*clique)->frontals().front());
47 #ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS
48 BOOST_FOREACH(
Key frontal, clique->conditional()->frontals()) {
49 assert(cliqueReplaced == replaced.
exists(frontal));
54 bool recalculate = cliqueReplaced;
56 BOOST_FOREACH(
Key parent, clique->conditional()->parents()) {
57 if(changed.
exists(parent)) {
69 FastVector<Vector> originalValues(clique->conditional()->nrFrontals());
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 BOOST_FOREACH(
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 BOOST_FOREACH(
const typename CLIQUE::shared_ptr& child, clique->children) {
114 template<
class CLIQUE>
115 bool optimizeWildfireNode(
const boost::shared_ptr<CLIQUE>& clique,
double threshold,
116 FastSet<Key>& changed,
const FastSet<Key>& replaced, VectorValues& delta,
size_t& count)
123 bool cliqueReplaced = replaced.exists(clique->conditional()->frontals().front());
124 #ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS
125 BOOST_FOREACH(
Key frontal, clique->conditional()->frontals()) {
126 assert(cliqueReplaced == replaced.exists(frontal));
131 bool recalculate = cliqueReplaced;
133 BOOST_FOREACH(
Key parent, clique->conditional()->parents()) {
134 if(changed.exists(parent)) {
146 FastVector<Vector> originalValues(clique->conditional()->nrFrontals());
148 for(it = clique->conditional()->beginFrontals(); it != clique->conditional()->endFrontals(); it++) {
149 originalValues[it - clique->conditional()->beginFrontals()] = delta[*it];
156 boost::shared_ptr<CLIQUE> parent = clique->parent_.lock();
157 if(clique->solnPointers_.empty() && (clique->isRoot() || !parent->solnPointers_.empty()))
159 BOOST_FOREACH(
Key key, clique->conditional()->frontals())
160 clique->solnPointers_.insert(std::make_pair(key, delta.find(key)));
161 BOOST_FOREACH(
Key key, clique->conditional()->parents())
162 clique->solnPointers_.insert(std::make_pair(key, parent->solnPointers_.at(key)));
167 if(!clique->solnPointers_.empty())
169 GaussianConditional& c = *clique->conditional();
175 FastVector<VectorValues::const_iterator> parentPointers;
176 parentPointers.reserve(clique->conditional()->nrParents());
177 BOOST_FOREACH(
Key parent, clique->conditional()->parents()) {
178 parentPointers.push_back(clique->solnPointers_.at(parent));
179 dim += parentPointers.back()->second.size();
186 const Vector& parentVector = parentPointer->second;
187 xS.block(vectorPos,0,parentVector.size(),1) = parentVector.block(0,0,parentVector.size(),1);
188 vectorPos += parentVector.size();
191 xS = c.getb() - c.get_S() * xS;
192 Vector soln = c.get_R().triangularView<Eigen::Upper>().
solve(xS);
195 if(soln.hasNaN())
throw IndeterminantLinearSystemException(c.keys().front());
200 clique->solnPointers_.at(*frontal)->second = soln.segment(vectorPosition, c.getDim(frontal));
201 vectorPosition += c.getDim(frontal);
207 delta.update(clique->conditional()->solve(delta));
210 count += clique->conditional()->nrFrontals();
214 bool valuesChanged = cliqueReplaced;
215 for(it = clique->conditional()->beginFrontals(); it != clique->conditional()->endFrontals(); it++) {
217 const Vector& oldValue(originalValues[it - clique->conditional()->beginFrontals()]);
218 const Vector& newValue(delta[*it]);
219 if((oldValue - newValue).lpNorm<Eigen::Infinity>() >= threshold) {
220 valuesChanged =
true;
230 BOOST_FOREACH(
Key frontal, clique->conditional()->frontals()) {
231 changed.insert(frontal);
235 for(it = clique->conditional()->beginFrontals(); it != clique->conditional()->endFrontals(); it++) {
236 delta[*it] = originalValues[it - clique->conditional()->beginFrontals()];
247 template<
class CLIQUE>
258 template<
class CLIQUE>
259 size_t optimizeWildfireNonRecursive(
const boost::shared_ptr<CLIQUE>& root,
double threshold,
const FastSet<Key>& keys, VectorValues& delta)
261 FastSet<Key> changed;
265 std::stack<boost::shared_ptr<CLIQUE> > travStack;
266 travStack.push(root);
267 boost::shared_ptr<CLIQUE> currentNode = root;
268 while (!travStack.empty()) {
269 currentNode = travStack.top();
271 bool recalculate = internal::optimizeWildfireNode(currentNode, threshold, changed, keys, delta, count);
273 BOOST_FOREACH(
const typename CLIQUE::shared_ptr& child, currentNode->children) {
274 travStack.push(child);
284 template<
class CLIQUE>
285 void nnz_internal(
const boost::shared_ptr<CLIQUE>& clique,
int& result) {
286 int dimR = (int)clique->conditional()->rows();
287 int dimSep = (int)clique->conditional()->get_S().cols();
288 result += ((dimR+1)*dimR)/2 + dimSep*dimR;
290 BOOST_FOREACH(
const typename CLIQUE::shared_ptr& child, clique->children) {
291 nnz_internal(child, result);
296 template<
class CLIQUE>
300 nnz_internal(clique, result);
Values calculateEstimate() const
Compute an estimate from the incomplete linear delta computed during the last update.
Definition: ISAM2.cpp:1016
void solve(Matrix &A, Matrix &B)
solve AX=B via in-place Lu factorization and backsubstitution After calling, A contains LU...
Definition: Matrix.cpp:283
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:97
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:70
size_t dim(const Vector &v)
dimensionality == size
Definition: Vector.h:90
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:297
const ValueType & at(Key j) const
Retrieve a variable by key j.
Definition: Values-inl.h:219
size_t optimizeWildfire(const boost::shared_ptr< CLIQUE > &root, double threshold, const FastSet< Key > &keys, VectorValues &delta)
Optimize the BayesTree, starting from the root.
Definition: ISAM2-inl.h:248
size_t Key
Integer nonlinear key type.
Definition: types.h:59
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:74
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:89
Values theta_
The current linearization point.
Definition: ISAM2.h:429
Vector delta(size_t n, size_t i, double value)
Create basis vector of dimension n, with a constant in spot i.
Definition: Vector.cpp:53
const VectorValues & getDelta() const
Access the current delta, computed during the last call to update.
Definition: ISAM2.cpp:1042
FastVector< Key >::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:64