25 #define DISABLE_TIMING 27 #include <boost/tokenizer.hpp> 28 #include <boost/assign/std/map.hpp> 29 #include <boost/assign/std/vector.hpp> 37 using namespace gtsam;
84 #ifndef DISABLE_TIMING 85 cout << boost::format(
"%s: %3d muls, %3d adds, %g ms.") % s %
muls %
adds 90 double mul(
const double&
a,
const double&
b) {
94 double add_(
const double&
a,
const double&
b) {
111 ADT note(E, 0.9, 0.1);
113 ADT cnotb = c * notb;
114 dot(cnotb,
"ADT-cnotb");
118 ADT acnotb = a * cnotb;
122 dot(acnotb,
"ADT-acnotb");
136 static size_t count = 0;
138 string dotfile = (boost::format(
"CPT-%03d-%d") % ++count % key.first).
str();
147 DiscreteKey A(0, 2),
S(1, 2),
T(2, 2),
L(3, 2),
B(4, 2),
E(5, 2),
X(6, 2),
D(7, 2);
161 elapsed = asiaCPTsNode->secs() + asiaCPTsNode->wall();
169 dot(joint,
"Asia-A");
171 dot(joint,
"Asia-AS");
173 dot(joint,
"Asia-AST");
175 dot(joint,
"Asia-ASTL");
177 dot(joint,
"Asia-ASTLB");
179 dot(joint,
"Asia-ASTLBE");
181 dot(joint,
"Asia-ASTLBEX");
183 dot(joint,
"Asia-ASTLBEXD");
187 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");
249 elapsed = asiaProdNode->secs() + asiaProdNode->wall();
255 ADT marginal = joint;
257 dot(marginal,
"Joint-Sum-ADBLEST");
259 dot(marginal,
"Joint-Sum-ADBLES");
261 dot(marginal,
"Joint-Sum-ADBLE");
263 dot(marginal,
"Joint-Sum-ADBL");
267 elapsed = asiaSumNode->secs() + asiaSumNode->wall();
275 DiscreteKey B(0,2),
L(1,2),
E(2,2),
S(3,2),
T(4,2),
X(5,2);
288 elapsed = createCPTsNode->secs() + createCPTsNode->wall();
302 dot(fg,
"FactorGraph");
306 elapsed = asiaFGNode->secs() + asiaFGNode->wall();
313 dot(fg,
"Marginalized-6X");
315 dot(fg,
"Marginalized-5T");
317 dot(fg,
"Marginalized-4S");
319 dot(fg,
"Marginalized-3E");
321 dot(fg,
"Marginalized-2L");
325 elapsed = margNode->secs() + margNode->wall();
335 dot(fE,
"Eliminate-01-fEX");
337 dot(fE,
"Eliminate-02-fE");
340 elapsed = elimXNode->secs() + elimXNode->wall();
349 dot(fLE,
"Eliminate-03-fLET");
351 dot(fLE,
"Eliminate-04-fLE");
354 elapsed = elimTNode->secs() + elimTNode->wall();
364 dot(fBL,
"Eliminate-05-fBLS");
366 dot(fBL,
"Eliminate-06-fBL");
369 elapsed = elimSNode->secs() + elimSNode->wall();
379 dot(fBL2,
"Eliminate-07-fBLE");
381 dot(fBL2,
"Eliminate-08-fBL2");
384 elapsed = elimENode->secs() + elimENode->wall();
393 dot(fB,
"Eliminate-09-fBL");
395 dot(fB,
"Eliminate-10-fB");
398 elapsed = elimLNode->secs() + elimLNode->wall();
410 rA += 80, 20; rB += 60, 40;
411 tableA += rA; tableB += rB;
449 x00[0] = 0, x00[1] = 0;
450 x01[0] = 0, x01[1] = 1;
451 x02[0] = 0, x02[1] = 2;
452 x10[0] = 1, x10[1] = 0;
453 x11[0] = 1, x11[1] = 1;
454 x12[0] = 1, x12[1] = 2;
456 ADT f1(
v0 & v1,
"0 1 2 3 4 5");
464 ADT f2(v1 &
v0,
"0 1 2 3 4 5");
473 vector<double>
table(5 * 4 * 3 * 2);
475 for(
double&
t: table)
492 ADT fDiscreteKey(
X & Y,
"0.2 0.5 0.3 0.6");
493 dot(fDiscreteKey,
"conversion-f1");
495 std::map<Key, Key> keyMap;
502 dot(fIndexKey,
"conversion-f2");
505 x00[5] = 0, x00[2] = 0;
506 x01[5] = 0, x01[2] = 1;
507 x10[5] = 1, x10[2] = 0;
508 x11[5] = 1, x11[2] = 1;
520 ADT f1(
A &
B & C,
"1 2 3 4 5 6 1 8 3 3 5 5");
521 dot(f1,
"elimination-f1");
525 ADT actualSum = f1.
sum(C);
526 ADT expectedSum(
A &
B,
"3 7 11 9 6 10");
530 ADT actual = f1 / actualSum;
532 cpt += 1.0 / 3, 2.0 / 3, 3.0 / 7, 4.0 / 7, 5.0 / 11, 6.0 / 11,
533 1.0 / 9, 8.0 / 9, 3.0 / 6, 3.0 / 6, 5.0 / 10, 5.0 / 10;
541 ADT expectedSum(
A, 21, 25);
545 ADT actual = f1 / actualSum;
547 cpt += 1.0 / 21, 2.0 / 21, 3.0 / 21, 4.0 / 21, 5.0 / 21, 6.0 / 21,
548 1.0 / 25, 8.0 / 25, 3.0 / 25, 3.0 / 25, 5.0 / 25, 5.0 / 25;
563 ADT expected_a_div_b(
A & B,
"4 2 8 4");
564 ADT expected_b_div_a(
A & B,
"0.25 0.5 0.125 0.25");
578 ADT anotb = a * notb;
581 x00[0] = 0, x00[1] = 0;
582 x01[0] = 0, x01[1] = 1;
583 x10[0] = 1, x10[1] = 0;
584 x11[0] = 1, x11[1] = 1;
#define tictoc_getNode(variable, label)
void printCounts(const string &s)
double add_(const double &a, const double &b)
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
signatures for conditional densities
double mul(const double &a, const double &b)
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
EIGEN_DONT_INLINE Scalar zero()
AlgebraicDecisionTree< Key > ADT
double f2(const Vector2 &x)
Matrix< SCALARB, Dynamic, Dynamic > B
std::vector< double > cpt() const
Algebraic Decision Trees.
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
DiscreteKeys discreteKeys() const
DecisionTree combine(const L &label, size_t cardinality, const Binary &op) const
std::pair< Key, size_t > DiscreteKey
#define EXPECT(condition)
Eigen::Triplet< double > T
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
std::vector< double > Row
Matrix< Scalar, Dynamic, Dynamic > C
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
specialized key for discrete variables
ADT create(const Signature &signature)
#define EXPECT_LONGS_EQUAL(expected, actual)
Point2 f1(const Point3 &p, OptionalJacobian< 2, 3 > H)
double f3(double x1, double x2)
AlgebraicDecisionTree sum(const L &label, size_t cardinality) 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
void dot(const T &f, const string &filename)
const DiscreteKey & key() const