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 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
gtsam::DiscreteLookupDAG::add
void add(Args &&... args)
Definition: DiscreteLookupDAG.h:107
DiscreteLookupDAG.h
gtsam::DiscreteLookupDAG
Definition: DiscreteLookupDAG.h:77
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
main
int main()
Definition: testDiscreteLookupDAG.cpp:49
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
gtsam::AlgebraicDecisionTree< Key >
TestResult
Definition: TestResult.h:26
gtsam
traits
Definition: chartTesting.h:28
gtsam::TEST
TEST(SmartFactorBase, Pinhole)
Definition: testSmartFactorBase.cpp:38
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::DiscreteLookupDAG::argmax
DiscreteValues argmax(DiscreteValues given=DiscreteValues()) const
argmax by back-substitution, optionally given certain variables.
Definition: DiscreteLookupDAG.cpp:120


gtsam
Author(s):
autogenerated on Tue Jun 25 2024 03:05:42