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


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