Public Types | Protected Member Functions | Protected Attributes | List of all members
gtsam::NonlinearOptimizer Class Referenceabstract

#include <NonlinearOptimizer.h>

Inheritance diagram for gtsam::NonlinearOptimizer:
Inheritance graph
[legend]

Public Types

using shared_ptr = std::shared_ptr< const NonlinearOptimizer >
 

Public Member Functions

Standard interface
virtual const Valuesoptimize ()
 
const ValuesoptimizeSafely ()
 
double error () const
 return error in current optimizer state More...
 
size_t iterations () const
 return number of iterations in current optimizer state More...
 
const Valuesvalues () const
 return values in current optimizer state More...
 
const NonlinearFactorGraphgraph () const
 return the graph with nonlinear factors More...
 
Advanced interface
virtual ~NonlinearOptimizer ()
 
virtual VectorValues solve (const GaussianFactorGraph &gfg, const NonlinearOptimizerParams &params) const
 
virtual GaussianFactorGraph::shared_ptr iterate ()=0
 

Protected Member Functions

virtual const NonlinearOptimizerParams_params () const =0
 
void defaultOptimize ()
 
 NonlinearOptimizer (const NonlinearFactorGraph &graph, std::unique_ptr< internal::NonlinearOptimizerState > state)
 

Protected Attributes

NonlinearFactorGraph graph_
 The graph with nonlinear factors. More...
 
std::unique_ptr< internal::NonlinearOptimizerStatestate_
 PIMPL'd state. More...
 

Detailed Description

This is the abstract interface for classes that can optimize for the maximum-likelihood estimate of a NonlinearFactorGraph.

To use a class derived from this interface, construct the class with a NonlinearFactorGraph and an initial Values variable assignment. Next, call the optimize() method which returns the optimized variable assignment.

Simple and compact example:

// One-liner to do full optimization and use the result.
Values result = DoglegOptimizer(graph, initialValues).optimize();

Example exposing more functionality and details:

// Create initial optimizer
DoglegOptimizer optimizer(graph, initialValues);
// Run full optimization until convergence.
Values result = optimizer->optimize();
// The new optimizer has results and statistics
cout << "Converged in " << optimizer.iterations() << " iterations "
"with final error " << optimizer.error() << endl;

Example of setting parameters before optimization:

// Each derived optimizer type has its own parameters class, which inherits from NonlinearOptimizerParams
DoglegParams params;
params.factorization = DoglegParams::QR;
params.relativeErrorTol = 1e-3;
params.absoluteErrorTol = 1e-3;
// Optimize
Values result = DoglegOptimizer(graph, initialValues, params).optimize();

This interface also exposes an iterate() method, which performs one iteration. The optimize() method simply calls iterate() multiple times, until the error changes less than a threshold. We expose iterate() so that you can easily control what happens between iterations, such as drawing or printing, moving points from behind the camera to in front, etc.

For more flexibility you may override virtual methods in your own derived class.

Definition at line 75 of file NonlinearOptimizer.h.

Member Typedef Documentation

◆ shared_ptr

A shared pointer to this class

Definition at line 84 of file NonlinearOptimizer.h.

Constructor & Destructor Documentation

◆ ~NonlinearOptimizer()

gtsam::NonlinearOptimizer::~NonlinearOptimizer ( )
virtual

Virtual destructor

Definition at line 46 of file NonlinearOptimizer.cpp.

◆ NonlinearOptimizer()

gtsam::NonlinearOptimizer::NonlinearOptimizer ( const NonlinearFactorGraph graph,
std::unique_ptr< internal::NonlinearOptimizerState state 
)
protected

Constructor for initial construction of base classes. Takes ownership of state.

Definition at line 41 of file NonlinearOptimizer.cpp.

Member Function Documentation

◆ _params()

virtual const NonlinearOptimizerParams& gtsam::NonlinearOptimizer::_params ( ) const
protectedpure virtual

◆ defaultOptimize()

void gtsam::NonlinearOptimizer::defaultOptimize ( )
protected

A default implementation of the optimization loop, which calls iterate() until checkConvergence returns true.

Definition at line 62 of file NonlinearOptimizer.cpp.

◆ error()

double gtsam::NonlinearOptimizer::error ( ) const

return error in current optimizer state

Definition at line 49 of file NonlinearOptimizer.cpp.

◆ graph()

const NonlinearFactorGraph& gtsam::NonlinearOptimizer::graph ( ) const
inline

return the graph with nonlinear factors

Definition at line 118 of file NonlinearOptimizer.h.

◆ iterate()

virtual GaussianFactorGraph::shared_ptr gtsam::NonlinearOptimizer::iterate ( )
pure virtual

Perform a single iteration, returning GaussianFactorGraph corresponding to the linearized factor graph.

Implemented in gtsam::NonlinearConjugateGradientOptimizer, gtsam::DoglegOptimizer, gtsam::LevenbergMarquardtOptimizer, and gtsam::GaussNewtonOptimizer.

◆ iterations()

size_t gtsam::NonlinearOptimizer::iterations ( ) const

return number of iterations in current optimizer state

Definition at line 53 of file NonlinearOptimizer.cpp.

◆ optimize()

virtual const Values& gtsam::NonlinearOptimizer::optimize ( )
inlinevirtual

Optimize for the maximum-likelihood estimate, returning a the optimized variable assignments.

This function simply calls iterate() in a loop, checking for convergence with check_convergence(). For fine-grain control over the optimization process, you may call iterate() and check_convergence() yourself, and if needed modify the optimization state between iterations.

Reimplemented in gtsam::NonlinearConjugateGradientOptimizer.

Definition at line 98 of file NonlinearOptimizer.h.

◆ optimizeSafely()

const Values & gtsam::NonlinearOptimizer::optimizeSafely ( )

Optimize, but return empty result if any uncaught exception is thrown Intended for MATLAB. In C++, use above and catch exceptions. No message is printed: it is up to the caller to check the result

Parameters
optimizera non-linear optimizer

Definition at line 120 of file NonlinearOptimizer.cpp.

◆ solve()

VectorValues gtsam::NonlinearOptimizer::solve ( const GaussianFactorGraph gfg,
const NonlinearOptimizerParams params 
) const
virtual

Default function to do linear solve, i.e. optimize a GaussianFactorGraph

Reimplemented in IterativeLM.

Definition at line 132 of file NonlinearOptimizer.cpp.

◆ values()

const Values & gtsam::NonlinearOptimizer::values ( ) const

return values in current optimizer state

Definition at line 57 of file NonlinearOptimizer.cpp.

Member Data Documentation

◆ graph_

NonlinearFactorGraph gtsam::NonlinearOptimizer::graph_
protected

The graph with nonlinear factors.

Definition at line 78 of file NonlinearOptimizer.h.

◆ state_

std::unique_ptr<internal::NonlinearOptimizerState> gtsam::NonlinearOptimizer::state_
protected

PIMPL'd state.

Definition at line 80 of file NonlinearOptimizer.h.


The documentation for this class was generated from the following files:
gtsam::NonlinearOptimizer::graph
const NonlinearFactorGraph & graph() const
return the graph with nonlinear factors
Definition: NonlinearOptimizer.h:118
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Values
vanilla::params
static const SmartProjectionParams params
Definition: smartFactorScenarios.h:69
result
Values result
Definition: OdometryOptimize.cpp:8


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:16:24