Some template magic and boost:tie cleared up the compile issues in removePath
parent
4449cfd30c
commit
7ce62f1626
|
@ -197,7 +197,7 @@ namespace gtsam {
|
||||||
BOOST_FOREACH(sharedClique child, clique->children_)
|
BOOST_FOREACH(sharedClique child, clique->children_)
|
||||||
child->parent_.reset();
|
child->parent_.reset();
|
||||||
|
|
||||||
BOOST_FOREACH(std::string key, clique->ordering())
|
BOOST_FOREACH(string key, clique->ordering())
|
||||||
nodes_.erase(key);
|
nodes_.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ namespace gtsam {
|
||||||
template<class Conditional>
|
template<class Conditional>
|
||||||
template<class Factor>
|
template<class Factor>
|
||||||
FactorGraph<Factor>
|
FactorGraph<Factor>
|
||||||
BayesTree<Conditional>::joint(const std::string& key1, const std::string& key2) const {
|
BayesTree<Conditional>::joint(const string& key1, const string& key2) const {
|
||||||
|
|
||||||
// get clique C1 and C2
|
// get clique C1 and C2
|
||||||
sharedClique C1 = (*this)[key1], C2 = (*this)[key2];
|
sharedClique C1 = (*this)[key1], C2 = (*this)[key2];
|
||||||
|
@ -334,7 +334,7 @@ namespace gtsam {
|
||||||
template<class Conditional>
|
template<class Conditional>
|
||||||
template<class Factor>
|
template<class Factor>
|
||||||
BayesNet<Conditional>
|
BayesNet<Conditional>
|
||||||
BayesTree<Conditional>::jointBayesNet(const std::string& key1, const std::string& key2) const {
|
BayesTree<Conditional>::jointBayesNet(const string& key1, const string& key2) const {
|
||||||
|
|
||||||
// calculate marginal as a factor graph
|
// calculate marginal as a factor graph
|
||||||
FactorGraph<Factor> fg = this->joint<Factor>(key1,key2);
|
FactorGraph<Factor> fg = this->joint<Factor>(key1,key2);
|
||||||
|
@ -344,32 +344,33 @@ namespace gtsam {
|
||||||
ordering += key1, key2;
|
ordering += key1, key2;
|
||||||
return eliminate<Factor,Conditional>(fg,ordering);
|
return eliminate<Factor,Conditional>(fg,ordering);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class Conditional>
|
template<class Conditional>
|
||||||
template<class Factor>
|
template<class Factor>
|
||||||
std::pair<FactorGraph<Factor>, std::list<sharedClique> >
|
pair<FactorGraph<Factor>, list<typename BayesTree<Conditional>::sharedClique> >
|
||||||
BayesTree<Conditional>::removePath(sharedClique clique) {
|
BayesTree<Conditional>::removePath(sharedClique clique) {
|
||||||
|
|
||||||
// base case is NULL, return empty factor graph
|
FactorGraph<Factor> factors;
|
||||||
if (clique==NULL) {
|
|
||||||
list<sharedClique> orphans;
|
list<sharedClique> orphans;
|
||||||
return make_pair<FactorGraph<Factor>(), orphans>;
|
|
||||||
}
|
// base case is NULL, if so we do nothing and return empties above
|
||||||
|
if (clique!=NULL) {
|
||||||
|
|
||||||
// remove path above me
|
// remove path above me
|
||||||
std::pair<FactorGraph<Factor>, std::list<sharedClique> > factors_orphans = removePath<Factor>(clique->parent_);
|
boost::tie(factors,orphans) = removePath<Factor>(clique->parent_);
|
||||||
|
|
||||||
// add children to list of orphans
|
// add children to list of orphans
|
||||||
factors_orphans.second.insert(factors_orphans.second.begin(), clique->children_.begin(), clique->children_.end());
|
orphans.insert(orphans.begin(), clique->children_.begin(), clique->children_.end());
|
||||||
|
|
||||||
// remove me and add my factors
|
// remove me and add my factors
|
||||||
removeClique(clique);
|
removeClique(clique);
|
||||||
factors.push_back(*clique);
|
factors.push_back(*clique);
|
||||||
|
|
||||||
return factors_orphans;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
return make_pair(factors,orphans);
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,11 +154,11 @@ namespace gtsam {
|
||||||
/** return joint on two variables as a BayesNet */
|
/** return joint on two variables as a BayesNet */
|
||||||
template<class Factor>
|
template<class Factor>
|
||||||
BayesNet<Conditional> jointBayesNet(const std::string& key1, const std::string& key2) const;
|
BayesNet<Conditional> jointBayesNet(const std::string& key1, const std::string& key2) const;
|
||||||
#if 0
|
|
||||||
/** Remove path from clique to root and return that path as factors plus a list of orphaned subtree roots */
|
/** Remove path from clique to root and return that path as factors plus a list of orphaned subtree roots */
|
||||||
template<class Factor>
|
template<class Factor>
|
||||||
std::pair<FactorGraph<Factor>, std::list<sharedClique> > removePath(sharedClique clique);
|
std::pair<FactorGraph<Factor>, std::list<sharedClique> > removePath(sharedClique clique);
|
||||||
#endif
|
|
||||||
}; // BayesTree
|
}; // BayesTree
|
||||||
|
|
||||||
} /// namespace gtsam
|
} /// namespace gtsam
|
||||||
|
|
|
@ -331,18 +331,18 @@ TEST( BayesTree, removePath )
|
||||||
expected.push_factor("A","B");
|
expected.push_factor("A","B");
|
||||||
expected.push_factor("A");
|
expected.push_factor("A");
|
||||||
expected.push_factor("A","C");
|
expected.push_factor("A","C");
|
||||||
#if 0
|
|
||||||
std::pair<FactorGraph<Factor>, std::list<sharedClique> > actual =
|
FactorGraph<SymbolicFactor> factors;
|
||||||
bayesTree.removePath<SymbolicFactor>(bayesTree["C"]);
|
list<SymbolicBayesTree::sharedClique> orphans;
|
||||||
CHECK(assert_equal(expected, actual.first));
|
boost::tie(factors,orphans) = bayesTree.removePath<SymbolicFactor>(bayesTree["C"]);
|
||||||
|
CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected, factors));
|
||||||
|
|
||||||
// remove E: factor graph with EB; E|B removed from second orphan tree
|
// remove E: factor graph with EB; E|B removed from second orphan tree
|
||||||
SymbolicFactorGraph expected3;
|
SymbolicFactorGraph expected3;
|
||||||
expected3.push_factor("B","E");
|
expected3.push_factor("B","E");
|
||||||
|
|
||||||
actual = bayesTree.removePath<SymbolicFactor>(bayesTree["E"]);
|
boost::tie(factors,orphans) = bayesTree.removePath<SymbolicFactor>(bayesTree["E"]);
|
||||||
CHECK(assert_equal(expected3, actual.first));
|
CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected3, factors));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue