added saveGraph function to BayesTree which writes out a dot file which can be visualized using graphviz dot command
parent
e87faa078d
commit
80d335ed77
|
@ -10,12 +10,14 @@
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/assign/std/list.hpp> // for operator +=
|
#include <boost/assign/std/list.hpp> // for operator +=
|
||||||
|
#include <fstream>
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
|
||||||
#include "Conditional.h"
|
#include "Conditional.h"
|
||||||
#include "BayesTree.h"
|
#include "BayesTree.h"
|
||||||
#include "Ordering.h"
|
#include "Ordering.h"
|
||||||
#include "inference-inl.h"
|
#include "inference-inl.h"
|
||||||
|
#include "Key.h"
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
@ -86,6 +88,47 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
template<class Conditional>
|
||||||
|
void BayesTree<Conditional>::saveGraph(const std::string &s) const {
|
||||||
|
ofstream of(s.c_str());
|
||||||
|
of<< "digraph G{\n";
|
||||||
|
saveGraph(of, root_);
|
||||||
|
of<<"}";
|
||||||
|
of.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Conditional>
|
||||||
|
void BayesTree<Conditional>::saveGraph(ostream &s,
|
||||||
|
BayesTree<Conditional>::sharedClique clique,
|
||||||
|
int parentnum, int num) const {
|
||||||
|
bool first = true;
|
||||||
|
std::stringstream out;
|
||||||
|
out << num;
|
||||||
|
string parent = out.str();
|
||||||
|
parent += "[label=\"";
|
||||||
|
BOOST_FOREACH(boost::shared_ptr<Conditional> c, clique->conditionals_) {
|
||||||
|
if(!first) parent += ","; first = false;
|
||||||
|
parent += (string(c->key())).c_str();
|
||||||
|
}
|
||||||
|
if( clique != root_){
|
||||||
|
parent += " : ";
|
||||||
|
s << parentnum << "->" << num << "\n";
|
||||||
|
}
|
||||||
|
first = true;
|
||||||
|
BOOST_FOREACH(const Symbol& sep, clique->separator_) {
|
||||||
|
if(!first) parent += ","; first = false;
|
||||||
|
parent += ((string)sep).c_str();
|
||||||
|
}
|
||||||
|
parent += "\"];\n";
|
||||||
|
s << parent;
|
||||||
|
parentnum = num;
|
||||||
|
BOOST_FOREACH(sharedClique c, clique->children_) {
|
||||||
|
saveGraph(s, c, parentnum, ++num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Conditional>
|
template<class Conditional>
|
||||||
typename BayesTree<Conditional>::CliqueStats
|
typename BayesTree<Conditional>::CliqueStats
|
||||||
BayesTree<Conditional>::CliqueData::getStats() const {
|
BayesTree<Conditional>::CliqueData::getStats() const {
|
||||||
|
|
|
@ -127,6 +127,13 @@ namespace gtsam {
|
||||||
/** print */
|
/** print */
|
||||||
void print(const std::string& s = "") const;
|
void print(const std::string& s = "") const;
|
||||||
|
|
||||||
|
/** saves the Tree to a text file in GraphViz format */
|
||||||
|
void saveGraph(const std::string& s) const;
|
||||||
|
private:
|
||||||
|
void saveGraph(std::ostream &s, sharedClique clique,
|
||||||
|
int parentnum = 0, int num = 0) const;
|
||||||
|
public:
|
||||||
|
|
||||||
/** check equality */
|
/** check equality */
|
||||||
bool equals(const BayesTree<Conditional>& other, double tol = 1e-9) const;
|
bool equals(const BayesTree<Conditional>& other, double tol = 1e-9) const;
|
||||||
|
|
||||||
|
@ -170,6 +177,7 @@ namespace gtsam {
|
||||||
CliqueStats getStats() const;
|
CliqueStats getStats() const;
|
||||||
};
|
};
|
||||||
CliqueData getCliqueData() const;
|
CliqueData getCliqueData() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void getCliqueData(CliqueData& stats, sharedClique clique) const;
|
void getCliqueData(CliqueData& stats, sharedClique clique) const;
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue