Merge pull request #2040 from borglab/discrete-pruning

Fix Pruning Bug
release/4.3a0
Varun Agrawal 2025-03-07 13:40:12 -05:00 committed by GitHub
commit 51d7483da6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -501,6 +501,10 @@ namespace gtsam {
};
this->visitWith(op);
// If total number of hypotheses is less than N, return 0.0
if (min_heap.size() < N) {
return 0.0;
}
return min_heap.top();
}

View File

@ -132,7 +132,6 @@ TEST(DecisionTreeFactor, Divide) {
KeySet keys(joint.keys());
keys.insert(pA.keys().begin(), pA.keys().end());
EXPECT(assert_inequal(KeySet(pS.keys()), keys));
}
/* ************************************************************************* */
@ -234,6 +233,12 @@ TEST(DecisionTreeFactor, Prune) {
maxNrAssignments = 5;
auto pruned3 = factor.prune(maxNrAssignments);
EXPECT(assert_equal(expected3, pruned3));
// Edge case where the number of hypotheses are less than maxNrAssignments
DecisionTreeFactor f(A, "0.50001 0.49999");
auto pruned4 = f.prune(10);
DecisionTreeFactor expected4(A, "0.50001 0.49999");
EXPECT(assert_equal(expected4, pruned4));
}
/* ************************************************************************** */