Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

ISAM2Result

ISAM2Result summarizes the work performed by one ISAM2.update() call: affected variables, relinearization and re-elimination counts, new factor indices, clique statistics, and optional nonlinear errors.

Open In Colab
import gtsam
import numpy as np
from gtsam.symbol_shorthand import L, V, X

Obtaining a result

Although a default constructor exists, useful results come from ISAM2.update(). Enable detailed results or nonlinear error evaluation in ISAM2Params before constructing the solver when those diagnostics are needed.

params = gtsam.ISAM2Params()
params.enableDetailedResults = True
params.evaluateNonlinearError = True
params.relinearizeSkip = 1
isam = gtsam.ISAM2(params)

graph = gtsam.NonlinearFactorGraph()
model = gtsam.noiseModel.Diagonal.Sigmas(np.array([0.1, 0.1, 0.05]))
graph.add(gtsam.PriorFactorPose2(X(0), gtsam.Pose2(), model))
values = gtsam.Values()
values.insert(X(0), gtsam.Pose2(0.2, -0.1, 0.05))
result = isam.update(graph, values)

Update work

getVariablesRelinearized(), getVariablesReeliminated(), getFactorsRecalculated(), and getCliques() quantify incremental work. getNewFactorsIndices() identifies where new factors were inserted.

print("new factor indices:", list(result.getNewFactorsIndices()))
print("relinearized:", result.getVariablesRelinearized())
print("re-eliminated:", result.getVariablesReeliminated())
print("cliques:", result.getCliques())

Error and affected-key diagnostics

When error evaluation is enabled, getErrorBefore() and getErrorAfter() report the nonlinear objective around the update. Key-set accessors distinguish observed, marked, unused, and factor-removal-related variables. getBatchReorderTriggered() and getTreeNnz() expose structural events.

print("error before:", result.getErrorBefore())
print("error after:", result.getErrorAfter())
print("observed keys:", [gtsam.DefaultKeyFormatter(k) for k in result.getObservedKeys()])
assert result.getErrorAfter() <= result.getErrorBefore()

Source

ISAM2Result.h

AI assistance caveat

AI was used to help draft this documentation, and inaccuracies could be present.