From 9d0be8f2b2692f2ae4a81c2c1acd3dfa26f227a9 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 8 Feb 2023 08:55:03 -0500 Subject: [PATCH] Use simpler normalization for max-product. --- gtsam/discrete/DiscreteFactorGraph.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gtsam/discrete/DiscreteFactorGraph.cpp b/gtsam/discrete/DiscreteFactorGraph.cpp index 2ed499a4c..2073164c3 100644 --- a/gtsam/discrete/DiscreteFactorGraph.cpp +++ b/gtsam/discrete/DiscreteFactorGraph.cpp @@ -121,9 +121,10 @@ namespace gtsam { for (auto&& factor : factors) product = (*factor) * product; gttoc(product); - // Normalize the product factor to prevent underflow - Ordering ordering = Ordering::Colamd(DiscreteFactorGraph{product}); - DecisionTreeFactor::shared_ptr normalization = product.sum(ordering); + // Sum all the potentials by pretending all keys are frontal: + auto normalization = product.sum(product.size()); + + // Normalize the product factor to prevent underflow. product = product / (*normalization); // max out frontals, this is the factor on the separator