From d4d95e2342e5c1d9759bc2e068d0d2049e97df70 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Tue, 28 Jan 2025 17:22:44 -0500 Subject: [PATCH] scale product and sum so we don't get all 0s --- gtsam/discrete/DiscreteFactorGraph.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gtsam/discrete/DiscreteFactorGraph.cpp b/gtsam/discrete/DiscreteFactorGraph.cpp index 7e059c5e5..1fb353423 100644 --- a/gtsam/discrete/DiscreteFactorGraph.cpp +++ b/gtsam/discrete/DiscreteFactorGraph.cpp @@ -125,11 +125,8 @@ namespace gtsam { DiscreteFactor::shared_ptr product = this->product(); gttoc(product); - // Max over all the potentials by pretending all keys are frontal: - auto denominator = product->max(product->size()); - // Normalize the product factor to prevent underflow. - product = product->operator/(denominator); + product = product->scale(); return product; } @@ -222,6 +219,8 @@ namespace gtsam { // sum out frontals, this is the factor on the separator gttic(sum); DiscreteFactor::shared_ptr sum = product->sum(frontalKeys); + // Normalize/scale to prevent underflow. + sum = sum->scale(); gttoc(sum); // Ordering keys for the conditional so that frontalKeys are really in front