Added dot methods

release/4.3a0
Frank Dellaert 2021-12-17 17:12:44 -05:00
parent 0bab7b00c8
commit 81b9724225
3 changed files with 20 additions and 5 deletions

View File

@ -248,8 +248,9 @@ namespace gtsam {
void dot(std::ostream& os, bool showZero) const override { void dot(std::ostream& os, bool showZero) const override {
os << "\"" << this->id() << "\" [shape=circle, label=\"" << label_ os << "\"" << this->id() << "\" [shape=circle, label=\"" << label_
<< "\"]\n"; << "\"]\n";
for (size_t i = 0; i < branches_.size(); i++) { size_t B = branches_.size();
NodePtr branch = branches_[i]; for (size_t i = 0; i < B; i++) {
const NodePtr& branch = branches_[i];
// Check if zero // Check if zero
if (!showZero) { if (!showZero) {
@ -258,8 +259,10 @@ namespace gtsam {
} }
os << "\"" << this->id() << "\" -> \"" << branch->id() << "\""; os << "\"" << this->id() << "\" -> \"" << branch->id() << "\"";
if (B == 2) {
if (i == 0) os << " [style=dashed]"; if (i == 0) os << " [style=dashed]";
if (i > 1) os << " [style=bold]"; if (i > 1) os << " [style=bold]";
}
os << std::endl; os << std::endl;
branch->dot(os, showZero); branch->dot(os, showZero);
} }
@ -673,6 +676,13 @@ namespace gtsam {
if (result==-1) throw std::runtime_error("DecisionTree::dot system call failed"); if (result==-1) throw std::runtime_error("DecisionTree::dot system call failed");
} }
template<typename L, typename Y>
std::string DecisionTree<L, Y>::dot(bool showZero) const {
std::stringstream ss;
dot(ss, showZero);
return ss.str();
}
/*********************************************************************************/ /*********************************************************************************/
} // namespace gtsam } // namespace gtsam

View File

@ -198,6 +198,9 @@ namespace gtsam {
/** output to graphviz format, open a file */ /** output to graphviz format, open a file */
void dot(const std::string& name, bool showZero = true) const; void dot(const std::string& name, bool showZero = true) const;
/** output to graphviz format string */
std::string dot(bool showZero = true) const;
/// @name Advanced Interface /// @name Advanced Interface
/// @{ /// @{

View File

@ -39,6 +39,7 @@ virtual class DecisionTreeFactor: gtsam::DiscreteFactor {
gtsam::DefaultKeyFormatter) const; gtsam::DefaultKeyFormatter) const;
bool equals(const gtsam::DecisionTreeFactor& other, double tol = 1e-9) const; bool equals(const gtsam::DecisionTreeFactor& other, double tol = 1e-9) const;
double operator()(const gtsam::DiscreteValues& values) const; // TODO(dellaert): why do I have to repeat??? double operator()(const gtsam::DiscreteValues& values) const; // TODO(dellaert): why do I have to repeat???
string dot(bool showZero = false) const;
}; };
#include <gtsam/discrete/DiscreteConditional.h> #include <gtsam/discrete/DiscreteConditional.h>
@ -67,6 +68,7 @@ virtual class DiscreteConditional : gtsam::DecisionTreeFactor {
size_t sample(const gtsam::DiscreteValues& parentsValues) const; size_t sample(const gtsam::DiscreteValues& parentsValues) const;
void solveInPlace(gtsam::DiscreteValues@ parentsValues) const; void solveInPlace(gtsam::DiscreteValues@ parentsValues) const;
void sampleInPlace(gtsam::DiscreteValues@ parentsValues) const; void sampleInPlace(gtsam::DiscreteValues@ parentsValues) const;
string dot(bool showZero = false) const;
}; };
#include <gtsam/discrete/DiscreteBayesNet.h> #include <gtsam/discrete/DiscreteBayesNet.h>