BIG CHANGE: I got rid of the BayesChain/ChordalBayesNet classes and we now simply have a BayesNet class. It will just happen to be chordal when it is the result of an elimination. This will simplify a lot of things.
The main renaming that happened is BayesChain -> BayesNet ChordalBayesNet -> GaussianBayesNet == BayesNet<ConditionalGaussian> SymbolicBayesChain -> SymbolicBayesNet == BayesNet<SymbolicConditional>release/4.3a0
parent
921cb0a8fc
commit
943b692a6b
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @file BayesChain-inl.h
|
||||
* @file BayesNet-inl.h
|
||||
* @brief Bayes chain template definitions
|
||||
* @author Frank Dellaert
|
||||
*/
|
||||
|
@ -8,7 +8,7 @@
|
|||
#include <boost/foreach.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#include "BayesChain.h"
|
||||
#include "BayesNet.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -19,7 +19,7 @@ namespace gtsam {
|
|||
|
||||
/* ************************************************************************* */
|
||||
template<class Conditional>
|
||||
void BayesChain<Conditional>::print(const string& s) const {
|
||||
void BayesNet<Conditional>::print(const string& s) const {
|
||||
cout << s << ":\n";
|
||||
BOOST_FOREACH(string key, keys_) {
|
||||
const_iterator it = nodes_.find(key);
|
||||
|
@ -29,7 +29,7 @@ namespace gtsam {
|
|||
|
||||
/* ************************************************************************* */
|
||||
template<class Conditional>
|
||||
bool BayesChain<Conditional>::equals(const BayesChain& cbn, double tol) const {
|
||||
bool BayesNet<Conditional>::equals(const BayesNet& cbn, double tol) const {
|
||||
if(size() != cbn.size()) return false;
|
||||
if(keys_ != cbn.keys_) return false;
|
||||
string key;
|
||||
|
@ -44,7 +44,7 @@ namespace gtsam {
|
|||
|
||||
/* ************************************************************************* */
|
||||
template<class Conditional>
|
||||
void BayesChain<Conditional>::insert
|
||||
void BayesNet<Conditional>::insert
|
||||
(const string& key, boost::shared_ptr<Conditional> node) {
|
||||
keys_.push_front(key);
|
||||
nodes_.insert(make_pair(key,node));
|
||||
|
@ -52,7 +52,7 @@ namespace gtsam {
|
|||
|
||||
/* ************************************************************************* */
|
||||
template<class Conditional>
|
||||
void BayesChain<Conditional>::erase(const string& key) {
|
||||
void BayesNet<Conditional>::erase(const string& key) {
|
||||
list<string>::iterator it;
|
||||
for (it=keys_.begin(); it != keys_.end(); ++it){
|
||||
if( strcmp(key.c_str(), (*it).c_str()) == 0 )
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* @file BayesChain
|
||||
* @brief Bayes Chain, the result of eliminating a factor graph
|
||||
* @file BayesNet
|
||||
* @brief Bayes network
|
||||
* @author Frank Dellaert
|
||||
*/
|
||||
|
||||
|
@ -17,13 +17,13 @@
|
|||
namespace gtsam {
|
||||
|
||||
/**
|
||||
* Bayes Chain, the result of eliminating a factor graph
|
||||
* This is the base class for SymbolicBayesChain, DiscreteBayesChain, and GaussianBayesChain
|
||||
* Corresponding to what is used for the "Conditional" template argument:
|
||||
* a ConditionalProbabilityTable, a ConditionalGaussian, or a SymbolicConditional.
|
||||
* Bayes network
|
||||
* This is the base class for SymbolicBayesNet, DiscreteBayesNet, and GaussianBayesNet
|
||||
* corresponding to what is used for the "Conditional" template argument:
|
||||
* a SymbolicConditional, ConditionalProbabilityTable, or a ConditionalGaussian
|
||||
*/
|
||||
template<class Conditional>
|
||||
class BayesChain: public Testable<BayesChain<Conditional> > {
|
||||
class BayesNet: public Testable<BayesNet<Conditional> > {
|
||||
protected:
|
||||
|
||||
/** nodes keys stored in topological sort order, i.e. from parents to children */
|
||||
|
@ -39,7 +39,7 @@ namespace gtsam {
|
|||
void print(const std::string& s = "") const;
|
||||
|
||||
/** check equality */
|
||||
bool equals(const BayesChain& other, double tol = 1e-9) const;
|
||||
bool equals(const BayesNet& other, double tol = 1e-9) const;
|
||||
|
||||
/** insert: use reverse topological sort (i.e. parents last) */
|
||||
void insert(const std::string& key, boost::shared_ptr<Conditional> node);
|
|
@ -53,7 +53,7 @@ namespace gtsam {
|
|||
/* ************************************************************************* */
|
||||
// TODO: traversal is O(n*log(n)) but could be O(n) with better bayesChain
|
||||
template<class Conditional>
|
||||
BayesTree<Conditional>::BayesTree(BayesChain<Conditional>& bayesChain, bool verbose) {
|
||||
BayesTree<Conditional>::BayesTree(BayesNet<Conditional>& bayesChain, bool verbose) {
|
||||
list<string> reverseOrdering = bayesChain.keys();
|
||||
BOOST_FOREACH(string key, reverseOrdering)
|
||||
insert(key,bayesChain[key],verbose);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <boost/serialization/map.hpp>
|
||||
#include <boost/serialization/list.hpp>
|
||||
#include "Testable.h"
|
||||
#include "BayesChain.h"
|
||||
#include "BayesNet.h"
|
||||
|
||||
namespace gtsam {
|
||||
|
||||
|
@ -88,8 +88,8 @@ namespace gtsam {
|
|||
/** Create an empty Bayes Tree */
|
||||
BayesTree();
|
||||
|
||||
/** Create a Bayes Tree from a SymbolicBayesChain */
|
||||
BayesTree(BayesChain<Conditional>& bayesChain, bool verbose=false);
|
||||
/** Create a Bayes Tree from a SymbolicBayesNet */
|
||||
BayesTree(BayesNet<Conditional>& bayesChain, bool verbose=false);
|
||||
|
||||
/** Destructor */
|
||||
virtual ~BayesTree() {}
|
||||
|
|
|
@ -69,8 +69,8 @@ bool ConstrainedLinearFactorGraph::equals(const LinearFactorGraph& fg, double to
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
ChordalBayesNet::shared_ptr ConstrainedLinearFactorGraph::eliminate(const Ordering& ordering) {
|
||||
ChordalBayesNet::shared_ptr cbn (new ChordalBayesNet());
|
||||
GaussianBayesNet::shared_ptr ConstrainedLinearFactorGraph::eliminate(const Ordering& ordering) {
|
||||
GaussianBayesNet::shared_ptr cbn (new GaussianBayesNet());
|
||||
|
||||
BOOST_FOREACH(string key, ordering) {
|
||||
// constraints take higher priority in elimination, so check if
|
||||
|
@ -219,7 +219,7 @@ void ConstrainedLinearFactorGraph::update_constraints(const std::string& key,
|
|||
|
||||
/* ************************************************************************* */
|
||||
VectorConfig ConstrainedLinearFactorGraph::optimize(const Ordering& ordering) {
|
||||
ChordalBayesNet::shared_ptr cbn = eliminate(ordering);
|
||||
GaussianBayesNet::shared_ptr cbn = eliminate(ordering);
|
||||
boost::shared_ptr<VectorConfig> newConfig = cbn->optimize();
|
||||
return *newConfig;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#define CONSTRAINEDLINEARFACTORGRAPH_H_
|
||||
|
||||
#include "LinearFactorGraph.h"
|
||||
#include "ChordalBayesNet.h"
|
||||
#include "GaussianBayesNet.h"
|
||||
#include "LinearConstraint.h"
|
||||
|
||||
namespace gtsam {
|
||||
|
@ -80,7 +80,7 @@ public:
|
|||
* gaussian, with a different solving procedure.
|
||||
* @param ordering is the order to eliminate the variables
|
||||
*/
|
||||
ChordalBayesNet::shared_ptr eliminate(const Ordering& ordering);
|
||||
GaussianBayesNet::shared_ptr eliminate(const Ordering& ordering);
|
||||
|
||||
/**
|
||||
* Picks one of the contraints in a set of constraints to eliminate
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @file ChordalBayesNet.cpp
|
||||
* @file GaussianBayesNet.cpp
|
||||
* @brief Chordal Bayes Net, the result of eliminating a factor graph
|
||||
* @author Frank Dellaert
|
||||
*/
|
||||
|
@ -8,21 +8,21 @@
|
|||
#include <boost/foreach.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#include "ChordalBayesNet.h"
|
||||
#include "GaussianBayesNet.h"
|
||||
#include "VectorConfig.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace gtsam;
|
||||
|
||||
// Explicitly instantiate so we don't have to include everywhere
|
||||
#include "BayesChain-inl.h"
|
||||
template class BayesChain<ConditionalGaussian>;
|
||||
#include "BayesNet-inl.h"
|
||||
template class BayesNet<ConditionalGaussian>;
|
||||
|
||||
// trick from some reading group
|
||||
#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
|
||||
|
||||
/* ************************************************************************* */
|
||||
boost::shared_ptr<VectorConfig> ChordalBayesNet::optimize() const
|
||||
boost::shared_ptr<VectorConfig> GaussianBayesNet::optimize() const
|
||||
{
|
||||
boost::shared_ptr<VectorConfig> result(new VectorConfig);
|
||||
|
||||
|
@ -37,7 +37,7 @@ boost::shared_ptr<VectorConfig> ChordalBayesNet::optimize() const
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
pair<Matrix,Vector> ChordalBayesNet::matrix() const {
|
||||
pair<Matrix,Vector> GaussianBayesNet::matrix() const {
|
||||
|
||||
// add the dimensions of all variables to get matrix dimension
|
||||
// and at the same time create a mapping from keys to indices
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* @file ChordalBayesNet.h
|
||||
* @file GaussianBayesNet.h
|
||||
* @brief Chordal Bayes Net, the result of eliminating a factor graph
|
||||
* @brief ChordalBayesNet
|
||||
* @brief GaussianBayesNet
|
||||
* @author Frank Dellaert
|
||||
*/
|
||||
|
||||
|
@ -12,25 +12,25 @@
|
|||
#include <list>
|
||||
|
||||
#include "ConditionalGaussian.h"
|
||||
#include "BayesChain.h"
|
||||
#include "BayesNet.h"
|
||||
|
||||
namespace gtsam {
|
||||
|
||||
/** Chordal Bayes Net, the result of eliminating a factor graph */
|
||||
class ChordalBayesNet : public BayesChain<ConditionalGaussian>
|
||||
class GaussianBayesNet : public BayesNet<ConditionalGaussian>
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<ChordalBayesNet> shared_ptr;
|
||||
typedef boost::shared_ptr<GaussianBayesNet> shared_ptr;
|
||||
|
||||
/** Construct an empty net */
|
||||
ChordalBayesNet() {}
|
||||
GaussianBayesNet() {}
|
||||
|
||||
/** Copy Constructor */
|
||||
// ChordalBayesNet(const ChordalBayesNet& cbn_in) :
|
||||
// GaussianBayesNet(const GaussianBayesNet& cbn_in) :
|
||||
// keys_(cbn_in.keys_), nodes_(cbn_in.nodes_) {}
|
||||
|
||||
/** Destructor */
|
||||
virtual ~ChordalBayesNet() {}
|
||||
virtual ~GaussianBayesNet() {}
|
||||
|
||||
/**
|
||||
* optimize, i.e. return x = inv(R)*d
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include <colamd/colamd.h>
|
||||
|
||||
#include "ChordalBayesNet.h"
|
||||
#include "GaussianBayesNet.h"
|
||||
#include "FactorGraph-inl.h"
|
||||
#include "LinearFactorGraph.h"
|
||||
|
||||
|
@ -23,16 +23,16 @@ using namespace gtsam;
|
|||
template class FactorGraph<LinearFactor>;
|
||||
|
||||
/* ************************************************************************* */
|
||||
LinearFactorGraph::LinearFactorGraph(const ChordalBayesNet& CBN)
|
||||
LinearFactorGraph::LinearFactorGraph(const GaussianBayesNet& CBN)
|
||||
{
|
||||
setCBN(CBN);
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void LinearFactorGraph::setCBN(const ChordalBayesNet& CBN)
|
||||
void LinearFactorGraph::setCBN(const GaussianBayesNet& CBN)
|
||||
{
|
||||
clear();
|
||||
ChordalBayesNet::const_iterator it = CBN.begin();
|
||||
GaussianBayesNet::const_iterator it = CBN.begin();
|
||||
for(; it != CBN.end(); it++) {
|
||||
LinearFactor::shared_ptr lf(new LinearFactor(it->first, it->second));
|
||||
push_back(lf);
|
||||
|
@ -55,10 +55,10 @@ set<string> LinearFactorGraph::find_separator(const string& key) const
|
|||
// eliminate factor graph using the given (not necessarily complete)
|
||||
// ordering, yielding a chordal Bayes net and partially eliminated FG
|
||||
/* ************************************************************************* */
|
||||
ChordalBayesNet::shared_ptr
|
||||
GaussianBayesNet::shared_ptr
|
||||
LinearFactorGraph::eliminate_partially(const Ordering& ordering)
|
||||
{
|
||||
ChordalBayesNet::shared_ptr chordalBayesNet (new ChordalBayesNet()); // empty
|
||||
GaussianBayesNet::shared_ptr chordalBayesNet (new GaussianBayesNet()); // empty
|
||||
|
||||
BOOST_FOREACH(string key, ordering) {
|
||||
ConditionalGaussian::shared_ptr cg = eliminateOne<ConditionalGaussian>(key);
|
||||
|
@ -71,10 +71,10 @@ LinearFactorGraph::eliminate_partially(const Ordering& ordering)
|
|||
/* ************************************************************************* */
|
||||
/** eliminate factor graph in the given order, yielding a chordal Bayes net */
|
||||
/* ************************************************************************* */
|
||||
ChordalBayesNet::shared_ptr
|
||||
GaussianBayesNet::shared_ptr
|
||||
LinearFactorGraph::eliminate(const Ordering& ordering)
|
||||
{
|
||||
ChordalBayesNet::shared_ptr chordalBayesNet = eliminate_partially(ordering);
|
||||
GaussianBayesNet::shared_ptr chordalBayesNet = eliminate_partially(ordering);
|
||||
return chordalBayesNet;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ LinearFactorGraph::eliminate(const Ordering& ordering)
|
|||
VectorConfig LinearFactorGraph::optimize(const Ordering& ordering)
|
||||
{
|
||||
// eliminate all nodes in the given ordering -> chordal Bayes net
|
||||
ChordalBayesNet::shared_ptr chordalBayesNet = eliminate(ordering);
|
||||
GaussianBayesNet::shared_ptr chordalBayesNet = eliminate(ordering);
|
||||
|
||||
// calculate new configuration (using backsubstitution)
|
||||
boost::shared_ptr<VectorConfig> newConfig = chordalBayesNet->optimize();
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "LinearFactor.h"
|
||||
#include "VectorConfig.h"
|
||||
#include "FactorGraph.h"
|
||||
#include "ChordalBayesNet.h"
|
||||
#include "GaussianBayesNet.h"
|
||||
|
||||
namespace gtsam {
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace gtsam {
|
|||
/**
|
||||
* Constructor that receives a Chordal Bayes Net and returns a LinearFactorGraph
|
||||
*/
|
||||
LinearFactorGraph(const ChordalBayesNet& CBN);
|
||||
LinearFactorGraph(const GaussianBayesNet& CBN);
|
||||
|
||||
/** unnormalized error */
|
||||
double error(const VectorConfig& c) const {
|
||||
|
@ -59,7 +59,7 @@ namespace gtsam {
|
|||
* given a chordal bayes net, sets the linear factor graph identical to that CBN
|
||||
* FD: imperative !!
|
||||
*/
|
||||
void setCBN(const ChordalBayesNet& CBN);
|
||||
void setCBN(const GaussianBayesNet& CBN);
|
||||
|
||||
/**
|
||||
* find the separator, i.e. all the nodes that have at least one
|
||||
|
@ -71,13 +71,13 @@ namespace gtsam {
|
|||
* eliminate factor graph in place(!) in the given order, yielding
|
||||
* a chordal Bayes net
|
||||
*/
|
||||
boost::shared_ptr<ChordalBayesNet> eliminate(const Ordering& ordering);
|
||||
boost::shared_ptr<GaussianBayesNet> eliminate(const Ordering& ordering);
|
||||
|
||||
/**
|
||||
* Same as eliminate but allows for passing an incomplete ordering
|
||||
* that does not completely eliminate the graph
|
||||
*/
|
||||
boost::shared_ptr<ChordalBayesNet> eliminate_partially(const Ordering& ordering);
|
||||
boost::shared_ptr<GaussianBayesNet> eliminate_partially(const Ordering& ordering);
|
||||
|
||||
/**
|
||||
* optimize a linear factor graph
|
||||
|
|
|
@ -86,20 +86,20 @@ timeLinearFactor: LDFLAGS += -L.libs -lgtsam
|
|||
|
||||
# graphs
|
||||
sources += SymbolicFactorGraph.cpp LinearFactorGraph.cpp
|
||||
sources += SymbolicBayesChain.cpp ChordalBayesNet.cpp
|
||||
sources += SymbolicBayesNet.cpp GaussianBayesNet.cpp
|
||||
sources += ConstrainedNonlinearFactorGraph.cpp ConstrainedLinearFactorGraph.cpp
|
||||
check_PROGRAMS += testFactorgraph testSymbolicFactorGraph
|
||||
check_PROGRAMS += testLinearFactorGraph testNonlinearFactorGraph
|
||||
check_PROGRAMS += testChordalBayesNet testNonlinearOptimizer
|
||||
check_PROGRAMS += testSymbolicBayesChain testBayesTree
|
||||
check_PROGRAMS += testGaussianBayesNet testNonlinearOptimizer
|
||||
check_PROGRAMS += testSymbolicBayesNet testBayesTree
|
||||
check_PROGRAMS += testConstrainedNonlinearFactorGraph testConstrainedLinearFactorGraph
|
||||
testFactorgraph_SOURCES = testFactorgraph.cpp
|
||||
testSymbolicFactorGraph_SOURCES = $(example) testSymbolicFactorGraph.cpp
|
||||
testLinearFactorGraph_SOURCES = $(example) testLinearFactorGraph.cpp
|
||||
testNonlinearFactorGraph_SOURCES = $(example) testNonlinearFactorGraph.cpp
|
||||
testNonlinearOptimizer_SOURCES = $(example) testNonlinearOptimizer.cpp
|
||||
testSymbolicBayesChain_SOURCES = $(example) testSymbolicBayesChain.cpp
|
||||
testChordalBayesNet_SOURCES = $(example) testChordalBayesNet.cpp
|
||||
testSymbolicBayesNet_SOURCES = $(example) testSymbolicBayesNet.cpp
|
||||
testGaussianBayesNet_SOURCES = $(example) testGaussianBayesNet.cpp
|
||||
testBayesTree_SOURCES = $(example) testBayesTree.cpp
|
||||
testConstrainedNonlinearFactorGraph_SOURCES = $(example) testConstrainedNonlinearFactorGraph.cpp
|
||||
testConstrainedLinearFactorGraph_SOURCES = $(example) testConstrainedLinearFactorGraph.cpp
|
||||
|
@ -109,8 +109,8 @@ testSymbolicFactorGraph_LDADD = libgtsam.la
|
|||
testLinearFactorGraph_LDADD = libgtsam.la
|
||||
testNonlinearFactorGraph_LDADD = libgtsam.la
|
||||
testNonlinearOptimizer_LDADD = libgtsam.la
|
||||
testSymbolicBayesChain_LDADD = libgtsam.la
|
||||
testChordalBayesNet_LDADD = libgtsam.la
|
||||
testSymbolicBayesNet_LDADD = libgtsam.la
|
||||
testGaussianBayesNet_LDADD = libgtsam.la
|
||||
testBayesTree_LDADD = libgtsam.la
|
||||
testConstrainedNonlinearFactorGraph_LDADD = libgtsam.la
|
||||
testConstrainedLinearFactorGraph_LDADD = libgtsam.la
|
||||
|
@ -168,7 +168,7 @@ headers += $(sources:.cpp=.h)
|
|||
headers += FactorGraph.h FactorGraph-inl.h
|
||||
headers += NonlinearFactorGraph.h NonlinearFactorGraph-inl.h
|
||||
headers += NonlinearOptimizer.h NonlinearOptimizer-inl.h
|
||||
headers += BayesChain.h BayesChain-inl.h BayesTree.h BayesTree-inl.h
|
||||
headers += BayesNet.h BayesNet-inl.h BayesTree.h BayesTree-inl.h
|
||||
|
||||
# create both dynamic and static libraries
|
||||
AM_CXXFLAGS = -I$(boost) -fPIC
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @file SymbolicBayesChain.cpp
|
||||
* @file SymbolicBayesNet.cpp
|
||||
* @brief Chordal Bayes Net, the result of eliminating a factor graph
|
||||
* @author Frank Dellaert
|
||||
*/
|
||||
|
@ -10,15 +10,15 @@
|
|||
// trick from some reading group
|
||||
#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
|
||||
|
||||
#include "SymbolicBayesChain.h"
|
||||
#include "BayesChain-inl.h"
|
||||
#include "SymbolicBayesNet.h"
|
||||
#include "BayesNet-inl.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace gtsam {
|
||||
|
||||
// Explicitly instantiate so we don't have to include everywhere
|
||||
template class BayesChain<SymbolicConditional>;
|
||||
template class BayesNet<SymbolicConditional>;
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @file SymbolicBayesChain.h
|
||||
* @file SymbolicBayesNet.h
|
||||
* @brief Symbolic Chordal Bayes Net, the result of eliminating a factor graph
|
||||
* @author Frank Dellaert
|
||||
*/
|
||||
|
@ -13,7 +13,7 @@
|
|||
#include <boost/serialization/list.hpp>
|
||||
|
||||
#include "Testable.h"
|
||||
#include "BayesChain.h"
|
||||
#include "BayesNet.h"
|
||||
#include "FactorGraph.h"
|
||||
#include "SymbolicConditional.h"
|
||||
|
||||
|
@ -24,19 +24,19 @@ namespace gtsam {
|
|||
/**
|
||||
* Symbolic Bayes Chain, the (symbolic) result of eliminating a factor graph
|
||||
*/
|
||||
class SymbolicBayesChain: public BayesChain<SymbolicConditional> {
|
||||
class SymbolicBayesNet: public BayesNet<SymbolicConditional> {
|
||||
public:
|
||||
|
||||
/** convenience typename for a shared pointer to this class */
|
||||
typedef boost::shared_ptr<SymbolicBayesChain> shared_ptr;
|
||||
typedef boost::shared_ptr<SymbolicBayesNet> shared_ptr;
|
||||
|
||||
/**
|
||||
* Empty constructor
|
||||
*/
|
||||
SymbolicBayesChain() {}
|
||||
SymbolicBayesNet() {}
|
||||
|
||||
/** Destructor */
|
||||
virtual ~SymbolicBayesChain() {
|
||||
virtual ~SymbolicBayesNet() {
|
||||
}
|
||||
};
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
#include "Ordering.h"
|
||||
#include "FactorGraph-inl.h"
|
||||
#include "SymbolicFactorGraph.h"
|
||||
#include "SymbolicBayesChain.h"
|
||||
#include "SymbolicBayesNet.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -19,10 +19,10 @@ namespace gtsam {
|
|||
template class FactorGraph<SymbolicFactor>;
|
||||
|
||||
/* ************************************************************************* */
|
||||
SymbolicBayesChain::shared_ptr
|
||||
SymbolicBayesNet::shared_ptr
|
||||
SymbolicFactorGraph::eliminate(const Ordering& ordering)
|
||||
{
|
||||
SymbolicBayesChain::shared_ptr bayesChain (new SymbolicBayesChain());
|
||||
SymbolicBayesNet::shared_ptr bayesChain (new SymbolicBayesNet());
|
||||
|
||||
BOOST_FOREACH(string key, ordering) {
|
||||
SymbolicConditional::shared_ptr conditional = eliminateOne<SymbolicConditional>(key);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
namespace gtsam {
|
||||
|
||||
class SymbolicBayesChain;
|
||||
class SymbolicBayesNet;
|
||||
|
||||
/** Symbolic Factor Graph */
|
||||
class SymbolicFactorGraph: public FactorGraph<SymbolicFactor> {
|
||||
|
@ -44,7 +44,7 @@ namespace gtsam {
|
|||
* eliminate factor graph in place(!) in the given order, yielding
|
||||
* a chordal Bayes net
|
||||
*/
|
||||
boost::shared_ptr<SymbolicBayesChain> eliminate(const Ordering& ordering);
|
||||
boost::shared_ptr<SymbolicBayesNet> eliminate(const Ordering& ordering);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -66,13 +66,13 @@ class Ordering {
|
|||
void print() const;
|
||||
};
|
||||
|
||||
class ChordalBayesNet {
|
||||
ChordalBayesNet();
|
||||
class GaussianBayesNet {
|
||||
GaussianBayesNet();
|
||||
void insert(string name, ConditionalGaussian* node);
|
||||
ConditionalGaussian* get(string name);
|
||||
VectorConfig* optimize();
|
||||
void print() const;
|
||||
bool equals(const ChordalBayesNet& cbn) const;
|
||||
bool equals(const GaussianBayesNet& cbn) const;
|
||||
pair<Matrix,Vector> matrix() const;
|
||||
};
|
||||
|
||||
|
@ -89,7 +89,7 @@ class LinearFactorGraph {
|
|||
VectorConfig optimize(const Ordering& ordering);
|
||||
LinearFactor* combine_factors(string key);
|
||||
ConditionalGaussian* eliminate_one(string key);
|
||||
ChordalBayesNet* eliminate(const Ordering& ordering);
|
||||
GaussianBayesNet* eliminate(const Ordering& ordering);
|
||||
pair<Matrix,Vector> matrix(const Ordering& ordering) const;
|
||||
};
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ LinearFactorGraph createLinearFactorGraph()
|
|||
* 1 1 9
|
||||
* 1 5
|
||||
*/
|
||||
ChordalBayesNet createSmallChordalBayesNet()
|
||||
GaussianBayesNet createSmallGaussianBayesNet()
|
||||
{
|
||||
Matrix R11 = Matrix_(1,1,1.0), S12 = Matrix_(1,1,1.0);
|
||||
Matrix R22 = Matrix_(1,1,1.0);
|
||||
|
@ -202,7 +202,7 @@ ChordalBayesNet createSmallChordalBayesNet()
|
|||
ConditionalGaussian::shared_ptr
|
||||
x(new ConditionalGaussian(d1,R11,"y",S12)),
|
||||
y(new ConditionalGaussian(d2,R22));
|
||||
ChordalBayesNet cbn;
|
||||
GaussianBayesNet cbn;
|
||||
cbn.insert("x",x);
|
||||
cbn.insert("y",y);
|
||||
|
||||
|
@ -428,9 +428,9 @@ ConstrainedLinearFactorGraph createMultiConstraintGraph() {
|
|||
//}
|
||||
|
||||
/* ************************************************************************* */
|
||||
//ConstrainedChordalBayesNet createConstrainedChordalBayesNet()
|
||||
//ConstrainedGaussianBayesNet createConstrainedGaussianBayesNet()
|
||||
//{
|
||||
// ConstrainedChordalBayesNet cbn;
|
||||
// ConstrainedGaussianBayesNet cbn;
|
||||
// VectorConfig c = createConstrainedConfig();
|
||||
//
|
||||
// // add regular conditional gaussian - no parent
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace gtsam {
|
|||
/**
|
||||
* create small Chordal Bayes Net x <- y
|
||||
*/
|
||||
ChordalBayesNet createSmallChordalBayesNet();
|
||||
GaussianBayesNet createSmallGaussianBayesNet();
|
||||
|
||||
/**
|
||||
* Create really non-linear factor graph (cos/sin)
|
||||
|
|
|
@ -10,7 +10,7 @@ using namespace boost::assign;
|
|||
|
||||
#include <CppUnitLite/TestHarness.h>
|
||||
|
||||
#include "SymbolicBayesChain.h"
|
||||
#include "SymbolicBayesNet.h"
|
||||
#include "BayesTree-inl.h"
|
||||
#include "SmallExample.h"
|
||||
|
||||
|
@ -56,7 +56,7 @@ TEST( BayesTree, constructor )
|
|||
CHECK(assert_equal(expected_root,actual_root));
|
||||
|
||||
// Create from symbolic Bayes chain in which we want to discover cliques
|
||||
SymbolicBayesChain ASIA;
|
||||
SymbolicBayesNet ASIA;
|
||||
ASIA.insert("X", X);
|
||||
ASIA.insert("T", T);
|
||||
ASIA.insert("S", S);
|
||||
|
@ -87,7 +87,7 @@ TEST( BayesTree, smoother )
|
|||
ordering.push_back(symbol('x', t));
|
||||
|
||||
// eliminate using the "natural" ordering
|
||||
ChordalBayesNet::shared_ptr chordalBayesNet = smoother.eliminate(ordering);
|
||||
GaussianBayesNet::shared_ptr chordalBayesNet = smoother.eliminate(ordering);
|
||||
|
||||
// Create the Bayes tree
|
||||
BayesTree<ConditionalGaussian> bayesTree(*chordalBayesNet,false);
|
||||
|
@ -109,7 +109,7 @@ TEST( BayesTree, balanced_smoother )
|
|||
ordering += "x1","x3","x5","x7","x2","x6","x4";
|
||||
|
||||
// eliminate using a "nested dissection" ordering
|
||||
ChordalBayesNet::shared_ptr chordalBayesNet = smoother.eliminate(ordering);
|
||||
GaussianBayesNet::shared_ptr chordalBayesNet = smoother.eliminate(ordering);
|
||||
|
||||
// Create the Bayes tree
|
||||
BayesTree<ConditionalGaussian> bayesTree(*chordalBayesNet,false);
|
||||
|
|
|
@ -25,7 +25,7 @@ TEST( ConstrainedLinearFactorGraph, elimination1 )
|
|||
// eliminate x
|
||||
Ordering ord;
|
||||
ord.push_back("x");
|
||||
ChordalBayesNet::shared_ptr cbn = fg.eliminate(ord);
|
||||
GaussianBayesNet::shared_ptr cbn = fg.eliminate(ord);
|
||||
|
||||
// verify result of elimination
|
||||
// CBN of size 1, as we only eliminated X now
|
||||
|
@ -399,10 +399,10 @@ TEST( ConstrainedLinearFactorGraph, optimize_multi_constraint )
|
|||
// ord1.push_back("x0");
|
||||
// ord1.push_back("x1");
|
||||
//
|
||||
// ConstrainedChordalBayesNet::shared_ptr actual = fg.eliminate(ord1);
|
||||
// ConstrainedGaussianBayesNet::shared_ptr actual = fg.eliminate(ord1);
|
||||
//
|
||||
// // create an expected bayes net
|
||||
// ConstrainedChordalBayesNet::shared_ptr expected(new ConstrainedChordalBayesNet);
|
||||
// ConstrainedGaussianBayesNet::shared_ptr expected(new ConstrainedGaussianBayesNet);
|
||||
//
|
||||
// ConstrainedConditionalGaussian::shared_ptr d(new ConstrainedConditionalGaussian);//(c["x0"], "x0"));
|
||||
// expected->insert_df("x0", d);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* @file testChordalBayesNet.cpp
|
||||
* @brief Unit tests for ChordalBayesNet
|
||||
* @file testGaussianBayesNet.cpp
|
||||
* @brief Unit tests for GaussianBayesNet
|
||||
* @author Frank Dellaert
|
||||
*/
|
||||
|
||||
|
@ -17,13 +17,13 @@
|
|||
#include <boost/archive/text_iarchive.hpp>
|
||||
#endif //HAVE_BOOST_SERIALIZATION
|
||||
|
||||
#include "ChordalBayesNet.h"
|
||||
#include "GaussianBayesNet.h"
|
||||
#include "smallExample.h"
|
||||
|
||||
using namespace gtsam;
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( ChordalBayesNet, constructor )
|
||||
TEST( GaussianBayesNet, constructor )
|
||||
{
|
||||
// small Bayes Net x <- y
|
||||
// x y d
|
||||
|
@ -38,16 +38,16 @@ TEST( ChordalBayesNet, constructor )
|
|||
ConditionalGaussian x(d1,R11,"y",S12), y(d2,R22);
|
||||
|
||||
// check small example which uses constructor
|
||||
ChordalBayesNet cbn = createSmallChordalBayesNet();
|
||||
GaussianBayesNet cbn = createSmallGaussianBayesNet();
|
||||
CHECK( x.equals(*cbn["x"]) );
|
||||
CHECK( y.equals(*cbn["y"]) );
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( ChordalBayesNet, matrix )
|
||||
TEST( GaussianBayesNet, matrix )
|
||||
{
|
||||
// Create a test graph
|
||||
ChordalBayesNet cbn = createSmallChordalBayesNet();
|
||||
GaussianBayesNet cbn = createSmallGaussianBayesNet();
|
||||
|
||||
Matrix R; Vector d;
|
||||
boost::tie(R,d) = cbn.matrix(); // find matrix and RHS
|
||||
|
@ -63,10 +63,10 @@ TEST( ChordalBayesNet, matrix )
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( ChordalBayesNet, optimize )
|
||||
TEST( GaussianBayesNet, optimize )
|
||||
{
|
||||
// optimize small Bayes Net
|
||||
ChordalBayesNet cbn = createSmallChordalBayesNet();
|
||||
GaussianBayesNet cbn = createSmallGaussianBayesNet();
|
||||
boost::shared_ptr<VectorConfig> actual = cbn.optimize();
|
||||
|
||||
VectorConfig expected;
|
||||
|
@ -80,10 +80,10 @@ TEST( ChordalBayesNet, optimize )
|
|||
|
||||
/* ************************************************************************* */
|
||||
#ifdef HAVE_BOOST_SERIALIZATION
|
||||
TEST( ChordalBayesNet, serialize )
|
||||
TEST( GaussianBayesNet, serialize )
|
||||
{
|
||||
// //create a starting CBN
|
||||
// ChordalBayesNet cbn = createSmallChordalBayesNet();
|
||||
// GaussianBayesNet cbn = createSmallGaussianBayesNet();
|
||||
//
|
||||
// //serialize the CBN
|
||||
// std::ostringstream in_archive_stream;
|
||||
|
@ -117,7 +117,7 @@ TEST( ChordalBayesNet, serialize )
|
|||
// //deserialize the CBN
|
||||
// std::istringstream out_archive_stream(clean);
|
||||
// boost::archive::text_iarchive out_archive(out_archive_stream);
|
||||
// ChordalBayesNet output;
|
||||
// GaussianBayesNet output;
|
||||
// out_archive >> output;
|
||||
// CHECK(cbn.equals(output));
|
||||
}
|
|
@ -272,7 +272,7 @@ TEST( LinearFactorGraph, eliminateAll )
|
|||
Vector d3(2); d3(0) = 2.23607; d3(1) = -1.56525;
|
||||
ConditionalGaussian::shared_ptr cg3(new ConditionalGaussian(d3, R3, "l1", A21, "x1", A22));
|
||||
|
||||
ChordalBayesNet expected;
|
||||
GaussianBayesNet expected;
|
||||
expected.insert("x2", cg3);
|
||||
expected.insert("l1", cg2);
|
||||
expected.insert("x1", cg1);
|
||||
|
@ -281,7 +281,7 @@ TEST( LinearFactorGraph, eliminateAll )
|
|||
LinearFactorGraph fg1 = createLinearFactorGraph();
|
||||
Ordering ord1;
|
||||
ord1 += "x2","l1","x1";
|
||||
ChordalBayesNet::shared_ptr actual = fg1.eliminate(ord1);
|
||||
GaussianBayesNet::shared_ptr actual = fg1.eliminate(ord1);
|
||||
CHECK(assert_equal(expected,*actual,tol));
|
||||
}
|
||||
|
||||
|
@ -311,7 +311,7 @@ TEST( LinearFactorGraph, copying )
|
|||
// now eliminate the copy
|
||||
Ordering ord1;
|
||||
ord1 += "x2","l1","x1";
|
||||
ChordalBayesNet::shared_ptr actual1 = copy.eliminate(ord1);
|
||||
GaussianBayesNet::shared_ptr actual1 = copy.eliminate(ord1);
|
||||
|
||||
// Create the same graph, but not by copying
|
||||
LinearFactorGraph expected = createLinearFactorGraph();
|
||||
|
@ -350,7 +350,7 @@ TEST( LinearFactorGraph, matrix )
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( LinearFactorGraph, CONSTRUCTOR_ChordalBayesNet )
|
||||
TEST( LinearFactorGraph, CONSTRUCTOR_GaussianBayesNet )
|
||||
{
|
||||
|
||||
LinearFactorGraph fg = createLinearFactorGraph();
|
||||
|
@ -358,9 +358,9 @@ TEST( LinearFactorGraph, CONSTRUCTOR_ChordalBayesNet )
|
|||
// render with a given ordering
|
||||
Ordering ord;
|
||||
ord += "x2","l1","x1";
|
||||
ChordalBayesNet::shared_ptr CBN = fg.eliminate(ord);
|
||||
GaussianBayesNet::shared_ptr CBN = fg.eliminate(ord);
|
||||
LinearFactorGraph fg2(*CBN);
|
||||
ChordalBayesNet::shared_ptr CBN2 = fg2.eliminate(ord);
|
||||
GaussianBayesNet::shared_ptr CBN2 = fg2.eliminate(ord);
|
||||
|
||||
CHECK(CBN->equals(*CBN2));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @file testSymbolicBayesChain.cpp
|
||||
* @file testSymbolicBayesNet.cpp
|
||||
* @brief Unit tests for a symbolic Bayes chain
|
||||
* @author Frank Dellaert
|
||||
*/
|
||||
|
@ -11,21 +11,21 @@ using namespace boost::assign;
|
|||
#include <CppUnitLite/TestHarness.h>
|
||||
|
||||
#include "smallExample.h"
|
||||
#include "SymbolicBayesChain.h"
|
||||
#include "SymbolicBayesNet.h"
|
||||
#include "SymbolicFactorGraph.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace gtsam;
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( SymbolicBayesChain, constructor )
|
||||
TEST( SymbolicBayesNet, constructor )
|
||||
{
|
||||
// Create manually
|
||||
SymbolicConditional::shared_ptr
|
||||
x2(new SymbolicConditional("l1", "x1")),
|
||||
l1(new SymbolicConditional("x1")),
|
||||
x1(new SymbolicConditional());
|
||||
SymbolicBayesChain expected;
|
||||
SymbolicBayesNet expected;
|
||||
expected.insert("x2",x2);
|
||||
expected.insert("l1",l1);
|
||||
expected.insert("x1",x1);
|
||||
|
@ -37,7 +37,7 @@ TEST( SymbolicBayesChain, constructor )
|
|||
// eliminate it
|
||||
Ordering ordering;
|
||||
ordering += "x2","l1","x1";
|
||||
SymbolicBayesChain::shared_ptr actual = fg.eliminate(ordering);
|
||||
SymbolicBayesNet::shared_ptr actual = fg.eliminate(ordering);
|
||||
|
||||
CHECK(assert_equal(expected, *actual));
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* @file testSymbolicBayesChain.cpp
|
||||
* @brief Unit tests for a symbolic Bayes chain
|
||||
* @file testSymbolicFactorGraph.cpp
|
||||
* @brief Unit tests for a symbolic Factor Graph
|
||||
* @author Frank Dellaert
|
||||
*/
|
||||
|
||||
|
@ -11,7 +11,7 @@ using namespace boost::assign;
|
|||
|
||||
#include "smallExample.h"
|
||||
#include "SymbolicFactorGraph.h"
|
||||
#include "SymbolicBayesChain.h"
|
||||
#include "SymbolicBayesNet.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace gtsam;
|
||||
|
@ -127,7 +127,7 @@ TEST( LinearFactorGraph, eliminate )
|
|||
SymbolicConditional::shared_ptr l1(new SymbolicConditional("x1"));
|
||||
SymbolicConditional::shared_ptr x1(new SymbolicConditional());
|
||||
|
||||
SymbolicBayesChain expected;
|
||||
SymbolicBayesNet expected;
|
||||
expected.insert("x2", x2);
|
||||
expected.insert("l1", l1);
|
||||
expected.insert("x1", x1);
|
||||
|
@ -139,7 +139,7 @@ TEST( LinearFactorGraph, eliminate )
|
|||
// eliminate it
|
||||
Ordering ordering;
|
||||
ordering += "x2","l1","x1";
|
||||
SymbolicBayesChain::shared_ptr actual = fg.eliminate(ordering);
|
||||
SymbolicBayesNet::shared_ptr actual = fg.eliminate(ordering);
|
||||
|
||||
CHECK(assert_equal(expected,*actual));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue