8000 dot argument order by dellaert · Pull Request #989 · borglab/gtsam · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

dot argument order #989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gtsam/discrete/DiscreteConditional.cpp
10000
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ std::string DiscreteConditional::markdown(
if (nrParents() == 0) {
// We have no parents, call factor method.
ss << ")$:" << std::endl;
ss << DecisionTreeFactor::markdown();
ss << DecisionTreeFactor::markdown(keyFormatter);
return ss.str();
}

Expand Down
18 changes: 10 additions & 8 deletions gtsam/discrete/discrete.i
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ class DiscreteBayesTree {

#include <gtsam/inference/DotWriter.h>
class DotWriter {
DotWriter();
DotWriter(double figureWidthInches = 5, double figureHeightInches = 5,
bool plotFactorPoints = true, bool connectKeysToFactor = true,
bool binaryEdges = true);
};

#include <gtsam/discrete/DiscreteFactorGraph.h>
Expand All @@ -153,13 +155,13 @@ class DiscreteFactorGraph {
void print(string s = "") const;
bool equals(const gtsam::DiscreteFactorGraph& fg, double tol = 1e-9) const;

string dot(const gtsam::DotWriter& dotWriter = gtsam::DotWriter(),
const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const;
void saveGraph(string s,
const gtsam::DotWriter& dotWriter = gtsam::DotWriter(),
const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const;
string dot(
const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter,
const gtsam::DotWriter& dotWriter = gtsam::DotWriter()) const;
void saveGraph(
string s,
const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter,
const gtsam::DotWriter& dotWriter = gtsam::DotWriter()) const;

gtsam::DecisionTreeFactor product() const;
double operator()(const gtsam::DiscreteValues& values) const;
Expand Down
2 changes: 1 addition & 1 deletion gtsam/discrete/tests/testDiscreteBayesNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ TEST(DiscreteBayesNet, markdown) {
"`DiscreteBayesNet` of size 2\n"
"\n"
" $P(Asia)$:\n"
"|0|value|\n"
"|Asia|value|\n"
"|:-:|:-:|\n"
"|0|0.99|\n"
"|1|0.01|\n"
Expand Down
15 changes: 9 additions & 6 deletions gtsam/inference/DotWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ struct GTSAM_EXPORT DotWriter {
///< the dot of the factor
bool binaryEdges; ///< just use non-dotted edges for binary factors

DotWriter()
: figureWidthInches(5),
figureHeightInches(5),
plotFactorPoints(true),
connectKeysToFactor(true),
binaryEdges(true) {}
explicit DotWriter(double figureWidthInches = 5,
double figureHeightInches = 5,
bool plotFactorPoints = true,
bool connectKeysToFactor = true, bool binaryEdges = true)
: figureWidthInches(figureWidthInches),
figureHeightInches(figureHeightInches),
plotFactorPoints(plotFactorPoints),
connectKeysToFactor(connectKeysToFactor),
binaryEdges(binaryEdges) {}

/// Write out preamble, including size.
void writePreamble(std::ostream* os) const;
Expand Down
17 changes: 9 additions & 8 deletions gtsam/inference/FactorGraph-inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ FactorIndices FactorGraph<FACTOR>::add_factors(const CONTAINER& factors,

/* ************************************************************************* */
template <class FACTOR>
void FactorGraph<FACTOR>::dot(std::ostream& os, const DotWriter& writer,
const KeyFormatter& keyFormatter) const {
void FactorGraph<FACTOR>::dot(std::ostream& os,
const KeyFormatter& keyFormatter,
const DotWriter& writer) const {
writer.writePreamble(&os);

// Create nodes for each variable in the graph
Expand All @@ -153,20 +154,20 @@ void FactorGraph<FACTOR>::dot(std::ostream& os, const DotWriter& writer,

/* ************************************************************************* */
template <class FACTOR>
std::string FactorGraph<FACTOR>::dot(const DotWriter& writer,
const KeyFormatter& keyFormatter) const {
std::string FactorGraph<FACTOR>::dot(const KeyFormatter& keyFormatter,
const DotWriter& writer) const {
std::stringstream ss;
dot(ss, writer, keyFormatter);
dot(ss, keyFormatter, writer);
return ss.str();
}

/* ************************************************************************* */
template <class FACTOR>
void FactorGraph<FACTOR>::saveGraph(const std::string& filename,
const DotWriter& writer,
const KeyFormatter& keyFormatter) const {
const KeyFormatter& keyFormatter,
const DotWriter& writer) const {
std::ofstream of(filename.c_str());
dot(of, writer, keyFormatter);
dot(of, keyFormatter, writer);
of.close();
}

Expand Down
13 changes: 7 additions & 6 deletions gtsam/inference/FactorGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,18 @@ class FactorGraph {
/// @{

/// Output to graphviz format, stream version.
void dot(std::ostream& os, const DotWriter& writer = DotWriter(),
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
void dot(std::ostream& os,
const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DotWriter& writer = DotWriter()) const;

/// Output to graphviz format string.
std::string dot(const DotWriter& writer = DotWriter(),
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
std::string dot(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DotWriter& writer = DotWriter()) const;

/// output to file with graphviz format.
void saveGraph(const std::string& filename,
const DotWriter& writer = DotWriter(),
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DotWriter& writer = DotWriter()) const;

/// @}
/// @name Advanced Interface
Expand Down
23 changes: 11 additions & 12 deletions gtsam/nonlinear/NonlinearFactorGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <gtsam/linear/linearExceptions.h>
#include <gtsam/linear/VectorValues.h>
#include <gtsam/inference/Ordering.h>
#include <gtsam/inference/DotWriter.h>
#include <gtsam/inference/FactorGraph-inst.h>
#include <gtsam/config.h> // for GTSAM_USE_TBB

Expand Down Expand Up @@ -92,8 +91,8 @@ bool NonlinearFactorGraph::equals(const NonlinearFactorGraph& other, double tol)

/* ************************************************************************* */
void NonlinearFactorGraph::dot(std::ostream& os, const Values& values,
const GraphvizFormatting& writer,
const KeyFormatter& keyFormatter) const {
const KeyFormatter& keyFormatter,
const GraphvizFormatting& writer) const {
writer.writePreamble(&os);

// Find bounds (imperative)
Expand Down Expand Up @@ -139,21 +138,21 @@ void NonlinearFactorGraph::dot(std::ostream& os, const Values& values,
}

/* ************************************************************************* */
std::string NonlinearFactorGraph::dot(
const Values& values, const GraphvizFormatting& writer,
const KeyFormatter& keyFormatter) const {
std::string NonlinearFactorGraph::dot(const Values& values,
const KeyFormatter& keyFormatter,
const GraphvizFormatting& writer) const {
std::stringstream ss;
dot(ss, values, writer, keyFormatter);
dot(ss, values, keyFormatter, writer);
return ss.str();
}

/* ************************************************************************* */
void NonlinearFactorGraph::saveGraph(
const std::string& filename, const Values& values,
const GraphvizFormatting& writer,
const KeyFormatter& keyFormatter) const {
void NonlinearFactorGraph::saveGraph(const std::string& filename,
const Values& values,
const KeyFormatter& keyFormatter,
const GraphvizFormatting& writer) const {
std::ofstream of(filename);
dot(of, values, writer, keyFormatter);
dot(of, values, keyFormatter, writer);
of.close();
}

Expand Down
34 changes: 20 additions & 14 deletions gtsam/nonlinear/NonlinearFactorGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,22 @@ namespace gtsam {
using FactorGraph::saveGraph;

/// Output to graphviz format, stream version, with Values/extra options.
void dot(
std::ostream& os, const Values& values,
const GraphvizFormatting& graphvizFormatting = GraphvizFormatting(),
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
void dot(std::ostream& os, const Values& values,
const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const GraphvizFormatting& graphvizFormatting =
GraphvizFormatting()) const;

/// Output to graphviz format string, with Values/extra options.
std::string dot(
const Values& values,
const GraphvizFormatting& graphvizFormatting = GraphvizFormatting(),
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
std::string dot(const Values& values,
const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const GraphvizFormatting& graphvizFormatting =
GraphvizFormatting()) const;

/// output to file with graphviz format, with Values/extra options.
void saveGraph(
const std::string& filename, const Values& values,
const GraphvizFormatting& graphvizFormatting = GraphvizFormatting(),
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;

void saveGraph(const std::string& filename, const Values& values,
const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const GraphvizFormatting& graphvizFormatting =
GraphvizFormatting()) const;
/// @}

private:
Expand Down Expand Up @@ -267,7 +266,14 @@ namespace gtsam {
std::ostream& os, const Values& values = Values(),
const GraphvizFormatting& graphvizFormatting = GraphvizFormatting(),
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
dot(os, values, graphvizFormatting, keyFormatter);
dot(os, values, keyFormatter, graphvizFormatting);
}
/** \deprecated */
void GTSAM_DEPRECATED saveGraph(
const std::string& filename, const Values& values,
const GraphvizFormatting& graphvizFormatting = GraphvizFormatting(),
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
saveGraph(filename, values, keyFormatter, graphvizFormatting);
}
#endif

Expand Down
13 changes: 12 additions & 1 deletion gtsam/nonlinear/nonlinear.i
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ class NonlinearFactorGraph {
// enabling serialization functionality
void serialize() const;

void saveGraph(const string& s) const;
string dot(
const gtsam::Values& values,
const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter);
void saveGraph(const string& s, const gtsam::Values& values,
const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const;
};

#include <gtsam/nonlinear/NonlinearFactor.h>
Expand Down Expand Up @@ -782,6 +787,12 @@ class ISAM2 {

void printStats() const;
gtsam::VectorValues gradientAtZero() const;

string dot(const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const;
void saveGraph(string s,
const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const;
};

#include <gtsam/nonlinear/NonlinearISAM.h>
Expand Down
0