33 using namespace gtsam;
45 auto prior = std::make_shared<DiscreteConditional>(Parent %
"6/4");
51 std::make_shared<DiscreteConditional>(Child | Parent =
"7/3 8/2");
61 const double expectedMarginal[2]{0.4, 0.6 * 0.3 + 0.4 * 0.2};
63 for (
size_t j = 0;
j < 2;
j++) {
92 Vector2 va(0.99, 0.01), vs(0.5, 0.5);
120 SETDEBUG(
"DiscreteConditional::sample",
false);
121 auto actualSample = chordal2->sample();
132 bn.
add((
E |
T,
L) =
"OR");
133 bn.
add((
E |
T,
L) =
"AND");
137 bn.
add(
C | S =
"1/1/2 5/2/3");
150 string actual = fragment.
dot();
155 " var0[label=\"0\"];\n" 156 " var3[label=\"3\"];\n" 157 " var4[label=\"4\"];\n" 158 " var5[label=\"5\"];\n" 159 " var6[label=\"6\"];\n" 176 "`DiscreteBayesNet` of size 2\n" 184 " *P(Smoking|Asia):*\n\n" 191 EXPECT(actual == expected);
const gtsam::Symbol key('X', 0)
sharedFactor back() const
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
double evaluate(const DiscreteValues &values) const
Point2 prior(const Point2 &x)
Prior on a single pose.
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
TEST(DiscreteBayesNet, bayesNet)
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.
void dot(std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DotWriter &writer=DotWriter()) const
Output to graphviz format, stream version.
DiscreteValues optimize(OptionalOrderingType orderingType={}) const
Find the maximum probable explanation (MPE) by doing max-product.
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteFactor::Names &names={}) const
Render as markdown tables.
EIGEN_DEVICE_FUNC const LogReturnType log() const
static enum @1107 ordering
void add(Args &&... args)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
const KeyFormatter & formatter
Key back() const
Last key.
static const DiscreteKey XRay(2, 2)
static const DiscreteKey Tuberculosis(3, 2)
#define EXPECT(condition)
Eigen::Triplet< double > T
double logProbability(const DiscreteValues &values) const
Vector marginalProbabilities(const DiscreteKey &key) const
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.)
A class for computing marginals in a DiscreteFactorGraph.
static const DiscreteKey Asia(0, 2)
Matrix< Scalar, Dynamic, Dynamic > C
#define LONGS_EQUAL(expected, actual)
typedef and functions to augment Eigen's VectorXd
#define EXPECT_LONGS_EQUAL(expected, actual)
std::shared_ptr< This > shared_ptr
static const DiscreteKey LungCancer(6, 2)
void add(const DiscreteKey &key, const std::string &spec)
std::pair< Key, size_t > DiscreteKey
static const DiscreteKey Dyspnea(1, 2)
static const DiscreteKey Smoking(4, 2)
static const DiscreteKey Bronchitis(7, 2)
AlgebraicDecisionTree< Key > ADT
static const DiscreteKey Either(5, 2)
std::uint64_t Key
Integer nonlinear key type.
Marginals marginals(graph, result)