HybridNonlinearISAM.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 
22 #include <iostream>
23 
24 using namespace std;
25 
26 namespace gtsam {
27 
28 /* ************************************************************************* */
29 void HybridNonlinearISAM::saveGraph(const string& s,
30  const KeyFormatter& keyFormatter) const {
31  isam_.saveGraph(s, keyFormatter);
32 }
33 
34 /* ************************************************************************* */
36  const Values& initialValues,
37  const std::optional<size_t>& maxNrLeaves,
38  const std::optional<Ordering>& ordering) {
39  if (newFactors.size() > 0) {
40  // Reorder and relinearize every reorderInterval updates
41  if (reorderInterval_ > 0 && ++reorderCounter_ >= reorderInterval_) {
42  // TODO(Varun) Relinearization doesn't take into account pruning
43  reorder_relinearize();
44  reorderCounter_ = 0;
45  }
46 
47  factors_.push_back(newFactors);
48 
49  // Linearize new factors and insert them
50  // TODO: optimize for whole config?
51  linPoint_.insert(initialValues);
52 
53  std::shared_ptr<HybridGaussianFactorGraph> linearizedNewFactors =
54  newFactors.linearize(linPoint_);
55 
56  // Update ISAM
57  isam_.update(*linearizedNewFactors, maxNrLeaves, ordering,
58  eliminationFunction_);
59  }
60 }
61 
62 /* ************************************************************************* */
63 void HybridNonlinearISAM::reorder_relinearize() {
64  if (factors_.size() > 0) {
65  // Obtain the new linearization point
66  const Values newLinPoint = estimate();
67 
68  isam_.clear();
69 
70  // Just recreate the whole BayesTree
71  // TODO: allow for constrained ordering here
72  // TODO: decouple relinearization and reordering to avoid
73  isam_.update(*factors_.linearize(newLinPoint), {}, {},
74  eliminationFunction_);
75 
76  // Update linearization point
77  linPoint_ = newLinPoint;
78  }
79 }
80 
81 /* ************************************************************************* */
82 Values HybridNonlinearISAM::estimate() {
83  Values result;
84  if (isam_.size() > 0) {
85  HybridValues values = isam_.optimize();
86  assignment_ = values.discrete();
87  return linPoint_.retract(values.continuous());
88  } else {
89  return linPoint_;
90  }
91 }
92 
93 // /* *************************************************************************
94 // */ Matrix HybridNonlinearISAM::marginalCovariance(Key key) const {
95 // return isam_.marginalCovariance(key);
96 // }
97 
98 /* ************************************************************************* */
99 void HybridNonlinearISAM::print(const string& s,
100  const KeyFormatter& keyFormatter) const {
101  cout << s << "ReorderInterval: " << reorderInterval_
102  << " Current Count: " << reorderCounter_ << endl;
103  std::cout << "HybridGaussianISAM:" << std::endl;
104  isam_.print("", keyFormatter);
105  linPoint_.print("Linearization Point:\n", keyFormatter);
106  std::cout << "Nonlinear Graph:" << std::endl;
107  factors_.print("", keyFormatter);
108 }
109 
110 /* ************************************************************************* */
111 void HybridNonlinearISAM::printStats() const {
112  isam_.getCliqueData().getStats().print();
113 }
114 
115 /* ************************************************************************* */
116 
117 } // namespace gtsam
def update(text)
Definition: relicense.py:46
leaf::MyValues values
Definition: BFloat16.h:88
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
const VectorValues & continuous() const
Return the multi-dimensional vector values.
Definition: HybridValues.h:89
static enum @1107 ordering
size_t size() const
Definition: FactorGraph.h:334
Values result
RealScalar s
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
Linearized Hybrid factor graph that uses type erasure.
traits
Definition: chartTesting.h:28
const DiscreteValues & discrete() const
Return the discrete values.
Definition: HybridValues.h:92
std::shared_ptr< HybridGaussianFactorGraph > linearize(const Values &continuousValues) const
Linearize all the continuous factors in the HybridNonlinearFactorGraph.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:20