Go to the documentation of this file.
34 using namespace gtsam;
43 #define DOT(x) (dot(x, #x))
52 void print(
const std::string&
s =
"")
const {
53 auto keyFormatter = [](
const std::string&
s) {
return s; };
56 ss <<
"{" <<
v.a <<
"," << std::setw(4) << std::setprecision(2) <<
v.b <<
"}";
103 void print(
const std::string&
s =
"")
const {
104 auto keyFormatter = [](
const std::string&
s) {
return s; };
106 return std::to_string(
v);
114 auto compare = [](
const int&
v,
const int&
w) {
return v ==
w; };
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; }
139 string A(
"A"),
B(
"B");
141 const std::vector<int> ys1 = {1, 2, 3, 4};
142 DT tree1({{
B, 2}, {
A, 2}}, ys1);
144 const std::vector<int> ys2 = {1, 3, 2, 4};
145 DT tree2({{
A, 2}, {
B, 2}}, ys2);
156 EXPECT(tree2.equals(tree1));
169 string A(
"A"),
B(
"B"),
C(
"C");
237 #ifdef GTSAM_DT_MERGING
262 x101[
A] = 1, x101[
B] = 0, x101[
C] = 1;
279 string A(
"A"),
B(
"B");
282 DT original(
A,
DT(
B, 1, 2),
DT(
B, 3, 4));
285 auto split_function = [](
const int&
value) -> std::pair<int, bool> {
290 auto [la,lb] = original.
split<
int,
bool>(split_function);
310 string A(
"A"),
B(
"B");
313 DT original(
A,
DT(
B, 1, 2),
DT(
B, 3, 4));
315 DT modified([](
int i){
return i*2;}, std::move(original));
334 string A(
"A"),
B(
"B");
354 string A(
"A"),
B(
"B");
367 x00 = {{
X, 0}, {
Y, 0}};
368 x01 = {{
X, 0}, {
Y, 1}};
369 x10 = {{
X, 1}, {
Y, 0}};
370 x11 = {{
X, 1}, {
Y, 1}};
382 string A(
"A"),
B(
"B"),
C(
"C");
399 DT f5(
keys,
"0 4 2 6 1 5 3 7");
407 using Container = std::vector<double>;
411 StringContainerTree
tree;
414 string A(
"A"),
B(
"B");
415 DT stringIntTree(
B,
DT(
A, 0, 1),
DT(
A, 2, 3));
418 auto container_of_int = [](
const int&
i) {
423 StringContainerTree converted(stringIntTree, container_of_int);
430 string A(
"A"),
B(
"B");
433 auto visitor = [&](
int y) { sum +=
y; };
442 string A(
"A"),
B(
"B");
446 tree.visitWith(visitor);
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};
459 std::vector<Assignment<string>> choices;
461 choices.push_back(choice);
465 #ifdef GTSAM_DT_MERGING
473 #ifdef GTSAM_DT_MERGING
474 expectedAssignment = {{
"B", 0}, {
"C", 0}};
475 EXPECT(expectedAssignment == choices.at(0));
477 expectedAssignment = {{
"A", 0}, {
"B", 1}, {
"C", 0}};
478 EXPECT(expectedAssignment == choices.at(1));
480 expectedAssignment = {{
"A", 1}, {
"B", 1}, {
"C", 0}};
481 EXPECT(expectedAssignment == choices.at(2));
483 expectedAssignment = {{
"B", 0}, {
"C", 1}};
484 EXPECT(expectedAssignment == choices.at(3));
486 expectedAssignment = {{
"A", 0}, {
"B", 1}, {
"C", 1}};
487 EXPECT(expectedAssignment == choices.at(4));
489 expectedAssignment = {{
"A", 1}, {
"B", 1}, {
"C", 1}};
490 EXPECT(expectedAssignment == choices.at(5));
492 expectedAssignment = {{
"A", 0}, {
"B", 0}, {
"C", 0}};
493 EXPECT(expectedAssignment == choices.at(0));
495 expectedAssignment = {{
"A", 1}, {
"B", 0}, {
"C", 0}};
496 EXPECT(expectedAssignment == choices.at(1));
498 expectedAssignment = {{
"A", 0}, {
"B", 1}, {
"C", 0}};
499 EXPECT(expectedAssignment == choices.at(2));
501 expectedAssignment = {{
"A", 1}, {
"B", 1}, {
"C", 0}};
502 EXPECT(expectedAssignment == choices.at(3));
504 expectedAssignment = {{
"A", 0}, {
"B", 0}, {
"C", 1}};
505 EXPECT(expectedAssignment == choices.at(4));
507 expectedAssignment = {{
"A", 1}, {
"B", 0}, {
"C", 1}};
508 EXPECT(expectedAssignment == choices.at(5));
516 string A(
"A"),
B(
"B");
518 auto add = [](
const int&
y,
double x) {
return y +
x; };
519 double sum =
tree.fold(
add, 0.0);
520 #ifdef GTSAM_DT_MERGING
531 string A(
"A"),
B(
"B");
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"}));
551 DT1 tree1(
B, DT1(
A, 0, 1), DT1(
A, 2, 1337));
552 DT2 tree2(
B, DT2(
A,
"zero",
"one"), DT2(
A,
"two",
"l33t"));
554 EXPECT(tree1.equals(dt1));
555 EXPECT(tree2.equals(dt2));
567 auto count = [](
const int&
value,
int count) {
568 return value == 0 ? count + 1 : count;
574 DT thresholded(
tree, threshold);
576 #ifdef GTSAM_DT_MERGING
595 keys,
"0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08");
596 double threshold = 0.045;
601 if (probTree(choices) < threshold) {
607 DT prunedTree =
tree.apply(pruner);
609 DT expectedTree(
keys,
"0 0 0 0 5 6 7 8");
617 DT prunedTree2 = prunedTree.
apply(counter);
619 #ifdef GTSAM_DT_MERGING
static int runAllTests(TestResult &result)
static int id(const int &a)
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
#define CHECK_EXCEPTION(condition, exception_name)
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
static Y add(const Y &y1, const Y &y2)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
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.
static const double d[K][N]
#define GTSAM_CONCEPT_TESTABLE_INST(T)
#define EXPECT_LONGS_EQUAL(expected, actual)
Concept check for values that can be used in unit tests.
#define EXPECT(condition)
bool equals(const Base &other, double tol=1e-9) const
Equality method customized to int node type.
GaussianFactorGraphValuePair Y
bool equals(const DecisionTree &other, const CompareFunc &compare=&DefaultCompare) const
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
double f2(const Vector2 &x)
void print(const std::string &s, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const
GTSAM-style print.
DecisionTree choose(const L &label, size_t index) const
bool bool_of_int(const int &y)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
static std::stringstream ss
std::vector< std::string > labels
void print(const std::string &s="") const
print to stdout
NodePtr root_
A DecisionTree just contains the root. TODO(dellaert): make protected.
signatures for conditional densities
double dot(const V1 &a, const V2 &b)
bool equals(const CrazyDecisionTree &other, double tol=1e-9) const
Equality method customized to Crazy node type.
static int add(const int &a, const int &b)
DecisionTree apply(const Unary &op) const
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
static enum @1096 ordering
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
a decision tree is a function from assignments to values.
Matrix< Scalar, Dynamic, Dynamic > C
TEST(SmartFactorBase, Pinhole)
DecisionTree< Label, bool > LabelBoolTree
double f3(double x1, double x2)
std::pair< string, size_t > LabelC
DecisionTree< string, bool > StringBoolTree
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
Apply unary operator op to DecisionTree f.
Array< int, Dynamic, 1 > v
double f4(double x, double y, double z)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
void print(const std::string &s="") const
print to stdout
std::pair< DecisionTree< L, T1 >, DecisionTree< L, T2 > > unzip(const DecisionTree< L, std::pair< T1, T2 > > &input)
unzip a DecisionTree with std::pair values.
static std::string valueFormatter(const double &v)
X fold(Func f, X x0) const
Fold a binary function over the tree, returning accumulator.
#define LONGS_EQUAL(expected, actual)
static int mul(const int &a, const int &b)
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:21