markdown for DiscreteFactorGraph
parent
edadd352af
commit
042cb9d902
|
@ -168,7 +168,7 @@ namespace gtsam {
|
||||||
|
|
||||||
/// Render as markdown table.
|
/// Render as markdown table.
|
||||||
std::string _repr_markdown_(
|
std::string _repr_markdown_(
|
||||||
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
|
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ public:
|
||||||
|
|
||||||
/// Render as markdown table.
|
/// Render as markdown table.
|
||||||
std::string _repr_markdown_(
|
std::string _repr_markdown_(
|
||||||
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
|
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
};
|
};
|
||||||
|
|
|
@ -88,6 +88,14 @@ public:
|
||||||
|
|
||||||
virtual DecisionTreeFactor toDecisionTreeFactor() const = 0;
|
virtual DecisionTreeFactor toDecisionTreeFactor() const = 0;
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
/// @name Wrapper support
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
/// Render as markdown table.
|
||||||
|
virtual std::string _repr_markdown_(
|
||||||
|
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const = 0;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
};
|
};
|
||||||
// DiscreteFactor
|
// DiscreteFactor
|
||||||
|
|
|
@ -129,6 +129,18 @@ namespace gtsam {
|
||||||
return std::make_pair(cond, sum);
|
return std::make_pair(cond, sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
} // namespace
|
std::string DiscreteFactorGraph::_repr_markdown_(
|
||||||
|
const KeyFormatter& keyFormatter) const {
|
||||||
|
using std::endl;
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "`DiscreteFactorGraph` of size " << size() << endl << endl;
|
||||||
|
for (size_t i = 0; i < factors_.size(); i++) {
|
||||||
|
ss << "factor " << i << ":\n";
|
||||||
|
ss << factors_[i]->_repr_markdown_(keyFormatter) << endl;
|
||||||
|
}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
} // namespace gtsam
|
||||||
|
|
|
@ -154,6 +154,14 @@ public:
|
||||||
// /** Apply a reduction, which is a remapping of variable indices. */
|
// /** Apply a reduction, which is a remapping of variable indices. */
|
||||||
// GTSAM_EXPORT void reduceWithInverse(const internal::Reduction& inverseReduction);
|
// GTSAM_EXPORT void reduceWithInverse(const internal::Reduction& inverseReduction);
|
||||||
|
|
||||||
|
/// @name Wrapper support
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
/// Render as markdown table.
|
||||||
|
std::string _repr_markdown_(
|
||||||
|
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
|
||||||
|
|
||||||
|
/// @}
|
||||||
}; // \ DiscreteFactorGraph
|
}; // \ DiscreteFactorGraph
|
||||||
|
|
||||||
/// traits
|
/// traits
|
||||||
|
|
|
@ -166,6 +166,9 @@ class DiscreteFactorGraph {
|
||||||
gtsam::DiscreteBayesNet eliminateSequential(const gtsam::Ordering& ordering);
|
gtsam::DiscreteBayesNet eliminateSequential(const gtsam::Ordering& ordering);
|
||||||
gtsam::DiscreteBayesTree eliminateMultifrontal();
|
gtsam::DiscreteBayesTree eliminateMultifrontal();
|
||||||
gtsam::DiscreteBayesTree eliminateMultifrontal(const gtsam::Ordering& ordering);
|
gtsam::DiscreteBayesTree eliminateMultifrontal(const gtsam::Ordering& ordering);
|
||||||
|
|
||||||
|
string _repr_markdown_(const gtsam::KeyFormatter& keyFormatter =
|
||||||
|
gtsam::DefaultKeyFormatter) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gtsam
|
} // namespace gtsam
|
||||||
|
|
|
@ -361,11 +361,9 @@ cout << unicorns;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST(DiscreteFactorGraph, Dot) {
|
TEST(DiscreteFactorGraph, Dot) {
|
||||||
// Declare a bunch of keys
|
|
||||||
DiscreteKey C(0, 2), A(1, 2), B(2, 2);
|
|
||||||
|
|
||||||
// Create Factor graph
|
// Create Factor graph
|
||||||
DiscreteFactorGraph graph;
|
DiscreteFactorGraph graph;
|
||||||
|
DiscreteKey C(0, 2), A(1, 2), B(2, 2);
|
||||||
graph.add(C & A, "0.2 0.8 0.3 0.7");
|
graph.add(C & A, "0.2 0.8 0.3 0.7");
|
||||||
graph.add(C & B, "0.1 0.9 0.4 0.6");
|
graph.add(C & B, "0.1 0.9 0.4 0.6");
|
||||||
|
|
||||||
|
@ -384,6 +382,44 @@ TEST(DiscreteFactorGraph, Dot) {
|
||||||
EXPECT(actual == expected);
|
EXPECT(actual == expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
// Check markdown representation looks as expected.
|
||||||
|
TEST(DiscreteFactorGraph, markdown) {
|
||||||
|
// Create Factor graph
|
||||||
|
DiscreteFactorGraph graph;
|
||||||
|
DiscreteKey C(0, 2), A(1, 2), B(2, 2);
|
||||||
|
graph.add(C & A, "0.2 0.8 0.3 0.7");
|
||||||
|
graph.add(C & B, "0.1 0.9 0.4 0.6");
|
||||||
|
|
||||||
|
string expected =
|
||||||
|
"`DiscreteFactorGraph` of size 2\n"
|
||||||
|
"\n"
|
||||||
|
"factor 0:\n"
|
||||||
|
"|C|A|value|\n"
|
||||||
|
"|:-:|:-:|:-:|\n"
|
||||||
|
"|0|0|0.2|\n"
|
||||||
|
"|0|1|0.8|\n"
|
||||||
|
"|1|0|0.3|\n"
|
||||||
|
"|1|1|0.7|\n"
|
||||||
|
"\n"
|
||||||
|
"factor 1:\n"
|
||||||
|
"|C|B|value|\n"
|
||||||
|
"|:-:|:-:|:-:|\n"
|
||||||
|
"|0|0|0.1|\n"
|
||||||
|
"|0|1|0.9|\n"
|
||||||
|
"|1|0|0.4|\n"
|
||||||
|
"|1|1|0.6|\n\n";
|
||||||
|
vector<string> names{"C", "A", "B"};
|
||||||
|
auto formatter = [names](Key key) { return names[key]; };
|
||||||
|
string actual = graph._repr_markdown_(formatter);
|
||||||
|
EXPECT(actual == expected);
|
||||||
|
|
||||||
|
// Make sure values are correctly displayed.
|
||||||
|
DiscreteValues values;
|
||||||
|
values[0] = 1;
|
||||||
|
values[1] = 0;
|
||||||
|
EXPECT_DOUBLES_EQUAL(0.3, graph[0]->operator()(values), 1e-9);
|
||||||
|
}
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
int main() {
|
int main() {
|
||||||
TestResult tr;
|
TestResult tr;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <gtsam_unstable/dllexport.h>
|
#include <gtsam_unstable/dllexport.h>
|
||||||
|
|
||||||
#include <boost/assign.hpp>
|
#include <boost/assign.hpp>
|
||||||
|
#include <boost/format.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
@ -81,6 +82,16 @@ class GTSAM_EXPORT Constraint : public DiscreteFactor {
|
||||||
/// Partially apply known values, domain version
|
/// Partially apply known values, domain version
|
||||||
virtual shared_ptr partiallyApply(const Domains&) const = 0;
|
virtual shared_ptr partiallyApply(const Domains&) const = 0;
|
||||||
/// @}
|
/// @}
|
||||||
|
/// @name Wrapper support
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
/// Render as markdown table.
|
||||||
|
std::string _repr_markdown_(
|
||||||
|
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
|
||||||
|
return (boost::format("`Constraint` on %1% variables\n") % (size())).str();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @}
|
||||||
};
|
};
|
||||||
// DiscreteFactor
|
// DiscreteFactor
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue