operator[] to retrieve clique
parent
e1716a39cd
commit
cd313e2f82
|
@ -102,10 +102,7 @@ namespace gtsam {
|
|||
|
||||
// otherwise, find the parent clique
|
||||
string parent = parents.front();
|
||||
typename Nodes::const_iterator it = nodes_.find(parent);
|
||||
if (it == nodes_.end()) throw(invalid_argument(
|
||||
"BayesTree::insert('"+key+"'): parent '" + parent + "' not yet inserted"));
|
||||
node_ptr parent_clique = it->second;
|
||||
node_ptr parent_clique = (*this)[parent];
|
||||
|
||||
// if the parents and parent clique have the same size, add to parent clique
|
||||
if (parent_clique->size() == parents.size()) {
|
||||
|
@ -130,13 +127,8 @@ namespace gtsam {
|
|||
template<class Factor>
|
||||
boost::shared_ptr<Conditional> BayesTree<Conditional>::marginal(const string& key) const {
|
||||
|
||||
// find the clique to which key belongs
|
||||
typename Nodes::const_iterator it = nodes_.find(key);
|
||||
if (it == nodes_.end()) throw(invalid_argument(
|
||||
"BayesTree::marginal('"+key+"'): key not found"));
|
||||
|
||||
// get clique containing key, and remove all factors below key
|
||||
node_ptr clique = it->second;
|
||||
node_ptr clique = (*this)[key];
|
||||
Ordering ordering = clique->ordering();
|
||||
FactorGraph<Factor> graph(*clique);
|
||||
while(ordering.front()!=key) {
|
||||
|
|
|
@ -93,6 +93,15 @@ namespace gtsam {
|
|||
/** return root clique */
|
||||
boost::shared_ptr<BayesNet<Conditional> > root() const {return root_;}
|
||||
|
||||
/** find the clique to which key belongs */
|
||||
node_ptr operator[](const std::string& key) const {
|
||||
typename Nodes::const_iterator it = nodes_.find(key);
|
||||
if (it == nodes_.end())
|
||||
throw(std::invalid_argument("BayesTree::operator['"+ key + "'): key not found"));
|
||||
node_ptr clique = it->second;
|
||||
return clique;
|
||||
}
|
||||
|
||||
/** return marginal on any variable */
|
||||
template<class Factor>
|
||||
boost::shared_ptr<Conditional> marginal(const std::string& key) const;
|
||||
|
|
Loading…
Reference in New Issue