testDiscreteConditional.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  * @file testDiscreteConditional.cpp
14  * @brief unit tests for DiscreteConditional
15  * @author Duy-Nguyen Ta
16  * @author Frank dellaert
17  * @date Feb 14, 2011
18  */
19 
24 #include <gtsam/inference/Symbol.h>
27 
28 
29 using namespace std;
30 using namespace gtsam;
31 
32 /* ************************************************************************* */
33 TEST(DiscreteConditional, constructors) {
34  DiscreteKey X(0, 2), Y(2, 3), Z(1, 2); // watch ordering !
35 
36  DiscreteConditional actual(X | Y = "1/1 2/3 1/4");
37  EXPECT_LONGS_EQUAL(0, *(actual.beginFrontals()));
38  EXPECT_LONGS_EQUAL(2, *(actual.beginParents()));
39  EXPECT(actual.endParents() == actual.end());
40  EXPECT(actual.endFrontals() == actual.beginParents());
41 
42  DecisionTreeFactor f1(X & Y, "0.5 0.4 0.2 0.5 0.6 0.8");
43  DiscreteConditional expected1(1, f1);
44  EXPECT(assert_equal(expected1, actual, 1e-9));
45 
47  X & Y & Z, "0.2 0.5 0.3 0.6 0.4 0.7 0.25 0.55 0.35 0.65 0.45 0.75");
48  DiscreteConditional actual2(1, f2);
49  DecisionTreeFactor expected2 = f2 / *f2.sum(1);
50  EXPECT(assert_equal(expected2, static_cast<DecisionTreeFactor>(actual2)));
51 
52  std::vector<double> probs{0.2, 0.5, 0.3, 0.6, 0.4, 0.7, 0.25, 0.55, 0.35, 0.65, 0.45, 0.75};
53  DiscreteConditional actual3(X, {Y, Z}, probs);
54  DecisionTreeFactor expected3 = f2;
55  EXPECT(assert_equal(expected3, static_cast<DecisionTreeFactor>(actual3)));
56 }
57 
58 /* ************************************************************************* */
59 TEST(DiscreteConditional, constructors_alt_interface) {
60  DiscreteKey X(0, 2), Y(2, 3), Z(1, 2); // watch ordering !
61 
62  const Signature::Row r1{1, 1}, r2{2, 3}, r3{1, 4};
63  const Signature::Table table{r1, r2, r3};
64  DiscreteConditional actual1(X, {Y}, table);
65 
66  DecisionTreeFactor f1(X & Y, "0.5 0.4 0.2 0.5 0.6 0.8");
67  DiscreteConditional expected1(1, f1);
68  EXPECT(assert_equal(expected1, actual1, 1e-9));
69 
71  X & Y & Z, "0.2 0.5 0.3 0.6 0.4 0.7 0.25 0.55 0.35 0.65 0.45 0.75");
72  DiscreteConditional actual2(1, f2);
73  DecisionTreeFactor expected2 = f2 / *f2.sum(1);
74  EXPECT(assert_equal(expected2, static_cast<DecisionTreeFactor>(actual2)));
75 }
76 
77 /* ************************************************************************* */
78 TEST(DiscreteConditional, constructors2) {
79  DiscreteKey C(0, 2), B(1, 2);
80  Signature signature((C | B) = "4/1 3/1");
81  DiscreteConditional actual(signature);
82 
83  DecisionTreeFactor expected(C & B, "0.8 0.75 0.2 0.25");
84  EXPECT(assert_equal(expected, static_cast<DecisionTreeFactor>(actual)));
85 }
86 
87 /* ************************************************************************* */
88 TEST(DiscreteConditional, constructors3) {
89  DiscreteKey C(0, 2), B(1, 2), A(2, 2);
90  Signature signature((C | B, A) = "4/1 1/1 1/1 1/4");
91  DiscreteConditional actual(signature);
92 
93  DecisionTreeFactor expected(C & B & A, "0.8 0.5 0.5 0.2 0.2 0.5 0.5 0.8");
94  EXPECT(assert_equal(expected, static_cast<DecisionTreeFactor>(actual)));
95 }
96 
97 /* ****************************************************************************/
98 // Test evaluate for a discrete Prior P(Asia).
99 TEST(DiscreteConditional, PriorProbability) {
100  constexpr Key asiaKey = 0;
101  const DiscreteKey Asia(asiaKey, 2);
102  DiscreteConditional dc(Asia, "4/6");
104  EXPECT_DOUBLES_EQUAL(0.4, dc.evaluate(values), 1e-9);
105  EXPECT(DiscreteConditional::CheckInvariants(dc, values));
106 }
107 
108 /* ************************************************************************* */
109 // Check that error, logProbability, evaluate all work as expected.
110 TEST(DiscreteConditional, probability) {
111  DiscreteKey C(2, 2), D(4, 2), E(3, 2);
112  DiscreteConditional C_given_DE((C | D, E) = "4/1 1/1 1/1 1/4");
113 
114  DiscreteValues given {{C.first, 1}, {D.first, 0}, {E.first, 0}};
115  EXPECT_DOUBLES_EQUAL(0.2, C_given_DE.evaluate(given), 1e-9);
116  EXPECT_DOUBLES_EQUAL(0.2, C_given_DE(given), 1e-9);
117  EXPECT_DOUBLES_EQUAL(log(0.2), C_given_DE.logProbability(given), 1e-9);
118  EXPECT_DOUBLES_EQUAL(-log(0.2), C_given_DE.error(given), 1e-9);
119  EXPECT(DiscreteConditional::CheckInvariants(C_given_DE, given));
120 }
121 
122 /* ************************************************************************* */
123 // Check calculation of joint P(A,B)
125  DiscreteKey A(1, 2), B(0, 2);
126  DiscreteConditional conditional(A | B = "1/2 2/1");
127  DiscreteConditional prior(B % "1/2");
128 
129  // The expected factor
130  DecisionTreeFactor f(A & B, "1 4 2 2");
132 
133  // P(A,B) = P(A|B) * P(B) = P(B) * P(A|B)
134  for (auto&& actual : {prior * conditional, conditional * prior}) {
135  EXPECT_LONGS_EQUAL(2, actual.nrFrontals());
136  KeyVector frontals(actual.beginFrontals(), actual.endFrontals());
137  EXPECT((frontals == KeyVector{0, 1}));
138  for (auto&& it : actual.enumerate()) {
139  const DiscreteValues& v = it.first;
140  EXPECT_DOUBLES_EQUAL(actual(v), conditional(v) * prior(v), 1e-9);
141  }
142  // And for good measure:
143  EXPECT(assert_equal(expected, actual));
144  }
145 }
146 
147 /* ************************************************************************* */
148 // Check calculation of conditional joint P(A,B|C)
150  DiscreteKey A(0, 2), B(1, 2), C(2, 2);
151  DiscreteConditional A_given_B(A | B = "1/3 3/1");
152  DiscreteConditional B_given_C(B | C = "1/3 3/1");
153 
154  // P(A,B|C) = P(A|B)P(B|C) = P(B|C)P(A|B)
155  for (auto&& actual : {A_given_B * B_given_C, B_given_C * A_given_B}) {
156  EXPECT_LONGS_EQUAL(2, actual.nrFrontals());
157  EXPECT_LONGS_EQUAL(1, actual.nrParents());
158  KeyVector frontals(actual.beginFrontals(), actual.endFrontals());
159  EXPECT((frontals == KeyVector{0, 1}));
160  for (auto&& it : actual.enumerate()) {
161  const DiscreteValues& v = it.first;
162  EXPECT_DOUBLES_EQUAL(actual(v), A_given_B(v) * B_given_C(v), 1e-9);
163  }
164  }
165 }
166 
167 /* ************************************************************************* */
168 // Check calculation of conditional joint P(A,B|C), double check keys
170  DiscreteKey A(1, 2), B(2, 2), C(0, 2); // different keys!!!
171  DiscreteConditional A_given_B(A | B = "1/3 3/1");
172  DiscreteConditional B_given_C(B | C = "1/3 3/1");
173 
174  // P(A,B|C) = P(A|B)P(B|C) = P(B|C)P(A|B)
175  for (auto&& actual : {A_given_B * B_given_C, B_given_C * A_given_B}) {
176  EXPECT_LONGS_EQUAL(2, actual.nrFrontals());
177  EXPECT_LONGS_EQUAL(1, actual.nrParents());
178  KeyVector frontals(actual.beginFrontals(), actual.endFrontals());
179  EXPECT((frontals == KeyVector{1, 2}));
180  for (auto&& it : actual.enumerate()) {
181  const DiscreteValues& v = it.first;
182  EXPECT_DOUBLES_EQUAL(actual(v), A_given_B(v) * B_given_C(v), 1e-9);
183  }
184  }
185 }
186 
187 /* ************************************************************************* */
188 // Check calculation of conditional joint P(A,B,C|D,E) = P(A,B|D) P(C|D,E)
190  DiscreteKey A(0, 2), B(1, 2), C(2, 2), D(4, 2), E(3, 2);
191  DiscreteConditional A_given_B(A | B = "1/3 3/1");
192  DiscreteConditional B_given_D(B | D = "1/3 3/1");
193  DiscreteConditional AB_given_D = A_given_B * B_given_D;
194  DiscreteConditional C_given_DE((C | D, E) = "4/1 1/1 1/1 1/4");
195 
196  // P(A,B,C|D,E) = P(A,B|D) P(C|D,E) = P(C|D,E) P(A,B|D)
197  for (auto&& actual : {AB_given_D * C_given_DE, C_given_DE * AB_given_D}) {
198  EXPECT_LONGS_EQUAL(3, actual.nrFrontals());
199  EXPECT_LONGS_EQUAL(2, actual.nrParents());
200  KeyVector frontals(actual.beginFrontals(), actual.endFrontals());
201  EXPECT((frontals == KeyVector{0, 1, 2}));
202  KeyVector parents(actual.beginParents(), actual.endParents());
203  EXPECT((parents == KeyVector{3, 4}));
204  for (auto&& it : actual.enumerate()) {
205  const DiscreteValues& v = it.first;
206  EXPECT_DOUBLES_EQUAL(actual(v), AB_given_D(v) * C_given_DE(v), 1e-9);
207  }
208  }
209 }
210 
211 /* ************************************************************************* */
212 // Check calculation of marginals for joint P(A,B)
214  DiscreteKey A(1, 2), B(0, 2);
215  DiscreteConditional conditional(A | B = "1/2 2/1");
216  DiscreteConditional prior(B % "1/2");
217  DiscreteConditional pAB = prior * conditional;
218 
219  // P(A=0) = P(A=0|B=0)P(B=0) + P(A=0|B=1)P(B=1) = 1*1 + 2*2 = 5
220  // P(A=1) = P(A=1|B=0)P(B=0) + P(A=1|B=1)P(B=1) = 2*1 + 1*2 = 4
221  DiscreteConditional actualA = pAB.marginal(A.first);
222  DiscreteConditional pA(A % "5/4");
223  EXPECT(assert_equal(pA, actualA));
224  EXPECT(actualA.frontals() == KeyVector{1});
225  EXPECT_LONGS_EQUAL(0, actualA.nrParents());
226 
227  DiscreteConditional actualB = pAB.marginal(B.first);
228  EXPECT(assert_equal(prior, actualB));
229  EXPECT(actualB.frontals() == KeyVector{0});
230  EXPECT_LONGS_EQUAL(0, actualB.nrParents());
231 }
232 
233 /* ************************************************************************* */
234 // Check calculation of marginals in case branches are pruned
235 TEST(DiscreteConditional, marginals2) {
236  DiscreteKey A(0, 2), B(1, 2); // changing keys need to make pruning happen!
237  DiscreteConditional conditional(A | B = "2/2 3/1");
238  DiscreteConditional prior(B % "1/2");
239  DiscreteConditional pAB = prior * conditional;
240  // P(A=0) = P(A=0|B=0)P(B=0) + P(A=0|B=1)P(B=1) = 2*1 + 3*2 = 8
241  // P(A=1) = P(A=1|B=0)P(B=0) + P(A=1|B=1)P(B=1) = 2*1 + 1*2 = 4
242  DiscreteConditional actualA = pAB.marginal(A.first);
243  DiscreteConditional pA(A % "8/4");
244  EXPECT(assert_equal(pA, actualA));
245 
246  DiscreteConditional actualB = pAB.marginal(B.first);
247  EXPECT(assert_equal(prior, actualB));
248 }
249 
250 /* ************************************************************************* */
251 TEST(DiscreteConditional, likelihood) {
252  DiscreteKey X(0, 2), Y(1, 3);
253  DiscreteConditional conditional(X | Y = "2/8 4/6 5/5");
254 
255  auto actual0 = conditional.likelihood(0);
256  DecisionTreeFactor expected0(Y, "0.2 0.4 0.5");
257  EXPECT(assert_equal(expected0, *actual0, 1e-9));
258 
259  auto actual1 = conditional.likelihood(1);
260  DecisionTreeFactor expected1(Y, "0.8 0.6 0.5");
261  EXPECT(assert_equal(expected1, *actual1, 1e-9));
262 }
263 
264 /* ************************************************************************* */
265 // Check choose on P(C|D,E)
267  DiscreteKey C(2, 2), D(4, 2), E(3, 2);
268  DiscreteConditional C_given_DE((C | D, E) = "4/1 1/1 1/1 1/4");
269 
270  // Case 1: no given values: no-op
271  DiscreteValues given;
272  auto actual1 = C_given_DE.choose(given);
273  EXPECT(assert_equal(C_given_DE, *actual1, 1e-9));
274 
275  // Case 2: 1 given value
276  given[D.first] = 1;
277  auto actual2 = C_given_DE.choose(given);
278  EXPECT_LONGS_EQUAL(1, actual2->nrFrontals());
279  EXPECT_LONGS_EQUAL(1, actual2->nrParents());
280  DiscreteConditional expected2(C | E = "1/1 1/4");
281  EXPECT(assert_equal(expected2, *actual2, 1e-9));
282 
283  // Case 2: 2 given values
284  given[E.first] = 0;
285  auto actual3 = C_given_DE.choose(given);
286  EXPECT_LONGS_EQUAL(1, actual3->nrFrontals());
287  EXPECT_LONGS_EQUAL(0, actual3->nrParents());
288  DiscreteConditional expected3(C % "1/1");
289  EXPECT(assert_equal(expected3, *actual3, 1e-9));
290 }
291 
292 /* ************************************************************************* */
293 // Check argmax on P(C|D) and P(D), plus tie-breaking for P(B)
295  DiscreteKey C(2, 2), D(4, 2);
296  DiscreteConditional B_prior(D, "1/1");
297  DiscreteConditional D_prior(D, "1/3");
298  DiscreteConditional C_given_D((C | D) = "1/4 1/1");
299 
300  // Case 1: Tie breaking
301  size_t actual1 = B_prior.argmax();
302  // In the case of ties, the first value is chosen.
303  EXPECT_LONGS_EQUAL(0, actual1);
304  // Case 2: No parents
305  size_t actual2 = D_prior.argmax();
306  // Selects 1 since it has 0.75 probability
307  EXPECT_LONGS_EQUAL(1, actual2);
308 
309  // Case 3: Given parent values
310  DiscreteValues given;
311  given[D.first] = 1;
312  size_t actual3 = C_given_D.argmax(given);
313  // Should be 0 since D=1 gives 0.5/0.5
314  EXPECT_LONGS_EQUAL(0, actual3);
315 
316  given[D.first] = 0;
317  size_t actual4 = C_given_D.argmax(given);
318  EXPECT_LONGS_EQUAL(1, actual4);
319 }
320 
321 /* ************************************************************************* */
322 // Check markdown representation looks as expected, no parents.
323 TEST(DiscreteConditional, markdown_prior) {
324  DiscreteKey A(Symbol('x', 1), 3);
325  DiscreteConditional conditional(A % "1/2/2");
326  string expected =
327  " *P(x1):*\n\n"
328  "|x1|value|\n"
329  "|:-:|:-:|\n"
330  "|0|0.2|\n"
331  "|1|0.4|\n"
332  "|2|0.4|\n";
333  string actual = conditional.markdown();
334  EXPECT(actual == expected);
335 }
336 
337 /* ************************************************************************* */
338 // Check markdown representation looks as expected, no parents + names.
339 TEST(DiscreteConditional, markdown_prior_names) {
340  Symbol x1('x', 1);
341  DiscreteKey A(x1, 3);
342  DiscreteConditional conditional(A % "1/2/2");
343  string expected =
344  " *P(x1):*\n\n"
345  "|x1|value|\n"
346  "|:-:|:-:|\n"
347  "|A0|0.2|\n"
348  "|A1|0.4|\n"
349  "|A2|0.4|\n";
350  DecisionTreeFactor::Names names{{x1, {"A0", "A1", "A2"}}};
351  string actual = conditional.markdown(DefaultKeyFormatter, names);
352  EXPECT(actual == expected);
353 }
354 
355 /* ************************************************************************* */
356 // Check markdown representation looks as expected, multivalued.
357 TEST(DiscreteConditional, markdown_multivalued) {
358  DiscreteKey A(Symbol('a', 1), 3), B(Symbol('b', 1), 5);
359  DiscreteConditional conditional(
360  A | B = "2/88/10 2/20/78 33/33/34 33/33/34 95/2/3");
361  string expected =
362  " *P(a1|b1):*\n\n"
363  "|*b1*|0|1|2|\n"
364  "|:-:|:-:|:-:|:-:|\n"
365  "|0|0.02|0.88|0.1|\n"
366  "|1|0.02|0.2|0.78|\n"
367  "|2|0.33|0.33|0.34|\n"
368  "|3|0.33|0.33|0.34|\n"
369  "|4|0.95|0.02|0.03|\n";
370  string actual = conditional.markdown();
371  EXPECT(actual == expected);
372 }
373 
374 /* ************************************************************************* */
375 // Check markdown representation looks as expected, two parents + names.
377  DiscreteKey A(2, 2), B(1, 2), C(0, 3);
378  DiscreteConditional conditional(A, {B, C}, "0/1 1/3 1/1 3/1 0/1 1/0");
379  string expected =
380  " *P(A|B,C):*\n\n"
381  "|*B*|*C*|T|F|\n"
382  "|:-:|:-:|:-:|:-:|\n"
383  "|-|Zero|0|1|\n"
384  "|-|One|0.25|0.75|\n"
385  "|-|Two|0.5|0.5|\n"
386  "|+|Zero|0.75|0.25|\n"
387  "|+|One|0|1|\n"
388  "|+|Two|1|0|\n";
389  vector<string> keyNames{"C", "B", "A"};
390  auto formatter = [keyNames](Key key) { return keyNames[key]; };
391  DecisionTreeFactor::Names names{
392  {0, {"Zero", "One", "Two"}}, {1, {"-", "+"}}, {2, {"T", "F"}}};
393  string actual = conditional.markdown(formatter, names);
394  EXPECT(actual == expected);
395 }
396 
397 /* ************************************************************************* */
398 // Check html representation looks as expected, two parents + names.
400  DiscreteKey A(2, 2), B(1, 2), C(0, 3);
401  DiscreteConditional conditional(A, {B, C}, "0/1 1/3 1/1 3/1 0/1 1/0");
402  string expected =
403  "<div>\n"
404  "<p> <i>P(A|B,C):</i></p>\n"
405  "<table class='DiscreteConditional'>\n"
406  " <thead>\n"
407  " <tr><th><i>B</i></th><th><i>C</i></th><th>T</th><th>F</th></tr>\n"
408  " </thead>\n"
409  " <tbody>\n"
410  " <tr><th>-</th><th>Zero</th><td>0</td><td>1</td></tr>\n"
411  " <tr><th>-</th><th>One</th><td>0.25</td><td>0.75</td></tr>\n"
412  " <tr><th>-</th><th>Two</th><td>0.5</td><td>0.5</td></tr>\n"
413  " <tr><th>+</th><th>Zero</th><td>0.75</td><td>0.25</td></tr>\n"
414  " <tr><th>+</th><th>One</th><td>0</td><td>1</td></tr>\n"
415  " <tr><th>+</th><th>Two</th><td>1</td><td>0</td></tr>\n"
416  " </tbody>\n"
417  "</table>\n"
418  "</div>";
419  vector<string> keyNames{"C", "B", "A"};
420  auto formatter = [keyNames](Key key) { return keyNames[key]; };
421  DecisionTreeFactor::Names names{
422  {0, {"Zero", "One", "Two"}}, {1, {"-", "+"}}, {2, {"T", "F"}}};
423  string actual = conditional.html(formatter, names);
424  EXPECT(actual == expected);
425 }
426 
427 /* ************************************************************************* */
428 int main() {
429  TestResult tr;
430  return TestRegistry::runAllTests(tr);
431 }
432 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
gtsam::DiscreteConditional::logProbability
double logProbability(const DiscreteValues &x) const
Log-probability is just -error(x).
Definition: DiscreteConditional.h:162
gtsam::Signature::Table
std::vector< Row > Table
Definition: Signature.h:60
DiscreteBayesNet.h
gtsam::markdown
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Definition: DiscreteValues.cpp:130
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:44
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
D
MatrixXcd D
Definition: EigenSolver_EigenSolver_MatrixType.cpp:14
test_constructor::f1
auto f1
Definition: testHybridNonlinearFactor.cpp:56
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EXPECT_LONGS_EQUAL
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:154
main
int main()
Definition: testDiscreteConditional.cpp:428
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
DiscreteFactorGraph.h
r2
static const double r2
Definition: testSmartRangeFactor.cpp:32
gtsam::Y
GaussianFactorGraphValuePair Y
Definition: HybridGaussianProductFactor.cpp:29
asiaCPTs::pA
ADT pA
Definition: testAlgebraicDecisionTree.cpp:153
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
f2
double f2(const Vector2 &x)
Definition: testNumericalDerivative.cpp:56
gtsam::DiscreteConditional::error
double error(const DiscreteValues &values) const override
Calculate error for DiscreteValues x, is -log(probability).
Definition: DecisionTreeFactor.cpp:56
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
log
const EIGEN_DEVICE_FUNC LogReturnType log() const
Definition: ArrayCwiseUnaryOps.h:128
gtsam::Signature::Row
std::vector< double > Row
Definition: Signature.h:59
X
#define X
Definition: icosphere.cpp:20
DiscreteConditional.h
gtsam::DiscreteConditional::markdown
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as markdown table.
Definition: DiscreteConditional.cpp:368
r1
static const double r1
Definition: testSmartRangeFactor.cpp:32
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
gtsam::Conditional::endParents
FACTOR::const_iterator endParents() const
Definition: Conditional.h:189
gtsam::DiscreteConditional::marginal
DiscreteConditional marginal(Key key) const
Definition: DiscreteConditional.cpp:112
table
ArrayXXf table(10, 4)
x1
Pose3 x1
Definition: testPose3.cpp:663
gtsam::Conditional::endFrontals
FACTOR::const_iterator endFrontals() const
Definition: Conditional.h:183
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
r3
static const double r3
Definition: testSmartRangeFactor.cpp:32
test_DiscreteBayesNet.Asia
tuple Asia
Definition: test_DiscreteBayesNet.py:25
Symbol.h
gtsam::Conditional::beginFrontals
FACTOR::const_iterator beginFrontals() const
Definition: Conditional.h:180
gtsam::DiscreteConditional::argmax
size_t argmax(const DiscreteValues &parentsValues=DiscreteValues()) const
Return assignment for single frontal variable that maximizes value.
Definition: DiscreteConditional.cpp:238
gtsam::Factor::end
const_iterator end() const
Definition: Factor.h:149
EXPECT_DOUBLES_EQUAL
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
gtsam::DiscreteConditional::likelihood
DecisionTreeFactor::shared_ptr likelihood(const DiscreteValues &frontalValues) const
Definition: DiscreteConditional.cpp:201
serializationTestHelpers.h
TestResult
Definition: TestResult.h:26
key
const gtsam::Symbol key('X', 0)
E
DiscreteKey E(5, 2)
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
gtsam::Conditional::beginParents
FACTOR::const_iterator beginParents() const
Definition: Conditional.h:186
process_shonan_timing_results.names
dictionary names
Definition: process_shonan_timing_results.py:175
gtsam::DiscreteConditional
Definition: DiscreteConditional.h:37
gtsam::DiscreteConditional::evaluate
double evaluate(const DiscreteValues &values) const
Evaluate, just look up in AlgebraicDecisionTree.
Definition: DiscreteConditional.h:172
C
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:50
gtsam
traits
Definition: SFMdata.h:40
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
std
Definition: BFloat16.h:88
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::DiscreteConditional::choose
shared_ptr choose(const DiscreteValues &given) const
< DiscreteValues version
Definition: DiscreteConditional.cpp:182
different_sigmas::prior
const auto prior
Definition: testHybridBayesNet.cpp:238
TEST
TEST(DiscreteConditional, constructors)
Definition: testDiscreteConditional.cpp:33
gtsam::html
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
Definition: DiscreteValues.cpp:135
marginals
Marginals marginals(graph, result)
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
Z
#define Z
Definition: icosphere.cpp:21
gtsam::Conditional::frontals
Frontals frontals() const
Definition: Conditional.h:145
DecisionTreeFactor.h
choose
static const T & choose(int layout, const T &col, const T &row)
Definition: cxx11_tensor_block_access.cpp:27
gtsam::Conditional::nrParents
size_t nrParents() const
Definition: Conditional.h:134
gtsam::Signature
Definition: Signature.h:54
asiaKey
static const Key asiaKey
Definition: testHybridBayesNet.cpp:44
gtsam::Symbol
Definition: inference/Symbol.h:37


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:21