gtsam
Loading...
Searching...
No Matches
RISAM.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
18#pragma once
20#include <gtsam/nonlinear/internal/ChiSquaredInverse.h>
21#include <gtsam/sam/RISAMGraduatedFactor.h>
22
23namespace gtsam {
24
61
70
72 std::set<Key> involvedVariables;
74 std::set<Key> affectedVariables;
76 std::set<FactorIndex> convexifiedFactors;
77};
78
89class GTSAM_EXPORT RISAM {
92 public:
98
101 protected:
105 std::unique_ptr<ISAM2> solver_;
117
130
133 public:
139 RISAM(const Parameters& params) : params_(params) {
150 // We must have relinearization skip as 1.
151 params_.isam2Params.relinearizeSkip = 1;
152 // We must not use cached factors.
153 params_.isam2Params.cacheLinearizedFactors = false;
154
155 // Construct the encapsulated solver using the modified parameters.
156 solver_ = std::make_unique<ISAM2>(params_.isam2Params);
157 }
158
164 UpdateResult update(
165 const NonlinearFactorGraph& newFactors = NonlinearFactorGraph(),
166 const Values& newTheta = Values(),
167 const std::optional<std::set<Key>> extraGncInvolvedKeys = std::nullopt,
168 const FactorIndices& removeFactorIndices = FactorIndices(),
169 const std::optional<FastMap<Key, int>>& constrainedKeys = std::nullopt,
170 const std::optional<FastList<Key>>& noRelinKeys = std::nullopt,
171 const std::optional<FastList<Key>>& extraReelimKeys = std::nullopt,
172 bool force_relinearize = false);
173
179 UpdateResult update(const NonlinearFactorGraph& newFactors,
180 const Values& newTheta,
181 const std::optional<std::set<Key>> extraGncInvolvedKeys,
182 const ISAM2UpdateParams& updateParams);
183
185 Values calculateEstimate();
186
189
197 std::set<size_t> getOutliers(double chiSquaredOutlierThreshold);
199
202 protected:
208 UpdateResult updateRobust(
209 const NonlinearFactorGraph& newFactors, const Values& newTheta,
210 const std::optional<std::set<Key>>& extraGncInvolvedKeys,
211 const ISAM2UpdateParams& updateParams);
212
218 FactorIndices runRobustIteration(
219 const FactorIndices& convexFactors,
220 std::map<FactorIndex, size_t>& muUpdateCount);
221
229 void updateConvexFactorMu(const Values& currentEstimate, const size_t fidx,
230 std::map<FactorIndex, size_t>& muUpdateCount,
231 FastList<Key>& convexKeys);
232
237 FactorIndices updateConvexFactors(const FactorIndices& convexFactors) const;
238
249 FactorIndices convexifyInvolvedFactors(
250 const NonlinearFactorGraph& newFactors, const Values& newTheta,
251 const std::optional<std::set<Key>>& extraGncInvolvedKeys,
252 ISAM2UpdateParams& internalUpdateParams, UpdateResult& updateResult);
253
260 KeySet accumulateInvolvedKeys(
261 const NonlinearFactorGraph& newFactors,
262 const std::optional<std::set<Key>>& extraGncInvolvedKeys,
263 ISAM2UpdateParams& updateParams) const;
264
272 void convexifyFactorIfInvolved(const FactorIndex fidx,
273 const KeySet& involvedKeys,
274 const KeySet& affectedKeys,
275 const bool isBatchUpdate,
276 std::set<FactorIndex>& convexFactors);
277
287 void updateHousekeeping(const NonlinearFactorGraph& newFactors,
288 const ISAM2UpdateParams& updateParams);
289
294 void augmentMu(const NonlinearFactorGraph& newFactors,
295 const FactorIndices& newFactorIndices);
296
301 void incrementMuInits();
303
306 public:
318 template <class FACTOR_TYPE>
319 static auto MakeGraduated(GraduatedFactor::RobustLoss::shared_ptr loss,
321 return [loss = std::move(loss),
322 scheduler = std::move(scheduler)](auto&&... factorArgs) ->
323 typename GenericGraduatedFactor<FACTOR_TYPE>::shared_ptr {
324 return std::make_shared<GenericGraduatedFactor<FACTOR_TYPE>>(
325 loss, scheduler,
326 std::forward<decltype(factorArgs)>(factorArgs)...);
327 };
328 }
329
330};
331
332} // namespace gtsam
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:33
Global functions in a separate testing namespace.
Definition chartTesting.h:28
std::uint64_t FactorIndex
Integer nonlinear factor index type.
Definition types.h:46
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition Factor.h:37
FastList is a thin wrapper around std::list that uses the boost fast_pool_allocator instead of the de...
Definition FastList.h:43
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:40
FastSet is a thin wrapper around std::set that uses the boost fast_pool_allocator instead of the defa...
Definition FastSet.h:54
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:41
Definition ISAM2Params.h:199
This struct is returned from ISAM2::update() and contains information about the update that is useful...
Definition ISAM2Result.h:39
This struct is used by ISAM2::update() to pass additional parameters to give the user a fine-grained ...
Definition ISAM2UpdateParams.h:32
Definition NonlinearFactorGraph.h:57
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
Struct Containing all configuration parameters for riSAM.
Definition RISAM.h:29
double outlierMuChiSquaredLowerBound
Decrement muInit if chi^2 < lower bound.
Definition RISAM.h:55
ISAM2Params isam2Params
The parameters for the encapsulated iSAM2 algorithm @Note some are overridden in RISAM::RISAM().
Definition RISAM.h:47
RISAMParams(ISAM2Params isam2Params=ISAM2Params(), bool incrementOutlierMu=true, double outlierMuChiSquaredUpperBound=0.95, double outlierMuChiSquaredLowerBound=0.25, double outlierMuAverageVariableConvergenceThreshold=0.01, size_t numberExtraIterations=1)
Explicit constructor to use default values.
Definition RISAM.h:31
double outlierMuAverageVariableConvergenceThreshold
Average variable delta threshold to identify value convergence.
Definition RISAM.h:57
bool incrementOutlierMu
Flag to increment muInit when the value estimate converges.
Definition RISAM.h:51
size_t numberExtraIterations
The number of extra iterations to perform after mu convergence.
Definition RISAM.h:59
double outlierMuChiSquaredUpperBound
Increment muInit if chi^2 > upper bound.
Definition RISAM.h:53
Struct containing information about the riSAM update.
Definition RISAM.h:66
std::set< Key > affectedVariables
The set of variables affected by the update.
Definition RISAM.h:74
std::set< Key > involvedVariables
The set variables directly involved in the update.
Definition RISAM.h:72
std::set< FactorIndex > convexifiedFactors
The set of factors convexified in this update.
Definition RISAM.h:76
ISAM2Result isam2Result
The iSAM2 result from the first internal update.
Definition RISAM.h:69
RISAMParams Parameters
Configuration parameters for the riSAM algorithm.
Definition RISAM.h:94
FastVector< std::shared_ptr< double > > mu_
The current control parameter values for all factors.
Definition RISAM.h:109
VariableIndex variableIndex_
RISAM maintains its own variable index and factors.
Definition RISAM.h:125
const NonlinearFactorGraph & getFactorsUnsafe() const
Returns the underlying factors of the system.
Definition RISAM.h:188
NonlinearFactorGraph factors_
The Factors for the underlying system.
Definition RISAM.h:128
std::unique_ptr< ISAM2 > solver_
The encapsulated iSAM2 algorithm.
Definition RISAM.h:105
Parameters params_
Configuration parameters for the riSAM algorithm.
Definition RISAM.h:103
FastVector< std::shared_ptr< double > > muInits_
The current initial control parameter values for all factors.
Definition RISAM.h:112
RISAMUpdateResult UpdateResult
Information about a riSAM update.
Definition RISAM.h:96
static auto MakeGraduated(GraduatedFactor::RobustLoss::shared_ptr loss, GraduationScheduler::shared_ptr scheduler)
Returns a factory that constructs FACTOR_TYPE graduated factors for riSAM, identifying them as potent...
Definition RISAM.h:319
RISAM(const Parameters &params)
Constructs an instance of the riSAM algorithm with provided configuration.
Definition RISAM.h:139
FastSet< size_t > factorsToCheckStatus_
The set of GraduatedFactors that have been convexified since the last muInit_ increment These are the...
Definition RISAM.h:116
std::shared_ptr< GraduationScheduler > shared_ptr
Shortcut for shared pointer.
Definition RISAMGraduationScheduler.h:47