Skip to content

Commit c254e4c

Browse files
committed
update removeFixedValues to reintroduce a discrete factor on the removed value.
1 parent 48ca735 commit c254e4c

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

gtsam/hybrid/HybridSmoother.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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: ";

gtsam/hybrid/HybridSmoother.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,19 @@ class GTSAM_EXPORT HybridSmoother {
145145
Ordering maybeComputeOrdering(const HybridGaussianFactorGraph& updatedGraph,
146146
const std::optional<Ordering> givenOrdering);
147147

148-
/// Remove fixed discrete values for discrete keys introduced in `newFactors`.
149-
void removeFixedValues(const HybridGaussianFactorGraph& newFactors);
148+
/**
149+
* @brief Remove fixed discrete values for discrete keys
150+
* introduced in `newFactors`, and reintroduce discrete factors
151+
* with marginalThreshold_ as the probability value.
152+
*
153+
* @param graph The factor graph with previous conditionals added in.
154+
* @param newFactors The new factors added to the smoother,
155+
* used to check if a fixed discrete value has been reintroduced.
156+
* @return HybridGaussianFactorGraph
157+
*/
158+
HybridGaussianFactorGraph removeFixedValues(
159+
const HybridGaussianFactorGraph& graph,
160+
const HybridGaussianFactorGraph& newFactors);
150161
};
151162

152163
} // namespace gtsam

0 commit comments

Comments
 (0)