Check MPE

release/4.3a0
Frank Dellaert 2025-01-27 00:51:55 -05:00
parent 9dcb52b697
commit 908e4dcd77
1 changed files with 11 additions and 5 deletions

View File

@ -45,8 +45,8 @@ TEST(DiscreteBayesNet, EmptyKBest) {
/* ************************************************************************* */
TEST(DiscreteBayesNet, AsiaKBest) {
using namespace asia_example;
DiscreteBayesNet asia = createAsiaExample();
DiscreteSearch search(asia);
const DiscreteBayesNet asia = createAsiaExample();
const DiscreteSearch search(asia);
// Ask for the MPE
auto mpe = search.run();
@ -55,6 +55,10 @@ TEST(DiscreteBayesNet, AsiaKBest) {
// Regression test: check the MPE solution
EXPECT_DOUBLES_EQUAL(1.236627, std::fabs(mpe[0].error), 1e-5);
// Check it is equal to MPE via inference
const DiscreteFactorGraph asiaFG(asia);
EXPECT(assert_equal(mpe[0].assignment, asiaFG.optimize()));
// Ask for top 4 solutions
auto solutions = search.run(4);
@ -72,7 +76,6 @@ TEST(DiscreteBayesTree, EmptyTree) {
auto solutions = search.run(3);
// We expect exactly 1 solution with error = 0.0 (the empty assignment).
assert(solutions.size() == 1 && "There should be exactly one empty solution");
EXPECT_LONGS_EQUAL(1, solutions.size());
EXPECT_DOUBLES_EQUAL(0, std::fabs(solutions[0].error), 1e-9);
}
@ -80,9 +83,9 @@ TEST(DiscreteBayesTree, EmptyTree) {
/* ************************************************************************* */
TEST(DiscreteBayesTree, AsiaTreeKBest) {
using namespace asia_example;
DiscreteFactorGraph asia(createAsiaExample());
DiscreteFactorGraph asiaFG(createAsiaExample());
const Ordering ordering{D, X, B, E, L, T, S, A};
DiscreteBayesTree::shared_ptr bt = asia.eliminateMultifrontal(ordering);
DiscreteBayesTree::shared_ptr bt = asiaFG.eliminateMultifrontal(ordering);
DiscreteSearch search(*bt);
// Ask for MPE
@ -92,6 +95,9 @@ TEST(DiscreteBayesTree, AsiaTreeKBest) {
// Regression test: check the MPE solution
EXPECT_DOUBLES_EQUAL(1.236627, std::fabs(mpe[0].error), 1e-5);
// Check it is equal to MPE via inference
EXPECT(assert_equal(mpe[0].assignment, asiaFG.optimize()));
// Ask for top 4 solutions
auto solutions = search.run(4);