27 using namespace gtsam;
34 graph.
add(AI,
"1 0 0 1");
35 graph.
add(AI,
"1 1 1 0");
36 graph.
add(A & AI,
"1 1 1 0 1 1 1 1 0 1 1 1");
37 graph.
add(ME,
"0 1 0 0");
38 graph.
add(ME,
"1 1 1 0");
39 graph.
add(A & ME,
"1 1 1 0 1 1 1 1 0 1 1 1");
40 graph.
add(PC,
"1 0 1 0");
41 graph.
add(PC,
"1 1 1 0");
42 graph.
add(A & PC,
"1 1 1 0 1 1 1 1 0 1 1 1");
43 graph.
add(ME & AI,
"0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0");
44 graph.
add(PC & ME,
"0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0");
45 graph.
add(PC & AI,
"0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0");
61 graph.
add(P1,
"0.9 0.3");
62 graph.
add(
P2,
"0.9 0.6");
63 graph.
add(P1 &
P2,
"4 1 10 4");
74 graph.
add(P3,
"0.9 0.2 0.5");
75 graph.
add(P1 & P2 & P3,
"1 2 3 4 5 6 7 8 9 10 11 12");
106 graph.
add(A &
C,
"3 1 1 3");
107 graph.
add(C &
B,
"3 1 1 3");
116 auto normalization = newFactor.
max(newFactor.
size());
118 newFactor = newFactor / *normalization;
122 Signature signature((C | B, A) =
"9/1 1/1 1/1 1/9");
130 normalization = expectedFactor.
max(expectedFactor.
size());
132 expectedFactor = expectedFactor / *normalization;
142 expectedBayesNet.
add(signature);
143 expectedBayesNet.
add(B | A =
"5/3 3/5");
144 expectedBayesNet.
add(A %
"1/1");
158 auto mpeProbability = expectedBayesNet(mpe);
166 {Ordering::COLAMD, Ordering::METIS, Ordering::NATURAL,
168 auto bayesNet = graph.
sumProduct(orderingType);
180 graph.
add(
C &
A,
"0.2 0.8 0.3 0.7");
181 graph.
add(
C & B,
"0.1 0.9 0.4 0.6");
188 {Ordering::COLAMD, Ordering::METIS, Ordering::NATURAL,
191 auto actualMPE = dag.
argmax();
206 bayesNet.
add(B |
A =
"1/1 1/2");
207 bayesNet.
add(
A %
"10/9");
226 graph.
add(
S,
"0.55 0.45");
227 graph.
add(
S &
C,
"0.05 0.95 0.01 0.99");
228 graph.
add(C &
T1,
"0.80 0.20 0.20 0.80");
229 graph.
add(
S & C & T2,
"0.80 0.20 0.20 0.80 0.95 0.05 0.05 0.95");
230 graph.
add(T1 & T2 &
A,
"1 0 0 1 0 1 1 0");
259 graph.
add(
C &
A,
"0.2 0.8 0.3 0.7");
260 graph.
add(
C & B,
"0.1 0.9 0.4 0.6");
262 string actual = graph.
dot();
267 " var0[label=\"0\"];\n" 268 " var1[label=\"1\"];\n" 269 " var2[label=\"2\"];\n" 271 " factor0[label=\"\", shape=point];\n" 274 " factor1[label=\"\", shape=point];\n" 278 EXPECT(actual == expected);
286 graph.
add(
C &
A,
"0.2 0.8 0.3 0.7");
287 graph.
add(
C & B,
"0.1 0.9 0.4 0.6");
289 vector<string>
names{
"C",
"A",
"B"};
296 " var0[label=\"C\"];\n" 297 " var1[label=\"A\"];\n" 298 " var2[label=\"B\"];\n" 300 " factor0[label=\"\", shape=point];\n" 303 " factor1[label=\"\", shape=point];\n" 307 EXPECT(actual == expected);
316 graph.
add(
C &
A,
"0.2 0.8 0.3 0.7");
317 graph.
add(
C & B,
"0.1 0.9 0.4 0.6");
320 "`DiscreteFactorGraph` of size 2\n" 337 vector<string>
names{
"C",
"A",
"B"};
340 EXPECT(actual == expected);
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
const gtsam::Symbol key('X', 0)
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteFactor::Names &names={}) const
Render as markdown tables.
std::pair< DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr > EliminateDiscrete(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Main elimination function for DiscreteFactorGraph.
static int runAllTests(TestResult &result)
DecisionTreeFactor product() const
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
shared_ptr max(size_t nrFrontals) const
Create new factor by maximizing over all values with the same separator.
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
NonlinearFactorGraph graph
DiscreteValues optimize(OptionalOrderingType orderingType={}) const
Find the maximum probable explanation (MPE) by doing max-product.
static enum @1107 ordering
void add(Args &&... args)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
const KeyFormatter & formatter
#define EXPECT(condition)
TEST(DiscreteFactorGraph, test)
std::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
OrderingType
Type of ordering to use.
void dot(std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DotWriter &writer=DotWriter()) const
Output to graphviz format, stream version.
DiscreteBayesNet sumProduct(OptionalOrderingType orderingType={}) const
Implement the sum-product algorithm.
Matrix< Scalar, Dynamic, Dynamic > C
static const Point3 P2(3.5,-8.2, 4.2)
#define EXPECT_LONGS_EQUAL(expected, actual)
TEST_UNSAFE(DiscreteFactorGraph, debugScheduler)
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
std::shared_ptr< This > shared_ptr
DiscreteLookupDAG maxProduct(OptionalOrderingType orderingType={}) const
Implement the max-product algorithm.
std::pair< std::shared_ptr< BayesNetType >, std::shared_ptr< FactorGraphType > > eliminate(Eliminate function) const
void add(const DiscreteKey &key, const std::string &spec)
std::pair< Key, size_t > DiscreteKey
std::shared_ptr< BayesTreeType > eliminateMultifrontal(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Elimination tree for discrete factors.
DiscreteValues argmax(DiscreteValues given=DiscreteValues()) const
argmax by back-substitution, optionally given certain variables.
std::shared_ptr< This > shared_ptr
std::uint64_t Key
Integer nonlinear key type.
void product(const MatrixType &m)