add explanatory comments

release/4.3a0
Varun Agrawal 2025-01-28 22:08:17 -05:00
parent 2702854c18
commit 2e4ae8ca0a
1 changed files with 5 additions and 1 deletions

View File

@ -215,6 +215,7 @@ 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);
@ -224,6 +225,9 @@ namespace gtsam {
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);