Go to the documentation of this file.
35 using namespace gtsam;
44 #define DOT(x) (dot(x, #x))
53 void print(
const std::string&
s =
"")
const {
54 auto keyFormatter = [](
const std::string&
s) {
return s; };
57 ss <<
"{" <<
v.a <<
"," << std::setw(4) << std::setprecision(2) <<
v.b <<
"}";
104 void print(
const std::string&
s =
"")
const {
105 auto keyFormatter = [](
const std::string&
s) {
return s; };
107 return std::to_string(
v);
115 auto compare = [](
const int&
v,
const int&
w) {
return v ==
w; };
132 string A(
"A"),
B(
"B");
134 const std::vector<int> ys1 = {1, 2, 3, 4};
135 DT tree1({{
B, 2}, {
A, 2}}, ys1);
137 const std::vector<int> ys2 = {1, 3, 2, 4};
138 DT tree2({{
A, 2}, {
B, 2}}, ys2);
149 EXPECT(tree2.equals(tree1));
162 string A(
"A"),
B(
"B"),
C(
"C");
230 #ifdef GTSAM_DT_MERGING
255 x101[
A] = 1, x101[
B] = 0, x101[
C] = 1;
272 string A(
"A"),
B(
"B");
275 DT original(
A,
DT(
B, 1, 2),
DT(
B, 3, 4));
278 auto split_function = [](
const int&
value) -> std::pair<int, bool> {
283 auto [la,lb] = original.
split<
int,
bool>(split_function);
303 string A(
"A"),
B(
"B");
306 DT original(
A,
DT(
B, 1, 2),
DT(
B, 3, 4));
308 DT modified([](
int i){
return i*2;}, std::move(original));
327 string A(
"A"),
B(
"B");
347 string A(
"A"),
B(
"B");
360 x00 = {{
X, 0}, {
Y, 0}};
361 x01 = {{
X, 0}, {
Y, 1}};
362 x10 = {{
X, 1}, {
Y, 0}};
363 x11 = {{
X, 1}, {
Y, 1}};
375 string A(
"A"),
B(
"B"),
C(
"C");
392 DT f5(
keys,
"0 4 2 6 1 5 3 7");
400 using Container = std::vector<double>;
404 StringContainerTree
tree;
407 string A(
"A"),
B(
"B");
408 DT stringIntTree(
B,
DT(
A, 0, 1),
DT(
A, 2, 3));
411 auto container_of_int = [](
const int&
i) {
416 StringContainerTree converted(stringIntTree, container_of_int);
423 string A(
"A"),
B(
"B");
426 auto visitor = [&](
int y) { sum +=
y; };
435 string A(
"A"),
B(
"B");
439 tree.visitWith(visitor);
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};
452 std::vector<Assignment<string>> choices;
454 choices.push_back(choice);
458 #ifdef GTSAM_DT_MERGING
466 #ifdef GTSAM_DT_MERGING
467 expectedAssignment = {{
"B", 0}, {
"C", 0}};
468 EXPECT(expectedAssignment == choices.at(0));
470 expectedAssignment = {{
"A", 0}, {
"B", 1}, {
"C", 0}};
471 EXPECT(expectedAssignment == choices.at(1));
473 expectedAssignment = {{
"A", 1}, {
"B", 1}, {
"C", 0}};
474 EXPECT(expectedAssignment == choices.at(2));
476 expectedAssignment = {{
"B", 0}, {
"C", 1}};
477 EXPECT(expectedAssignment == choices.at(3));
479 expectedAssignment = {{
"A", 0}, {
"B", 1}, {
"C", 1}};
480 EXPECT(expectedAssignment == choices.at(4));
482 expectedAssignment = {{
"A", 1}, {
"B", 1}, {
"C", 1}};
483 EXPECT(expectedAssignment == choices.at(5));
485 expectedAssignment = {{
"A", 0}, {
"B", 0}, {
"C", 0}};
486 EXPECT(expectedAssignment == choices.at(0));
488 expectedAssignment = {{
"A", 1}, {
"B", 0}, {
"C", 0}};
489 EXPECT(expectedAssignment == choices.at(1));
491 expectedAssignment = {{
"A", 0}, {
"B", 1}, {
"C", 0}};
492 EXPECT(expectedAssignment == choices.at(2));
494 expectedAssignment = {{
"A", 1}, {
"B", 1}, {
"C", 0}};
495 EXPECT(expectedAssignment == choices.at(3));
497 expectedAssignment = {{
"A", 0}, {
"B", 0}, {
"C", 1}};
498 EXPECT(expectedAssignment == choices.at(4));
500 expectedAssignment = {{
"A", 1}, {
"B", 0}, {
"C", 1}};
501 EXPECT(expectedAssignment == choices.at(5));
509 string A(
"A"),
B(
"B");
511 auto add = [](
const int&
y,
double x) {
return y +
x; };
512 double sum =
tree.fold(
add, 0.0);
513 #ifdef GTSAM_DT_MERGING
524 string A(
"A"),
B(
"B");
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"}));
544 DT1 tree1(
B, DT1(
A, 0, 1), DT1(
A, 2, 1337));
545 DT2 tree2(
B, DT2(
A,
"zero",
"one"), DT2(
A,
"two",
"l33t"));
547 EXPECT(tree1.equals(dt1));
548 EXPECT(tree2.equals(dt2));
560 auto count = [](
const int&
value,
int count) {
561 return value == 0 ? count + 1 : count;
567 DT thresholded(
tree, threshold);
569 #ifdef GTSAM_DT_MERGING
588 keys,
"0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08");
589 double threshold = 0.045;
594 if (probTree(choices) < threshold) {
600 DT prunedTree =
tree.apply(pruner);
602 DT expectedTree(
keys,
"0 0 0 0 5 6 7 8");
610 DT prunedTree2 = prunedTree.
apply(counter);
612 #ifdef GTSAM_DT_MERGING
static int runAllTests(TestResult &result)
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)
static double mul(const double &a, const double &b)
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.
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.
static double id(const double &x)
#define LONGS_EQUAL(expected, actual)
gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:06:11