Skip to content

Commit

Permalink
Test sum-product in discrete factor graph up to scale.
Browse files Browse the repository at this point in the history
  • Loading branch information
keevindoherty committed Feb 12, 2023
1 parent 70fa568 commit 9fa2d30
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions gtsam/discrete/tests/testDiscreteFactorGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ TEST(DiscreteFactorGraph, test) {

// Test EliminateDiscrete
const Ordering frontalKeys{0};
const auto [conditional, newFactor] = EliminateDiscrete(graph, frontalKeys);
const auto [conditional, newFactorPtr] = EliminateDiscrete(graph, frontalKeys);

DecisionTreeFactor newFactor = *newFactorPtr;

// Normalize newFactor by max for comparison with expected
auto normalization = newFactor.max(newFactor.size());

newFactor = newFactor / *normalization;

// Check Conditional
CHECK(conditional);
Expand All @@ -117,12 +124,13 @@ TEST(DiscreteFactorGraph, test) {
EXPECT(assert_equal(expectedConditional, *conditional));

// Check Factor
CHECK(newFactor);
CHECK(&newFactor);
DecisionTreeFactor expectedFactor(B & A, "10 6 6 10");
auto normalization = expectedFactor.sum(expectedFactor.size());
// Normalize by max.
normalization = expectedFactor.max(expectedFactor.size());
// Ensure normalization is correct.
expectedFactor = expectedFactor / *normalization;
EXPECT(assert_equal(expectedFactor, *newFactor));
EXPECT(assert_equal(expectedFactor, newFactor));

// Test using elimination tree
const Ordering ordering{0, 1, 2};
Expand Down

0 comments on commit 9fa2d30

Please sign in to comment.