Skip to content

Commit e1f5a51

Browse files
committed
update the HybridCity10000 script
1 parent d2f1371 commit e1f5a51

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

gtsam/hybrid/HybridSmoother.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,9 @@ Values HybridSmoother::linearizationPoint() const {
307307
return linearizationPoint_;
308308
}
309309

310+
/* ************************************************************************* */
311+
HybridNonlinearFactorGraph HybridSmoother::allFactors() const {
312+
return allFactors_;
313+
}
314+
310315
} // namespace gtsam

gtsam/hybrid/HybridSmoother.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class GTSAM_EXPORT HybridSmoother {
133133
/// Return the current linearization point.
134134
Values linearizationPoint() const;
135135

136+
/// Return all the recorded nonlinear factors
137+
HybridNonlinearFactorGraph allFactors() const;
138+
136139
private:
137140
/// Helper to compute the ordering if ordering is not given.
138141
Ordering maybeComputeOrdering(const HybridGaussianFactorGraph& updatedGraph,

gtsam/hybrid/hybrid.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class HybridSmoother {
291291
void relinearize();
292292

293293
gtsam::Values linearizationPoint() const;
294+
gtsam::HybridNonlinearFactorGraph allFactors() const;
294295

295296
gtsam::Ordering getOrdering(const gtsam::HybridGaussianFactorGraph& factors,
296297
const gtsam::KeySet& newFactorKeys);

python/gtsam/examples/HybridCity10000.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def __init__(self,
194194

195195
self.smoother_ = HybridSmoother(marginal_threshold)
196196
self.new_factors_ = HybridNonlinearFactorGraph()
197-
self.all_factors_ = HybridNonlinearFactorGraph()
198197
self.initial_ = Values()
199198

200199
self.plot_hypotheses = plot_hypotheses
@@ -231,24 +230,18 @@ def smoother_update(self, max_num_hypotheses) -> float:
231230
"""Perform smoother update and optimize the graph."""
232231
print(f"Smoother update: {self.new_factors_.size()}")
233232
before_update = time.time()
234-
linearized = self.new_factors_.linearize(self.initial_)
235-
self.smoother_.update(linearized, max_num_hypotheses)
236-
self.all_factors_.push_back(self.new_factors_)
233+
self.smoother_.update(self.new_factors_, self.initial_,
234+
max_num_hypotheses)
237235
self.new_factors_.resize(0)
238236
after_update = time.time()
239237
return after_update - before_update
240238

241239
def reinitialize(self) -> float:
242240
"""Re-linearize, solve ALL, and re-initialize smoother."""
243-
print(f"================= Re-Initialize: {self.all_factors_.size()}")
241+
print(f"================= Re-Initialize: {self.smoother_.allFactors().size()}")
244242
before_update = time.time()
245-
self.all_factors_ = self.all_factors_.restrict(
246-
self.smoother_.fixedValues())
247-
linearized = self.all_factors_.linearize(self.initial_)
248-
bayesNet = linearized.eliminateSequential()
249-
delta: HybridValues = bayesNet.optimize()
250-
self.initial_ = self.initial_.retract(delta.continuous())
251-
self.smoother_.reInitialize(bayesNet)
243+
self.smoother_.relinearize()
244+
self.initial_ = self.smoother_.linearizationPoint()
252245
after_update = time.time()
253246
print(f"Took {after_update - before_update} seconds.")
254247
return after_update - before_update

0 commit comments

Comments
 (0)