30 using namespace gtsam;
35 vector<double> dropoutmask(size);
37 uniform_int_distribution<> dist(1, 9);
38 auto gen = [&dist, &
g]() {
return dist(g); };
39 generate(dropoutmask.begin(), dropoutmask.end(), gen);
41 fill_n(dropoutmask.begin(), dropoutmask.size() * (dropout), 0);
42 shuffle(dropoutmask.begin(), dropoutmask.end(),
g);
47 map<double, pair<chrono::microseconds, chrono::microseconds>>
measureTime(
49 vector<double> dropouts = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
50 map<double, pair<chrono::microseconds, chrono::microseconds>> measured_times;
52 for (
auto dropout : dropouts) {
53 vector<double> arr1 =
genArr(dropout, size);
54 vector<double> arr2 =
genArr(dropout, size);
61 auto tb_start = chrono::high_resolution_clock::now();
63 auto tb_end = chrono::high_resolution_clock::now();
65 chrono::duration_cast<chrono::microseconds>(tb_end - tb_start);
68 auto dt_start = chrono::high_resolution_clock::now();
70 auto dt_end = chrono::high_resolution_clock::now();
72 chrono::duration_cast<chrono::microseconds>(dt_end - dt_start);
75 for (
auto assignmentVal : actual_dt.
enumerate()) {
76 flag = actual_dt(assignmentVal.first) != actual(assignmentVal.first);
78 std::cout <<
"something is wrong: " << std::endl;
79 assignmentVal.first.print();
80 std::cout <<
"dt: " << actual_dt(assignmentVal.first) << std::endl;
81 std::cout <<
"tb: " << actual(assignmentVal.first) << std::endl;
86 measured_times[dropout] = make_pair(tb_time_diff, dt_time_diff);
88 return measured_times;
91 void printTime(map<
double, pair<chrono::microseconds, chrono::microseconds>>
93 for (
auto&& kv : measured_time) {
94 cout <<
"dropout: " << kv.first
95 <<
" | TableFactor time: " << kv.second.first.count()
96 <<
" | DecisionTreeFactor time: " << kv.second.second.count() << endl;
145 TableFactor expected2(
v0 & v1 & v2,
"5 6 14 16 15 18 28 32");
152 TableFactor expected3(
A &
B & C,
"0 0 0 0 0 0 0 10 0 0 0 15");
160 DiscreteKey A(0, 5),
B(1, 2),
C(2, 5),
D(3, 2),
E(4, 5),
F(5, 2),
G(6, 3),
161 H(7, 2),
I(8, 5),
J(9, 7),
K(10, 2),
L(11, 3);
166 map<double, pair<chrono::microseconds, chrono::microseconds>> time_map_1 =
172 map<double, pair<chrono::microseconds, chrono::microseconds>> time_map_2 =
178 map<double, pair<chrono::microseconds, chrono::microseconds>> time_map_3 =
184 map<double, pair<chrono::microseconds, chrono::microseconds>> time_map_4 =
190 map<double, pair<chrono::microseconds, chrono::microseconds>> time_map_5 =
196 map<double, pair<chrono::microseconds, chrono::microseconds>> time_map_6 =
202 map<double, pair<chrono::microseconds, chrono::microseconds>> time_map_7 =
208 map<double, pair<chrono::microseconds, chrono::microseconds>> time_map_8 =
214 map<double, pair<chrono::microseconds, chrono::microseconds>> time_map_9 =
243 std::vector<std::pair<DiscreteValues, double>>
expected;
245 for (
size_t a : {0, 1, 2}) {
246 for (
size_t b : {0, 1}) {
249 expected.emplace_back(values,
f(values));
252 EXPECT(actual == expected);
262 size_t maxNrAssignments = 5;
263 auto pruned5 = f.
prune(maxNrAssignments);
270 maxNrAssignments = 2;
271 auto pruned2 = f.
prune(maxNrAssignments);
278 "0.0 0.0 0.0 0.60658897 0.61241912 0.61241969 0.61247685 0.61247742 0.0 " 279 "0.0 0.0 0.99995287 1.0 1.0 1.0 1.0");
282 "0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 " 283 "0.999952870000 1.0 1.0 1.0 1.0");
284 maxNrAssignments = 5;
285 auto pruned3 = factor.
prune(maxNrAssignments);
305 EXPECT(actual == expected);
322 auto keyFormatter = [](
Key key) {
return key == 12 ?
"A" :
"B"; };
323 TableFactor::Names
names{{12, {
"Zero",
"One",
"Two"}}, {5, {
"-",
"+"}}};
325 EXPECT(actual == expected);
335 "<table class='TableFactor'>\n" 337 " <tr><th>A</th><th>B</th><th>value</th></tr>\n" 340 " <tr><th>Zero</th><th>-</th><td>1</td></tr>\n" 341 " <tr><th>Zero</th><th>+</th><td>2</td></tr>\n" 342 " <tr><th>One</th><th>-</th><td>3</td></tr>\n" 343 " <tr><th>One</th><th>+</th><td>4</td></tr>\n" 344 " <tr><th>Two</th><th>-</th><td>5</td></tr>\n" 345 " <tr><th>Two</th><th>+</th><td>6</td></tr>\n" 349 auto keyFormatter = [](
Key key) {
return key == 12 ?
"A" :
"B"; };
350 TableFactor::Names
names{{12, {
"Zero",
"One",
"Two"}}, {5, {
"-",
"+"}}};
351 string actual = f.
html(keyFormatter,
names);
352 EXPECT(actual == expected);
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
const gtsam::Symbol key('X', 0)
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as markdown table.
shared_ptr max(size_t nrFrontals) const
Create new factor by maximizing over all values with the same separator.
TEST(TableFactor, constructors)
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as html table.
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
DecisionTreeFactor toDecisionTreeFactor() const override
Convert into a decisiontree.
signatures for conditional densities
JacobiRotation< float > G
Point2 prior(const Point2 &x)
Prior on a single pose.
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.
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
std::shared_ptr< TableFactor > shared_ptr
double f2(const Vector2 &x)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange [*:*] noreverse nowriteback set trange [*:*] noreverse nowriteback set urange [*:*] noreverse nowriteback set vrange [*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
EIGEN_DEVICE_FUNC const LogReturnType log() const
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
void g(const string &key, int i)
std::vector< std::pair< DiscreteValues, double > > enumerate() const
Enumerate all values into a map from values to double.
const KeyFormatter & formatter
void printTime(map< double, pair< chrono::microseconds, chrono::microseconds >> measured_time)
#define EXPECT(condition)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
JacobiRotation< float > J
TableFactor prune(size_t maxNrAssignments) const
Prune the decision tree of discrete variables.
Matrix< Scalar, Dynamic, Dynamic > C
#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)
map< double, pair< chrono::microseconds, chrono::microseconds > > measureTime(DiscreteKeys keys1, DiscreteKeys keys2, size_t size)
std::vector< std::pair< DiscreteValues, double > > enumerate() const
Enumerate all values into a map from values to double.
shared_ptr sum(size_t nrFrontals) const
Create new factor by summing all values with the same separator values.
vector< double > genArr(double dropout, size_t size)
std::uint64_t Key
Integer nonlinear key type.
DiscreteKeys is a set of keys that can be assembled using the & operator.