markdown for DiscreteBayesTree

release/4.3a0
Frank Dellaert 2021-12-24 14:34:47 -05:00
parent 1ab8a23792
commit 00c4af16ec
4 changed files with 68 additions and 62 deletions

View File

@ -55,8 +55,21 @@ namespace gtsam {
return result; return result;
} }
} // \namespace gtsam /* **************************************************************************/
std::string DiscreteBayesTree::_repr_markdown_(
const KeyFormatter& keyFormatter) const {
using std::endl;
std::stringstream ss;
ss << "`DiscreteBayesTree` of size " << nodes_.size() << endl << endl;
auto visitor = [&](const DiscreteBayesTreeClique::shared_ptr& clique,
size_t& indent) {
ss << "\n" << clique->conditional()->_repr_markdown_(keyFormatter);
return indent + 1;
};
size_t indent;
treeTraversal::DepthFirstForest(*this, indent, visitor);
return ss.str();
}
/* **************************************************************************/
} // namespace gtsam

View File

@ -72,6 +72,8 @@ class GTSAM_EXPORT DiscreteBayesTree
typedef DiscreteBayesTree This; typedef DiscreteBayesTree This;
typedef boost::shared_ptr<This> shared_ptr; typedef boost::shared_ptr<This> shared_ptr;
/// @name Standard interface
/// @{
/** Default constructor, creates an empty Bayes tree */ /** Default constructor, creates an empty Bayes tree */
DiscreteBayesTree() {} DiscreteBayesTree() {}
@ -82,10 +84,19 @@ class GTSAM_EXPORT DiscreteBayesTree
double evaluate(const DiscreteValues& values) const; double evaluate(const DiscreteValues& values) const;
//** (Preferred) sugar for the above for given DiscreteValues */ //** (Preferred) sugar for the above for given DiscreteValues */
double operator()(const DiscreteValues & values) const { double operator()(const DiscreteValues& values) const {
return evaluate(values); return evaluate(values);
} }
/// @}
/// @name Wrapper support
/// @{
/// Render as markdown table.
std::string _repr_markdown_(
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
/// @}
}; };
} // namespace gtsam } // namespace gtsam

View File

@ -126,6 +126,9 @@ class DiscreteBayesTree {
const gtsam::KeyFormatter& keyFormatter = const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const; gtsam::DefaultKeyFormatter) const;
double operator()(const gtsam::DiscreteValues& values) const; double operator()(const gtsam::DiscreteValues& values) const;
string _repr_markdown_(const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const;
}; };
#include <gtsam/inference/DotWriter.h> #include <gtsam/inference/DotWriter.h>

File diff suppressed because one or more lines are too long