Go to the documentation of this file.
29 using namespace gtsam;
88 #ifndef DISABLE_TIMING
89 cout <<
s <<
": " << std::setw(3) <<
muls <<
" muls, " << std::setw(3) <<
adds
94 double mul(
const double&
a,
const double&
b) {
98 double add_(
const double&
a,
const double&
b) {
114 ADT note(
E, 0.9, 0.1);
116 ADT cnotb =
c * notb;
117 dot(cnotb,
"ADT-cnotb");
121 ADT acnotb =
a * cnotb;
125 dot(acnotb,
"ADT-acnotb");
138 static size_t count = 0;
140 std::stringstream
ss;
141 ss <<
"CPT-" << std::setw(3) << std::setfill(
'0') << ++count <<
"-"
143 string DOTfile =
ss.str();
150 DiscreteKey A(0, 2),
S(1, 2),
T(2, 2),
L(3, 2),
B(4, 2),
E(5, 2),
X(6, 2),
171 dot(joint,
"Asia-A");
173 dot(joint,
"Asia-AS");
175 dot(joint,
"Asia-AST");
177 dot(joint,
"Asia-ASTL");
179 dot(joint,
"Asia-ASTLB");
181 dot(joint,
"Asia-ASTLBE");
183 dot(joint,
"Asia-ASTLBEX");
185 dot(joint,
"Asia-ASTLBEXD");
186 #ifdef GTSAM_DT_MERGING
215 B(2, 2),
L(3, 2),
E(4, 2),
S(5, 2),
T(6, 2),
X(7, 2);
229 dot(joint,
"Joint-Product-A");
231 dot(joint,
"Joint-Product-AS");
233 dot(joint,
"Joint-Product-AST");
235 dot(joint,
"Joint-Product-ASTL");
237 dot(joint,
"Joint-Product-ASTLB");
239 dot(joint,
"Joint-Product-ASTLBE");
241 dot(joint,
"Joint-Product-ASTLBEX");
243 dot(joint,
"Joint-Product-ASTLBEXD");
244 #ifdef GTSAM_DT_MERGING
252 ADT marginal = joint;
254 dot(marginal,
"Joint-Sum-ADBLEST");
256 dot(marginal,
"Joint-Sum-ADBLES");
258 dot(marginal,
"Joint-Sum-ADBLE");
260 dot(marginal,
"Joint-Sum-ADBL");
261 #ifdef GTSAM_DT_MERGING
271 DiscreteKey B(0, 2),
L(1, 2),
E(2, 2),
S(3, 2),
T(4, 2),
X(5, 2);
290 dot(fg,
"FactorGraph");
291 #ifdef GTSAM_DT_MERGING
300 dot(fg,
"Marginalized-6X");
302 dot(fg,
"Marginalized-5T");
304 dot(fg,
"Marginalized-4S");
306 dot(fg,
"Marginalized-3E");
308 dot(fg,
"Marginalized-2L");
309 #ifdef GTSAM_DT_MERGING
321 dot(fE,
"Eliminate-01-fEX");
323 dot(fE,
"Eliminate-02-fE");
330 dot(fLE,
"Eliminate-03-fLET");
332 dot(fLE,
"Eliminate-04-fLE");
340 dot(fBL,
"Eliminate-05-fBLS");
342 dot(fBL,
"Eliminate-06-fBL");
350 dot(fBL2,
"Eliminate-07-fBLE");
352 dot(fBL2,
"Eliminate-08-fBL2");
359 dot(fB,
"Eliminate-09-fBL");
361 dot(fB,
"Eliminate-10-fB");
406 x00[0] = 0, x00[1] = 0;
407 x01[0] = 0, x01[1] = 1;
408 x02[0] = 0, x02[1] = 2;
409 x10[0] = 1, x10[1] = 0;
410 x11[0] = 1, x11[1] = 1;
411 x12[0] = 1, x12[1] = 2;
430 vector<double>
table(5 * 4 * 3 * 2);
447 ADT fDiscreteKey(
X &
Y,
"0.2 0.5 0.3 0.6");
448 dot(fDiscreteKey,
"conversion-f1");
450 std::map<Key, Key> keyMap;
457 dot(fIndexKey,
"conversion-f2");
460 x00[5] = 0, x00[2] = 0;
461 x01[5] = 0, x01[2] = 1;
462 x10[5] = 1, x10[2] = 0;
463 x11[5] = 1, x11[2] = 1;
474 ADT f1(
A &
B &
C,
"1 2 3 4 5 6 1 8 3 3 5 5");
475 dot(
f1,
"elimination-f1");
479 ADT actualSum =
f1.sum(
C);
480 ADT expectedSum(
A &
B,
"3 7 11 9 6 10");
484 ADT actual =
f1 / actualSum;
485 const vector<double> cpt{
486 1.0 / 3, 2.0 / 3, 3.0 / 7, 4.0 / 7, 5.0 / 11, 6.0 / 11,
487 1.0 / 9, 8.0 / 9, 3.0 / 6, 3.0 / 6, 5.0 / 10, 5.0 / 10};
494 ADT actualSum =
f1.sum(
C).sum(
B);
495 ADT expectedSum(
A, 21, 25);
499 ADT actual =
f1 / actualSum;
500 const vector<double> cpt{
501 1.0 / 21, 2.0 / 21, 3.0 / 21, 4.0 / 21, 5.0 / 21, 6.0 / 21,
502 1.0 / 25, 8.0 / 25, 3.0 / 25, 3.0 / 25, 5.0 / 25, 5.0 / 25};
516 ADT expected_a_div_b(
A &
B,
"4 2 8 4");
517 ADT expected_b_div_a(
A &
B,
"0.25 0.5 0.125 0.25");
530 ADT anotb =
a * notb;
533 x00[0] = 0, x00[1] = 0;
534 x01[0] = 0, x01[1] = 1;
535 x10[0] = 1, x10[1] = 0;
536 x11[0] = 1, x11[1] = 1;
546 ADT f(
A &
B &
C,
"0 6 2 8 4 10 1 7 3 9 5 11");
553 double expected_sum = 0;
554 for (
double i = 0;
i < 12;
i++) {
564 double sum =
a.sum();
565 auto actual =
a.normalize();
569 std::vector<double> cpt{0 / sum, 6 / sum, 2 / sum, 8 / sum,
570 4 / sum, 10 / sum, 1 / sum, 7 / sum,
571 3 / sum, 9 / sum, 5 / sum, 11 / sum};
580 double min =
a.min();
588 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 Dec 22 2024 04:16:03