Go to the documentation of this file.
29 using namespace gtsam;
76 #ifndef DISABLE_TIMING
77 cout <<
s <<
": " << std::setw(3) <<
muls <<
" muls, " << std::setw(3) <<
adds
82 double mul(
const double&
a,
const double&
b) {
86 double add_(
const double&
a,
const double&
b) {
102 ADT note(
E, 0.9, 0.1);
104 ADT cnotb =
c * notb;
105 dot(cnotb,
"ADT-cnotb");
109 ADT acnotb =
a * cnotb;
113 dot(acnotb,
"ADT-acnotb");
126 static size_t count = 0;
128 std::stringstream
ss;
129 ss <<
"CPT-" << std::setw(3) << std::setfill(
'0') << ++count <<
"-"
131 string DOTfile =
ss.str();
138 DiscreteKey A(0, 2),
S(1, 2),
T(2, 2),
L(3, 2),
B(4, 2),
E(5, 2),
X(6, 2),
159 dot(joint,
"Asia-A");
161 dot(joint,
"Asia-AS");
163 dot(joint,
"Asia-AST");
165 dot(joint,
"Asia-ASTL");
167 dot(joint,
"Asia-ASTLB");
169 dot(joint,
"Asia-ASTLBE");
171 dot(joint,
"Asia-ASTLBEX");
173 dot(joint,
"Asia-ASTLBEXD");
174 #ifdef GTSAM_DT_MERGING
203 B(2, 2),
L(3, 2),
E(4, 2),
S(5, 2),
T(6, 2),
X(7, 2);
217 dot(joint,
"Joint-Product-A");
219 dot(joint,
"Joint-Product-AS");
221 dot(joint,
"Joint-Product-AST");
223 dot(joint,
"Joint-Product-ASTL");
225 dot(joint,
"Joint-Product-ASTLB");
227 dot(joint,
"Joint-Product-ASTLBE");
229 dot(joint,
"Joint-Product-ASTLBEX");
231 dot(joint,
"Joint-Product-ASTLBEXD");
232 #ifdef GTSAM_DT_MERGING
240 ADT marginal = joint;
242 dot(marginal,
"Joint-Sum-ADBLEST");
244 dot(marginal,
"Joint-Sum-ADBLES");
246 dot(marginal,
"Joint-Sum-ADBLE");
248 dot(marginal,
"Joint-Sum-ADBL");
249 #ifdef GTSAM_DT_MERGING
259 DiscreteKey B(0, 2),
L(1, 2),
E(2, 2),
S(3, 2),
T(4, 2),
X(5, 2);
278 dot(fg,
"FactorGraph");
279 #ifdef GTSAM_DT_MERGING
288 dot(fg,
"Marginalized-6X");
290 dot(fg,
"Marginalized-5T");
292 dot(fg,
"Marginalized-4S");
294 dot(fg,
"Marginalized-3E");
296 dot(fg,
"Marginalized-2L");
297 #ifdef GTSAM_DT_MERGING
309 dot(fE,
"Eliminate-01-fEX");
311 dot(fE,
"Eliminate-02-fE");
318 dot(fLE,
"Eliminate-03-fLET");
320 dot(fLE,
"Eliminate-04-fLE");
328 dot(fBL,
"Eliminate-05-fBLS");
330 dot(fBL,
"Eliminate-06-fBL");
338 dot(fBL2,
"Eliminate-07-fBLE");
340 dot(fBL2,
"Eliminate-08-fBL2");
347 dot(fB,
"Eliminate-09-fBL");
349 dot(fB,
"Eliminate-10-fB");
394 x00[0] = 0, x00[1] = 0;
395 x01[0] = 0, x01[1] = 1;
396 x02[0] = 0, x02[1] = 2;
397 x10[0] = 1, x10[1] = 0;
398 x11[0] = 1, x11[1] = 1;
399 x12[0] = 1, x12[1] = 2;
418 vector<double>
table(5 * 4 * 3 * 2);
435 ADT fDiscreteKey(
X &
Y,
"0.2 0.5 0.3 0.6");
436 dot(fDiscreteKey,
"conversion-f1");
438 std::map<Key, Key> keyMap;
445 dot(fIndexKey,
"conversion-f2");
448 x00[5] = 0, x00[2] = 0;
449 x01[5] = 0, x01[2] = 1;
450 x10[5] = 1, x10[2] = 0;
451 x11[5] = 1, x11[2] = 1;
462 ADT f1(
A &
B &
C,
"1 2 3 4 5 6 1 8 3 3 5 5");
463 dot(
f1,
"elimination-f1");
467 ADT actualSum =
f1.sum(
C);
468 ADT expectedSum(
A &
B,
"3 7 11 9 6 10");
472 ADT actual =
f1 / actualSum;
473 const vector<double> cpt{
474 1.0 / 3, 2.0 / 3, 3.0 / 7, 4.0 / 7, 5.0 / 11, 6.0 / 11,
475 1.0 / 9, 8.0 / 9, 3.0 / 6, 3.0 / 6, 5.0 / 10, 5.0 / 10};
482 ADT actualSum =
f1.sum(
C).sum(
B);
483 ADT expectedSum(
A, 21, 25);
487 ADT actual =
f1 / actualSum;
488 const vector<double> cpt{
489 1.0 / 21, 2.0 / 21, 3.0 / 21, 4.0 / 21, 5.0 / 21, 6.0 / 21,
490 1.0 / 25, 8.0 / 25, 3.0 / 25, 3.0 / 25, 5.0 / 25, 5.0 / 25};
504 ADT expected_a_div_b(
A &
B,
"4 2 8 4");
505 ADT expected_b_div_a(
A &
B,
"0.25 0.5 0.125 0.25");
518 ADT anotb =
a * notb;
521 x00[0] = 0, x00[1] = 0;
522 x01[0] = 0, x01[1] = 1;
523 x10[0] = 1, x10[1] = 0;
524 x11[0] = 1, x11[1] = 1;
534 ADT f(
A &
B &
C,
"0 6 2 8 4 10 1 7 3 9 5 11");
541 double expected_sum = 0;
542 for (
double i = 0;
i < 12;
i++) {
552 double sum =
a.sum();
553 auto actual =
a.normalize(sum);
557 std::vector<double> cpt{0 / sum, 6 / sum, 2 / sum, 8 / sum,
558 4 / sum, 10 / sum, 1 / sum, 7 / sum,
559 3 / sum, 9 / sum, 5 / sum, 11 / sum};
568 double min =
a.min();
576 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)
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.
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 Sat Sep 28 2024 03:05:08