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) Re-linearization doesn't take into account pruning
43  reorderRelinearize();
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::reorderRelinearize() {
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 re-linearization 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
Eigen::internal::print
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: NEON/PacketMath.h:3115
relicense.update
def update(text)
Definition: relicense.py:46
gtsam::HybridValues
Definition: HybridValues.h:37
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::HybridNonlinearFactorGraph
Definition: HybridNonlinearFactorGraph.h:33
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
Ordering.h
Variable ordering for the elimination algorithm.
result
Values result
Definition: OdometryOptimize.cpp:8
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
ordering
static enum @1096 ordering
gtsam::FactorGraph::size
size_t size() const
Definition: FactorGraph.h:297
HybridGaussianFactorGraph.h
Linearized Hybrid factor graph that uses type erasure.
gtsam
traits
Definition: SFMdata.h:40
gtsam::Values
Definition: Values.h:65
std
Definition: BFloat16.h:88
gtsam::HybridNonlinearFactorGraph::linearize
std::shared_ptr< HybridGaussianFactorGraph > linearize(const Values &continuousValues) const
Linearize all the continuous factors in the HybridNonlinearFactorGraph.
Definition: HybridNonlinearFactorGraph.cpp:139
HybridNonlinearISAM.h


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:43