Go to the documentation of this file.
30 using namespace gtsam;
47 X &
Y &
Z,
"0.2 0.5 0.3 0.6 0.4 0.7 0.25 0.55 0.35 0.65 0.45 0.75");
52 std::vector<double> probs{0.2, 0.5, 0.3, 0.6, 0.4, 0.7, 0.25, 0.55, 0.35, 0.65, 0.45, 0.75};
71 X &
Y &
Z,
"0.2 0.5 0.3 0.6 0.4 0.7 0.25 0.55 0.35 0.65 0.45 0.75");
105 EXPECT(DiscreteConditional::CheckInvariants(dc,
values));
119 EXPECT(DiscreteConditional::CheckInvariants(C_given_DE, given));
134 for (
auto&& actual : {
prior * conditional, conditional *
prior}) {
136 KeyVector frontals(actual.beginFrontals(), actual.endFrontals());
138 for (
auto&& it : actual.enumerate()) {
155 for (
auto&& actual : {A_given_B * B_given_C, B_given_C * A_given_B}) {
158 KeyVector frontals(actual.beginFrontals(), actual.endFrontals());
160 for (
auto&& it : actual.enumerate()) {
175 for (
auto&& actual : {A_given_B * B_given_C, B_given_C * A_given_B}) {
178 KeyVector frontals(actual.beginFrontals(), actual.endFrontals());
180 for (
auto&& it : actual.enumerate()) {
197 for (
auto&& actual : {AB_given_D * C_given_DE, C_given_DE * AB_given_D}) {
200 KeyVector frontals(actual.beginFrontals(), actual.endFrontals());
202 KeyVector parents(actual.beginParents(), actual.endParents());
204 for (
auto&& it : actual.enumerate()) {
272 auto actual1 = C_given_DE.
choose(given);
277 auto actual2 = C_given_DE.
choose(given);
285 auto actual3 = C_given_DE.
choose(given);
301 size_t actual1 = B_prior.
argmax();
305 size_t actual2 = D_prior.
argmax();
312 size_t actual3 = C_given_D.
argmax(given);
317 size_t actual4 = C_given_D.
argmax(given);
333 string actual = conditional.
markdown();
350 DecisionTreeFactor::Names
names{{
x1, {
"A0",
"A1",
"A2"}}};
360 A |
B =
"2/88/10 2/20/78 33/33/34 33/33/34 95/2/3");
364 "|:-:|:-:|:-:|:-:|\n"
365 "|0|0.02|0.88|0.1|\n"
366 "|1|0.02|0.2|0.78|\n"
367 "|2|0.33|0.33|0.34|\n"
368 "|3|0.33|0.33|0.34|\n"
369 "|4|0.95|0.02|0.03|\n";
370 string actual = conditional.
markdown();
382 "|:-:|:-:|:-:|:-:|\n"
384 "|-|One|0.25|0.75|\n"
386 "|+|Zero|0.75|0.25|\n"
389 vector<string> keyNames{
"C",
"B",
"A"};
391 DecisionTreeFactor::Names
names{
392 {0, {
"Zero",
"One",
"Two"}}, {1, {
"-",
"+"}}, {2, {
"T",
"F"}}};
404 "<p> <i>P(A|B,C):</i></p>\n"
405 "<table class='DiscreteConditional'>\n"
407 " <tr><th><i>B</i></th><th><i>C</i></th><th>T</th><th>F</th></tr>\n"
410 " <tr><th>-</th><th>Zero</th><td>0</td><td>1</td></tr>\n"
411 " <tr><th>-</th><th>One</th><td>0.25</td><td>0.75</td></tr>\n"
412 " <tr><th>-</th><th>Two</th><td>0.5</td><td>0.5</td></tr>\n"
413 " <tr><th>+</th><th>Zero</th><td>0.75</td><td>0.25</td></tr>\n"
414 " <tr><th>+</th><th>One</th><td>0</td><td>1</td></tr>\n"
415 " <tr><th>+</th><th>Two</th><td>1</td><td>0</td></tr>\n"
419 vector<string> keyNames{
"C",
"B",
"A"};
421 DecisionTreeFactor::Names
names{
422 {0, {
"Zero",
"One",
"Two"}}, {1, {
"-",
"+"}}, {2, {
"T",
"F"}}};
static int runAllTests(TestResult &result)
double logProbability(const DiscreteValues &x) const
Log-probability is just -error(x).
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Array< double, 1, 3 > e(1./3., 0.5, 2.)
#define EXPECT_LONGS_EQUAL(expected, actual)
#define EXPECT(condition)
GaussianFactorGraphValuePair Y
const KeyFormatter & formatter
double f2(const Vector2 &x)
double error(const DiscreteValues &values) const override
Calculate error for DiscreteValues x, is -log(probability).
const EIGEN_DEVICE_FUNC LogReturnType log() const
std::vector< double > Row
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as markdown table.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
FACTOR::const_iterator endParents() const
DiscreteConditional marginal(Key key) const
FACTOR::const_iterator endFrontals() const
FACTOR::const_iterator beginFrontals() const
size_t argmax(const DiscreteValues &parentsValues=DiscreteValues()) const
Return assignment for single frontal variable that maximizes value.
const_iterator end() const
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
DecisionTreeFactor::shared_ptr likelihood(const DiscreteValues &frontalValues) const
const gtsam::Symbol key('X', 0)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
FACTOR::const_iterator beginParents() const
double evaluate(const DiscreteValues &values) const
Evaluate, just look up in AlgebraicDecisionTree.
Matrix< Scalar, Dynamic, Dynamic > C
std::pair< Key, size_t > DiscreteKey
Array< int, Dynamic, 1 > v
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
shared_ptr choose(const DiscreteValues &given) const
< DiscreteValues version
TEST(DiscreteConditional, constructors)
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
Marginals marginals(graph, result)
std::uint64_t Key
Integer nonlinear key type.
Frontals frontals() const
static const T & choose(int layout, const T &col, const T &row)
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:21