/** * @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 BayesNet bn; removeTop(newFactors.keys(), bn, orphans); FactorGraph factors(bn); // add the factors themselves factors.push_back(newFactors); // create an ordering for the new and contaminated factors Ordering ordering; #ifndef SORT_KEYS ordering = factors.getOrdering(); #else list keys = factors.keys(); keys.sort(); // todo: correct sorting order? ordering = keys; #endif // Create Index from ordering IndexTable index(ordering); // 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, index); // add orphans to the bottom of the new tree BOOST_FOREACH(sharedClique orphan, orphans) { Symbol parentRepresentative = findParentClique(orphan->separator_, index); sharedClique parent = (*this)[parentRepresentative]; 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