diff --git a/gtsam/nonlinear/GaussianISAM2.h b/gtsam/nonlinear/GaussianISAM2.h index 943e53aa1..0c6d4c289 100644 --- a/gtsam/nonlinear/GaussianISAM2.h +++ b/gtsam/nonlinear/GaussianISAM2.h @@ -26,15 +26,16 @@ namespace gtsam { * * @tparam VALUES The Values or TupleValues\Emph{N} that contains the * variables. + * @tparam GRAPH The NonlinearFactorGraph structure to store factors. Defaults to standard NonlinearFactorGraph */ -template -class GaussianISAM2 : public ISAM2 { +template > +class GaussianISAM2 : public ISAM2 { public: /** Create an empty ISAM2 instance */ - GaussianISAM2(const ISAM2Params& params) : ISAM2(params) {} + GaussianISAM2(const ISAM2Params& params) : ISAM2(params) {} /** Create an empty ISAM2 instance using the default set of parameters (see ISAM2Params) */ - GaussianISAM2() : ISAM2() {} + GaussianISAM2() : ISAM2() {} }; // optimize the BayesTree, starting from the root diff --git a/gtsam/nonlinear/ISAM2-impl-inl.h b/gtsam/nonlinear/ISAM2-impl-inl.h index d32085eeb..07cb0a036 100644 --- a/gtsam/nonlinear/ISAM2-impl-inl.h +++ b/gtsam/nonlinear/ISAM2-impl-inl.h @@ -23,10 +23,10 @@ namespace gtsam { -template -struct ISAM2::Impl { +template +struct ISAM2::Impl { - typedef ISAM2 ISAM2Type; + typedef ISAM2 ISAM2Type; struct PartialSolveResult { typename ISAM2Type::sharedClique bayesTree; @@ -58,7 +58,7 @@ struct ISAM2::Impl { * @param factors The factors from which to extract the variables * @return The set of variables indices from the factors */ - static FastSet IndicesFromFactors(const Ordering& ordering, const NonlinearFactorGraph& factors); + static FastSet IndicesFromFactors(const Ordering& ordering, const GRAPH& factors); /** * Find the set of variables to be relinearized according to relinearizeThreshold. @@ -138,8 +138,8 @@ struct _VariableAdder { }; /* ************************************************************************* */ -template -void ISAM2::Impl::AddVariables( +template +void ISAM2::Impl::AddVariables( const VALUES& newTheta, VALUES& theta, Permuted& delta, Ordering& ordering, typename Base::Nodes& nodes) { const bool debug = ISDEBUG("ISAM2 AddVariables"); @@ -166,8 +166,8 @@ void ISAM2::Impl::AddVariables( } /* ************************************************************************* */ -template -FastSet ISAM2::Impl::IndicesFromFactors(const Ordering& ordering, const NonlinearFactorGraph& factors) { +template +FastSet ISAM2::Impl::IndicesFromFactors(const Ordering& ordering, const GRAPH& factors) { FastSet indices; BOOST_FOREACH(const typename NonlinearFactor::shared_ptr& factor, factors) { BOOST_FOREACH(const Symbol& key, factor->keys()) { @@ -178,8 +178,8 @@ FastSet ISAM2::Impl::IndicesFromFactors(const Orderin } /* ************************************************************************* */ -template -FastSet ISAM2::Impl::CheckRelinearization(Permuted& delta, double relinearizeThreshold) { +template +FastSet ISAM2::Impl::CheckRelinearization(Permuted& delta, double relinearizeThreshold) { FastSet relinKeys; for(Index var=0; var(); @@ -191,8 +191,8 @@ FastSet ISAM2::Impl::CheckRelinearization(Permuted -void ISAM2::Impl::FindAll(ISAM2Type::sharedClique clique, FastSet& keys, const vector& markedMask) { +template +void ISAM2::Impl::FindAll(ISAM2Type::sharedClique clique, FastSet& keys, const vector& markedMask) { static const bool debug = false; // does the separator contain any of the variables? bool found = false; @@ -245,8 +245,8 @@ struct _SelectiveExpmapAndClear { }; /* ************************************************************************* */ -template -void ISAM2::Impl::ExpmapMasked(VALUES& values, const Permuted& delta, +template +void ISAM2::Impl::ExpmapMasked(VALUES& values, const Permuted& delta, const Ordering& ordering, const vector& mask, boost::optional&> invalidateIfDebug) { // If debugging, invalidate if requested, otherwise do not invalidate. // Invalidating means setting expmapped entries to Inf, to trigger assertions @@ -260,9 +260,9 @@ void ISAM2::Impl::ExpmapMasked(VALUES& values, const Permut } /* ************************************************************************* */ -template -typename ISAM2::Impl::PartialSolveResult -ISAM2::Impl::PartialSolve(GaussianFactorGraph& factors, +template +typename ISAM2::Impl::PartialSolveResult +ISAM2::Impl::PartialSolve(GaussianFactorGraph& factors, const FastSet& keys, const ReorderingMode& reorderingMode) { static const bool debug = ISDEBUG("ISAM2 recalculate"); diff --git a/gtsam/nonlinear/ISAM2-inl.h b/gtsam/nonlinear/ISAM2-inl.h index b5dfea527..914ac5449 100644 --- a/gtsam/nonlinear/ISAM2-inl.h +++ b/gtsam/nonlinear/ISAM2-inl.h @@ -50,24 +50,24 @@ static const bool latestLast = true; static const bool structuralLast = false; /* ************************************************************************* */ -template -ISAM2::ISAM2(const ISAM2Params& params): +template +ISAM2::ISAM2(const ISAM2Params& params): delta_(Permutation(), deltaUnpermuted_), params_(params) {} /* ************************************************************************* */ -template -ISAM2::ISAM2(): +template +ISAM2::ISAM2(): delta_(Permutation(), deltaUnpermuted_) {} /* ************************************************************************* */ -template -FastList ISAM2::getAffectedFactors(const FastList& keys) const { +template +FastList ISAM2::getAffectedFactors(const FastList& keys) const { static const bool debug = false; if(debug) cout << "Getting affected factors for "; if(debug) { BOOST_FOREACH(const Index key, keys) { cout << key << " "; } } if(debug) cout << endl; - FactorGraph > allAffected; + FactorGraph > allAffected; FastList indices; BOOST_FOREACH(const Index key, keys) { // const list l = nonlinearFactors_.factors(key); @@ -89,15 +89,15 @@ FastList ISAM2::getAffectedFactors(const FastList +template FactorGraph::shared_ptr -ISAM2::relinearizeAffectedFactors(const FastList& affectedKeys) const { +ISAM2::relinearizeAffectedFactors(const FastList& affectedKeys) const { tic(1,"getAffectedFactors"); FastList candidates = getAffectedFactors(affectedKeys); toc(1,"getAffectedFactors"); - NonlinearFactorGraph nonlinearAffectedFactors; + GRAPH nonlinearAffectedFactors; tic(2,"affectedKeysSet"); // for fast lookup below @@ -128,9 +128,9 @@ ISAM2::relinearizeAffectedFactors(const FastList& af /* ************************************************************************* */ // find intermediate (linearized) factors from cache that are passed into the affected area -template -FactorGraph::CacheFactor> -ISAM2::getCachedBoundaryFactors(Cliques& orphans) { +template +FactorGraph::CacheFactor> +ISAM2::getCachedBoundaryFactors(Cliques& orphans) { static const bool debug = false; @@ -140,9 +140,9 @@ ISAM2::getCachedBoundaryFactors(Cliques& orphans) { // find the last variable that was eliminated Index key = (*orphan)->frontals().back(); #ifndef NDEBUG -// typename BayesNet::const_iterator it = orphan->end(); -// const Conditional& lastConditional = **(--it); -// typename Conditional::const_iterator keyit = lastConditional.endParents(); +// typename BayesNet::const_iterator it = orphan->end(); +// const CONDITIONAL& lastCONDITIONAL = **(--it); +// typename CONDITIONAL::const_iterator keyit = lastCONDITIONAL.endParents(); // const Index lastKey = *(--keyit); // assert(key == lastKey); #endif @@ -154,8 +154,8 @@ ISAM2::getCachedBoundaryFactors(Cliques& orphans) { return cachedBoundary; } -template -boost::shared_ptr > ISAM2::recalculate( +template +boost::shared_ptr > ISAM2::recalculate( const FastSet& markedKeys, const FastSet& structuralKeys, const FastVector& newKeys, const FactorGraph::shared_ptr newFactors, ISAM2Result& result) { // TODO: new factors are linearized twice, the newFactors passed in are not used. @@ -174,8 +174,8 @@ boost::shared_ptr > ISAM2::recalculate( if (counter>0) { // cannot call on empty tree GaussianISAM2_P::CliqueData cdata = this->getCliqueData(); GaussianISAM2_P::CliqueStats cstats = cdata.getStats(); - maxClique = cstats.maxConditionalSize; - avgClique = cstats.avgConditionalSize; + maxClique = cstats.maxCONDITIONALSize; + avgClique = cstats.avgCONDITIONALSize; numCliques = cdata.conditionalSizes.size(); nnzR = calculate_nnz(this->root()); } @@ -292,7 +292,7 @@ boost::shared_ptr > ISAM2::recalculate( toc(5,"eliminate"); tic(6,"insert"); - BayesTree::clear(); + BayesTree::clear(); this->insert(newRoot); toc(6,"insert"); @@ -418,9 +418,9 @@ boost::shared_ptr > ISAM2::recalculate( } /* ************************************************************************* */ -template -ISAM2Result ISAM2::update( - const NonlinearFactorGraph& newFactors, const Values& newTheta, bool force_relinearize) { +template +ISAM2Result ISAM2::update( + const GRAPH& newFactors, const Values& newTheta, bool force_relinearize) { static const bool debug = ISDEBUG("ISAM2 update"); static const bool verbose = ISDEBUG("ISAM2 update verbose"); @@ -554,28 +554,28 @@ ISAM2Result ISAM2::update( } /* ************************************************************************* */ -template -Values ISAM2::calculateEstimate() const { +template +VALUES ISAM2::calculateEstimate() const { // We use ExpmapMasked here instead of regular expmap because the former // handles Permuted - Values ret(theta_); + VALUES ret(theta_); vector mask(ordering_.nVars(), true); Impl::ExpmapMasked(ret, delta_, ordering_, mask); return ret; } /* ************************************************************************* */ -template +template template -typename KEY::Value ISAM2::calculateEstimate(const KEY& key) const { +typename KEY::Value ISAM2::calculateEstimate(const KEY& key) const { const Index index = getOrdering()[key]; const SubVector delta = getDelta()[index]; return getLinearizationPoint()[key].retract(delta); } /* ************************************************************************* */ -template -Values ISAM2::calculateBestEstimate() const { +template +VALUES ISAM2::calculateBestEstimate() const { VectorValues delta(theta_.dims(ordering_)); optimize2(this->root(), delta); return theta_.retract(delta, ordering_); diff --git a/gtsam/nonlinear/ISAM2.h b/gtsam/nonlinear/ISAM2.h index 67335648e..b567d94a6 100644 --- a/gtsam/nonlinear/ISAM2.h +++ b/gtsam/nonlinear/ISAM2.h @@ -123,8 +123,9 @@ struct ISAM2Result { * to the constructor, then add measurements and variables as they arrive using the update() * method. At any time, calculateEstimate() may be called to obtain the current * estimate of all variables. + * */ -template +template > class ISAM2: public BayesTree { protected: @@ -148,7 +149,7 @@ protected: Permuted delta_; /** All original nonlinear factors are stored here to use during relinearization */ - NonlinearFactorGraph nonlinearFactors_; + GRAPH nonlinearFactors_; /** @brief The current elimination ordering Symbols to Index (integer) keys. * @@ -170,6 +171,8 @@ public: typedef BayesTree Base; ///< The BayesTree base class typedef ISAM2 This; ///< This class + typedef VALUES Values; + typedef GRAPH Graph; /** Create an empty ISAM2 instance */ ISAM2(const ISAM2Params& params); @@ -198,7 +201,7 @@ public: * (Params::relinearizeSkip). * @return An ISAM2Result struct containing information about the update */ - ISAM2Result update(const NonlinearFactorGraph& newFactors, const VALUES& newTheta, + ISAM2Result update(const GRAPH& newFactors, const VALUES& newTheta, bool force_relinearize = false); /** Access the current linearization point */ @@ -233,7 +236,7 @@ public: const Permuted& getDelta() const { return delta_; } /** Access the set of nonlinear factors */ - const NonlinearFactorGraph& getFactorsUnsafe() const { return nonlinearFactors_; } + const GRAPH& getFactorsUnsafe() const { return nonlinearFactors_; } /** Access the current ordering */ const Ordering& getOrdering() const { return ordering_; }