testDiscreteLookupDAG.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 
12 /*
13  * testDiscreteLookupDAG.cpp
14  *
15  * @date January, 2022
16  * @author Frank Dellaert
17  */
18 
20 #include <gtsam/base/Testable.h>
22 
23 using namespace gtsam;
24 
25 /* ************************************************************************* */
28 
29  // Declare 2 keys
30  DiscreteKey A(0, 2), B(1, 2);
31 
32  // Create lookup table corresponding to "marginalIsNotMPE" in testDFG.
34 
35  ADT adtB(DiscreteKeys{B, A}, std::vector<double>{0.5, 1. / 3, 0.5, 2. / 3});
36  dag.add(1, DiscreteKeys{B, A}, adtB);
37 
38  ADT adtA(A, 0.5 * 10 / 19, (2. / 3) * (9. / 19));
39  dag.add(1, DiscreteKeys{A}, adtA);
40 
41  // The expected MPE is A=1, B=1
42  DiscreteValues mpe{{0, 1}, {1, 1}};
43 
44  // check:
45  auto actualMPE = dag.argmax();
46  EXPECT(assert_equal(mpe, actualMPE));
47 }
48 /* ************************************************************************* */
49 int main() {
50  TestResult tr;
51  return TestRegistry::runAllTests(tr);
52 }
53 /* ************************************************************************* */
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
#define EXPECT(condition)
Definition: Test.h:150
traits
Definition: chartTesting.h:28
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
TEST(SmartFactorBase, Pinhole)
int main()
DiscreteValues argmax(DiscreteValues given=DiscreteValues()) const
argmax by back-substitution, optionally given certain variables.
void add(Args &&... args)
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:38:01