ISAM2UpdateParams supplies per-update controls to iSAM2: factor removal, constrained ordering groups, relinearization exclusions, extra re-elimination keys, and full-solve overrides.
import gtsam
import numpy as np
from gtsam.symbol_shorthand import L, V, XCreating update parameters¶
The default object requests an ordinary incremental update. Set only the fields needed for a particular call; persistent solver behavior belongs in ISAM2Params.
update_params = gtsam.ISAM2UpdateParams()
update_params.force_relinearize = True
update_params.forceFullSolve = False
update_params.removeFactorIndices = []
print("force relinearization:", update_params.force_relinearize)Using the object with ISAM2.update()¶
The dedicated overload takes new factors, new values, and ISAM2UpdateParams. This example adds a prior in one update and a relative-pose factor in the next.
isam = gtsam.ISAM2()
model = gtsam.noiseModel.Diagonal.Sigmas(np.array([0.1, 0.1, 0.05]))
first_graph = gtsam.NonlinearFactorGraph()
first_graph.add(gtsam.PriorFactorPose2(X(0), gtsam.Pose2(), model))
first_values = gtsam.Values()
first_values.insert(X(0), gtsam.Pose2(0.1, 0.0, 0.01))
isam.update(first_graph, first_values)
second_graph = gtsam.NonlinearFactorGraph()
second_graph.add(
gtsam.BetweenFactorPose2(X(0), X(1), gtsam.Pose2(1.0, 0.0, 0.0), model)
)
second_values = gtsam.Values()
second_values.insert(X(1), gtsam.Pose2(1.1, 0.1, 0.02))
result = isam.update(second_graph, second_values, update_params)
print("estimate for X1:", isam.calculateEstimatePose2(X(1)))Advanced fields¶
constrainedKeys groups variables for constrained COLAMD ordering. noRelinKeys protects selected variables from relinearization, while extraReelimKeys forces selected variables through re-elimination. removeFactorIndices uses the indices returned by earlier ISAM2Result.getNewFactorsIndices() calls. forceFullSolve performs a full back-substitution after the incremental update.
Source¶
AI assistance caveat¶
AI was used to help draft this documentation, and inaccuracies could be present.