fix return value of pruned factors

release/4.3a0
Varun Agrawal 2024-10-06 11:15:46 -04:00
parent 94fda5dd5a
commit 873b2a7142
1 changed files with 6 additions and 3 deletions

View File

@ -240,7 +240,9 @@ discreteElimination(const HybridGaussianFactorGraph &factors,
// In this case, compute discrete probabilities.
auto logProbability =
[&](const GaussianFactor::shared_ptr &factor) -> double {
if (!factor) return 0.0;
// If the factor is null, it is has been pruned hence return ∞
// so that the exp(-∞)=0.
if (!factor) return std::numeric_limits<double>::infinity();
return factor->error(VectorValues());
};
AlgebraicDecisionTree<Key> logProbabilities =
@ -300,8 +302,9 @@ static std::shared_ptr<Factor> createDiscreteFactor(
auto negLogProbability = [&](const Result &pair) -> double {
const auto &[conditional, factor] = pair;
static const VectorValues kEmpty;
// If the factor is not null, it has no keys, just contains the residual.
if (!factor) return 1.0; // TODO(dellaert): not loving this.
// If the factor is null, it has been pruned, hence return ∞
// so that the exp(-∞)=0.
if (!factor) return std::numeric_limits<double>::infinity();
// Negative logspace version of:
// exp(-factor->error(kEmpty)) / conditional->normalizationConstant();