testDecisionTree.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 testDecisionTree.cpp
14  * @brief DecisionTree unit tests
15  * @author Frank Dellaert
16  * @author Can Erdogan
17  * @date Jan 30, 2012
18  */
19 
20 // #define DT_DEBUG_MEMORY
21 #define DISABLE_DOT
23 #include <gtsam/base/Testable.h>
26 #include <gtsam/discrete/Ring.h>
28 #include <gtsam/inference/Symbol.h>
29 
30 #include <iomanip>
31 
32 using std::vector;
33 using std::string;
34 using std::map;
35 using namespace gtsam;
36 
37 template <typename T>
38 void dot(const T& f, const string& filename) {
39 #ifndef DISABLE_DOT
40  f.dot(filename);
41 #endif
42 }
43 
44 #define DOT(x) (dot(x, #x))
45 
46 struct Crazy {
47  int a;
48  double b;
49 };
50 
51 struct CrazyDecisionTree : public DecisionTree<string, Crazy> {
53  void print(const std::string& s = "") const {
54  auto keyFormatter = [](const std::string& s) { return s; };
55  auto valueFormatter = [](const Crazy& v) {
56  std::stringstream ss;
57  ss << "{" << v.a << "," << std::setw(4) << std::setprecision(2) << v.b << "}";
58  return ss.str();
59  };
61  }
63  bool equals(const CrazyDecisionTree& other, double tol = 1e-9) const {
64  auto compare = [tol](const Crazy& v, const Crazy& w) {
65  return v.a == w.a && std::abs(v.b - w.b) < tol;
66  };
68  }
69 };
70 
71 // traits
72 namespace gtsam {
73 template <>
74 struct traits<CrazyDecisionTree> : public Testable<CrazyDecisionTree> {};
75 } // namespace gtsam
76 
78 
79 /* ************************************************************************** */
80 // Test char labels and int range
81 /* ************************************************************************** */
82 
83 // Create a decision stump one one variable 'a' with values 10 and 20.
84 TEST(DecisionTree, Constructor) {
85  DecisionTree<char, int> tree('a', 10, 20);
86 
87  // Evaluate the tree on an assignment to the variable.
88  EXPECT_LONGS_EQUAL(10, tree({{'a', 0}}));
89  EXPECT_LONGS_EQUAL(20, tree({{'a', 1}}));
90 }
91 
92 /* ************************************************************************** */
93 // Test string labels and int range
94 /* ************************************************************************** */
95 
96 struct DT : public DecisionTree<string, int> {
99  DT() = default;
100 
101  DT(const Base& dt) : Base(dt) {}
102 
104  void print(const std::string& s = "") const {
105  auto keyFormatter = [](const std::string& s) { return s; };
106  auto valueFormatter = [](const int& v) {
107  return std::to_string(v);
108  };
109  std::cout << s;
110  Base::print("", keyFormatter, valueFormatter);
111  }
112 
114  bool equals(const Base& other, double tol = 1e-9) const {
115  auto compare = [](const int& v, const int& w) { return v == w; };
116  return Base::equals(other, compare);
117  }
118 };
119 
120 // traits
121 namespace gtsam {
122 template <>
123 struct traits<DT> : public Testable<DT> {};
124 } // namespace gtsam
125 
127 
128 /* ************************************************************************** */
129 // Check that creating decision trees respects key order.
130 TEST(DecisionTree, ConstructorOrder) {
131  // Create labels
132  string A("A"), B("B");
133 
134  const std::vector<int> ys1 = {1, 2, 3, 4};
135  DT tree1({{B, 2}, {A, 2}}, ys1); // faster version, as B is "higher" than A!
136 
137  const std::vector<int> ys2 = {1, 3, 2, 4};
138  DT tree2({{A, 2}, {B, 2}}, ys2); // slower version !
139 
140  // Both trees will be the same, tree is order from high to low labels.
141  // Choice(B)
142  // 0 Choice(A)
143  // 0 0 Leaf 1
144  // 0 1 Leaf 2
145  // 1 Choice(A)
146  // 1 0 Leaf 3
147  // 1 1 Leaf 4
148 
149  EXPECT(tree2.equals(tree1));
150 
151  // Check the values are as expected by calling the () operator:
152  EXPECT_LONGS_EQUAL(1, tree1({{A, 0}, {B, 0}}));
153  EXPECT_LONGS_EQUAL(3, tree1({{A, 0}, {B, 1}}));
154  EXPECT_LONGS_EQUAL(2, tree1({{A, 1}, {B, 0}}));
155  EXPECT_LONGS_EQUAL(4, tree1({{A, 1}, {B, 1}}));
156 }
157 
158 /* ************************************************************************** */
159 // test DT
160 TEST(DecisionTree, Example) {
161  // Create labels
162  string A("A"), B("B"), C("C");
163 
164  // Create assignments using brace initialization:
165  Assignment<string> x00{{A, 0}, {B, 0}};
166  Assignment<string> x01{{A, 0}, {B, 1}};
167  Assignment<string> x10{{A, 1}, {B, 0}};
168  Assignment<string> x11{{A, 1}, {B, 1}};
169 
170  // empty
171  DT empty;
172 
173  // A
174  DT a(A, 0, 5);
175  LONGS_EQUAL(0, a(x00))
176  LONGS_EQUAL(5, a(x10))
177  DOT(a);
178 
179  // pruned
180  DT p(A, 2, 2);
181  LONGS_EQUAL(2, p(x00))
182  LONGS_EQUAL(2, p(x10))
183  DOT(p);
184 
185  // \neg B
186  DT notb(B, 5, 0);
187  LONGS_EQUAL(5, notb(x00))
188  LONGS_EQUAL(5, notb(x10))
189  DOT(notb);
190 
191  // Check supplying empty trees yields an exception
192  CHECK_EXCEPTION(gtsam::apply(empty, &Ring::id), std::runtime_error);
193  CHECK_EXCEPTION(gtsam::apply(empty, a, &Ring::mul), std::runtime_error);
194  CHECK_EXCEPTION(gtsam::apply(a, empty, &Ring::mul), std::runtime_error);
195 
196  // apply, two nodes, in natural order
197  DT anotb = apply(a, notb, &Ring::mul);
198  LONGS_EQUAL(0, anotb(x00))
199  LONGS_EQUAL(0, anotb(x01))
200  LONGS_EQUAL(25, anotb(x10))
201  LONGS_EQUAL(0, anotb(x11))
202  DOT(anotb);
203 
204  // check pruning
205  DT pnotb = apply(p, notb, &Ring::mul);
206  LONGS_EQUAL(10, pnotb(x00))
207  LONGS_EQUAL(0, pnotb(x01))
208  LONGS_EQUAL(10, pnotb(x10))
209  LONGS_EQUAL(0, pnotb(x11))
210  DOT(pnotb);
211 
212  // check pruning
213  DT zeros = apply(DT(A, 0, 0), notb, &Ring::mul);
214  LONGS_EQUAL(0, zeros(x00))
215  LONGS_EQUAL(0, zeros(x01))
216  LONGS_EQUAL(0, zeros(x10))
217  LONGS_EQUAL(0, zeros(x11))
218  DOT(zeros);
219 
220  // apply, two nodes, in switched order
221  DT notba = apply(a, notb, &Ring::mul);
222  LONGS_EQUAL(0, notba(x00))
223  LONGS_EQUAL(0, notba(x01))
224  LONGS_EQUAL(25, notba(x10))
225  LONGS_EQUAL(0, notba(x11))
226  DOT(notba);
227 
228  // Test choose 0
229  DT actual0 = notba.choose(A, 0);
230 #ifdef GTSAM_DT_MERGING
231  EXPECT(assert_equal(DT(0.0), actual0));
232 #else
233  EXPECT(assert_equal(DT({0.0, 0.0}), actual0));
234 #endif
235  DOT(actual0);
236 
237  // Test choose 1
238  DT actual1 = notba.choose(A, 1);
239  EXPECT(assert_equal(DT(B, 25, 0), actual1));
240  DOT(actual1);
241 
242  // apply, two nodes at same level
243  DT a_and_a = apply(a, a, &Ring::mul);
244  LONGS_EQUAL(0, a_and_a(x00))
245  LONGS_EQUAL(0, a_and_a(x01))
246  LONGS_EQUAL(25, a_and_a(x10))
247  LONGS_EQUAL(25, a_and_a(x11))
248  DOT(a_and_a);
249 
250  // create a function on C
251  DT c(C, 0, 5);
252 
253  // and a model assigning stuff to C
254  Assignment<string> x101;
255  x101[A] = 1, x101[B] = 0, x101[C] = 1;
256 
257  // mul notba with C
258  DT notbac = apply(notba, c, &Ring::mul);
259  LONGS_EQUAL(125, notbac(x101))
260  DOT(notbac);
261 
262  // mul now in different order
263  DT acnotb = apply(apply(a, c, &Ring::mul), notb, &Ring::mul);
264  LONGS_EQUAL(125, acnotb(x101))
265  DOT(acnotb);
266 }
267 
268 /* ************************************************************************** */
269 // Test that we can create two trees out of one, using a function that returns a pair.
271  // Create labels
272  string A("A"), B("B");
273 
274  // Create a decision tree
275  DT original(A, DT(B, 1, 2), DT(B, 3, 4));
276 
277  // Define a function that returns an int/bool pair
278  auto split_function = [](const int& value) -> std::pair<int, bool> {
279  return {value*3, value*3 % 2 == 0};
280  };
281 
282  // Split the original tree into two new trees
283  auto [la,lb] = original.split<int,bool>(split_function);
284 
285  // Check the first resulting tree
286  EXPECT_LONGS_EQUAL(3, la(Assignment<string>{{A, 0}, {B, 0}}));
287  EXPECT_LONGS_EQUAL(6, la(Assignment<string>{{A, 0}, {B, 1}}));
288  EXPECT_LONGS_EQUAL(9, la(Assignment<string>{{A, 1}, {B, 0}}));
289  EXPECT_LONGS_EQUAL(12, la(Assignment<string>{{A, 1}, {B, 1}}));
290 
291  // Check the second resulting tree
292  EXPECT(!lb(Assignment<string>{{A, 0}, {B, 0}}));
293  EXPECT(lb(Assignment<string>{{A, 0}, {B, 1}}));
294  EXPECT(!lb(Assignment<string>{{A, 1}, {B, 0}}));
295  EXPECT(lb(Assignment<string>{{A, 1}, {B, 1}}));
296 }
297 
298 
299 /* ************************************************************************** */
300 // Test that we can create a tree by modifying an rvalue.
301 TEST(DecisionTree, Consume) {
302  // Create labels
303  string A("A"), B("B");
304 
305  // Create a decision tree
306  DT original(A, DT(B, 1, 2), DT(B, 3, 4));
307 
308  DT modified([](int i){return i*2;}, std::move(original));
309 
310  // Check the first resulting tree
311  EXPECT_LONGS_EQUAL(2, modified(Assignment<string>{{A, 0}, {B, 0}}));
312  EXPECT_LONGS_EQUAL(4, modified(Assignment<string>{{A, 0}, {B, 1}}));
313  EXPECT_LONGS_EQUAL(6, modified(Assignment<string>{{A, 1}, {B, 0}}));
314  EXPECT_LONGS_EQUAL(8, modified(Assignment<string>{{A, 1}, {B, 1}}));
315 
316  // Check original was moved
317  EXPECT(original.root_ == nullptr);
318 }
319 
320 /* ************************************************************************** */
321 // test Conversion of values
322 bool bool_of_int(const int& y) { return y != 0; };
324 
325 TEST(DecisionTree, ConvertValuesOnly) {
326  // Create labels
327  string A("A"), B("B");
328 
329  // apply, two nodes, in natural order
330  DT f1 = apply(DT(A, 0, 5), DT(B, 5, 0), &Ring::mul);
331 
332  // convert
334 
335  // Check a value
336  Assignment<string> x00 {{A, 0}, {B, 0}};
337  EXPECT(!f2(x00));
338 }
339 
340 /* ************************************************************************** */
341 // test Conversion of both values and labels.
342 enum Label { U, V, X, Y, Z };
344 
345 TEST(DecisionTree, ConvertBoth) {
346  // Create labels
347  string A("A"), B("B");
348 
349  // apply, two nodes, in natural order
350  DT f1 = apply(DT(A, 0, 5), DT(B, 5, 0), &Ring::mul);
351 
352  // convert
353  map<string, Label> ordering;
354  ordering[A] = X;
355  ordering[B] = Y;
357 
358  // Check some values
359  Assignment<Label> x00, x01, x10, x11;
360  x00 = {{X, 0}, {Y, 0}};
361  x01 = {{X, 0}, {Y, 1}};
362  x10 = {{X, 1}, {Y, 0}};
363  x11 = {{X, 1}, {Y, 1}};
364 
365  EXPECT(!f2(x00));
366  EXPECT(!f2(x01));
367  EXPECT(f2(x10));
368  EXPECT(!f2(x11));
369 }
370 
371 /* ************************************************************************** */
372 // test Compose expansion
373 TEST(DecisionTree, Compose) {
374  // Create labels
375  string A("A"), B("B"), C("C");
376 
377  // Put two stumps on A together
378  DT f1(B, DT(A, 0, 1), DT(A, 2, 3));
379 
380  // Create from string
381  vector<DT::LabelC> keys{DT::LabelC(A, 2), DT::LabelC(B, 2)};
382  DT f2(keys, "0 2 1 3");
383  EXPECT(assert_equal(f2, f1, 1e-9));
384 
385  // Put this AB tree together with another one
386  DT f3(keys, "4 6 5 7");
387  DT f4(C, f1, f3);
388  DOT(f4);
389 
390  // a bigger tree
391  keys.push_back(DT::LabelC(C, 2));
392  DT f5(keys, "0 4 2 6 1 5 3 7");
393  EXPECT(assert_equal(f5, f4, 1e-9));
394  DOT(f5);
395 }
396 
397 /* ************************************************************************** */
398 // Check we can create a decision tree of containers.
399 TEST(DecisionTree, Containers) {
400  using Container = std::vector<double>;
401  using StringContainerTree = DecisionTree<string, Container>;
402 
403  // Check default constructor
404  StringContainerTree tree;
405 
406  // Create small two-level tree
407  string A("A"), B("B");
408  DT stringIntTree(B, DT(A, 0, 1), DT(A, 2, 3));
409 
410  // Check conversion
411  auto container_of_int = [](const int& i) {
412  Container c;
413  c.emplace_back(i);
414  return c;
415  };
416  StringContainerTree converted(stringIntTree, container_of_int);
417 }
418 
419 /* ************************************************************************** */
420 // Test visit.
422  // Create small two-level tree
423  string A("A"), B("B");
424  DT tree(B, DT(A, 0, 1), DT(A, 2, 3));
425  double sum = 0.0;
426  auto visitor = [&](int y) { sum += y; };
427  tree.visit(visitor);
428  EXPECT_DOUBLES_EQUAL(6.0, sum, 1e-9);
429 }
430 
431 /* ************************************************************************** */
432 // Test visit, with Choices argument.
433 TEST(DecisionTree, visitWith) {
434  // Create small two-level tree
435  string A("A"), B("B");
436  DT tree(B, DT(A, 0, 1), DT(A, 2, 3));
437  double sum = 0.0;
438  auto visitor = [&](const Assignment<string>& choices, int y) { sum += y; };
439  tree.visitWith(visitor);
440  EXPECT_DOUBLES_EQUAL(6.0, sum, 1e-9);
441 }
442 
443 /* ************************************************************************** */
444 // Test visit, with Choices argument.
445 TEST(DecisionTree, VisitWithPruned) {
446  // Create pruned tree
447  std::pair<string, size_t> A("A", 2), B("B", 2), C("C", 2);
448  std::vector<std::pair<string, size_t>> labels = {C, B, A};
449  std::vector<int> nodes = {0, 0, 2, 3, 4, 4, 6, 7};
450  DT tree(labels, nodes);
451 
452  std::vector<Assignment<string>> choices;
453  auto func = [&](const Assignment<string>& choice, const int& d) {
454  choices.push_back(choice);
455  };
456  tree.visitWith(func);
457 
458 #ifdef GTSAM_DT_MERGING
459  EXPECT_LONGS_EQUAL(6, choices.size());
460 #else
461  EXPECT_LONGS_EQUAL(8, choices.size());
462 #endif
463 
464  Assignment<string> expectedAssignment;
465 
466 #ifdef GTSAM_DT_MERGING
467  expectedAssignment = {{"B", 0}, {"C", 0}};
468  EXPECT(expectedAssignment == choices.at(0));
469 
470  expectedAssignment = {{"A", 0}, {"B", 1}, {"C", 0}};
471  EXPECT(expectedAssignment == choices.at(1));
472 
473  expectedAssignment = {{"A", 1}, {"B", 1}, {"C", 0}};
474  EXPECT(expectedAssignment == choices.at(2));
475 
476  expectedAssignment = {{"B", 0}, {"C", 1}};
477  EXPECT(expectedAssignment == choices.at(3));
478 
479  expectedAssignment = {{"A", 0}, {"B", 1}, {"C", 1}};
480  EXPECT(expectedAssignment == choices.at(4));
481 
482  expectedAssignment = {{"A", 1}, {"B", 1}, {"C", 1}};
483  EXPECT(expectedAssignment == choices.at(5));
484 #else
485  expectedAssignment = {{"A", 0}, {"B", 0}, {"C", 0}};
486  EXPECT(expectedAssignment == choices.at(0));
487 
488  expectedAssignment = {{"A", 1}, {"B", 0}, {"C", 0}};
489  EXPECT(expectedAssignment == choices.at(1));
490 
491  expectedAssignment = {{"A", 0}, {"B", 1}, {"C", 0}};
492  EXPECT(expectedAssignment == choices.at(2));
493 
494  expectedAssignment = {{"A", 1}, {"B", 1}, {"C", 0}};
495  EXPECT(expectedAssignment == choices.at(3));
496 
497  expectedAssignment = {{"A", 0}, {"B", 0}, {"C", 1}};
498  EXPECT(expectedAssignment == choices.at(4));
499 
500  expectedAssignment = {{"A", 1}, {"B", 0}, {"C", 1}};
501  EXPECT(expectedAssignment == choices.at(5));
502 #endif
503 }
504 
505 /* ************************************************************************** */
506 // Test fold.
508  // Create small two-level tree
509  string A("A"), B("B");
510  DT tree(B, DT(A, 1, 1), DT(A, 2, 3));
511  auto add = [](const int& y, double x) { return y + x; };
512  double sum = tree.fold(add, 0.0);
513 #ifdef GTSAM_DT_MERGING
514  EXPECT_DOUBLES_EQUAL(6.0, sum, 1e-9); // Note, not 7, due to merging!
515 #else
516  EXPECT_DOUBLES_EQUAL(7.0, sum, 1e-9);
517 #endif
518 }
519 
520 /* ************************************************************************** */
521 // Test retrieving all labels.
523  // Create small two-level tree
524  string A("A"), B("B");
525  DT tree(B, DT(A, 0, 1), DT(A, 2, 3));
526  auto labels = tree.labels();
527  EXPECT_LONGS_EQUAL(2, labels.size());
528 }
529 
530 /* ************************************************************************** */
531 // Test unzip method.
534  using DT1 = DecisionTree<string, int>;
535  using DT2 = DecisionTree<string, string>;
536 
537  // Create small two-level tree
538  string A("A"), B("B"), C("C");
539  DTP tree(B, DTP(A, {0, "zero"}, {1, "one"}),
540  DTP(A, {2, "two"}, {1337, "l33t"}));
541 
542  const auto [dt1, dt2] = unzip(tree);
543 
544  DT1 tree1(B, DT1(A, 0, 1), DT1(A, 2, 1337));
545  DT2 tree2(B, DT2(A, "zero", "one"), DT2(A, "two", "l33t"));
546 
547  EXPECT(tree1.equals(dt1));
548  EXPECT(tree2.equals(dt2));
549 }
550 
551 /* ************************************************************************** */
552 // Test thresholding.
553 TEST(DecisionTree, threshold) {
554  // Create three level tree
555  const vector<DT::LabelC> keys{DT::LabelC("C", 2), DT::LabelC("B", 2),
556  DT::LabelC("A", 2)};
557  DT tree(keys, "0 1 2 3 4 5 6 7");
558 
559  // Check number of leaves equal to zero
560  auto count = [](const int& value, int count) {
561  return value == 0 ? count + 1 : count;
562  };
563  EXPECT_LONGS_EQUAL(1, tree.fold(count, 0));
564 
565  // Now threshold
566  auto threshold = [](int value) { return value < 5 ? 0 : value; };
567  DT thresholded(tree, threshold);
568 
569 #ifdef GTSAM_DT_MERGING
570  // Check number of leaves equal to zero now = 2
571  // Note: it is 2, because the pruned branches are counted as 1!
572  EXPECT_LONGS_EQUAL(2, thresholded.fold(count, 0));
573 #else
574  // if GTSAM_DT_MERGING is disabled, the count will be larger
575  EXPECT_LONGS_EQUAL(5, thresholded.fold(count, 0));
576 #endif
577 }
578 
579 /* ************************************************************************** */
580 // Test apply with assignment.
581 TEST(DecisionTree, ApplyWithAssignment) {
582  // Create three level tree
583  const vector<DT::LabelC> keys{DT::LabelC("C", 2), DT::LabelC("B", 2),
584  DT::LabelC("A", 2)};
585  DT tree(keys, "1 2 3 4 5 6 7 8");
586 
588  keys, "0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08");
589  double threshold = 0.045;
590 
591  // We test pruning one tree by indexing into another.
592  auto pruner = [&](const Assignment<string>& choices, const int& x) {
593  // Prune out all the leaves with even numbers
594  if (probTree(choices) < threshold) {
595  return 0;
596  } else {
597  return x;
598  }
599  };
600  DT prunedTree = tree.apply(pruner);
601 
602  DT expectedTree(keys, "0 0 0 0 5 6 7 8");
603  EXPECT(assert_equal(expectedTree, prunedTree));
604 
605  size_t count = 0;
606  auto counter = [&](const Assignment<string>& choices, const int& x) {
607  count += 1;
608  return x;
609  };
610  DT prunedTree2 = prunedTree.apply(counter);
611 
612 #ifdef GTSAM_DT_MERGING
613  // Check if apply doesn't enumerate all leaves.
614  EXPECT_LONGS_EQUAL(5, count);
615 #else
616  // if GTSAM_DT_MERGING is disabled, the count will be full
617  EXPECT_LONGS_EQUAL(8, count);
618 #endif
619 }
620 
621 /* ************************************************************************* */
622 int main() {
623  TestResult tr;
624  return TestRegistry::runAllTests(tr);
625 }
626 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
w
RowVector3d w
Definition: Matrix_resize_int.cpp:3
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
compare
bool compare
Definition: SolverComparer.cpp:98
Eigen::internal::print
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: NEON/PacketMath.h:3115
CHECK_EXCEPTION
#define CHECK_EXCEPTION(condition, exception_name)
Definition: Test.h:118
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
gtsam::add
static Y add(const Y &y1, const Y &y2)
Definition: HybridGaussianProductFactor.cpp:32
test_constructor::f1
auto f1
Definition: testHybridNonlinearFactor.cpp:56
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::DecisionTree::split
std::pair< DecisionTree< L, A >, DecisionTree< L, B > > split(std::function< std::pair< A, B >(const Y &)> AB_of_Y) const
Convert into two trees with value types A and B.
Definition: DecisionTree-inl.h:1096
d
static const double d[K][N]
Definition: igam.h:11
GTSAM_CONCEPT_TESTABLE_INST
#define GTSAM_CONCEPT_TESTABLE_INST(T)
Definition: Testable.h:176
EXPECT_LONGS_EQUAL
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:154
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
DT::equals
bool equals(const Base &other, double tol=1e-9) const
Equality method customized to int node type.
Definition: testDecisionTree.cpp:114
tree
Definition: testExpression.cpp:212
gtsam::Y
GaussianFactorGraphValuePair Y
Definition: HybridGaussianProductFactor.cpp:29
gtsam::DecisionTree::equals
bool equals(const DecisionTree &other, const CompareFunc &compare=&DefaultCompare) const
Definition: DecisionTree-inl.h:972
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
dt
const double dt
Definition: testVelocityConstraint.cpp:15
f2
double f2(const Vector2 &x)
Definition: testNumericalDerivative.cpp:58
gtsam::DecisionTree::DecisionTree
DecisionTree()
Definition: DecisionTree-inl.h:491
gtsam::DecisionTree::print
void print(const std::string &s, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const
GTSAM-style print.
Definition: DecisionTree-inl.h:978
gtsam::DecisionTree::choose
DecisionTree choose(const L &label, size_t index) const
Definition: DecisionTree.h:391
bool_of_int
bool bool_of_int(const int &y)
Definition: testDecisionTree.cpp:322
Ring::mul
static double mul(const double &a, const double &b)
Definition: Ring.h:31
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
ss
static std::stringstream ss
Definition: testBTree.cpp:31
DOT
#define DOT(x)
Definition: testDecisionTree.cpp:44
labels
std::vector< std::string > labels
Definition: dense_solvers.cpp:11
DT::print
void print(const std::string &s="") const
print to stdout
Definition: testDecisionTree.cpp:104
gtsam::DecisionTree::root_
NodePtr root_
A DecisionTree just contains the root. TODO(dellaert): make protected.
Definition: DecisionTree.h:149
DT
Definition: testDecisionTree.cpp:96
relicense.filename
filename
Definition: relicense.py:57
V
@ V
Definition: testDecisionTree.cpp:342
Signature.h
signatures for conditional densities
Crazy::a
int a
Definition: testDecisionTree.cpp:47
gtsam::dot
double dot(const V1 &a, const V2 &b)
Definition: Vector.h:196
main
int main()
Definition: testDecisionTree.cpp:622
CrazyDecisionTree::equals
bool equals(const CrazyDecisionTree &other, double tol=1e-9) const
Equality method customized to Crazy node type.
Definition: testDecisionTree.cpp:63
Symbol.h
gtsam::Assignment
Definition: Assignment.h:37
Eigen::Triplet< double >
gtsam::DecisionTree::apply
DecisionTree apply(const Unary &op) const
Definition: DecisionTree-inl.h:1000
EXPECT_DOUBLES_EQUAL
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
ordering
static enum @1096 ordering
serializationTestHelpers.h
TestResult
Definition: TestResult.h:26
y
Scalar * y
Definition: level1_cplx_impl.h:124
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
gtsam::DecisionTree
a decision tree is a function from assignments to values.
Definition: DecisionTree.h:62
nodes
KeyVector nodes
Definition: testMFAS.cpp:28
DT::DT
DT(const Base &dt)
Definition: testDecisionTree.cpp:101
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
Label
Label
Definition: testDecisionTree.cpp:342
empty
Definition: test_copy_move.cpp:19
C
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:50
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::TEST
TEST(SmartFactorBase, Pinhole)
Definition: testSmartFactorBase.cpp:38
DecisionTree-inl.h
gtsam::traits
Definition: Group.h:36
LabelBoolTree
DecisionTree< Label, bool > LabelBoolTree
Definition: testDecisionTree.cpp:343
f3
double f3(double x1, double x2)
Definition: testNumericalDerivative.cpp:78
CrazyDecisionTree
Definition: testDecisionTree.cpp:51
gtsam::DecisionTree< string, int >::LabelC
std::pair< string, size_t > LabelC
Definition: DecisionTree.h:80
X
@ X
Definition: testDecisionTree.cpp:342
p
float * p
Definition: Tutorial_Map_using.cpp:9
Ring.h
Real Ring definition.
StringBoolTree
DecisionTree< string, bool > StringBoolTree
Definition: testDecisionTree.cpp:322
gtsam::apply
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
Apply unary operator op to DecisionTree f.
Definition: DecisionTree.h:460
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
f4
double f4(double x, double y, double z)
Definition: testNumericalDerivative.cpp:107
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:41
CrazyDecisionTree::print
void print(const std::string &s="") const
print to stdout
Definition: testDecisionTree.cpp:53
gtsam::tol
const G double tol
Definition: Group.h:79
U
@ U
Definition: testDecisionTree.cpp:342
abs
#define abs(x)
Definition: datatypes.h:17
func
Definition: benchGeometry.cpp:23
gtsam::unzip
std::pair< DecisionTree< L, T1 >, DecisionTree< L, T2 > > unzip(const DecisionTree< L, std::pair< T1, T2 > > &input)
unzip a DecisionTree with std::pair values.
Definition: DecisionTree.h:487
gtsam::valueFormatter
static std::string valueFormatter(const double &v)
Definition: DecisionTreeFactor.cpp:248
gtsam::DecisionTree::fold
X fold(Func f, X x0) const
Fold a binary function over the tree, returning accumulator.
Definition: DecisionTree-inl.h:939
Ring::id
static double id(const double &x)
Definition: Ring.h:35
test_callbacks.value
value
Definition: test_callbacks.py:160
LONGS_EQUAL
#define LONGS_EQUAL(expected, actual)
Definition: Test.h:134
Z
@ Z
Definition: testDecisionTree.cpp:342
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Crazy
Definition: testDecisionTree.cpp:46
Crazy::b
double b
Definition: testDecisionTree.cpp:48


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:06:11