Add normalization to max-product, avoiding underflow.

release/4.3a0
Kevin 2023-02-07 10:15:57 -05:00
parent 2856282932
commit 148d99f1d1
1 changed files with 5 additions and 0 deletions

View File

@ -121,6 +121,11 @@ namespace gtsam {
for (auto&& factor : factors) product = (*factor) * product; for (auto&& factor : factors) product = (*factor) * product;
gttoc(product); gttoc(product);
// Normalize the product factor to prevent underflow
Ordering ordering = Ordering::Colamd(DiscreteFactorGraph{product});
DecisionTreeFactor::shared_ptr normalization = product.sum(ordering);
product = product / (*normalization);
// max out frontals, this is the factor on the separator // max out frontals, this is the factor on the separator
gttic(max); gttic(max);
DecisionTreeFactor::shared_ptr max = product.max(frontalKeys); DecisionTreeFactor::shared_ptr max = product.max(frontalKeys);