testSymbolicFactor.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
23 
24 
25 using namespace std;
26 using namespace gtsam;
27 
28 /* ************************************************************************* */
29 #ifdef TRACK_ELIMINATE
30 TEST(SymbolicFactor, eliminate) {
31  KeyVector keys {2, 3, 4, 6, 7, 9, 10, 11};
32  IndexFactor actual(keys.begin(), keys.end());
33  BayesNet<IndexConditional> fragment = *actual.eliminate(3);
34 
35  IndexFactor expected(keys.begin()+3, keys.end());
36  IndexConditional::shared_ptr expected0 = IndexConditional::FromRange(keys.begin(), keys.end(), 1);
37  IndexConditional::shared_ptr expected1 = IndexConditional::FromRange(keys.begin()+1, keys.end(), 1);
38  IndexConditional::shared_ptr expected2 = IndexConditional::FromRange(keys.begin()+2, keys.end(), 1);
39 
40  CHECK(assert_equal(fragment.size(), size_t(3)));
41  CHECK(assert_equal(expected, actual));
42  BayesNet<IndexConditional>::const_iterator fragmentCond = fragment.begin();
43  CHECK(assert_equal(**fragmentCond++, *expected0));
44  CHECK(assert_equal(**fragmentCond++, *expected1));
45  CHECK(assert_equal(**fragmentCond++, *expected2));
46 }
47 #endif
48 
49 /* ************************************************************************* */
50 TEST(SymbolicFactor, Constructors)
51 {
53 
54  SymbolicFactor actual1 = SymbolicFactor::FromKeys(expected.keys());
55  SymbolicFactor actual2 = SymbolicFactor::FromIterators(expected.begin(), expected.end());
56  SymbolicFactor actual3 = *SymbolicFactor::FromKeysShared(expected.keys());
57  SymbolicFactor actual4 = *SymbolicFactor::FromIteratorsShared(expected.begin(), expected.end());
58 
59  EXPECT(assert_equal(expected, actual1));
60  EXPECT(assert_equal(expected, actual2));
61  EXPECT(assert_equal(expected, actual3));
62  EXPECT(assert_equal(expected, actual4));
63 }
64 
65 /* ************************************************************************* */
67 {
69  std::make_shared<SymbolicFactor>(2, 4, 6),
70  std::make_shared<SymbolicFactor>(1, 2, 5),
71  std::make_shared<SymbolicFactor>(0, 3)};
72 
73  const SymbolicFactor expectedFactor(4,5,6);
74  const SymbolicConditional expectedConditional =
75  SymbolicConditional::FromKeys(KeyVector{0,1,2,3,4,5,6}, 4);
76 
77  const auto [actualConditional, actualFactor] =
78  EliminateSymbolic(factors, Ordering{0, 1, 2, 3});
79 
80  CHECK(assert_equal(expectedConditional, *actualConditional));
81  CHECK(assert_equal(expectedFactor, *actualFactor));
82 }
83 
84 /* ************************************************************************* */
85 int main() {
86  TestResult tr;
87  return TestRegistry::runAllTests(tr);
88 }
89 /* ************************************************************************* */
Provides additional testing facilities for common data structures.
int main()
#define CHECK(condition)
Definition: Test.h:108
static int runAllTests(TestResult &result)
Matrix expected
Definition: testMatrix.cpp:971
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
const GaussianFactorGraph factors
Definition: BFloat16.h:88
std::pair< std::shared_ptr< SymbolicConditional >, std::shared_ptr< SymbolicFactor > > EliminateSymbolic(const FactorGraph< FACTOR > &factors, const Ordering &keys)
const_iterator end() const
Definition: Factor.h:148
const_iterator begin() const
Definition: FactorGraph.h:361
#define EXPECT(condition)
Definition: Test.h:150
traits
Definition: chartTesting.h:28
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:142
const KeyVector keys
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
const_iterator begin() const
Definition: Factor.h:145
TEST(SymbolicFactor, Constructors)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:39:43