Implemented [equals] using binary predicate and STL's equal
parent
b9ceca7dc6
commit
e1f14b34c3
|
@ -33,7 +33,9 @@ namespace gtsam {
|
||||||
template<class Conditional>
|
template<class Conditional>
|
||||||
bool BayesTree<Conditional>::equals(const BayesTree<Conditional>& other,
|
bool BayesTree<Conditional>::equals(const BayesTree<Conditional>& other,
|
||||||
double tol) const {
|
double tol) const {
|
||||||
return false;
|
return size()==other.size() &&
|
||||||
|
equal(nodeMap_.begin(),nodeMap_.end(),other.nodeMap_.begin()) &&
|
||||||
|
equal(nodes_.begin(),nodes_.end(),other.nodes_.begin(),equals_star<Node>);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace gtsam {
|
||||||
private:
|
private:
|
||||||
typedef boost::shared_ptr<Conditional> cond_ptr;
|
typedef boost::shared_ptr<Conditional> cond_ptr;
|
||||||
std::list<std::string> keys_; /** frontal keys */
|
std::list<std::string> keys_; /** frontal keys */
|
||||||
std::list<cond_ptr> nodes_; /** conditionals */
|
std::list<cond_ptr> conditionals_; /** conditionals */
|
||||||
std::list<std::string> separator_; /** separator keys */
|
std::list<std::string> separator_; /** separator keys */
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -50,13 +50,14 @@ namespace gtsam {
|
||||||
|
|
||||||
/** check equality. TODO: only keys */
|
/** check equality. TODO: only keys */
|
||||||
bool equals(const Front<Conditional>& other, double tol = 1e-9) const {
|
bool equals(const Front<Conditional>& other, double tol = 1e-9) const {
|
||||||
return (keys_ == other.keys_);
|
return (keys_ == other.keys_) &&
|
||||||
|
equal(conditionals_.begin(),conditionals_.end(),other.conditionals_.begin(),equals_star<Conditional>);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** add a frontal node */
|
/** add a frontal node */
|
||||||
void add(std::string key, cond_ptr conditional) {
|
void add(std::string key, cond_ptr conditional) {
|
||||||
keys_.push_front(key);
|
keys_.push_front(key);
|
||||||
nodes_.push_front(conditional);
|
conditionals_.push_front(conditional);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** return size of the clique */
|
/** return size of the clique */
|
||||||
|
@ -122,6 +123,9 @@ namespace gtsam {
|
||||||
/** insert a new conditional */
|
/** insert a new conditional */
|
||||||
void insert(std::string key, conditional_ptr conditional);
|
void insert(std::string key, conditional_ptr conditional);
|
||||||
|
|
||||||
|
/** number of cliques */
|
||||||
|
inline size_t size() const { return nodes_.size();}
|
||||||
|
|
||||||
/** return root clique */
|
/** return root clique */
|
||||||
const Front<Conditional>& root() const {return *(nodes_[0]);}
|
const Front<Conditional>& root() const {return *(nodes_[0]);}
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,9 @@ TEST( BayesTree, Front )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST( BayesTree, insert )
|
TEST( BayesTree, constructor )
|
||||||
{
|
{
|
||||||
// Insert
|
// Create using insert
|
||||||
BayesTree<SymbolicConditional> bayesTree;
|
BayesTree<SymbolicConditional> bayesTree;
|
||||||
bayesTree.insert("B",B);
|
bayesTree.insert("B",B);
|
||||||
bayesTree.insert("L",L);
|
bayesTree.insert("L",L);
|
||||||
|
@ -44,33 +44,25 @@ TEST( BayesTree, insert )
|
||||||
bayesTree.insert("S",S);
|
bayesTree.insert("S",S);
|
||||||
bayesTree.insert("T",T);
|
bayesTree.insert("T",T);
|
||||||
bayesTree.insert("X",X);
|
bayesTree.insert("X",X);
|
||||||
//bayesTree.print("bayesTree");
|
|
||||||
|
|
||||||
//LONGS_EQUAL(1,bayesTree.size());
|
// Check Size
|
||||||
|
LONGS_EQUAL(4,bayesTree.size());
|
||||||
|
|
||||||
// Check root
|
// Check root
|
||||||
Front<SymbolicConditional> expected_root("B",B);
|
Front<SymbolicConditional> expected_root("B",B);
|
||||||
//CHECK(assert_equal(expected_root,bayesTree.root()));
|
expected_root.add("L",L);
|
||||||
}
|
expected_root.add("E",E);
|
||||||
|
Front<SymbolicConditional> actual_root = bayesTree.root();
|
||||||
|
CHECK(assert_equal(expected_root,actual_root));
|
||||||
|
|
||||||
/* ************************************************************************* */
|
// Create from symbolic Bayes chain in which we want to discover cliques
|
||||||
TEST( BayesTree, constructor )
|
|
||||||
{
|
|
||||||
// Create Symbolic Bayes Chain in which we want to discover cliques
|
|
||||||
map<string, SymbolicConditional::shared_ptr> nodes;
|
map<string, SymbolicConditional::shared_ptr> nodes;
|
||||||
insert(nodes)("B",B)("L",L)("E",E)("S",S)("T",T)("X",X);
|
insert(nodes)("B",B)("L",L)("E",E)("S",S)("T",T)("X",X);
|
||||||
SymbolicBayesChain ASIA(nodes);
|
SymbolicBayesChain ASIA(nodes);
|
||||||
|
BayesTree<SymbolicConditional> bayesTree2(ASIA);
|
||||||
|
|
||||||
// Create Bayes Tree from Symbolic Bayes Chain
|
// Check whether the same
|
||||||
BayesTree<SymbolicConditional> bayesTree(ASIA);
|
//CHECK(assert_equal(bayesTree,bayesTree2));
|
||||||
bayesTree.insert("B",B);
|
|
||||||
//bayesTree.print("bayesTree");
|
|
||||||
|
|
||||||
//LONGS_EQUAL(1,bayesTree.size());
|
|
||||||
|
|
||||||
// Check root
|
|
||||||
Front<SymbolicConditional> expected_root("B",B);
|
|
||||||
//CHECK(assert_equal(expected_root,bayesTree.root()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue