Skip to content

Commit

Permalink
add explanatory comments
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Jan 29, 2025
1 parent 2702854 commit 2e4ae8c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gtsam/discrete/DiscreteFactorGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,19 @@ namespace gtsam {
EliminateDiscrete(const DiscreteFactorGraph& factors,
const Ordering& frontalKeys) {
gttic(product);
// `product` is scaled later to prevent underflow.
DiscreteFactor::shared_ptr product = factors.product();
gttoc(product);

// sum out frontals, this is the factor on the separator
gttic(sum);
DiscreteFactor::shared_ptr sum = product->sum(frontalKeys);
gttoc(sum);

// Normalize/scale to prevent underflow.
// We divide both `product` and `sum` by `max(sum)`
// since it is faster to compute and when the conditional
// is formed by `product/sum`, the scaling term cancels out.
gttic(scale);
DiscreteFactor::shared_ptr denominator = sum->max(sum->size());
product = product->operator/(denominator);
Expand Down

0 comments on commit 2e4ae8c

Please sign in to comment.