ConcurrentBatchFilter.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
21 #include <gtsam/base/timing.h>
22 #include <gtsam/base/debug.h>
23 
24 #include <cassert>
25 
26 namespace gtsam {
27 
28 /* ************************************************************************* */
30  const std::string& indent, const KeyFormatter& keyFormatter) {
31  std::cout << indent;
32  if(factor) {
33  if(std::dynamic_pointer_cast<LinearContainerFactor>(factor)) {
34  std::cout << "l( ";
35  } else {
36  std::cout << "f( ";
37  }
38  for(Key key: *factor) {
39  std::cout << keyFormatter(key) << " ";
40  }
41  std::cout << ")" << std::endl;
42  } else {
43  std::cout << "{ nullptr }" << std::endl;
44  }
45 }
46 
47 /* ************************************************************************* */
49  const std::string& indent, const std::string& title, const KeyFormatter& keyFormatter) {
50  std::cout << indent << title << std::endl;
52  PrintNonlinearFactor(factor, indent + " ", keyFormatter);
53  }
54 }
55 
56 /* ************************************************************************* */
58  const std::string& indent, const std::string& title, const KeyFormatter& keyFormatter) {
59  std::cout << indent << title << std::endl;
60  for(size_t slot: slots) {
61  PrintNonlinearFactor(factors.at(slot), indent + " ", keyFormatter);
62  }
63 }
64 
65 /* ************************************************************************* */
67  const std::string& indent, const KeyFormatter& keyFormatter) {
68  std::cout << indent;
69  if(factor) {
70  JacobianFactor::shared_ptr jf = std::dynamic_pointer_cast<JacobianFactor>(factor);
71  HessianFactor::shared_ptr hf = std::dynamic_pointer_cast<HessianFactor>(factor);
72  if(jf) {
73  std::cout << "j( ";
74  } else if(hf) {
75  std::cout << "h( ";
76  } else {
77  std::cout << "g( ";
78  }
79  for(Key key: *factor) {
80  std::cout << keyFormatter(key) << " ";
81  }
82  std::cout << ")" << std::endl;
83  } else {
84  std::cout << "{ nullptr }" << std::endl;
85  }
86 }
87 
88 /* ************************************************************************* */
90  const std::string& indent, const std::string& title, const KeyFormatter& keyFormatter) {
91  std::cout << indent << title << std::endl;
93  PrintLinearFactor(factor, indent + " ", keyFormatter);
94  }
95 }
96 
97 /* ************************************************************************* */
98 void ConcurrentBatchFilter::print(const std::string& s, const KeyFormatter& keyFormatter) const {
99  std::cout << s;
100  PrintNonlinearFactorGraph(factors_, " ", "Factors:");
101  PrintKeys(theta_.keys(), " ", "Values:");
102  PrintNonlinearFactorGraph(smootherFactors_, " ", "Cached Smoother Factors:");
103  PrintKeys(smootherValues_.keys(), " ", "Cached Smoother Values:");
104 }
105 
106 /* ************************************************************************* */
107 bool ConcurrentBatchFilter::equals(const ConcurrentFilter& rhs, double tol) const {
108  const ConcurrentBatchFilter* filter = dynamic_cast<const ConcurrentBatchFilter*>(&rhs);
109  return filter
110  && factors_.equals(filter->factors_)
111  && theta_.equals(filter->theta_)
112  && ordering_.equals(filter->ordering_)
113  && delta_.equals(filter->delta_)
120 }
121 
122 /* ************************************************************************* */
124  const std::optional<FastList<Key> >& keysToMove, const std::optional< std::vector<size_t> >& removeFactorIndices) {
125 
126  gttic(update);
127 
128 // const bool debug = ISDEBUG("ConcurrentBatchFilter update");
129  const bool debug = false;
130 
131  if(debug) std::cout << "ConcurrentBatchFilter::update Begin" << std::endl;
132 
133  // Create the return result meta-data
134  Result result;
135 
136  if(debug) std::cout << "ConcurrentBatchFilter::update Augmenting System ..." << std::endl;
137 
138  // Update all of the internal variables with the new information
139  gttic(augment_system);
140 
141  // Add the new variables to theta
142  theta_.insert(newTheta);
143  // Add new variables to the end of the ordering
144  for (const auto key : newTheta.keys()) {
145  ordering_.push_back(key);
146  }
147  // Augment Delta
148  delta_.insert(newTheta.zeroVectors());
149 
150  // Add the new factors to the graph, updating the variable index
151  result.newFactorsIndices = insertFactors(newFactors);
152 
153  if(removeFactorIndices){
154  if(debug){
155  std::cout << "ConcurrentBatchFilter::update removeFactorIndices " << std::endl;
156  }
157  removeFactors(*removeFactorIndices);
158  }
159 
160  gttoc(augment_system);
161 
162  if(debug) std::cout << "ConcurrentBatchFilter::update Reordering System ..." << std::endl;
163 
164  // Reorder the system to ensure efficient optimization (and marginalization) performance
165  gttic(reorder);
166  reorder(keysToMove);
167  gttoc(reorder);
168 
169  if(debug) std::cout << "ConcurrentBatchFilter::update Optimizing System ..." << std::endl;
170 
171  // Optimize the factors using a modified version of L-M
172  gttic(optimize);
173  if(factors_.size() > 0) {
175  }
176  gttoc(optimize);
177 
178  if(debug) std::cout << "ConcurrentBatchFilter::update Moving Separator ..." << std::endl;
179 
180  gttic(move_separator);
181  if(keysToMove && keysToMove->size() > 0){
182  moveSeparator(*keysToMove);
183  }
184  gttoc(move_separator);
185 
186  if(debug) std::cout << "ConcurrentBatchFilter::update End" << std::endl;
187 
188  gttoc(update);
189 
190  return result;
191 }
192 
193 /* ************************************************************************* */
195 
196  gttic(presync);
197 
198  gttoc(presync);
199 }
200 
201 /* ************************************************************************* */
202 void ConcurrentBatchFilter::synchronize(const NonlinearFactorGraph& smootherSummarization, const Values& smootherSummarizationValues) {
203 
205 
206 // const bool debug = ISDEBUG("ConcurrentBatchFilter synchronize");
207  const bool debug = false;
208 
209  if(debug) std::cout << "ConcurrentBatchFilter::synchronize Begin" << std::endl;
210 
211  if(debug) { PrintNonlinearFactorGraph(smootherSummarization_, "ConcurrentBatchFilter::synchronize ", "Previous Smoother Summarization:", DefaultKeyFormatter); }
212 
213 #ifndef NDEBUG
214  std::set<Key> oldKeys = smootherSummarization_.keys();
215  std::set<Key> newKeys = smootherSummarization.keys();
216  assert(oldKeys.size() == newKeys.size());
217  assert(std::equal(oldKeys.begin(), oldKeys.end(), newKeys.begin()));
218 #endif
219 
220  // Update the smoother summarization on the old separator
221  smootherSummarization_ = smootherSummarization;
222 
223  if(debug) { PrintNonlinearFactorGraph(smootherSummarization_, "ConcurrentBatchFilter::synchronize ", "Updated Smoother Summarization:", DefaultKeyFormatter); }
224 
225  // Find the set of new separator keys
226  const KeySet newSeparatorKeys = separatorValues_.keySet();
227 
228  if(debug) { PrintKeys(newSeparatorKeys, "ConcurrentBatchFilter::synchronize ", "Current Separator Keys:"); }
229 
230  // Use the shortcut to calculate an updated marginal on the current separator
231  {
232  // Combine just the shortcut and the previousSmootherSummarization
234  graph.push_back(smootherSummarization_);
235  graph.push_back(smootherShortcut_);
236  Values values;
237  values.insert(smootherSummarizationValues);
238  for(const auto key: newSeparatorKeys) {
239  if(!values.exists(key)) {
240  values.insert(key, separatorValues_.at(key));
241  }
242  }
243  // Calculate the summarized factor on just the new separator keys
245 
246  // Remove the old factors on the separator and insert new
249 
250  // Clear the smoother shortcut
252  }
253 
254  if(debug) { PrintNonlinearFactorGraph(factors_, separatorSummarizationSlots_, "ConcurrentBatchFilter::synchronize ", "Current Separator Summarization:", DefaultKeyFormatter); }
255 
256  // Calculate the marginal on the new separator from the filter factors
257  // Note: This could also be done during each filter update so it would simply be available
258  {
259  // Calculate the summarized factor on just the new separator keys (from the filter side)
260  // Copy all of the factors from the filter, not including the smoother summarization
262  for(size_t slot = 0; slot < factors_.size(); ++slot) {
263  if(factors_.at(slot) && std::find(separatorSummarizationSlots_.begin(), separatorSummarizationSlots_.end(), slot) == separatorSummarizationSlots_.end()) {
264  factors.push_back(factors_.at(slot));
265  }
266  }
268  }
269 
270  if(debug) { PrintNonlinearFactorGraph(filterSummarization_, "ConcurrentBatchFilter::synchronize ", "Updated Filter Summarization:", DefaultKeyFormatter); }
271 
272  if(debug) std::cout << "ConcurrentBatchFilter::synchronize End" << std::endl;
273 
275 }
276 
277 /* ************************************************************************* */
278 void ConcurrentBatchFilter::getSummarizedFactors(NonlinearFactorGraph& filterSummarization, Values& filterSummarizationValues) {
279 
280  gttic(get_summarized_factors);
281 
282  // Copy the previous calculated smoother summarization factors into the output
283  filterSummarization.push_back(filterSummarization_);
284  filterSummarizationValues.insert(separatorValues_);
285 
286  gttoc(get_summarized_factors);
287 }
288 
289 /* ************************************************************************* */
291 
292  gttic(get_smoother_factors);
293 
294  // Copy the previous calculated smoother summarization factors into the output
295  smootherFactors.push_back(smootherFactors_);
296  smootherValues.insert(smootherValues_);
297 
298  gttoc(get_smoother_factors);
299 }
300 
301 /* ************************************************************************* */
303 
304  gttic(postsync);
305 
306  // Clear out the factors and values that were just sent to the smoother
309 
310  gttoc(postsync);
311 }
312 
313 /* ************************************************************************* */
315 
316  gttic(insert_factors);
317 
318  // create the output vector
319  std::vector<size_t> slots;
320  slots.reserve(factors.size());
321 
322  // Insert the factor into an existing hole in the factor graph, if possible
324  size_t slot;
325  if(availableSlots_.size() > 0) {
326  slot = availableSlots_.front();
327  availableSlots_.pop();
328  factors_.replace(slot, factor);
329  } else {
330  slot = factors_.size();
332  }
333  slots.push_back(slot);
334  }
335 
336  gttoc(insert_factors);
337 
338  return slots;
339 }
340 
341 /* ************************************************************************* */
342 void ConcurrentBatchFilter::removeFactors(const std::vector<size_t>& slots) {
343 
344  gttic(remove_factors);
345 
346  // For each factor slot to delete...
347  for(size_t slot: slots) {
348 
349  // Remove the factor from the graph
350  factors_.remove(slot);
351 
352  // Mark the factor slot as available
353  availableSlots_.push(slot);
354  }
355 
356  gttoc(remove_factors);
357 }
358 
359 /* ************************************************************************* */
360 void ConcurrentBatchFilter::reorder(const std::optional<FastList<Key> >& keysToMove) {
361 
362  // COLAMD groups will be used to place marginalize keys in Group 0, and everything else in Group 1
363  if(keysToMove && keysToMove->size() > 0) {
364  ordering_ = Ordering::ColamdConstrainedFirst(factors_, KeyVector(keysToMove->begin(), keysToMove->end()));
365  }else{
367  }
368 
369 }
370 
371 /* ************************************************************************* */
373  VectorValues& delta, const Values& linearValues, const LevenbergMarquardtParams& parameters,
375 
376  // const bool debug = ISDEBUG("ConcurrentBatchFilter optimize");
377  const bool debug = false;
378 
379  if(debug) std::cout << "ConcurrentBatchFilter::optimize Begin" << std::endl;
380 
381  // Create output result structure
382  result.nonlinearVariables = theta.size() - linearValues.size();
383  result.linearVariables = linearValues.size();
384 
385  // Set optimization parameters
386  double lambda = parameters.lambdaInitial;
387  double lambdaFactor = parameters.lambdaFactor;
388  double lambdaUpperBound = parameters.lambdaUpperBound;
389  double lambdaLowerBound = 1.0e-10;
390  size_t maxIterations = parameters.maxIterations;
391  double relativeErrorTol = parameters.relativeErrorTol;
392  double absoluteErrorTol = parameters.absoluteErrorTol;
393  double errorTol = parameters.errorTol;
394 
395  // Create a Values that holds the current evaluation point
396  Values evalpoint = theta.retract(delta);
397  result.error = factors.error(evalpoint);
398 
399  // check if we're already close enough
400  if(result.error <= errorTol) {
401  if(debug) { std::cout << "Exiting, as error = " << result.error << " < " << errorTol << std::endl; }
402  }
403 
404  if(debug) {
405  std::cout << "linearValues: " << linearValues.size() << std::endl;
406  std::cout << "Initial error: " << result.error << std::endl;
407  }
408 
409  // Use a custom optimization loop so the linearization points can be controlled
410  double previousError;
411  VectorValues newDelta;
412  do {
413  previousError = result.error;
414 
415  // Do next iteration
416  gttic(optimizer_iteration);
417 
418  // Linearize graph around the linearization point
419  GaussianFactorGraph linearFactorGraph = *factors.linearize(theta);
420 
421  // Keep increasing lambda until we make make progress
422  while(true) {
423 
424  if(debug) { std::cout << "trying lambda = " << lambda << std::endl; }
425 
426  // Add prior factors at the current solution
427  gttic(damp);
428  GaussianFactorGraph dampedFactorGraph(linearFactorGraph);
429  dampedFactorGraph.reserve(linearFactorGraph.size() + delta.size());
430  double sigma = 1.0 / std::sqrt(lambda);
431 
432  // for each of the variables, add a prior at the current solution
433  for(const VectorValues::KeyValuePair& key_value: delta) {
434  size_t dim = key_value.second.size();
435  Matrix A = Matrix::Identity(dim,dim);
436  Vector b = key_value.second;
438  GaussianFactor::shared_ptr prior(new JacobianFactor(key_value.first, A, b, model));
439  dampedFactorGraph.push_back(prior);
440  }
441 
442  gttoc(damp);
443  result.lambdas++;
444 
445  gttic(solve);
446  // Solve Damped Gaussian Factor Graph
447  newDelta = dampedFactorGraph.optimize(ordering, parameters.getEliminationFunction());
448  // update the evalpoint with the new delta
449  evalpoint = theta.retract(newDelta);
450  gttoc(solve);
451 
452  // Evaluate the new nonlinear error
453  gttic(compute_error);
454  double error = factors.error(evalpoint);
455  gttoc(compute_error);
456 
457  if(debug) {
458  std::cout << "linear delta norm = " << newDelta.norm() << std::endl;
459  std::cout << "next error = " << error << std::endl;
460  }
461 
462  if(error < result.error) {
463  // Keep this change
464  // Update the error value
465  result.error = error;
466  // Update the linearization point
467  theta = evalpoint;
468  // Reset the deltas to zeros
469  delta.setZero();
470  // Put the linearization points and deltas back for specific variables
471  if(linearValues.size() > 0) {
472  theta.update(linearValues);
473  for(const auto key: linearValues.keys()) {
474  delta.at(key) = newDelta.at(key);
475  }
476  }
477 
478  // Decrease lambda for next time
479  lambda /= lambdaFactor;
480  if(lambda < lambdaLowerBound) {
481  lambda = lambdaLowerBound;
482  }
483  // End this lambda search iteration
484  break;
485  } else {
486  // Reject this change
487  if(lambda >= lambdaUpperBound) {
488  // The maximum lambda has been used. Print a warning and end the search.
489  std::cout << "Warning: Levenberg-Marquardt giving up because cannot decrease error with maximum lambda" << std::endl;
490  break;
491  } else {
492  // Increase lambda and continue searching
493  lambda *= lambdaFactor;
494  }
495  }
496  } // end while
497 
498  gttoc(optimizer_iteration);
499 
500  if(debug) { std::cout << "using lambda = " << lambda << std::endl; }
501 
502  result.iterations++;
503  } while(result.iterations < maxIterations &&
504  !checkConvergence(relativeErrorTol, absoluteErrorTol, errorTol, previousError, result.error, NonlinearOptimizerParams::SILENT));
505 
506  if(debug) { std::cout << "newError: " << result.error << std::endl; }
507 
508  if(debug) std::cout << "ConcurrentBatchFilter::optimize End" << std::endl;
509 }
510 
511 /* ************************************************************************* */
513  // In order to move the separator, we need to calculate the marginal information on the new
514  // separator from all of the factors on the smoother side (both the factors actually in the
515  // smoother and the ones to be transitioned to the smoother but stored in the filter).
516  // This is exactly the same operation that is performed by a fixed-lag smoother, calculating
517  // a marginal factor from the variables outside the smoother window.
518  //
519  // However, for the concurrent system, we would like to calculate this marginal in a particular
520  // way, such that an intermediate term is produced that provides a "shortcut" between the old
521  // separator (as defined in the smoother) and the new separator. This will allow us to quickly
522  // update the new separator with changes at the old separator (from the smoother)
523 
524  // TODO: This is currently not very efficient: multiple calls to graph.keys(), etc.
525 
526 // const bool debug = ISDEBUG("ConcurrentBatchFilter moveSeparator");
527  const bool debug = false;
528 
529  if(debug) std::cout << "ConcurrentBatchFilter::moveSeparator Begin" << std::endl;
530 
531  if(debug) { PrintKeys(keysToMove, "ConcurrentBatchFilter::moveSeparator ", "Keys To Move:", DefaultKeyFormatter); }
532 
533 
534  // Identify all of the new factors to be sent to the smoother (any factor involving keysToMove)
535  std::vector<size_t> removedFactorSlots;
536  VariableIndex variableIndex(factors_);
537  for(Key key: keysToMove) {
538  const auto& slots = variableIndex[key];
539  removedFactorSlots.insert(removedFactorSlots.end(), slots.begin(), slots.end());
540  }
541 
542  // Sort and remove duplicates
543  std::sort(removedFactorSlots.begin(), removedFactorSlots.end());
544  removedFactorSlots.erase(std::unique(removedFactorSlots.begin(), removedFactorSlots.end()), removedFactorSlots.end());
545  // Remove any linear/marginal factor that made it into the set
546  for(size_t index: separatorSummarizationSlots_) {
547  removedFactorSlots.erase(std::remove(removedFactorSlots.begin(), removedFactorSlots.end(), index), removedFactorSlots.end());
548  }
549 
550  // TODO: Make this compact
551  if(debug) {
552  std::cout << "ConcurrentBatchFilter::moveSeparator Removed Factor Slots: ";
553  for(size_t slot: removedFactorSlots) {
554  std::cout << slot << " ";
555  }
556  std::cout << std::endl;
557  }
558 
559  // Add these factors to a factor graph
560  NonlinearFactorGraph removedFactors;
561  for(size_t slot: removedFactorSlots) {
562  if(factors_.at(slot)) {
563  removedFactors.push_back(factors_.at(slot));
564  }
565  }
566 
567  if(debug) {
568  PrintNonlinearFactorGraph(removedFactors, "ConcurrentBatchFilter::synchronize ", "Removed Factors:", DefaultKeyFormatter);
569  PrintNonlinearFactorGraph(smootherShortcut_, "ConcurrentBatchFilter::synchronize ", "Old Shortcut:", DefaultKeyFormatter);
570  PrintKeys(smootherShortcut_.keys(), "ConcurrentBatchFilter::moveSeparator ", "Old Shortcut Keys:", DefaultKeyFormatter);
571  PrintKeys(separatorValues_.keys(), "ConcurrentBatchFilter::moveSeparator ", "Previous Separator Keys:", DefaultKeyFormatter);
572  }
573 
574  // Calculate the set of new separator keys: AffectedKeys + PreviousSeparatorKeys - KeysToMove
575  KeySet newSeparatorKeys = removedFactors.keys();
576  newSeparatorKeys.merge(separatorValues_.keySet());
577  for(Key key: keysToMove) {
578  newSeparatorKeys.erase(key);
579  }
580 
581  if(debug) { PrintKeys(newSeparatorKeys, "ConcurrentBatchFilter::synchronize ", "New Separator Keys:", DefaultKeyFormatter); }
582 
583  // Calculate the set of shortcut keys: NewSeparatorKeys + OldSeparatorKeys
584  KeySet shortcutKeys = newSeparatorKeys;
586  shortcutKeys.insert(key);
587  }
588 
589  if(debug) { PrintKeys(shortcutKeys, "ConcurrentBatchFilter::moveSeparator ", "Old Shortcut Keys:", DefaultKeyFormatter); }
590 
591  // Calculate a new shortcut
592  {
593  // Combine the previous shortcut factor with all of the new factors being sent to the smoother
595  graph.push_back(removedFactors);
596  graph.push_back(smootherShortcut_);
597  Values values;
598  values.insert(smootherValues_);
599  values.insert(theta_);
600  // Calculate the summarized factor on the shortcut keys
602  }
603 
604  if(debug) {
605  PrintNonlinearFactorGraph(smootherShortcut_, "ConcurrentBatchFilter::synchronize ", "New Shortcut:", DefaultKeyFormatter);
606  PrintNonlinearFactorGraph(smootherSummarization_, "ConcurrentBatchFilter::synchronize ", "Smoother Summarization:", DefaultKeyFormatter);
607  PrintNonlinearFactorGraph(factors_, separatorSummarizationSlots_, "ConcurrentBatchFilter::synchronize ", "Current Separator Summarization:", DefaultKeyFormatter);
608  }
609 
610  // Calculate the new smoother summarization on the new separator using the shortcut
611  NonlinearFactorGraph separatorSummarization;
612  {
613  // Combine just the shortcut and the previousSmootherSummarization
615  graph.push_back(smootherSummarization_);
616  graph.push_back(smootherShortcut_);
617  Values values;
618  values.insert(smootherValues_);
619  values.insert(theta_);
620  // Calculate the summarized factor on just the new separator
621  separatorSummarization = internal::calculateMarginalFactors(graph, values, newSeparatorKeys, parameters_.getEliminationFunction());
622  }
623 
624  // Remove the previous marginal factors and insert the new marginal factors
626  separatorSummarizationSlots_ = insertFactors(separatorSummarization);
627 
628  if(debug) { PrintNonlinearFactorGraph(factors_, separatorSummarizationSlots_, "ConcurrentBatchFilter::synchronize ", "New Separator Summarization:", DefaultKeyFormatter); }
629 
630  // Update the separatorValues object (should only contain the new separator keys)
632  for(Key key: separatorSummarization.keys()) {
634  }
635 
636  // Remove the marginalized factors and add them to the smoother cache
637  smootherFactors_.push_back(removedFactors);
638  removeFactors(removedFactorSlots);
639 
640  // Add the linearization point of the moved variables to the smoother cache
641  for(Key key: keysToMove) {
643  }
644 
645  // Remove marginalized keys from values (and separator)
646  for(Key key: keysToMove) {
647  theta_.erase(key);
648  ordering_.erase(std::find(ordering_.begin(), ordering_.end(), key));
649  delta_.erase(key);
650  }
651 
652  if(debug) std::cout << "ConcurrentBatchFilter::moveSeparator End" << std::endl;
653 }
654 
655 /* ************************************************************************* */
656 }
gttoc
#define gttoc(label)
Definition: timing.h:296
timing.h
Timing utilities.
gtsam::ConcurrentBatchFilter::removeFactors
void removeFactors(const std::vector< size_t > &slots)
Definition: ConcurrentBatchFilter.cpp:342
gtsam::NonlinearFactor::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: NonlinearFactor.h:79
gtsam::NonlinearFactorGraph::equals
bool equals(const NonlinearFactorGraph &other, double tol=1e-9) const
Definition: NonlinearFactorGraph.cpp:97
gtsam::Values::keys
KeyVector keys() const
Definition: Values.cpp:219
gtsam::ConcurrentBatchFilter::separatorValues_
Values separatorValues_
The linearization points of the separator variables. These should not be updated during optimization.
Definition: ConcurrentBatchFilter.h:175
gtsam::Values::size
size_t size() const
Definition: Values.h:178
s
RealScalar s
Definition: level1_cplx_impl.h:126
LinearContainerFactor.h
Wrap Jacobian and Hessian linear factors to allow simple injection into a nonlinear graph.
gtsam::VectorValues::insert
iterator insert(const std::pair< Key, Vector > &key_value)
Definition: VectorValues.cpp:90
gtsam::VectorValues::at
Vector & at(Key j)
Definition: VectorValues.h:142
simple_graph::factors
const GaussianFactorGraph factors
Definition: testJacobianFactor.cpp:213
gtsam::ConcurrentBatchFilter::getSmootherFactors
void getSmootherFactors(NonlinearFactorGraph &smootherFactors, Values &smootherValues) override
Definition: ConcurrentBatchFilter.cpp:290
ConcurrentBatchFilter.h
A Levenberg-Marquardt Batch Filter that implements the Concurrent Filtering and Smoothing interface.
gtsam::JacobianFactor
Definition: JacobianFactor.h:91
gtsam::ConcurrentBatchFilter::factors_
NonlinearFactorGraph factors_
The set of all factors currently in the filter.
Definition: ConcurrentBatchFilter.h:170
gtsam::NonlinearOptimizerParams::SILENT
@ SILENT
Definition: NonlinearOptimizerParams.h:39
gtsam::ConcurrentBatchFilter::optimize
static void optimize(const NonlinearFactorGraph &factors, Values &theta, const Ordering &ordering, VectorValues &delta, const Values &linearValues, const LevenbergMarquardtParams &parameters, Result &result)
Definition: ConcurrentBatchFilter.cpp:372
gtsam::FastSet::merge
void merge(const FastSet &other)
Definition: FastSet.h:121
gtsam::ConcurrentBatchFilter::presync
void presync() override
Definition: ConcurrentBatchFilter.cpp:194
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::HessianFactor::shared_ptr
std::shared_ptr< This > shared_ptr
A shared_ptr to this class.
Definition: HessianFactor.h:108
gtsam::ConcurrentBatchFilter::smootherFactors_
NonlinearFactorGraph smootherFactors_
A temporary holding place for the set of full nonlinear factors being sent to the smoother.
Definition: ConcurrentBatchFilter.h:184
gtsam::FastSet< Key >
GaussianJunctionTree.h
gtsam::Values::update
void update(Key j, const Value &val)
Definition: Values.cpp:170
gtsam::ConcurrentBatchFilter::Result
Definition: ConcurrentBatchFilter.h:38
gtsam::ConcurrentBatchFilter::PrintKeys
static void PrintKeys(const Container &keys, const std::string &indent, const std::string &title, const KeyFormatter &keyFormatter=DefaultKeyFormatter)
Implementation of PrintKeys.
Definition: ConcurrentBatchFilter.h:245
gtsam::ConcurrentBatchFilter::PrintLinearFactor
static void PrintLinearFactor(const GaussianFactor::shared_ptr &factor, const std::string &indent="", const KeyFormatter &keyFormatter=DefaultKeyFormatter)
Definition: ConcurrentBatchFilter.cpp:66
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::ConcurrentBatchFilter::smootherSummarization_
NonlinearFactorGraph smootherSummarization_
The smoother summarization on the old separator sent by the smoother during the last synchronization.
Definition: ConcurrentBatchFilter.h:179
sampling::sigma
static const double sigma
Definition: testGaussianBayesNet.cpp:170
gtsam::ConcurrentBatchFilter::print
void print(const std::string &s="Concurrent Batch Filter:\n", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: ConcurrentBatchFilter.cpp:98
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::checkConvergence
bool checkConvergence(double relativeErrorTreshold, double absoluteErrorTreshold, double errorThreshold, double currentError, double newError, NonlinearOptimizerParams::Verbosity verbosity)
Definition: NonlinearOptimizer.cpp:182
gtsam::ConcurrentBatchFilter::parameters_
LevenbergMarquardtParams parameters_
LM parameters.
Definition: ConcurrentBatchFilter.h:169
pruning_fixture::factor
DecisionTreeFactor factor(D &C &B &A, "0.0 0.0 0.0 0.60658897 0.61241912 0.61241969 0.61247685 0.61247742 0.0 " "0.0 0.0 0.99995287 1.0 1.0 1.0 1.0")
gtsam::ConcurrentBatchFilter::moveSeparator
void moveSeparator(const FastList< Key > &keysToMove)
Definition: ConcurrentBatchFilter.cpp:512
gtsam::FactorGraph::at
const sharedFactor at(size_t i) const
Definition: FactorGraph.h:306
gtsam::ConcurrentFilter
Definition: ConcurrentFilteringAndSmoothing.h:39
gtsam::ConcurrentBatchFilter::smootherValues_
Values smootherValues_
A temporary holding place for the linearization points of all keys being sent to the smoother.
Definition: ConcurrentBatchFilter.h:185
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
gtsam::ConcurrentBatchFilter::PrintLinearFactorGraph
static void PrintLinearFactorGraph(const GaussianFactorGraph &factors, const std::string &indent="", const std::string &title="", const KeyFormatter &keyFormatter=DefaultKeyFormatter)
Definition: ConcurrentBatchFilter.cpp:89
gtsam::Values::at
const ValueType at(Key j) const
Definition: Values-inl.h:261
gtsam::Values::retract
Values retract(const VectorValues &delta) const
Definition: Values.cpp:99
gtsam::FactorGraph::resize
virtual void resize(size_t size)
Definition: FactorGraph.h:367
gtsam::ConcurrentBatchFilter::getSummarizedFactors
void getSummarizedFactors(NonlinearFactorGraph &filterSummarization, Values &filterSummarizationValues) override
Definition: ConcurrentBatchFilter.cpp:278
A
Definition: test_numpy_dtypes.cpp:298
gtsam::ConcurrentBatchFilter::equals
bool equals(const ConcurrentFilter &rhs, double tol=1e-9) const override
Definition: ConcurrentBatchFilter.cpp:107
gtsam::ConcurrentBatchFilter::availableSlots_
std::queue< size_t > availableSlots_
The set of available factor graph slots caused by deleting factors.
Definition: ConcurrentBatchFilter.h:174
gtsam.examples.PlanarManipulatorExample.delta
def delta(g0, g1)
Definition: PlanarManipulatorExample.py:45
gtsam::VectorValues
Definition: VectorValues.h:74
gtsam::internal::calculateMarginalFactors
NonlinearFactorGraph calculateMarginalFactors(const NonlinearFactorGraph &graph, const Values &theta, const KeySet &remainingKeys, const GaussianFactorGraph::Eliminate &eliminateFunction)
Definition: ConcurrentFilteringAndSmoothing.cpp:54
gtsam::Ordering::ColamdConstrainedFirst
static Ordering ColamdConstrainedFirst(const FACTOR_GRAPH &graph, const KeyVector &constrainFirst, bool forceOrder=false)
Definition: inference/Ordering.h:139
gtsam::ConcurrentBatchFilter::PrintNonlinearFactorGraph
static void PrintNonlinearFactorGraph(const NonlinearFactorGraph &factors, const std::string &indent="", const std::string &title="", const KeyFormatter &keyFormatter=DefaultKeyFormatter)
Definition: ConcurrentBatchFilter.cpp:48
gtsam::Ordering::Colamd
static Ordering Colamd(const FACTOR_GRAPH &graph)
Definition: inference/Ordering.h:93
gtsam::KeyFormatter
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
parameters
static ConjugateGradientParameters parameters
Definition: testIterative.cpp:33
gtsam::FactorGraph::replace
void replace(size_t index, sharedFactor factor)
Definition: FactorGraph.h:374
gtsam::ConcurrentBatchFilter::reorder
void reorder(const std::optional< FastList< Key > > &keysToMove={})
Definition: ConcurrentBatchFilter.cpp:360
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
debug
static constexpr bool debug
Definition: testDiscreteBayesTree.cpp:31
gtsam::GaussianFactor::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
gtsam::SharedDiagonal
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:764
gtsam::FactorGraph::keys
KeySet keys() const
Definition: FactorGraph-inst.h:85
gtsam::Values::equals
bool equals(const Values &other, double tol=1e-9) const
Definition: Values.cpp:78
gtsam::ConcurrentBatchFilter
Definition: ConcurrentBatchFilter.h:31
gtsam::Ordering::equals
bool equals(const Ordering &other, double tol=1e-9) const
Definition: Ordering.cpp:309
gtsam::FastList
Definition: FastList.h:43
gtsam::VariableIndex
Definition: VariableIndex.h:41
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
lambda
static double lambda[]
Definition: jv.c:524
ordering
static enum @1096 ordering
gtsam::VectorValues::norm
double norm() const
Definition: VectorValues.cpp:255
gtsam::ConcurrentBatchFilter::postsync
void postsync() override
Definition: ConcurrentBatchFilter.cpp:302
key
const gtsam::Symbol key('X', 0)
gtsam::FactorGraph::remove
void remove(size_t i)
Definition: FactorGraph.h:371
gtsam::FactorGraph::size
size_t size() const
Definition: FactorGraph.h:297
gtsam::Values::zeroVectors
VectorValues zeroVectors() const
Definition: Values.cpp:261
gtsam::b
const G & b
Definition: Group.h:79
gtsam::Values::keySet
KeySet keySet() const
Definition: Values.cpp:228
gtsam::ConcurrentBatchFilter::synchronize
void synchronize(const NonlinearFactorGraph &smootherSummarization, const Values &smootherSummarizationValues) override
Definition: ConcurrentBatchFilter.cpp:202
gtsam::VectorValues::equals
bool equals(const VectorValues &x, double tol=1e-9) const
Definition: VectorValues.cpp:161
gtsam
traits
Definition: SFMdata.h:40
error
static double error
Definition: testRot3.cpp:37
gtsam::FactorGraph::push_back
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:147
gtsam::Values
Definition: Values.h:65
gtsam::Values::clear
void clear()
Definition: Values.h:347
gtsam::Values::insert
void insert(Key j, const Value &val)
Definition: Values.cpp:156
gtsam::LevenbergMarquardtParams
Definition: LevenbergMarquardtParams.h:35
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::JacobianFactor::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: JacobianFactor.h:97
gtsam::noiseModel::Isotropic::Sigma
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
Definition: NoiseModel.cpp:625
different_sigmas::prior
const auto prior
Definition: testHybridBayesNet.cpp:238
gtsam::Values::erase
void erase(Key j)
Definition: Values.cpp:211
gtsam::ConcurrentBatchFilter::insertFactors
std::vector< size_t > insertFactors(const NonlinearFactorGraph &factors)
Definition: ConcurrentBatchFilter.cpp:314
gtsam::FactorGraph::reserve
void reserve(size_t size)
Definition: FactorGraph.h:143
gtsam::ConcurrentBatchFilter::delta_
VectorValues delta_
The current set of linear deltas from the linearization point.
Definition: ConcurrentBatchFilter.h:173
gtsam::ConcurrentBatchFilter::ordering_
Ordering ordering_
The current ordering used to calculate the linear deltas.
Definition: ConcurrentBatchFilter.h:172
gtsam::ConcurrentBatchFilter::theta_
Values theta_
Current linearization point of all variables in the filter.
Definition: ConcurrentBatchFilter.h:171
gtsam::VectorValues::erase
void erase(Key var)
Definition: VectorValues.h:229
gtsam::ConcurrentBatchFilter::update
virtual Result update(const NonlinearFactorGraph &newFactors=NonlinearFactorGraph(), const Values &newTheta=Values(), const std::optional< FastList< Key > > &keysToMove={}, const std::optional< std::vector< size_t > > &removeFactorIndices={})
Definition: ConcurrentBatchFilter.cpp:123
gtsam::GaussianFactorGraph::optimize
VectorValues optimize(const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
Definition: GaussianFactorGraph.cpp:309
gtsam::VectorValues::KeyValuePair
value_type KeyValuePair
Typedef to pair<Key, Vector>
Definition: VectorValues.h:88
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::NonlinearOptimizerParams::getEliminationFunction
GaussianFactorGraph::Eliminate getEliminationFunction() const
Definition: NonlinearOptimizerParams.h:137
gtsam::Ordering
Definition: inference/Ordering.h:33
gtsam::ConcurrentBatchFilter::filterSummarization_
NonlinearFactorGraph filterSummarization_
A temporary holding place for calculated filter summarization factors to be sent to the smoother.
Definition: ConcurrentBatchFilter.h:183
gtsam::equal
bool equal(const T &obj1, const T &obj2, double tol)
Definition: Testable.h:85
gtsam::ConcurrentBatchFilter::PrintNonlinearFactor
static void PrintNonlinearFactor(const NonlinearFactor::shared_ptr &factor, const std::string &indent="", const KeyFormatter &keyFormatter=DefaultKeyFormatter)
Definition: ConcurrentBatchFilter.cpp:29
ceres::sqrt
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418
gttic
#define gttic(label)
Definition: timing.h:295
debug.h
Global debugging flags.
gtsam::ConcurrentBatchFilter::smootherShortcut_
NonlinearFactorGraph smootherShortcut_
A set of conditional factors from the old separator to the current separator (recursively calculated ...
Definition: ConcurrentBatchFilter.h:180
gtsam::ConcurrentBatchFilter::separatorSummarizationSlots_
std::vector< size_t > separatorSummarizationSlots_
The slots in factor graph that correspond to the current smoother summarization on the current separa...
Definition: ConcurrentBatchFilter.h:176


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:17