/** * @file ISAM2.h * @brief Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization. * @author Michael Kaess */ // \callgraph #pragma once #include #include #include //#include //#include #include #include #include #include #include #include #include #include namespace gtsam { typedef SymbolMap CachedFactors; template class ISAM2: public BayesTree { protected: // current linearization point Config theta_; // the linear solution, an update to the estimate in theta VectorConfig delta_; // for keeping all original nonlinear factors NonlinearFactorGraph nonlinearFactors_; // cached intermediate results for restarting computation in the middle CachedFactors cached_; public: /** Create an empty Bayes Tree */ ISAM2(); /** Create a Bayes Tree from a Bayes Net */ ISAM2(const NonlinearFactorGraph& fg, const Ordering& ordering, const Config& config); /** Destructor */ virtual ~ISAM2() {} typedef typename BayesTree::sharedClique sharedClique; typedef typename BayesTree::Cliques Cliques; /** * ISAM2. */ void update(const NonlinearFactorGraph& newFactors, const Config& newTheta, double wildfire_threshold = 0., double relinearize_threshold = 0., bool relinearize = true); // needed to create initial estimates const Config getLinearizationPoint() const {return theta_;} // estimate based on incomplete delta (threshold!) const Config calculateEstimate() const {return theta_.expmap(delta_);} // estimate based on full delta (note that this is based on the current linearization point) const Config calculateBestEstimate() const {return theta_.expmap(*optimize2(this->root()));} const NonlinearFactorGraph& getFactorsUnsafe() const { return nonlinearFactors_; } size_t lastAffectedVariableCount; size_t lastAffectedFactorCount; size_t lastAffectedCliqueCount; size_t lastAffectedMarkedCount; size_t lastBacksubVariableCount; size_t lastNnzTop; private: std::list getAffectedFactors(const std::list& keys) const; boost::shared_ptr relinearizeAffectedFactors(const std::list& affectedKeys) const; FactorGraph getCachedBoundaryFactors(Cliques& orphans); boost::shared_ptr > recalculate(const std::list& markedKeys, const FactorGraph* newFactors = NULL); void linear_update(const FactorGraph& newFactors); void find_all(sharedClique clique, std::list& keys, const std::list& marked); // helper function }; // ISAM2 } /// namespace gtsam