Check MPE
parent
9dcb52b697
commit
908e4dcd77
|
|
@ -45,8 +45,8 @@ TEST(DiscreteBayesNet, EmptyKBest) {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST(DiscreteBayesNet, AsiaKBest) {
|
TEST(DiscreteBayesNet, AsiaKBest) {
|
||||||
using namespace asia_example;
|
using namespace asia_example;
|
||||||
DiscreteBayesNet asia = createAsiaExample();
|
const DiscreteBayesNet asia = createAsiaExample();
|
||||||
DiscreteSearch search(asia);
|
const DiscreteSearch search(asia);
|
||||||
|
|
||||||
// Ask for the MPE
|
// Ask for the MPE
|
||||||
auto mpe = search.run();
|
auto mpe = search.run();
|
||||||
|
|
@ -55,6 +55,10 @@ TEST(DiscreteBayesNet, AsiaKBest) {
|
||||||
// Regression test: check the MPE solution
|
// Regression test: check the MPE solution
|
||||||
EXPECT_DOUBLES_EQUAL(1.236627, std::fabs(mpe[0].error), 1e-5);
|
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
|
// Ask for top 4 solutions
|
||||||
auto solutions = search.run(4);
|
auto solutions = search.run(4);
|
||||||
|
|
||||||
|
|
@ -72,7 +76,6 @@ TEST(DiscreteBayesTree, EmptyTree) {
|
||||||
auto solutions = search.run(3);
|
auto solutions = search.run(3);
|
||||||
|
|
||||||
// We expect exactly 1 solution with error = 0.0 (the empty assignment).
|
// 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_LONGS_EQUAL(1, solutions.size());
|
||||||
EXPECT_DOUBLES_EQUAL(0, std::fabs(solutions[0].error), 1e-9);
|
EXPECT_DOUBLES_EQUAL(0, std::fabs(solutions[0].error), 1e-9);
|
||||||
}
|
}
|
||||||
|
|
@ -80,9 +83,9 @@ TEST(DiscreteBayesTree, EmptyTree) {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST(DiscreteBayesTree, AsiaTreeKBest) {
|
TEST(DiscreteBayesTree, AsiaTreeKBest) {
|
||||||
using namespace asia_example;
|
using namespace asia_example;
|
||||||
DiscreteFactorGraph asia(createAsiaExample());
|
DiscreteFactorGraph asiaFG(createAsiaExample());
|
||||||
const Ordering ordering{D, X, B, E, L, T, S, A};
|
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);
|
DiscreteSearch search(*bt);
|
||||||
|
|
||||||
// Ask for MPE
|
// Ask for MPE
|
||||||
|
|
@ -92,6 +95,9 @@ TEST(DiscreteBayesTree, AsiaTreeKBest) {
|
||||||
// Regression test: check the MPE solution
|
// Regression test: check the MPE solution
|
||||||
EXPECT_DOUBLES_EQUAL(1.236627, std::fabs(mpe[0].error), 1e-5);
|
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
|
// Ask for top 4 solutions
|
||||||
auto solutions = search.run(4);
|
auto solutions = search.run(4);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue