/** * @file ISAM-inl.h * @brief Incremental update functionality (iSAM) for BayesTree. * @author Michael Kaess */ #include #include // for operator += using namespace boost::assign; #include #include #include 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); // eliminate into a Bayes net typename BayesNet::shared_ptr bayesNet = Inference::Eliminate(factors); // 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); // add orphans to the bottom of the new tree BOOST_FOREACH(sharedClique orphan, orphans) { this->insert(orphan); } } template template void ISAM::update(const FactorGraph& newFactors) { Cliques orphans; this->update_internal(newFactors, orphans); } } /// namespace gtsam