/** * @file ISAM-inl.h * @brief Incremental update functionality (iSAM) for BayesTree. * @author Michael Kaess */ #include #include // for operator += using namespace boost::assign; #include "Conditional.h" #include "ISAM.h" #include "BayesTree-inl.h" namespace gtsam { using namespace std; /** Create an empty Bayes Tree */ template ISAM::ISAM() : BayesTree() {} /** Create a Bayes Tree from a Bayes Net */ template ISAM::ISAM(const BayesNet& bayesNet) : BayesTree(bayesNet) {} /* ************************************************************************* */ template template void ISAM::update_internal(const FactorGraph& newFactors, Cliques& orphans) { // Remove the contaminated part of the Bayes tree FactorGraph factors; removeTop(newFactors.keys(), factors, orphans); // add the factors themselves factors.push_back(newFactors); // create an ordering for the new and contaminated factors Ordering ordering; if (true) { ordering = factors.getOrdering(); } else { list keys = factors.keys(); keys.sort(); // todo: correct sorting order? ordering = keys; } // eliminate into a Bayes net BayesNet bayesNet = eliminate(factors,ordering); // insert conditionals back in, straight into the topless bayesTree typename BayesNet::const_reverse_iterator rit; for ( rit=bayesNet.rbegin(); rit != bayesNet.rend(); ++rit ) this->insert(*rit, &ordering); int count = 0; // add orphans to the bottom of the new tree BOOST_FOREACH(sharedClique orphan, orphans) { Symbol key = findParentClique(orphan->separator_, ordering); sharedClique parent = (*this)[key]; parent->children_ += orphan; orphan->parent_ = parent; // set new parent! } } template template void ISAM::update(const FactorGraph& newFactors) { Cliques orphans; this->update_internal(newFactors, orphans); } } /// namespace gtsam