@@ -86,13 +86,28 @@ Ordering HybridSmoother::maybeComputeOrdering(
8686}
8787
8888/* ************************************************************************* */
89- void HybridSmoother::removeFixedValues (
89+ HybridGaussianFactorGraph HybridSmoother::removeFixedValues (
90+ const HybridGaussianFactorGraph &graph,
9091 const HybridGaussianFactorGraph &newFactors) {
91- for (Key key : newFactors.discreteKeySet ()) {
92+ // Initialize graph
93+ HybridGaussianFactorGraph updatedGraph (graph);
94+
95+ for (DiscreteKey dkey : newFactors.discreteKeys ()) {
96+ Key key = dkey.first ;
9297 if (fixedValues_.find (key) != fixedValues_.end ()) {
98+ // Add corresponding discrete factor to reintroduce the information
99+ std::vector<double > probabilities (
100+ dkey.second , (1 - *marginalThreshold_) / dkey.second );
101+ probabilities[fixedValues_[key]] = *marginalThreshold_;
102+ DecisionTreeFactor dtf ({dkey}, probabilities);
103+ updatedGraph.push_back (dtf);
104+
105+ // Remove fixed value
93106 fixedValues_.erase (key);
94107 }
95108 }
109+
110+ return updatedGraph;
96111}
97112
98113/* ************************************************************************* */
@@ -126,6 +141,11 @@ void HybridSmoother::update(const HybridNonlinearFactorGraph &newFactors,
126141 << std::endl;
127142#endif
128143
144+ if (marginalThreshold_) {
145+ // Remove fixed values for discrete keys which are introduced in newFactors
146+ updatedGraph = removeFixedValues (updatedGraph, newFactors);
147+ }
148+
129149 Ordering ordering = this ->maybeComputeOrdering (updatedGraph, given_ordering);
130150
131151#if GTSAM_HYBRID_TIMING
@@ -145,9 +165,6 @@ void HybridSmoother::update(const HybridNonlinearFactorGraph &newFactors,
145165 }
146166#endif
147167
148- // Remove fixed values for discrete keys which are introduced in newFactors
149- removeFixedValues (newFactors);
150-
151168#ifdef DEBUG_SMOOTHER
152169 // Print discrete keys in the bayesNetFragment:
153170 std::cout << " Discrete keys in bayesNetFragment: " ;
0 commit comments