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.

GncOptimizer

This API walkthrough introduces the wrapped classes GncOptimizer declared by GncOptimizer.h and demonstrates their principal Python operations.

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

Overview

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 ρ(e)\rho(e), where ee is the error term. The goal is to minimize the sum of these robust costs over all measurements:

minxiρ(ei(x))\min_x \sum_i \rho(e_i(x))

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 μ\mu, which is adjusted during the optimization process:

ρμ(e)\rho_\mu(e)

As μ\mu increases from [0,1][0,1], the function ρμ(e)\rho_\mu(e) 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 μ\mu using an auxiliary parameter λ\lambda (referred to as μ\mu in the original publication) where the mapping from μ\mu to λ\lambda is dependent on the selection of loss function. This is necessitated to adhere to the GTSAM definition of the control parameter μ[0,1]\mu\in[0,1].

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:

ParameterTypeDefault ValueDescription
lossTypeGncLossTypeTLSType of robust loss function (GM = Geman McClure or TLS = Truncated least squares)
maxIterationssize_t100Maximum number of iterations
lambdaStepdouble1.4Multiplicative factor to reduce/increase lambda in GNC
relativeCostToldouble1e-5Threshold for relative cost change to stop iterating
weightsToldouble1e-4Threshold for weights being close to binary to stop iterating (TLS only)
verbosityVerbosity enumSILENTVerbosity level (options: SILENT, SUMMARY, LAMBDA, WEIGHTS, VALUES)
knownInliersIndexVectorEmptySlots in factor graph for measurements known to be inliers
knownOutliersIndexVectorEmptySlots 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 GncOptimizer is 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('_')])