gtsam
hybrid
tests
testHybridConditional.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
18
#include <
gtsam/hybrid/HybridConditional.h
>
19
20
#include "
TinyHybridExample.h
"
21
22
// Include for test suite
23
#include <
CppUnitLite/TestHarness.h
>
24
25
using namespace
gtsam
;
26
27
using
symbol_shorthand::M
;
28
using
symbol_shorthand::X
;
29
using
symbol_shorthand::Z
;
30
31
/* ****************************************************************************/
32
// Check invariants for all conditionals in a tiny Bayes net.
33
TEST
(
HybridConditional
, Invariants) {
34
// Create hybrid Bayes net p(z|x,m)p(x)P(m)
35
auto
bn =
tiny::createHybridBayesNet
();
36
37
// Create values to check invariants.
38
const
VectorValues
c
{{
X
(0),
Vector1
(5.1)}, {
Z
(0),
Vector1
(4.9)}};
39
const
DiscreteValues
d
{{
M
(0), 1}};
40
const
HybridValues
values
{
c
,
d
};
41
42
// Check invariants for p(z|x,m)
43
auto
hc0 = bn.at(0);
44
CHECK
(hc0->isHybrid());
45
46
// Check invariants as a HybridGaussianConditional.
47
const
auto
conditional = hc0->asHybrid();
48
EXPECT
(
HybridGaussianConditional::CheckInvariants
(*conditional,
values
));
49
50
// Check invariants as a HybridConditional.
51
EXPECT
(
HybridConditional::CheckInvariants
(*hc0,
values
));
52
53
// Check invariants for p(x)
54
auto
hc1 = bn.at(1);
55
CHECK
(hc1->isContinuous());
56
57
// Check invariants as a GaussianConditional.
58
const
auto
gaussian = hc1->asGaussian();
59
EXPECT
(
GaussianConditional::CheckInvariants
(*gaussian,
c
));
60
EXPECT
(
GaussianConditional::CheckInvariants
(*gaussian,
values
));
61
62
// Check invariants as a HybridConditional.
63
EXPECT
(
HybridConditional::CheckInvariants
(*hc1,
values
));
64
65
// Check invariants for p(m)
66
auto
hc2 = bn.at(2);
67
CHECK
(hc2->isDiscrete());
68
69
// Check invariants as a DiscreteConditional.
70
const
auto
discrete = hc2->asDiscrete();
71
EXPECT
(
DiscreteConditional::CheckInvariants
(*discrete,
d
));
72
EXPECT
(
DiscreteConditional::CheckInvariants
(*discrete,
values
));
73
74
// Check invariants as a HybridConditional.
75
EXPECT
(
HybridConditional::CheckInvariants
(*hc2,
values
));
76
}
77
78
/* ************************************************************************* */
79
int
main
() {
80
TestResult
tr;
81
return
TestRegistry::runAllTests
(tr);
82
}
83
/* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition:
TestRegistry.cpp:27
gtsam::Vector1
Eigen::Matrix< double, 1, 1 > Vector1
Definition:
Vector.h:41
gtsam::HybridValues
Definition:
HybridValues.h:37
gtsam::HybridConditional
Definition:
HybridConditional.h:60
d
static const double d[K][N]
Definition:
igam.h:11
EXPECT
#define EXPECT(condition)
Definition:
Test.h:150
TestHarness.h
gtsam::symbol_shorthand::M
Key M(std::uint64_t j)
Definition:
inference/Symbol.h:160
c
Scalar Scalar * c
Definition:
benchVecAdd.cpp:17
different_sigmas::values
HybridValues values
Definition:
testHybridBayesNet.cpp:245
X
#define X
Definition:
icosphere.cpp:20
gtsam::symbol_shorthand::X
Key X(std::uint64_t j)
Definition:
inference/Symbol.h:171
gtsam::VectorValues
Definition:
VectorValues.h:74
gtsam::symbol_shorthand::Z
Key Z(std::uint64_t j)
Definition:
inference/Symbol.h:173
gtsam::Conditional< HybridGaussianFactor, HybridGaussianConditional >::CheckInvariants
static bool CheckInvariants(const HybridGaussianConditional &conditional, const VALUES &x)
Definition:
Conditional-inst.h:69
TinyHybridExample.h
TestResult
Definition:
TestResult.h:26
gtsam
traits
Definition:
SFMdata.h:40
gtsam::TEST
TEST(SmartFactorBase, Pinhole)
Definition:
testSmartFactorBase.cpp:38
gtsam::DiscreteValues
Definition:
DiscreteValues.h:34
CHECK
#define CHECK(condition)
Definition:
Test.h:108
gtsam::tiny::createHybridBayesNet
HybridBayesNet createHybridBayesNet(size_t num_measurements=1, bool manyModes=false)
Definition:
TinyHybridExample.h:39
main
int main()
Definition:
testHybridConditional.cpp:79
Z
#define Z
Definition:
icosphere.cpp:21
HybridConditional.h
M
Matrix< RealScalar, Dynamic, Dynamic > M
Definition:
bench_gemm.cpp:51
gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:40:14