From fe880826ac9519b19b4244a66a1864920226034a Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 26 Jan 2025 10:16:25 -0500 Subject: [PATCH] check for keys leftover after pruning so marginalization works correctly --- gtsam/hybrid/HybridBayesNet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gtsam/hybrid/HybridBayesNet.cpp b/gtsam/hybrid/HybridBayesNet.cpp index 68c248119..e64284a94 100644 --- a/gtsam/hybrid/HybridBayesNet.cpp +++ b/gtsam/hybrid/HybridBayesNet.cpp @@ -66,7 +66,9 @@ HybridBayesNet HybridBayesNet::prune( pruned.prune(maxNrLeaves); DiscreteValues deadModesValues; - if (deadModeThreshold.has_value()) { + // If we have a dead mode threshold and discrete variables left after pruning, + // then we run dead mode removal. + if (deadModeThreshold.has_value() && pruned.keys().size() > 0) { DiscreteMarginals marginals(DiscreteFactorGraph{pruned}); for (auto dkey : pruned.discreteKeys()) { Vector probabilities = marginals.marginalProbabilities(dkey);