Go to the documentation of this file.
25 #define DISABLE_TIMING
32 using namespace gtsam;
80 #ifndef DISABLE_TIMING
81 cout <<
s <<
": " << std::setw(3) <<
muls <<
" muls, " <<
82 std::setw(3) <<
adds <<
" adds, " << 1000 *
elapsed <<
" ms."
87 double mul(
const double&
a,
const double&
b) {
91 double add_(
const double&
a,
const double&
b) {
107 ADT note(
E, 0.9, 0.1);
109 ADT cnotb =
c * notb;
110 dot(cnotb,
"ADT-cnotb");
114 ADT acnotb =
a * cnotb;
118 dot(acnotb,
"ADT-acnotb");
131 static size_t count = 0;
133 std::stringstream
ss;
134 ss <<
"CPT-" << std::setw(3) << std::setfill(
'0') << ++count <<
"-" <<
key.first;
135 string DOTfile =
ss.str();
143 DiscreteKey A(0, 2),
S(1, 2),
T(2, 2),
L(3, 2),
B(4, 2),
E(5, 2),
X(6, 2),
158 elapsed = asiaCPTsNode->secs() + asiaCPTsNode->wall();
166 dot(joint,
"Asia-A");
168 dot(joint,
"Asia-AS");
170 dot(joint,
"Asia-AST");
172 dot(joint,
"Asia-ASTL");
174 dot(joint,
"Asia-ASTLB");
176 dot(joint,
"Asia-ASTLBE");
178 dot(joint,
"Asia-ASTLBEX");
180 dot(joint,
"Asia-ASTLBEXD");
181 #ifdef GTSAM_DT_MERGING
188 elapsed = asiaJointNode->secs() + asiaJointNode->wall();
209 B(2, 2),
L(3, 2),
E(4, 2),
S(5, 2),
T(6, 2),
X(7, 2);
223 elapsed = infCPTsNode->secs() + infCPTsNode->wall();
231 dot(joint,
"Joint-Product-A");
233 dot(joint,
"Joint-Product-AS");
235 dot(joint,
"Joint-Product-AST");
237 dot(joint,
"Joint-Product-ASTL");
239 dot(joint,
"Joint-Product-ASTLB");
241 dot(joint,
"Joint-Product-ASTLBE");
243 dot(joint,
"Joint-Product-ASTLBEX");
245 dot(joint,
"Joint-Product-ASTLBEXD");
246 #ifdef GTSAM_DT_MERGING
253 elapsed = asiaProdNode->secs() + asiaProdNode->wall();
259 ADT marginal = joint;
261 dot(marginal,
"Joint-Sum-ADBLEST");
263 dot(marginal,
"Joint-Sum-ADBLES");
265 dot(marginal,
"Joint-Sum-ADBLE");
267 dot(marginal,
"Joint-Sum-ADBL");
268 #ifdef GTSAM_DT_MERGING
275 elapsed = asiaSumNode->secs() + asiaSumNode->wall();
282 DiscreteKey B(0, 2),
L(1, 2),
E(2, 2),
S(3, 2),
T(4, 2),
X(5, 2);
295 elapsed = createCPTsNode->secs() + createCPTsNode->wall();
309 dot(fg,
"FactorGraph");
310 #ifdef GTSAM_DT_MERGING
317 elapsed = asiaFGNode->secs() + asiaFGNode->wall();
324 dot(fg,
"Marginalized-6X");
326 dot(fg,
"Marginalized-5T");
328 dot(fg,
"Marginalized-4S");
330 dot(fg,
"Marginalized-3E");
332 dot(fg,
"Marginalized-2L");
333 #ifdef GTSAM_DT_MERGING
340 elapsed = margNode->secs() + margNode->wall();
350 dot(fE,
"Eliminate-01-fEX");
352 dot(fE,
"Eliminate-02-fE");
355 elapsed = elimXNode->secs() + elimXNode->wall();
364 dot(fLE,
"Eliminate-03-fLET");
366 dot(fLE,
"Eliminate-04-fLE");
369 elapsed = elimTNode->secs() + elimTNode->wall();
379 dot(fBL,
"Eliminate-05-fBLS");
381 dot(fBL,
"Eliminate-06-fBL");
384 elapsed = elimSNode->secs() + elimSNode->wall();
394 dot(fBL2,
"Eliminate-07-fBLE");
396 dot(fBL2,
"Eliminate-08-fBL2");
399 elapsed = elimENode->secs() + elimENode->wall();
408 dot(fB,
"Eliminate-09-fBL");
410 dot(fB,
"Eliminate-10-fB");
413 elapsed = elimLNode->secs() + elimLNode->wall();
459 x00[0] = 0, x00[1] = 0;
460 x01[0] = 0, x01[1] = 1;
461 x02[0] = 0, x02[1] = 2;
462 x10[0] = 1, x10[1] = 0;
463 x11[0] = 1, x11[1] = 1;
464 x12[0] = 1, x12[1] = 2;
483 vector<double>
table(5 * 4 * 3 * 2);
500 ADT fDiscreteKey(
X &
Y,
"0.2 0.5 0.3 0.6");
501 dot(fDiscreteKey,
"conversion-f1");
503 std::map<Key, Key> keyMap;
510 dot(fIndexKey,
"conversion-f2");
513 x00[5] = 0, x00[2] = 0;
514 x01[5] = 0, x01[2] = 1;
515 x10[5] = 1, x10[2] = 0;
516 x11[5] = 1, x11[2] = 1;
527 ADT f1(
A &
B &
C,
"1 2 3 4 5 6 1 8 3 3 5 5");
528 dot(
f1,
"elimination-f1");
532 ADT actualSum =
f1.sum(
C);
533 ADT expectedSum(
A &
B,
"3 7 11 9 6 10");
537 ADT actual =
f1 / actualSum;
538 const vector<double> cpt{
539 1.0 / 3, 2.0 / 3, 3.0 / 7, 4.0 / 7, 5.0 / 11, 6.0 / 11,
540 1.0 / 9, 8.0 / 9, 3.0 / 6, 3.0 / 6, 5.0 / 10, 5.0 / 10};
547 ADT actualSum =
f1.sum(
C).sum(
B);
548 ADT expectedSum(
A, 21, 25);
552 ADT actual =
f1 / actualSum;
553 const vector<double> cpt{
554 1.0 / 21, 2.0 / 21, 3.0 / 21, 4.0 / 21, 5.0 / 21, 6.0 / 21,
555 1.0 / 25, 8.0 / 25, 3.0 / 25, 3.0 / 25, 5.0 / 25, 5.0 / 25};
569 ADT expected_a_div_b(
A &
B,
"4 2 8 4");
570 ADT expected_b_div_a(
A &
B,
"0.25 0.5 0.125 0.25");
583 ADT anotb =
a * notb;
586 x00[0] = 0, x00[1] = 0;
587 x01[0] = 0, x01[1] = 1;
588 x10[0] = 1, x10[1] = 0;
589 x11[0] = 1, x11[1] = 1;
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)
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)
Eigen::Triplet< double > T
double mul(const double &a, const double &b)
std::vector< double > Row
bool equals(const AlgebraicDecisionTree &other, double tol=1e-9) const
Equality method customized to value type double.
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
void printCounts(const string &s)
static std::stringstream ss
Algebraic Decision Trees.
AlgebraicDecisionTree< Key > ADT
#define tictoc_getNode(variable, label)
signatures for conditional densities
EIGEN_DONT_INLINE Scalar zero()
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
Point2 f1(const Point3 &p, OptionalJacobian< 2, 3 > H)
DecisionTree combine(const L &label, size_t cardinality, const Binary &op) const
#define LONGS_EQUAL(expected, actual)
gtsam
Author(s):
autogenerated on Tue Jun 25 2024 03:05:32