DiscreteBayesTree of size " << nodes_.size()
+ << "
";
+ auto visitor = [&](const DiscreteBayesTreeClique::shared_ptr& clique,
+ size_t& indent) {
+ ss << clique->conditional()->html(keyFormatter, names);
+ return indent + 1;
+ };
+ size_t indent;
+ treeTraversal::DepthFirstForest(*this, indent, visitor);
+ return ss.str();
+ }
+
/* **************************************************************************/
} // namespace gtsam
diff --git a/gtsam/discrete/DiscreteBayesTree.h b/gtsam/discrete/DiscreteBayesTree.h
index 6189f25d5..809ce9c83 100644
--- a/gtsam/discrete/DiscreteBayesTree.h
+++ b/gtsam/discrete/DiscreteBayesTree.h
@@ -92,10 +92,14 @@ class GTSAM_EXPORT DiscreteBayesTree
/// @name Wrapper support
/// @{
- /// Render as markdown table.
+ /// Render as markdown tables.
std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DiscreteFactor::Names& names = {}) const;
+ /// Render as html tables.
+ std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
+ const DiscreteFactor::Names& names = {}) const;
+
/// @}
};
diff --git a/gtsam/discrete/DiscreteConditional.cpp b/gtsam/discrete/DiscreteConditional.cpp
index 48f8fd322..512ff88b4 100644
--- a/gtsam/discrete/DiscreteConditional.cpp
+++ b/gtsam/discrete/DiscreteConditional.cpp
@@ -410,16 +410,19 @@ string DiscreteConditional::html(const KeyFormatter& keyFormatter,
}
auto frontalAssignments = this->frontalAssignments();
for (const auto& a : frontalAssignments) {
+ ss << "
";
for (auto&& it = beginFrontals(); it != endFrontals(); ++it) {
size_t index = a.at(*it);
- ss << " | " << Translate(names, *it, index) << " | ";
+ ss << Translate(names, *it, index);
}
+ ss << "";
}
ss << "\n";
// Finish header and start body.
ss << " \n
\n";
+ // Output all rows, one per assignment:
size_t count = 0, n = frontalAssignments.size();
for (const auto& a : allAssignments()) {
if (count == 0) {
diff --git a/gtsam/discrete/DiscreteFactorGraph.cpp b/gtsam/discrete/DiscreteFactorGraph.cpp
index be046d290..c1248c60b 100644
--- a/gtsam/discrete/DiscreteFactorGraph.cpp
+++ b/gtsam/discrete/DiscreteFactorGraph.cpp
@@ -131,7 +131,7 @@ namespace gtsam {
return std::make_pair(cond, sum);
}
- /* ************************************************************************* */
+ /* ************************************************************************ */
string DiscreteFactorGraph::markdown(
const KeyFormatter& keyFormatter,
const DiscreteFactor::Names& names) const {
@@ -145,5 +145,18 @@ namespace gtsam {
return ss.str();
}
- /* ************************************************************************* */
+ /* ************************************************************************ */
+ string DiscreteFactorGraph::html(const KeyFormatter& keyFormatter,
+ const DiscreteFactor::Names& names) const {
+ using std::endl;
+ std::stringstream ss;
+ ss << "DiscreteFactorGraph of size " << size() << "
";
+ for (size_t i = 0; i < factors_.size(); i++) {
+ ss << "
factor " << i << ":
";
+ ss << factors_[i]->html(keyFormatter, names) << endl;
+ }
+ return ss.str();
+ }
+
+ /* ************************************************************************ */
} // namespace gtsam
diff --git a/gtsam/discrete/DiscreteFactorGraph.h b/gtsam/discrete/DiscreteFactorGraph.h
index 9aa04d649..08c3d893d 100644
--- a/gtsam/discrete/DiscreteFactorGraph.h
+++ b/gtsam/discrete/DiscreteFactorGraph.h
@@ -22,18 +22,17 @@
#include
#include
#include
-#include
#include
#include
#include
+#include
#include
namespace gtsam {
// Forward declarations
class DiscreteFactorGraph;
-class DiscreteFactor;
class DiscreteConditional;
class DiscreteBayesNet;
class DiscreteEliminationTree;
@@ -144,8 +143,8 @@ public:
/// @{
/**
- * @brief Render as markdown table
- *
+ * @brief Render as markdown tables
+ *
* @param keyFormatter GTSAM-style Key formatter.
* @param names optional, a map from Key to category names.
* @return std::string a (potentially long) markdown string.
@@ -153,6 +152,16 @@ public:
std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DiscreteFactor::Names& names = {}) const;
+ /**
+ * @brief Render as html tables
+ *
+ * @param keyFormatter GTSAM-style Key formatter.
+ * @param names optional, a map from Key to category names.
+ * @return std::string a (potentially long) html string.
+ */
+ std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
+ const DiscreteFactor::Names& names = {}) const;
+
/// @}
}; // \ DiscreteFactorGraph
diff --git a/gtsam/discrete/discrete.i b/gtsam/discrete/discrete.i
index 3e8013ce8..9bf324fd3 100644
--- a/gtsam/discrete/discrete.i
+++ b/gtsam/discrete/discrete.i
@@ -144,6 +144,10 @@ class DiscreteBayesNet {
gtsam::DefaultKeyFormatter) const;
string markdown(const gtsam::KeyFormatter& keyFormatter,
std::map> names) const;
+ string html(const gtsam::KeyFormatter& keyFormatter =
+ gtsam::DefaultKeyFormatter) const;
+ string html(const gtsam::KeyFormatter& keyFormatter,
+ std::map> names) const;
};
#include
@@ -180,6 +184,10 @@ class DiscreteBayesTree {
gtsam::DefaultKeyFormatter) const;
string markdown(const gtsam::KeyFormatter& keyFormatter,
std::map> names) const;
+ string html(const gtsam::KeyFormatter& keyFormatter =
+ gtsam::DefaultKeyFormatter) const;
+ string html(const gtsam::KeyFormatter& keyFormatter,
+ std::map> names) const;
};
#include
@@ -229,6 +237,10 @@ class DiscreteFactorGraph {
gtsam::DefaultKeyFormatter) const;
string markdown(const gtsam::KeyFormatter& keyFormatter,
std::map> names) const;
+ string html(const gtsam::KeyFormatter& keyFormatter =
+ gtsam::DefaultKeyFormatter) const;
+ string html(const gtsam::KeyFormatter& keyFormatter,
+ std::map> names) const;
};
} // namespace gtsam