optimize
Description
optimizes the solnInfo
= optimize(graph
,solverOptions
)factorGraph
object
graph
using the specified factor graph solver options,
solverOptions
, and returns the resulting solution info
solnInfo
.
Examples
Create and Optimize Factor Graph with Custom Options
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 1.08e-03 8.65e-03 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.007575 Residual only evaluation 0.000000 (0) Jacobian & residual evaluation 0.000983 (1) Linear solver 0.000000 (0) Minimizer 0.010046 Postprocessor 0.000010 Total 0.017631 Termination: CONVERGENCE (Gradient tolerance reached. Gradient max norm: 0.000000e+00 <= 1.000000e-10)
Input Arguments
graph
— Factor graph
factorGraph
object
Factor graph, specified as a factorGraph
object.
solverOptions
— Solver options for factor graph
factorGraphSolverOptions
object
Solver options for the factor graph, specified as a factorGraphSolverOptions
object.
Output Arguments
solnInfo
— Results of optimization
structure
Results of the optimization, returned as a structure containing:
InitialCost
— Initial cost of the non-linear least squares problem formulated by the factor graph before the optimization.FinalCost
— Final cost of the non-linear least squares problem formulated by the factor graph after the optimization.Note
Cost is the sum of error terms, known as residuals, where each residual is a function of a subset of factor measurements.
NumSuccessfulSteps
— Number of iterations in which the solver decreases the cost. This value includes the initialization iteration at 0 in addition to the minimizer iterations.NumUnsuccessfulSteps
— Number of iterations in which the iteration is numerically invalid or the solver does not decrease the cost.TotalTime
— Total solver optimization time in seconds.TerminationType
— Termination type as an integer in the range [0, 2]:0
— Solver found a solution that meets convergence criterion and decreases in cost after optimization.1
— Solver could not find a solution that meets convergence criterion after running for the maximum number of iterations.2
— Solver terminated due to an error.
IsSolutionUsable
— Solution is usable if1
(true
), not usable if0
(false
).
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2022a
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)