Formatting and documentation
parent
9cab332190
commit
8d00897abf
|
|
@ -23,64 +23,71 @@
|
||||||
#include <gtsam/inference/JunctionTree-inl.h>
|
#include <gtsam/inference/JunctionTree-inl.h>
|
||||||
#include <gtsam/inference/BayesNet-inl.h>
|
#include <gtsam/inference/BayesNet-inl.h>
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class FACTOR, class JUNCTIONTREE>
|
template<class F, class JT>
|
||||||
GenericMultifrontalSolver<FACTOR, JUNCTIONTREE>::GenericMultifrontalSolver(const FactorGraph<FACTOR>& factorGraph) :
|
GenericMultifrontalSolver<F, JT>::GenericMultifrontalSolver(
|
||||||
structure_(new VariableIndex(factorGraph)), junctionTree_(new JUNCTIONTREE(factorGraph, *structure_)) {}
|
const FactorGraph<F>& graph) :
|
||||||
|
structure_(new VariableIndex(graph)), junctionTree_(
|
||||||
|
new JT(graph, *structure_)) {
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class FACTOR, class JUNCTIONTREE>
|
template<class F, class JT>
|
||||||
GenericMultifrontalSolver<FACTOR, JUNCTIONTREE>::GenericMultifrontalSolver(
|
GenericMultifrontalSolver<F, JT>::GenericMultifrontalSolver(
|
||||||
const typename FactorGraph<FACTOR>::shared_ptr& factorGraph, const VariableIndex::shared_ptr& variableIndex) :
|
const typename FactorGraph<F>::shared_ptr& graph,
|
||||||
structure_(variableIndex), junctionTree_(new JUNCTIONTREE(*factorGraph, *structure_)) {}
|
const VariableIndex::shared_ptr& variableIndex) :
|
||||||
|
structure_(variableIndex), junctionTree_(new JT(*graph, *structure_)) {
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class FACTOR, class JUNCTIONTREE>
|
template<class F, class JT>
|
||||||
void GenericMultifrontalSolver<FACTOR, JUNCTIONTREE>::replaceFactors(const typename FactorGraph<FACTOR>::shared_ptr& factorGraph) {
|
void GenericMultifrontalSolver<F, JT>::replaceFactors(
|
||||||
junctionTree_.reset(new JUNCTIONTREE(*factorGraph, *structure_));
|
const typename FactorGraph<F>::shared_ptr& graph) {
|
||||||
}
|
junctionTree_.reset(new JT(*graph, *structure_));
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class FACTOR, class JUNCTIONTREE>
|
template<class F, class JT>
|
||||||
typename JUNCTIONTREE::BayesTree::shared_ptr GenericMultifrontalSolver<
|
typename JT::BayesTree::shared_ptr GenericMultifrontalSolver<F, JT>::eliminate(
|
||||||
FACTOR, JUNCTIONTREE>::eliminate(
|
typename FactorGraph<F>::Eliminate function) const {
|
||||||
typename FactorGraph<FACTOR>::Eliminate function) const {
|
|
||||||
typename JUNCTIONTREE::BayesTree::shared_ptr bayesTree(
|
|
||||||
new typename JUNCTIONTREE::BayesTree);
|
|
||||||
bayesTree->insert(junctionTree_->eliminate(function));
|
|
||||||
return bayesTree;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
// eliminate junction tree, returns pointer to root
|
||||||
template<class FACTOR, class JUNCTIONTREE>
|
typename JT::BayesTree::sharedClique root = junctionTree_->eliminate(function);
|
||||||
typename FactorGraph<FACTOR>::shared_ptr GenericMultifrontalSolver<FACTOR,
|
|
||||||
JUNCTIONTREE>::jointFactorGraph(const std::vector<Index>& js,
|
|
||||||
Eliminate function) const {
|
|
||||||
|
|
||||||
// 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(
|
// return the Bayes tree
|
||||||
"*MultifrontalSolver::joint(js) currently can only compute joint marginals\n"
|
return bayesTree;
|
||||||
"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 FactorGraph<F>::shared_ptr GenericMultifrontalSolver<F, JT>::jointFactorGraph(
|
||||||
|
const std::vector<Index>& js, Eliminate function) const {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
// We currently have code written only for computing the
|
||||||
template<class FACTOR, class JUNCTIONTREE>
|
|
||||||
typename FACTOR::shared_ptr GenericMultifrontalSolver<FACTOR, JUNCTIONTREE>::marginalFactor(
|
if (js.size() != 2) throw domain_error(
|
||||||
Index j, Eliminate function) const {
|
"*MultifrontalSolver::joint(js) currently can only compute joint marginals\n"
|
||||||
return eliminate(function)->marginalFactor(j, function);
|
"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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue