/** * @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 #include namespace gtsam { //typedef std::vector CachedFactors; template class ISAM2: public BayesTree { protected: // current linearization point Values theta_; // VariableIndex lets us look up factors by involved variable and keeps track of dimensions typedef GaussianVariableIndex VariableIndexType; VariableIndexType variableIndex_; // the linear solution, an update to the estimate in theta VectorValues deltaUnpermuted_; // The residual permutation through which the deltaUnpermuted_ is // referenced. Permuting the VectorValues is slow, so for performance the // permutation is applied at access time instead of to the VectorValues // itself. Permuted delta_; // for keeping all original nonlinear factors NonlinearFactorGraph nonlinearFactors_; // The "ordering" allows converting Symbols to varid_t (integer) keys. We // keep it up to date as we add and reorder variables. Ordering ordering_; // cached intermediate results for restarting computation in the middle // CachedFactors cached_; #ifndef NDEBUG std::vector lastRelinVariables_; #endif public: /** Create an empty Bayes Tree */ ISAM2(); // /** Create a Bayes Tree from a Bayes Net */ // ISAM2(const NonlinearFactorGraph& fg, const Ordering& ordering, const Values& config); /** Destructor */ virtual ~ISAM2() {} typedef typename BayesTree::sharedClique sharedClique; typedef typename BayesTree::Cliques Cliques; /** * ISAM2. */ void update(const NonlinearFactorGraph& newFactors, const Values& newTheta, double wildfire_threshold = 0., double relinearize_threshold = 0., bool relinearize = true); // needed to create initial estimates const Values& getLinearizationPoint() const {return theta_;} // estimate based on incomplete delta (threshold!) Values calculateEstimate() const; // estimate based on full delta (note that this is based on the current linearization point) Values calculateBestEstimate() const; const Permuted& getDelta() const { return delta_; } const NonlinearFactorGraph& getFactorsUnsafe() const { return nonlinearFactors_; } const Ordering& getOrdering() const { return ordering_; } 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; GaussianFactorGraph getCachedBoundaryFactors(Cliques& orphans); boost::shared_ptr > recalculate(const std::set& markedKeys, const std::vector& newKeys, const GaussianFactorGraph* newFactors = NULL); // void linear_update(const GaussianFactorGraph& newFactors); void find_all(sharedClique clique, std::set& keys, const std::vector& marked); // helper function }; // ISAM2 } /// namespace gtsam