formatting testHybridGaussianFactorGraph

release/4.3a0
Varun Agrawal 2024-10-08 15:05:05 -04:00
parent 21b4c4c8d3
commit 8b8466e046
1 changed files with 18 additions and 21 deletions

View File

@ -17,6 +17,8 @@
* @author Frank Dellaert * @author Frank Dellaert
*/ */
#include <CppUnitLite/Test.h>
#include <CppUnitLite/TestHarness.h>
#include <gtsam/base/Testable.h> #include <gtsam/base/Testable.h>
#include <gtsam/base/TestableAssertions.h> #include <gtsam/base/TestableAssertions.h>
#include <gtsam/base/Vector.h> #include <gtsam/base/Vector.h>
@ -37,9 +39,6 @@
#include <gtsam/inference/Symbol.h> #include <gtsam/inference/Symbol.h>
#include <gtsam/linear/JacobianFactor.h> #include <gtsam/linear/JacobianFactor.h>
#include <CppUnitLite/Test.h>
#include <CppUnitLite/TestHarness.h>
#include <cstddef> #include <cstddef>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -73,8 +72,8 @@ TEST(HybridGaussianFactorGraph, Creation) {
HybridGaussianConditional gm( HybridGaussianConditional gm(
m0, m0,
{std::make_shared<GaussianConditional>(X(0), Z_3x1, I_3x3, X(1), I_3x3), {std::make_shared<GaussianConditional>(X(0), Z_3x1, I_3x3, X(1), I_3x3),
std::make_shared<GaussianConditional>( std::make_shared<GaussianConditional>(X(0), Vector3::Ones(), I_3x3, X(1),
X(0), Vector3::Ones(), I_3x3, X(1), I_3x3)}); I_3x3)});
hfg.add(gm); hfg.add(gm);
EXPECT_LONGS_EQUAL(2, hfg.size()); EXPECT_LONGS_EQUAL(2, hfg.size());
@ -118,8 +117,8 @@ TEST(HybridGaussianFactorGraph, hybridEliminationOneFactor) {
auto factor = std::dynamic_pointer_cast<DecisionTreeFactor>(result.second); auto factor = std::dynamic_pointer_cast<DecisionTreeFactor>(result.second);
CHECK(factor); CHECK(factor);
// regression test // regression test
EXPECT( // Originally 15.74961, which is normalized to 1
assert_equal(DecisionTreeFactor{m1, "15.74961 15.74961"}, *factor, 1e-5)); EXPECT(assert_equal(DecisionTreeFactor{m1, "1 1"}, *factor, 1e-5));
} }
/* ************************************************************************* */ /* ************************************************************************* */
@ -215,8 +214,8 @@ TEST(HybridBayesNet, Switching) {
// Check errorTree // Check errorTree
AlgebraicDecisionTree<Key> actualErrors = graph.errorTree(continuousValues); AlgebraicDecisionTree<Key> actualErrors = graph.errorTree(continuousValues);
// Create expected error tree // Create expected error tree
const AlgebraicDecisionTree<Key> expectedErrors( const AlgebraicDecisionTree<Key> expectedErrors(M(0), expectedError0,
M(0), expectedError0, expectedError1); expectedError1);
// Check that the actual error tree matches the expected one // Check that the actual error tree matches the expected one
EXPECT(assert_equal(expectedErrors, actualErrors, 1e-5)); EXPECT(assert_equal(expectedErrors, actualErrors, 1e-5));
@ -232,8 +231,8 @@ TEST(HybridBayesNet, Switching) {
const AlgebraicDecisionTree<Key> graphPosterior = const AlgebraicDecisionTree<Key> graphPosterior =
graph.discretePosterior(continuousValues); graph.discretePosterior(continuousValues);
const double sum = probPrime0 + probPrime1; const double sum = probPrime0 + probPrime1;
const AlgebraicDecisionTree<Key> expectedPosterior( const AlgebraicDecisionTree<Key> expectedPosterior(M(0), probPrime0 / sum,
M(0), probPrime0 / sum, probPrime1 / sum); probPrime1 / sum);
EXPECT(assert_equal(expectedPosterior, graphPosterior, 1e-5)); EXPECT(assert_equal(expectedPosterior, graphPosterior, 1e-5));
// Make the clique of factors connected to x0: // Make the clique of factors connected to x0:
@ -275,11 +274,9 @@ TEST(HybridBayesNet, Switching) {
// Check that the scalars incorporate the negative log constant of the // Check that the scalars incorporate the negative log constant of the
// conditional // conditional
EXPECT_DOUBLES_EQUAL(scalar0 - (*p_x0_given_x1_m)(modeZero)->negLogConstant(), EXPECT_DOUBLES_EQUAL(scalar0 - (*p_x0_given_x1_m)(modeZero)->negLogConstant(),
(*phi_x1_m)(modeZero).second, (*phi_x1_m)(modeZero).second, 1e-9);
1e-9);
EXPECT_DOUBLES_EQUAL(scalar1 - (*p_x0_given_x1_m)(modeOne)->negLogConstant(), EXPECT_DOUBLES_EQUAL(scalar1 - (*p_x0_given_x1_m)(modeOne)->negLogConstant(),
(*phi_x1_m)(modeOne).second, (*phi_x1_m)(modeOne).second, 1e-9);
1e-9);
// Check that the conditional and remaining factor are consistent for both // Check that the conditional and remaining factor are consistent for both
// modes // modes