From 82dba6322f4d4018a59c55f11d9a982a23d4ab7a Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 6 Jan 2025 22:14:59 -0500 Subject: [PATCH] new scaledProduct method instead of DiscreteProduct --- gtsam/discrete/DiscreteFactorGraph.cpp | 9 ++++----- gtsam/discrete/DiscreteFactorGraph.h | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gtsam/discrete/DiscreteFactorGraph.cpp b/gtsam/discrete/DiscreteFactorGraph.cpp index eb3221819..cd31c52a0 100644 --- a/gtsam/discrete/DiscreteFactorGraph.cpp +++ b/gtsam/discrete/DiscreteFactorGraph.cpp @@ -124,11 +124,10 @@ namespace gtsam { * @param factors The factors to multiply as a DiscreteFactorGraph. * @return DiscreteFactor::shared_ptr */ - static DiscreteFactor::shared_ptr DiscreteProduct( - const DiscreteFactorGraph& factors) { + DiscreteFactor::shared_ptr DiscreteFactorGraph::scaledProduct() const { // PRODUCT: multiply all factors gttic(product); - DiscreteFactor::shared_ptr product = factors.product(); + DiscreteFactor::shared_ptr product = this->product(); gttoc(product); // Max over all the potentials by pretending all keys are frontal: @@ -145,7 +144,7 @@ namespace gtsam { std::pair // EliminateForMPE(const DiscreteFactorGraph& factors, const Ordering& frontalKeys) { - DiscreteFactor::shared_ptr product = DiscreteProduct(factors); + DiscreteFactor::shared_ptr product = factors.scaledProduct(); // max out frontals, this is the factor on the separator gttic(max); @@ -223,7 +222,7 @@ namespace gtsam { std::pair // EliminateDiscrete(const DiscreteFactorGraph& factors, const Ordering& frontalKeys) { - DiscreteFactor::shared_ptr product = DiscreteProduct(factors); + DiscreteFactor::shared_ptr product = factors.scaledProduct(); // sum out frontals, this is the factor on the separator gttic(sum); diff --git a/gtsam/discrete/DiscreteFactorGraph.h b/gtsam/discrete/DiscreteFactorGraph.h index 3d9e86cd1..162d9b748 100644 --- a/gtsam/discrete/DiscreteFactorGraph.h +++ b/gtsam/discrete/DiscreteFactorGraph.h @@ -150,6 +150,11 @@ class GTSAM_EXPORT DiscreteFactorGraph /** return product of all factors as a single factor */ DiscreteFactor::shared_ptr product() const; + /** Return product of all factors as a single factor, + * which is scaled by the max to prevent underflow + */ + DiscreteFactor::shared_ptr scaledProduct() const; + /** * Evaluates the factor graph given values, returns the joint probability of * the factor graph given specific instantiation of values