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);
113 auto compare = [](
const int&
v,
const int&
w) {
return v ==
w; };
127 static inline int zero() {
return 0; }
128 static inline int one() {
return 1; }
129 static inline int id(
const int&
a) {
return a; }
130 static inline int add(
const int&
a,
const int&
b) {
return a +
b; }
131 static inline int mul(
const int&
a,
const int&
b) {
return a *
b; }
138 string A(
"A"),
B(
"B");
140 const std::vector<int> ys1 = {1, 2, 3, 4};
141 DT tree1({{
B, 2}, {
A, 2}}, ys1);
143 const std::vector<int> ys2 = {1, 3, 2, 4};
144 DT tree2({{
A, 2}, {
B, 2}}, ys2);
155 EXPECT(tree2.equals(tree1));
168 string A(
"A"),
B(
"B"),
C(
"C");
236 #ifdef GTSAM_DT_MERGING
261 x101[
A] = 1, x101[
B] = 0, x101[
C] = 1;
281 string A(
"A"),
B(
"B");
301 string A(
"A"),
B(
"B");
314 x00 = {{
X, 0}, {
Y, 0}};
315 x01 = {{
X, 0}, {
Y, 1}};
316 x10 = {{
X, 1}, {
Y, 0}};
317 x11 = {{
X, 1}, {
Y, 1}};
329 string A(
"A"),
B(
"B"),
C(
"C");
346 DT f5(
keys,
"0 4 2 6 1 5 3 7");
354 using Container = std::vector<double>;
358 StringContainerTree
tree;
361 string A(
"A"),
B(
"B");
362 DT stringIntTree(
B,
DT(
A, 0, 1),
DT(
A, 2, 3));
365 auto container_of_int = [](
const int&
i) {
370 StringContainerTree converted(stringIntTree, container_of_int);
377 string A(
"A"),
B(
"B");
380 auto visitor = [&](
int y) { sum +=
y; };
389 string A(
"A"),
B(
"B");
393 tree.visitWith(visitor);
401 std::pair<string, size_t>
A(
"A", 2),
B(
"B", 2),
C(
"C", 2);
402 std::vector<std::pair<string, size_t>>
labels = {
C,
B,
A};
403 std::vector<int>
nodes = {0, 0, 2, 3, 4, 4, 6, 7};
406 std::vector<Assignment<string>> choices;
408 choices.push_back(choice);
412 #ifdef GTSAM_DT_MERGING
420 #ifdef GTSAM_DT_MERGING
421 expectedAssignment = {{
"B", 0}, {
"C", 0}};
422 EXPECT(expectedAssignment == choices.at(0));
424 expectedAssignment = {{
"A", 0}, {
"B", 1}, {
"C", 0}};
425 EXPECT(expectedAssignment == choices.at(1));
427 expectedAssignment = {{
"A", 1}, {
"B", 1}, {
"C", 0}};
428 EXPECT(expectedAssignment == choices.at(2));
430 expectedAssignment = {{
"B", 0}, {
"C", 1}};
431 EXPECT(expectedAssignment == choices.at(3));
433 expectedAssignment = {{
"A", 0}, {
"B", 1}, {
"C", 1}};
434 EXPECT(expectedAssignment == choices.at(4));
436 expectedAssignment = {{
"A", 1}, {
"B", 1}, {
"C", 1}};
437 EXPECT(expectedAssignment == choices.at(5));
439 expectedAssignment = {{
"A", 0}, {
"B", 0}, {
"C", 0}};
440 EXPECT(expectedAssignment == choices.at(0));
442 expectedAssignment = {{
"A", 1}, {
"B", 0}, {
"C", 0}};
443 EXPECT(expectedAssignment == choices.at(1));
445 expectedAssignment = {{
"A", 0}, {
"B", 1}, {
"C", 0}};
446 EXPECT(expectedAssignment == choices.at(2));
448 expectedAssignment = {{
"A", 1}, {
"B", 1}, {
"C", 0}};
449 EXPECT(expectedAssignment == choices.at(3));
451 expectedAssignment = {{
"A", 0}, {
"B", 0}, {
"C", 1}};
452 EXPECT(expectedAssignment == choices.at(4));
454 expectedAssignment = {{
"A", 1}, {
"B", 0}, {
"C", 1}};
455 EXPECT(expectedAssignment == choices.at(5));
463 string A(
"A"),
B(
"B");
465 auto add = [](
const int&
y,
double x) {
return y +
x; };
466 double sum =
tree.fold(
add, 0.0);
467 #ifdef GTSAM_DT_MERGING
478 string A(
"A"),
B(
"B");
492 string A(
"A"),
B(
"B"),
C(
"C");
493 DTP
tree(
B, DTP(
A, {0,
"zero"}, {1,
"one"}),
494 DTP(
A, {2,
"two"}, {1337,
"l33t"}));
498 DT1 tree1(
B, DT1(
A, 0, 1), DT1(
A, 2, 1337));
499 DT2 tree2(
B, DT2(
A,
"zero",
"one"), DT2(
A,
"two",
"l33t"));
501 EXPECT(tree1.equals(dt1));
502 EXPECT(tree2.equals(dt2));
514 auto count = [](
const int&
value,
int count) {
515 return value == 0 ? count + 1 : count;
521 DT thresholded(
tree, threshold);
523 #ifdef GTSAM_DT_MERGING
542 keys,
"0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08");
543 double threshold = 0.045;
548 if (probTree(choices) < threshold) {
554 DT prunedTree =
tree.apply(pruner);
556 DT expectedTree(
keys,
"0 0 0 0 5 6 7 8");
564 DT prunedTree2 = prunedTree.
apply(counter);
566 #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
Array< double, 1, 3 > e(1./3., 0.5, 2.)
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.
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
signatures for conditional densities
graph add(PriorFactor< Pose2 >(1, priorMean, priorNoise))
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
Point2 f1(const Point3 &p, OptionalJacobian< 2, 3 > H)
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 Thu Jun 13 2024 03:09:08