28 using namespace gtsam;
98 std::vector<std::pair<DiscreteValues, double>>
expected;
100 for (
size_t a : {0, 1, 2}) {
101 for (
size_t b : {0, 1}) {
104 expected.emplace_back(values,
f(values));
107 EXPECT(actual == expected);
117 size_t maxNrAssignments = 5;
118 auto pruned5 = f.
prune(maxNrAssignments);
125 maxNrAssignments = 2;
126 auto pruned2 = f.
prune(maxNrAssignments);
133 "0.0 0.0 0.0 0.60658897 0.61241912 0.61241969 0.61247685 0.61247742 0.0 " 134 "0.0 0.0 0.99995287 1.0 1.0 1.0 1.0");
138 "0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 " 139 "0.999952870000 1.0 1.0 1.0 1.0");
140 maxNrAssignments = 5;
141 auto pruned3 = factor.
prune(maxNrAssignments);
151 for (
bool showZero:{
true,
false}) {
175 EXPECT(actual == expected);
192 auto keyFormatter = [](
Key key) {
return key == 12 ?
"A" :
"B"; };
193 DecisionTreeFactor::Names
names{{12, {
"Zero",
"One",
"Two"}},
196 EXPECT(actual == expected);
206 "<table class='DecisionTreeFactor'>\n" 208 " <tr><th>A</th><th>B</th><th>value</th></tr>\n" 211 " <tr><th>Zero</th><th>-</th><td>1</td></tr>\n" 212 " <tr><th>Zero</th><th>+</th><td>2</td></tr>\n" 213 " <tr><th>One</th><th>-</th><td>3</td></tr>\n" 214 " <tr><th>One</th><th>+</th><td>4</td></tr>\n" 215 " <tr><th>Two</th><th>-</th><td>5</td></tr>\n" 216 " <tr><th>Two</th><th>+</th><td>6</td></tr>\n" 220 auto keyFormatter = [](
Key key) {
return key == 12 ?
"A" :
"B"; };
221 DecisionTreeFactor::Names
names{{12, {
"Zero",
"One",
"Two"}},
223 string actual = f.
html(keyFormatter,
names);
224 EXPECT(actual == expected);
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
const gtsam::Symbol key('X', 0)
DecisionTreeFactor prune(size_t maxNrAssignments) const
Prune the decision tree of discrete variables.
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
signatures for conditional densities
Point2 prior(const Point2 &x)
Prior on a single pose.
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as html table.
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.
double f2(const Vector2 &x)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
EIGEN_DEVICE_FUNC const LogReturnType log() const
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
const KeyFormatter & formatter
#define EXPECT(condition)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
void dot(std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const
Matrix< Scalar, Dynamic, Dynamic > C
TEST(DecisionTreeFactor, constructors)
std::shared_ptr< DecisionTreeFactor > shared_ptr
#define EXPECT_LONGS_EQUAL(expected, actual)
Point2 f1(const Point3 &p, OptionalJacobian< 2, 3 > H)
std::pair< Key, size_t > DiscreteKey
double f3(double x1, double x2)
shared_ptr sum(size_t nrFrontals) const
Create new factor by summing all values with the same separator values.
std::vector< std::pair< DiscreteValues, double > > enumerate() const
Enumerate all values into a map from values to double.
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as markdown table.
std::uint64_t Key
Integer nonlinear key type.