Loop over all variants

release/4.3a0
Frank Dellaert 2025-01-27 19:06:09 -05:00
parent 0bc566f692
commit 8d6b6055fe
1 changed files with 23 additions and 43 deletions

View File

@ -41,11 +41,6 @@ static const DiscreteBayesTree bayesTree =
*factorGraph.eliminateMultifrontal(ordering); *factorGraph.eliminateMultifrontal(ordering);
} // namespace asia } // namespace asia
/* ************************************************************************* */
TEST(DiscreteBayesNet, AsiaFactorGraphKBest) {
DiscreteSearch search(asia::factorGraph, asia::ordering);
}
/* ************************************************************************* */ /* ************************************************************************* */
TEST(DiscreteBayesNet, EmptyKBest) { TEST(DiscreteBayesNet, EmptyKBest) {
DiscreteBayesNet net; // no factors DiscreteBayesNet net; // no factors
@ -57,9 +52,28 @@ TEST(DiscreteBayesNet, EmptyKBest) {
} }
/* ************************************************************************* */ /* ************************************************************************* */
TEST(DiscreteBayesNet, AsiaKBest) { TEST(DiscreteBayesTree, EmptyTree) {
const DiscreteSearch search(asia::bayesNet); DiscreteBayesTree bt;
DiscreteSearch search(bt);
auto solutions = search.run(3);
// We expect exactly 1 solution with error = 0.0 (the empty assignment).
EXPECT_LONGS_EQUAL(1, solutions.size());
EXPECT_DOUBLES_EQUAL(0, std::fabs(solutions[0].error), 1e-9);
}
/* ************************************************************************* */
TEST(DiscreteBayesNet, AsiaKBest) {
auto fromETree =
DiscreteSearch::FromFactorGraph(asia::factorGraph, asia::ordering);
auto fromJunctionTree =
DiscreteSearch::FromFactorGraph(asia::factorGraph, asia::ordering, true);
const DiscreteSearch fromBayesNet(asia::bayesNet);
const DiscreteSearch fromBayesTree(asia::bayesTree);
for (auto& search :
{fromETree, fromJunctionTree, fromBayesNet, fromBayesTree}) {
// Ask for the MPE // Ask for the MPE
auto mpe = search.run(); auto mpe = search.run();
@ -77,41 +91,7 @@ TEST(DiscreteBayesNet, AsiaKBest) {
// Regression test: check the first and last solution // Regression test: check the first and last solution
EXPECT_DOUBLES_EQUAL(1.236627, std::fabs(solutions[0].error), 1e-5); EXPECT_DOUBLES_EQUAL(1.236627, std::fabs(solutions[0].error), 1e-5);
EXPECT_DOUBLES_EQUAL(2.201708, std::fabs(solutions[3].error), 1e-5); EXPECT_DOUBLES_EQUAL(2.201708, std::fabs(solutions[3].error), 1e-5);
} }
/* ************************************************************************* */
TEST(DiscreteBayesTree, EmptyTree) {
DiscreteBayesTree bt;
DiscreteSearch search(bt);
auto solutions = search.run(3);
// We expect exactly 1 solution with error = 0.0 (the empty assignment).
EXPECT_LONGS_EQUAL(1, solutions.size());
EXPECT_DOUBLES_EQUAL(0, std::fabs(solutions[0].error), 1e-9);
}
/* ************************************************************************* */
TEST(DiscreteBayesTree, AsiaTreeKBest) {
DiscreteSearch search(asia::bayesTree);
// Ask for MPE
auto mpe = search.run();
EXPECT_LONGS_EQUAL(1, mpe.size());
// 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(asia::mpe, mpe[0].assignment));
// Ask for top 4 solutions
auto solutions = search.run(4);
EXPECT_LONGS_EQUAL(4, solutions.size());
// Regression test: check the first and last solution
EXPECT_DOUBLES_EQUAL(1.236627, std::fabs(solutions[0].error), 1e-5);
EXPECT_DOUBLES_EQUAL(2.201708, std::fabs(solutions[3].error), 1e-5);
} }
/* ************************************************************************* */ /* ************************************************************************* */