Go to the documentation of this file.
29 using namespace gtsam;
62 #ifdef GTSAM_DT_MERGING
72 #ifdef GTSAM_DT_MERGING
81 #ifdef GTSAM_DT_MERGING
97 #ifndef DISABLE_TIMING
98 cout <<
s <<
": " << std::setw(3) <<
muls <<
" muls, " << std::setw(3) <<
adds
103 double mul(
const double&
a,
const double&
b) {
107 double add_(
const double&
a,
const double&
b) {
123 ADT note(
E, 0.9, 0.1);
125 ADT cnotb =
c * notb;
126 dot(cnotb,
"ADT-cnotb");
130 ADT acnotb =
a * cnotb;
134 dot(acnotb,
"ADT-acnotb");
147 static size_t count = 0;
149 std::stringstream
ss;
150 ss <<
"CPT-" << std::setw(3) << std::setfill(
'0') << ++count <<
"-"
152 string DOTfile =
ss.str();
159 DiscreteKey A(0, 2),
S(1, 2),
T(2, 2),
L(3, 2),
B(4, 2),
E(5, 2),
X(6, 2),
180 dot(joint,
"Asia-A");
182 dot(joint,
"Asia-AS");
184 dot(joint,
"Asia-AST");
186 dot(joint,
"Asia-ASTL");
188 dot(joint,
"Asia-ASTLB");
190 dot(joint,
"Asia-ASTLBE");
192 dot(joint,
"Asia-ASTLBEX");
194 dot(joint,
"Asia-ASTLBEXD");
195 #ifdef GTSAM_DT_MERGING
224 B(2, 2),
L(3, 2),
E(4, 2),
S(5, 2),
T(6, 2),
X(7, 2);
238 dot(joint,
"Joint-Product-A");
240 dot(joint,
"Joint-Product-AS");
242 dot(joint,
"Joint-Product-AST");
244 dot(joint,
"Joint-Product-ASTL");
246 dot(joint,
"Joint-Product-ASTLB");
248 dot(joint,
"Joint-Product-ASTLBE");
250 dot(joint,
"Joint-Product-ASTLBEX");
252 dot(joint,
"Joint-Product-ASTLBEXD");
253 #ifdef GTSAM_DT_MERGING
261 ADT marginal = joint;
263 dot(marginal,
"Joint-Sum-ADBLEST");
265 dot(marginal,
"Joint-Sum-ADBLES");
267 dot(marginal,
"Joint-Sum-ADBLE");
269 dot(marginal,
"Joint-Sum-ADBL");
270 #ifdef GTSAM_DT_MERGING
280 DiscreteKey B(0, 2),
L(1, 2),
E(2, 2),
S(3, 2),
T(4, 2),
X(5, 2);
299 dot(fg,
"FactorGraph");
300 #ifdef GTSAM_DT_MERGING
309 dot(fg,
"Marginalized-6X");
311 dot(fg,
"Marginalized-5T");
313 dot(fg,
"Marginalized-4S");
315 dot(fg,
"Marginalized-3E");
317 dot(fg,
"Marginalized-2L");
318 #ifdef GTSAM_DT_MERGING
330 dot(fE,
"Eliminate-01-fEX");
332 dot(fE,
"Eliminate-02-fE");
339 dot(fLE,
"Eliminate-03-fLET");
341 dot(fLE,
"Eliminate-04-fLE");
349 dot(fBL,
"Eliminate-05-fBLS");
351 dot(fBL,
"Eliminate-06-fBL");
359 dot(fBL2,
"Eliminate-07-fBLE");
361 dot(fBL2,
"Eliminate-08-fBL2");
368 dot(fB,
"Eliminate-09-fBL");
370 dot(fB,
"Eliminate-10-fB");
415 x00[0] = 0, x00[1] = 0;
416 x01[0] = 0, x01[1] = 1;
417 x02[0] = 0, x02[1] = 2;
418 x10[0] = 1, x10[1] = 0;
419 x11[0] = 1, x11[1] = 1;
420 x12[0] = 1, x12[1] = 2;
439 vector<double>
table(5 * 4 * 3 * 2);
456 ADT fDiscreteKey(
X &
Y,
"0.2 0.5 0.3 0.6");
457 dot(fDiscreteKey,
"conversion-f1");
459 std::map<Key, Key> keyMap;
466 dot(fIndexKey,
"conversion-f2");
469 x00[5] = 0, x00[2] = 0;
470 x01[5] = 0, x01[2] = 1;
471 x10[5] = 1, x10[2] = 0;
472 x11[5] = 1, x11[2] = 1;
483 ADT f1(
A &
B &
C,
"1 2 3 4 5 6 1 8 3 3 5 5");
484 dot(
f1,
"elimination-f1");
488 ADT actualSum =
f1.sum(
C);
489 ADT expectedSum(
A &
B,
"3 7 11 9 6 10");
493 ADT actual =
f1 / actualSum;
494 const vector<double> cpt{
495 1.0 / 3, 2.0 / 3, 3.0 / 7, 4.0 / 7, 5.0 / 11, 6.0 / 11,
496 1.0 / 9, 8.0 / 9, 3.0 / 6, 3.0 / 6, 5.0 / 10, 5.0 / 10};
503 ADT actualSum =
f1.sum(
C).sum(
B);
504 ADT expectedSum(
A, 21, 25);
508 ADT actual =
f1 / actualSum;
509 const vector<double> cpt{
510 1.0 / 21, 2.0 / 21, 3.0 / 21, 4.0 / 21, 5.0 / 21, 6.0 / 21,
511 1.0 / 25, 8.0 / 25, 3.0 / 25, 3.0 / 25, 5.0 / 25, 5.0 / 25};
525 ADT expected_a_div_b(
A &
B,
"4 2 8 4");
526 ADT expected_b_div_a(
A &
B,
"0.25 0.5 0.125 0.25");
539 ADT anotb =
a * notb;
542 x00[0] = 0, x00[1] = 0;
543 x01[0] = 0, x01[1] = 1;
544 x10[0] = 1, x10[1] = 0;
545 x11[0] = 1, x11[1] = 1;
555 ADT f(
A &
B &
C,
"0 6 2 8 4 10 1 7 3 9 5 11");
562 double expected_sum = 0;
563 for (
double i = 0;
i < 12;
i++) {
573 double sum =
a.sum();
574 auto actual =
a.normalize();
578 std::vector<double> cpt{0 / sum, 6 / sum, 2 / sum, 8 / sum,
579 4 / sum, 10 / sum, 1 / sum, 7 / sum,
580 3 / sum, 9 / sum, 5 / sum, 11 / sum};
589 double min =
a.min();
597 double max =
a.max();
std::vector< double > cpt() const
static int runAllTests(TestResult &result)
ADT create(const Signature &signature)
const DiscreteKey & key() const
double add_(const double &a, const double &b)
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static const double d[K][N]
#define EXPECT_LONGS_EQUAL(expected, actual)
Concept check for values that can be used in unit tests.
#define EXPECT(condition)
GaussianFactorGraphValuePair Y
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)
double mul(const double &a, const double &b)
std::vector< double > Row
DiscreteKeys is a set of keys that can be assembled using the & operator.
bool equals(const AlgebraicDecisionTree &other, double tol=1e-9) const
Equality method customized to value type double.
Annotation to mark enums as an arithmetic type.
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
void printCounts(const string &s)
static std::stringstream ss
Algebraic Decision Trees.
AlgebraicDecisionTree< Key > ADT
signatures for conditional densities
EIGEN_DONT_INLINE Scalar zero()
ADT exampleADT()
Example ADT from 0 to 11.
void dot(const T &f, const string &filename)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
specialized key for discrete variables
const gtsam::Symbol key('X', 0)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Matrix< Scalar, Dynamic, Dynamic > C
double f3(double x1, double x2)
std::pair< Key, size_t > DiscreteKey
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
Apply unary operator op to DecisionTree f.
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
DiscreteKeys discreteKeys() const
DecisionTree combine(const L &label, size_t cardinality, const Binary &op) const
#define LONGS_EQUAL(expected, actual)
gtsam
Author(s):
autogenerated on Sun Feb 16 2025 04:06:00