/* ---------------------------------------------------------------------------- * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) * See LICENSE for the license information * -------------------------------------------------------------------------- */ /** * GaussianJunctionTree.cpp * Created on: Jul 12, 2010 * @author Kai Ni * @author Frank Dellaert * @brief: the Gaussian junction tree */ #include #include #include #include #include namespace gtsam { // explicit template instantiation template class JunctionTree; template class ClusterTree; using namespace std; /* ************************************************************************* */ /** * GaussianJunctionTree */ void GaussianJunctionTree::btreeBackSubstitute(const boost::shared_ptr& current, VectorValues& config) const { // solve the bayes net in the current node GaussianBayesNet::const_reverse_iterator it = current->rbegin(); for (; it!=current->rend(); ++it) { Vector x = (*it)->solve(config); // Solve for that variable config[(*it)->key()] = x; // store result in partial solution } // solve the bayes nets in the child nodes BOOST_FOREACH(const BayesTree::sharedClique& child, current->children()) { btreeBackSubstitute(child, config); } } /* ************************************************************************* */ void countDims(const boost::shared_ptr::Clique>& clique, vector& dims) { BOOST_FOREACH(const boost::shared_ptr& cond, *clique) { // There should be no two conditionals on the same variable assert(dims[cond->key()] == 0); dims[cond->key()] = cond->dim(); } BOOST_FOREACH(const boost::shared_ptr::Clique>& child, clique->children()) { countDims(child, dims); } } /* ************************************************************************* */ VectorValues GaussianJunctionTree::optimize() const { tic("GJT optimize 1: eliminate"); // eliminate from leaves to the root boost::shared_ptr rootClique(this->eliminate()); toc("GJT optimize 1: eliminate"); // Allocate solution vector tic("GJT optimize 2: allocate VectorValues"); vector dims(rootClique->back()->key() + 1, 0); countDims(rootClique, dims); VectorValues result(dims); toc("GJT optimize 2: allocate VectorValues"); // back-substitution tic("GJT optimize 3: back-substitute"); btreeBackSubstitute(rootClique, result); toc("GJT optimize 3: back-substitute"); return result; } } //namespace gtsam