Main Content

optimize

Optimize factor graph

Description

example

solnInfo = optimize(graph,solverOptions) optimizes the factorGraph object graph using the specified factor graph solver options, solverOptions, and returns the resulting solution info solnInfo.

Examples

collapse all

Create and optimize a factor graph with custom solver options.

Create Factor Graph and Solver Settings

Create a factor graph and solver options with custom settings. Set the maximum number of iterations to 1000 and set the verbosity of the optimize output to 2.

G = factorGraph;
optns = factorGraphSolverOptions(MaxIterations=1000,VerbosityLevel=2)
optns = 
  factorGraphSolverOptions with properties:

              MaxIterations: 1000
          FunctionTolerance: 1.0000e-06
          GradientTolerance: 1.0000e-10
              StepTolerance: 1.0000e-08
             VerbosityLevel: 2
    TrustRegionStrategyType: 1

Add GPS Factor

Create a GPS factor with node identification number of 1 with NED ReferenceFrame and add it to the factor graph.

fgps = factorGPS(1,ReferenceFrame="NED");
addFactor(G,fgps);

Optimize Factor Graph

Optimize the factor graph with the custom settings. The results of the optimization are displayed with the level of detail depending on the VerbosityLevel.

optimize(G,optns);
iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_iter  iter_time  total_time
   0  0.000000e+00    0.00e+00    0.00e+00   0.00e+00   0.00e+00  1.00e+04        0    4.20e-05    2.45e-04
Terminating: Gradient tolerance reached. Gradient max norm: 0.000000e+00 <= 1.000000e-10

Solver Summary (v 2.0.0-eigen-(3.3.4)-no_lapack-eigensparse-no_openmp-no_custom_blas)

                                     Original                  Reduced
Parameter blocks                            1                        1
Parameters                                  7                        7
Effective parameters                        6                        6
Residual blocks                             1                        1
Residuals                                   3                        3

Minimizer                        TRUST_REGION

Sparse linear algebra library    EIGEN_SPARSE
Trust region strategy                  DOGLEG (TRADITIONAL)

                                        Given                     Used
Linear solver          SPARSE_NORMAL_CHOLESKY   SPARSE_NORMAL_CHOLESKY
Threads                                     1                        1
Linear solver ordering              AUTOMATIC                        1

Cost:
Initial                          0.000000e+00
Final                            0.000000e+00
Change                           0.000000e+00

Minimizer iterations                        1
Successful steps                            1
Unsuccessful steps                          0

Time (in seconds):
Preprocessor                         0.000203

  Residual only evaluation           0.000000 (0)
  Jacobian & residual evaluation     0.000014 (1)
  Linear solver                      0.000000 (0)
Minimizer                            0.003924

Postprocessor                        0.000009
Total                                0.004136

Termination:                      CONVERGENCE (Gradient tolerance reached. Gradient max norm: 0.000000e+00 <= 1.000000e-10)

Input Arguments

collapse all

Factor graph, specified as a factorGraph object.

Solver options for the factor graph, specified as a factorGraphSolverOptions object.

Output Arguments

collapse all

Results of the optimization, returned as a structure containing:

  • InitialCost — Initial cost

  • FinalCost — Final cost

  • NumSuccessfulSteps — Number of successful optimization steps

  • NumUnsuccessfulSteps — Number of unsuccessful optimization steps

  • TotalTime — Total optimization time in seconds

  • TerminationType — Termination type

  • IsSolutionUsable — Solution is usable if 1 (true), not usable if 0 (false)

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2022a