From 04cfb063aec39c026a38f1cb254627fdeb5e8b7f Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Mon, 7 Oct 2024 09:19:35 +0900 Subject: [PATCH] Cherry-pick Varun's bugfix --- gtsam/hybrid/HybridGaussianFactorGraph.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gtsam/hybrid/HybridGaussianFactorGraph.cpp b/gtsam/hybrid/HybridGaussianFactorGraph.cpp index 2d4ff38bd..38995b60a 100644 --- a/gtsam/hybrid/HybridGaussianFactorGraph.cpp +++ b/gtsam/hybrid/HybridGaussianFactorGraph.cpp @@ -247,7 +247,8 @@ static std::pair> discret // In this case, compute discrete probabilities. auto logProbability = [&](const auto& pair) -> double { auto [factor, _] = pair; - if (!factor) return 0.0; + // If the factor is null, it is has been pruned hence return ∞ + // so that the exp(-∞)=0. return factor->error(VectorValues()); }; AlgebraicDecisionTree logProbabilities = @@ -299,7 +300,9 @@ static std::shared_ptr createDiscreteFactor(const ResultTree& eliminatio // which is `-log(k) = log(1/k) = log(\sqrt{|2πΣ|})`. return factor->error(kEmpty) - conditional->negLogConstant(); } else if (!conditional && !factor) { - return 1.0; // TODO(dellaert): not loving this, what should this be?? + // If the factor is null, it has been pruned, hence return ∞ + // so that the exp(-∞)=0. + return std::numeric_limits::infinity(); } else { throw std::runtime_error("createDiscreteFactor has mixed NULLs"); }