Formatting and documentation

release/4.3a0
Frank Dellaert 2011-09-04 03:34:58 +00:00
parent 9cab332190
commit 8d00897abf
1 changed files with 53 additions and 46 deletions

View File

@ -23,64 +23,71 @@
#include <gtsam/inference/JunctionTree-inl.h>
#include <gtsam/inference/BayesNet-inl.h>
#include <boost/foreach.hpp>
using namespace std;
namespace gtsam {
/* ************************************************************************* */
template<class FACTOR, class JUNCTIONTREE>
GenericMultifrontalSolver<FACTOR, JUNCTIONTREE>::GenericMultifrontalSolver(const FactorGraph<FACTOR>& factorGraph) :
structure_(new VariableIndex(factorGraph)), junctionTree_(new JUNCTIONTREE(factorGraph, *structure_)) {}
/* ************************************************************************* */
template<class F, class JT>
GenericMultifrontalSolver<F, JT>::GenericMultifrontalSolver(
const FactorGraph<F>& graph) :
structure_(new VariableIndex(graph)), junctionTree_(
new JT(graph, *structure_)) {
}
/* ************************************************************************* */
template<class FACTOR, class JUNCTIONTREE>
GenericMultifrontalSolver<FACTOR, JUNCTIONTREE>::GenericMultifrontalSolver(
const typename FactorGraph<FACTOR>::shared_ptr& factorGraph, const VariableIndex::shared_ptr& variableIndex) :
structure_(variableIndex), junctionTree_(new JUNCTIONTREE(*factorGraph, *structure_)) {}
/* ************************************************************************* */
template<class F, class JT>
GenericMultifrontalSolver<F, JT>::GenericMultifrontalSolver(
const typename FactorGraph<F>::shared_ptr& graph,
const VariableIndex::shared_ptr& variableIndex) :
structure_(variableIndex), junctionTree_(new JT(*graph, *structure_)) {
}
/* ************************************************************************* */
template<class FACTOR, class JUNCTIONTREE>
void GenericMultifrontalSolver<FACTOR, JUNCTIONTREE>::replaceFactors(const typename FactorGraph<FACTOR>::shared_ptr& factorGraph) {
junctionTree_.reset(new JUNCTIONTREE(*factorGraph, *structure_));
}
/* ************************************************************************* */
template<class F, class JT>
void GenericMultifrontalSolver<F, JT>::replaceFactors(
const typename FactorGraph<F>::shared_ptr& graph) {
junctionTree_.reset(new JT(*graph, *structure_));
}
/* ************************************************************************* */
template<class FACTOR, class JUNCTIONTREE>
typename JUNCTIONTREE::BayesTree::shared_ptr GenericMultifrontalSolver<
FACTOR, JUNCTIONTREE>::eliminate(
typename FactorGraph<FACTOR>::Eliminate function) const {
typename JUNCTIONTREE::BayesTree::shared_ptr bayesTree(
new typename JUNCTIONTREE::BayesTree);
bayesTree->insert(junctionTree_->eliminate(function));
return bayesTree;
}
/* ************************************************************************* */
template<class F, class JT>
typename JT::BayesTree::shared_ptr GenericMultifrontalSolver<F, JT>::eliminate(
typename FactorGraph<F>::Eliminate function) const {
/* ************************************************************************* */
template<class FACTOR, class JUNCTIONTREE>
typename FactorGraph<FACTOR>::shared_ptr GenericMultifrontalSolver<FACTOR,
JUNCTIONTREE>::jointFactorGraph(const std::vector<Index>& js,
Eliminate function) const {
// eliminate junction tree, returns pointer to root
typename JT::BayesTree::sharedClique root = junctionTree_->eliminate(function);
// We currently have code written only for computing the
// create an empty Bayes tree and insert root clique
typename JT::BayesTree::shared_ptr bayesTree(new typename JT::BayesTree);
bayesTree->insert(root);
if (js.size() != 2) throw domain_error(
"*MultifrontalSolver::joint(js) currently can only compute joint marginals\n"
"for exactly two variables. You can call marginal to compute the\n"
"marginal for one variable. *SequentialSolver::joint(js) can compute the\n"
"joint marginal over any number of variables, so use that if necessary.\n");
// return the Bayes tree
return bayesTree;
}
return eliminate(function)->joint(js[0], js[1], function);
}
/* ************************************************************************* */
template<class F, class JT>
typename FactorGraph<F>::shared_ptr GenericMultifrontalSolver<F, JT>::jointFactorGraph(
const std::vector<Index>& js, Eliminate function) const {
/* ************************************************************************* */
template<class FACTOR, class JUNCTIONTREE>
typename FACTOR::shared_ptr GenericMultifrontalSolver<FACTOR, JUNCTIONTREE>::marginalFactor(
Index j, Eliminate function) const {
return eliminate(function)->marginalFactor(j, function);
}
// We currently have code written only for computing the
if (js.size() != 2) throw domain_error(
"*MultifrontalSolver::joint(js) currently can only compute joint marginals\n"
"for exactly two variables. You can call marginal to compute the\n"
"marginal for one variable. *SequentialSolver::joint(js) can compute the\n"
"joint marginal over any number of variables, so use that if necessary.\n");
return eliminate(function)->joint(js[0], js[1], function);
}
/* ************************************************************************* */
template<class F, class JT>
typename F::shared_ptr GenericMultifrontalSolver<F, JT>::marginalFactor(
Index j, Eliminate function) const {
return eliminate(function)->marginalFactor(j, function);
}
}