This API walkthrough introduces the wrapped classes GncOptimizer declared by GncOptimizer.h and demonstrates their principal Python operations.
import gtsam
import numpy as np
from gtsam.symbol_shorthand import L, XOverview¶
The GncOptimizer class in GTSAM is designed to perform robust optimization using Graduated Non-Convexity (GNC). This method is particularly useful in scenarios where the optimization problem is affected by outliers. The GNC approach gradually transitions from a convex approximation of the problem to the original non-convex problem, thereby improving robustness and convergence.
The GncOptimizer leverages a robust cost function , where is the error term. The goal is to minimize the sum of these robust costs over all measurements:
In the context of GNC, the robust cost function is gradually transformed from a convex approximation to the original non-convex form. This transformation is controlled by a parameter , which is adjusted during the optimization process:
As increases from , the function transitions from a convex to a non-convex shape, allowing the optimizer to handle outliers effectively.
Note that internally (and in its param interface) GNC parameterizes using an auxiliary parameter (referred to as in the original publication) where the mapping from to is dependent on the selection of loss function. This is necessitated to adhere to the GTSAM definition of the control parameter .
Key features:
Robust Optimization: The GncOptimizer is specifically tailored to handle optimization problems with outliers, using a robust cost function that can mitigate their effects.
Graduated Non-Convexity: This technique allows the optimizer to start with a convex problem and gradually transform it into the original non-convex problem, which helps in avoiding local minima.
Customizable Parameters: Users can adjust various parameters to control the behavior of the optimizer, such as the type of robust loss function and the parameters governing the GNC process.
Key Methods¶
Please see the base class NonlinearOptimizer.
Parameters¶
The GncParams class defines parameters specific to the GNC optimization algorithm:
| Parameter | Type | Default Value | Description |
|---|---|---|---|
| lossType | GncLossType | TLS | Type of robust loss function (GM = Geman McClure or TLS = Truncated least squares) |
| maxIterations | size_t | 100 | Maximum number of iterations |
| lambdaStep | double | 1.4 | Multiplicative factor to reduce/increase lambda in GNC |
| relativeCostTol | double | 1e-5 | Threshold for relative cost change to stop iterating |
| weightsTol | double | 1e-4 | Threshold for weights being close to binary to stop iterating (TLS only) |
| verbosity | Verbosity enum | SILENT | Verbosity level (options: SILENT, SUMMARY, LAMBDA, WEIGHTS, VALUES) |
| knownInliers | IndexVector | Empty | Slots in factor graph for measurements known to be inliers |
| knownOutliers | IndexVector | Empty | Slots in factor graph for measurements known to be outliers |
These parameters complement the standard optimization parameters inherited from NonlinearOptimizerParams, which include:
Maximum iterations
Relative and absolute error thresholds
Error function verbosity
Linear solver type
Usage Considerations¶
Outlier Rejection: The
GncOptimizeris particularly effective in scenarios with significant outlier presence, such as SLAM or bundle adjustment problems.Parameter Tuning: Proper tuning of the GNC parameters is crucial for achieving optimal performance. Users should experiment with different settings to find the best configuration for their specific problem.
Files¶
Python wrapper walkthrough¶
The following cell exercises the wrapped API directly.
params = gtsam.GncGaussNewtonParams()
print(type(params).__name__)
print([name for name in dir(params) if not name.startswith('_')])