29 #include <boost/assign/list_inserter.hpp> 30 #include <boost/assign/std/map.hpp> 39 using namespace gtsam;
46 auto prior = boost::make_shared<DiscreteConditional>(Parent %
"6/4");
52 boost::make_shared<DiscreteConditional>(Child | Parent =
"7/3 8/2");
62 const double expectedMarginal[2]{0.4, 0.6 * 0.3 + 0.4 * 0.2};
64 for (
size_t j = 0;
j < 2;
j++) {
74 DiscreteKey Asia(0, 2), Smoking(4, 2), Tuberculosis(3, 2), LungCancer(6, 2),
75 Bronchitis(7, 2), Either(5, 2), XRay(2, 2), Dyspnea(1, 2);
77 asia.
add(Asia %
"99/1");
78 asia.
add(Smoking %
"50/50");
80 asia.
add(Tuberculosis | Asia =
"99/1 95/5");
81 asia.
add(LungCancer | Smoking =
"99/1 90/10");
82 asia.
add(Bronchitis | Smoking =
"70/30 40/60");
84 asia.
add((Either | Tuberculosis, LungCancer) =
"F T T T");
86 asia.
add(XRay | Either =
"95/5 2/98");
87 asia.
add((Dyspnea | Either, Bronchitis) =
"9/1 2/8 3/7 1/9");
95 Vector2 va(0.99, 0.01), vs(0.5, 0.5);
109 insert(expectedMPE)(Asia.first, 0)(Dyspnea.first, 0)(XRay.first, 0)(
110 Tuberculosis.first, 0)(Smoking.first, 0)(Either.first, 0)(
111 LungCancer.first, 0)(Bronchitis.first, 0);
116 fg.
add(Dyspnea,
"0 1");
122 insert(expectedMPE2)(Asia.first, 1)(Dyspnea.first, 1)(XRay.first, 0)(
123 Tuberculosis.first, 0)(Smoking.first, 1)(Either.first, 0)(
124 LungCancer.first, 0)(Bronchitis.first, 1);
129 SETDEBUG(
"DiscreteConditional::sample",
false);
130 insert(expectedSample)(Asia.first, 1)(Dyspnea.first, 1)(XRay.first, 1)(
131 Tuberculosis.first, 0)(Smoking.first, 1)(Either.first, 1)(
132 LungCancer.first, 1)(Bronchitis.first, 0);
144 bn.
add((
E |
T,
L) =
"OR");
145 bn.
add((
E |
T,
L) =
"AND");
149 bn.
add(
C | S =
"1/1/2 5/2/3");
void add(const DiscreteKey &j, SOURCE table)
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Vector marginalProbabilities(const DiscreteKey &key) const
Point2 prior(const Point2 &x)
Prior on a single pose.
static enum @843 ordering
TEST_UNSAFE(DiscreteBayesNet, Sugar)
TEST(DiscreteBayesNet, bayesNet)
void add(const Signature &s)
sharedFactor back() const
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Key back() const
Last key.
std::pair< Key, size_t > DiscreteKey
#define EXPECT(condition)
Eigen::Triplet< double > T
Array< double, 1, 3 > e(1./3., 0.5, 2.)
A class for computing marginals in a DiscreteFactorGraph.
Matrix< Scalar, Dynamic, Dynamic > C
#define LONGS_EQUAL(expected, actual)
typedef and functions to augment Eigen's VectorXd
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
#define EXPECT_LONGS_EQUAL(expected, actual)
boost::shared_ptr< Values > sharedValues
boost::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
boost::shared_ptr< This > shared_ptr
std::uint64_t Key
Integer nonlinear key type.
Marginals marginals(graph, result)