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 #include <boost/assign/std/vector.hpp>
25 #include <boost/assign/list_of.hpp>
26 #include <boost/make_shared.hpp>
27 #include <boost/tuple/tuple.hpp>
28 
29 using namespace std;
30 using namespace gtsam;
31 using namespace boost::assign;
32 
33 /* ************************************************************************* */
34 #ifdef TRACK_ELIMINATE
35 TEST(SymbolicFactor, eliminate) {
36  KeyVector keys {2, 3, 4, 6, 7, 9, 10, 11};
37  IndexFactor actual(keys.begin(), keys.end());
38  BayesNet<IndexConditional> fragment = *actual.eliminate(3);
39 
40  IndexFactor expected(keys.begin()+3, keys.end());
41  IndexConditional::shared_ptr expected0 = IndexConditional::FromRange(keys.begin(), keys.end(), 1);
42  IndexConditional::shared_ptr expected1 = IndexConditional::FromRange(keys.begin()+1, keys.end(), 1);
43  IndexConditional::shared_ptr expected2 = IndexConditional::FromRange(keys.begin()+2, keys.end(), 1);
44 
45  CHECK(assert_equal(fragment.size(), size_t(3)));
46  CHECK(assert_equal(expected, actual));
47  BayesNet<IndexConditional>::const_iterator fragmentCond = fragment.begin();
48  CHECK(assert_equal(**fragmentCond++, *expected0));
49  CHECK(assert_equal(**fragmentCond++, *expected1));
50  CHECK(assert_equal(**fragmentCond++, *expected2));
51 }
52 #endif
53 
54 /* ************************************************************************* */
55 TEST(SymbolicFactor, Constructors)
56 {
58 
59  SymbolicFactor actual1 = SymbolicFactor::FromKeys(expected.keys());
60  SymbolicFactor actual2 = SymbolicFactor::FromIterators(expected.begin(), expected.end());
61  SymbolicFactor actual3 = *SymbolicFactor::FromKeysShared(expected.keys());
62  SymbolicFactor actual4 = *SymbolicFactor::FromIteratorsShared(expected.begin(), expected.end());
63 
64  EXPECT(assert_equal(expected, actual1));
65  EXPECT(assert_equal(expected, actual2));
66  EXPECT(assert_equal(expected, actual3));
67  EXPECT(assert_equal(expected, actual4));
68 }
69 
70 /* ************************************************************************* */
72 {
73  const SymbolicFactorGraph factors = list_of
74  (SymbolicFactor(2,4,6))
75  (SymbolicFactor(1,2,5))
76  (SymbolicFactor(0,3));
77 
78  const SymbolicFactor expectedFactor(4,5,6);
79  const SymbolicConditional expectedConditional =
80  SymbolicConditional::FromKeys(list_of(0)(1)(2)(3)(4)(5)(6), 4);
81 
82  SymbolicFactor::shared_ptr actualFactor;
83  SymbolicConditional::shared_ptr actualConditional;
84  boost::tie(actualConditional, actualFactor) =
85  EliminateSymbolic(factors, list_of(0)(1)(2)(3));
86 
87  CHECK(assert_equal(expectedConditional, *actualConditional));
88  CHECK(assert_equal(expectedFactor, *actualFactor));
89 }
90 
91 /* ************************************************************************* */
92 int main() {
93  TestResult tr;
94  return TestRegistry::runAllTests(tr);
95 }
96 /* ************************************************************************* */
Provides additional testing facilities for common data structures.
int main()
#define CHECK(condition)
Definition: Test.h:109
static int runAllTests(TestResult &result)
Matrix expected
Definition: testMatrix.cpp:974
const_iterator end() const
Definition: Factor.h:130
Definition: Half.h:150
GaussianFactorGraph factors(list_of(factor1)(factor2)(factor3))
const_iterator begin() const
Definition: FactorGraph.h:333
boost::shared_ptr< This > shared_ptr
Typedef to the conditional base class.
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:127
#define EXPECT(condition)
Definition: Test.h:151
boost::shared_ptr< This > shared_ptr
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:124
const KeyVector keys
std::pair< boost::shared_ptr< SymbolicConditional >, boost::shared_ptr< SymbolicFactor > > EliminateSymbolic(const FactorGraph< FACTOR > &factors, const Ordering &keys)
TEST(SymbolicFactor, Constructors)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:49:57