gtsam/cpp/GaussianBayesTree.cpp

46 lines
1.5 KiB
C++
Raw Normal View History

2009-12-10 06:02:50 +08:00
/**
* @file GaussianBayesTree
* @brief Bayes Tree is a tree of cliques of a Bayes Chain
* @author Michael Kaess
*/
#include <boost/foreach.hpp>
#include "GaussianBayesTree.h"
#include "VectorConfig.h"
using namespace std;
using namespace gtsam;
// Explicitly instantiate so we don't have to include everywhere
#include "BayesTree-inl.h"
template class BayesTree<GaussianConditional>;
namespace gtsam {
/* ************************************************************************* */
2009-12-10 06:15:38 +08:00
void optimize(const GaussianBayesTree::sharedClique& clique, VectorConfig& result) {
2009-12-10 06:02:50 +08:00
// parents are assumed to already be solved and available in result
2009-12-10 06:15:38 +08:00
GaussianBayesTree::Clique::const_reverse_iterator it;
2009-12-11 01:00:11 +08:00
for (it = clique->rbegin(); it!=clique->rend(); it++) {
2009-12-10 06:15:38 +08:00
GaussianConditional::shared_ptr cg = *it;
2009-12-10 06:02:50 +08:00
Vector x = cg->solve(result); // Solve for that variable
2009-12-11 01:00:11 +08:00
result.insert(cg->key(), x); // store result in partial solution
2009-12-10 06:02:50 +08:00
}
BOOST_FOREACH(GaussianBayesTree::sharedClique child, clique->children_) {
2009-12-11 01:00:11 +08:00
// list<GaussianBayesTree::Clique::shared_ptr>::const_iterator child;
// for (child = clique->children_.begin(); child != clique->children_.end(); child++) {
2009-12-10 06:02:50 +08:00
optimize(child, result);
}
}
/* ************************************************************************* */
2009-12-10 06:15:38 +08:00
VectorConfig optimize(const GaussianBayesTree& bayesTree) {
2009-12-10 06:02:50 +08:00
VectorConfig result;
// starting from the root, call optimize on each conditional
optimize(bayesTree.root(), result);
2009-12-11 01:00:11 +08:00
return result;
2009-12-10 06:02:50 +08:00
}
} /// namespace gtsam