testSignature.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 
21 #include <gtsam/base/Testable.h>
23 
24 #include <boost/assign/std/vector.hpp>
25 #include <vector>
26 
27 using namespace std;
28 using namespace gtsam;
29 using namespace boost::assign;
30 
31 DiscreteKey X(0, 2), Y(1, 3), Z(2, 2);
32 
33 /* ************************************************************************* */
34 TEST(testSignature, simple_conditional) {
35  Signature sig(X | Y = "1/1 2/3 1/4");
36  Signature::Table table = *sig.table();
37  vector<double> row[3]{{0.5, 0.5}, {0.4, 0.6}, {0.2, 0.8}};
38  CHECK(row[0] == table[0]);
39  CHECK(row[1] == table[1]);
40  CHECK(row[2] == table[2]);
41  DiscreteKey actKey = sig.key();
42  LONGS_EQUAL(X.first, actKey.first);
43 
44  DiscreteKeys actKeys = sig.discreteKeys();
45  LONGS_EQUAL(2, actKeys.size());
46  LONGS_EQUAL(X.first, actKeys.front().first);
47  LONGS_EQUAL(Y.first, actKeys.back().first);
48 
49  vector<double> actCpt = sig.cpt();
50  EXPECT_LONGS_EQUAL(6, actCpt.size());
51 }
52 
53 /* ************************************************************************* */
54 TEST(testSignature, simple_conditional_nonparser) {
56  Signature::Row row1, row2, row3;
57  row1 += 1.0, 1.0;
58  row2 += 2.0, 3.0;
59  row3 += 1.0, 4.0;
60  table += row1, row2, row3;
61 
62  Signature sig(X | Y = table);
63  DiscreteKey actKey = sig.key();
64  EXPECT_LONGS_EQUAL(X.first, actKey.first);
65 
66  DiscreteKeys actKeys = sig.discreteKeys();
67  LONGS_EQUAL(2, actKeys.size());
68  LONGS_EQUAL(X.first, actKeys.front().first);
69  LONGS_EQUAL(Y.first, actKeys.back().first);
70 
71  vector<double> actCpt = sig.cpt();
72  EXPECT_LONGS_EQUAL(6, actCpt.size());
73 }
74 
75 /* ************************************************************************* */
76 int main() {
77  TestResult tr;
78  return TestRegistry::runAllTests(tr);
79 }
80 /* ************************************************************************* */
#define CHECK(condition)
Definition: Test.h:109
const boost::optional< Table > & table() const
Definition: Signature.h:96
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
signatures for conditional densities
TEST(testSignature, simple_conditional)
Definition: Half.h:150
std::vector< double > cpt() const
Definition: Signature.cpp:139
DiscreteKey Z(2, 2)
int main()
DiscreteKeys discreteKeys() const
Definition: Signature.cpp:125
std::vector< Row > Table
Definition: Signature.h:58
m row(1)
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:34
std::vector< double > Row
Definition: Signature.h:57
DiscreteKey X(0, 2)
#define LONGS_EQUAL(expected, actual)
Definition: Test.h:135
traits
Definition: chartTesting.h:28
DiscreteKey Y(1, 3)
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:155
ArrayXXf table(10, 4)
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:37
const DiscreteKey & key() const
Definition: Signature.h:80


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