Skip to content

Commit

Permalink
compute expected error
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Oct 1, 2024
1 parent 2463245 commit dc5c4cb
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,28 @@ TEST(HybridNonlinearFactorGraph, ErrorTree) {
Switching s(3);

HybridNonlinearFactorGraph graph = s.nonlinearFactorGraph;
Values values = s.linearizationPoint;

auto error_tree = graph.errorTree(s.linearizationPoint);

auto dkeys = graph.discreteKeys();
std::vector<DiscreteKey> discrete_keys(dkeys.begin(), dkeys.end());
std::vector<double> leaves = {152.79175946923, 151.59861228867,
151.70397280433, 151.60943791243};
DiscreteKeys discrete_keys(dkeys.begin(), dkeys.end());

// Compute the sum of errors for each factor.
auto assignments = DiscreteValues::CartesianProduct(discrete_keys);
std::vector<double> leaves(assignments.size());
for (auto &&factor : graph) {
for (size_t i = 0; i < assignments.size(); ++i) {
leaves[i] +=
factor->error(HybridValues(VectorValues(), assignments[i], values));
}
}
// Swap i=1 and i=2 to give correct ordering.
double temp = leaves[1];
leaves[1] = leaves[2];
leaves[2] = temp;
AlgebraicDecisionTree<Key> expected_error(discrete_keys, leaves);
// regression

EXPECT(assert_equal(expected_error, error_tree, 1e-7));
}

Expand Down

0 comments on commit dc5c4cb

Please sign in to comment.