42 std::unique_ptr<internal::NonlinearOptimizerState>
state)
43 : graph_(graph), state_(
std::
move(state)) {}
64 double currentError =
error();
67 if (currentError <= params.
errorTol) {
69 cout <<
"Exiting, as error = " << currentError <<
" < " << params.
errorTol << endl;
77 cout <<
"Initial error: " << currentError << endl;
88 double newError = currentError;
91 currentError = newError;
106 cout <<
"newError: " << newError << endl;
115 cout <<
"Terminating because reached maximum iterations" << endl;
157 throw std::runtime_error(
158 "NonlinearOptimizer::solve: cg parameter has to be assigned ...");
160 if (
auto pcg = std::dynamic_pointer_cast<PCGSolverParameters>(
163 }
else if (
auto spcg =
164 std::dynamic_pointer_cast<SubgraphSolverParameters>(
167 throw std::runtime_error(
"SubgraphSolver needs an ordering");
170 throw std::runtime_error(
171 "NonlinearOptimizer::solve: special cg parameter type is not handled in LM solver ...");
174 throw std::runtime_error(
"NonlinearOptimizer::solve: Optimization parameter is invalid");
183 double errorThreshold,
double currentError,
double newError,
186 if (newError <= errorThreshold)
187 cout <<
"errorThreshold: " << newError <<
" < " << errorThreshold << endl;
189 cout <<
"errorThreshold: " << newError <<
" > " << errorThreshold << endl;
192 if (newError <= errorThreshold)
196 double absoluteDecrease = currentError - newError;
198 if (absoluteDecrease <= absoluteErrorTreshold)
199 cout <<
"absoluteDecrease: " << setprecision(12) << absoluteDecrease <<
" < " 200 << absoluteErrorTreshold << endl;
202 cout <<
"absoluteDecrease: " << setprecision(12) << absoluteDecrease
203 <<
" >= " << absoluteErrorTreshold << endl;
207 double relativeDecrease = absoluteDecrease / currentError;
209 if (relativeDecrease <= relativeErrorTreshold)
210 cout <<
"relativeDecrease: " << setprecision(12) << relativeDecrease <<
" < " 211 << relativeErrorTreshold << endl;
213 cout <<
"relativeDecrease: " << setprecision(12) << relativeDecrease
214 <<
" >= " << relativeErrorTreshold << endl;
216 bool converged = (relativeErrorTreshold && (relativeDecrease <= relativeErrorTreshold)) ||
217 (absoluteDecrease <= absoluteErrorTreshold);
219 if (absoluteDecrease >= 0.0)
220 cout <<
"converged" << endl;
222 cout <<
"Warning: stopping nonlinear iterations because error increased" << endl;
224 cout <<
"errorThreshold: " << newError <<
" <? " << errorThreshold << endl;
225 cout <<
"absoluteDecrease: " << setprecision(12) << absoluteDecrease <<
" <? " 226 << absoluteErrorTreshold << endl;
227 cout <<
"relativeDecrease: " << setprecision(12) << relativeDecrease <<
" <? " 228 << relativeErrorTreshold << endl;
237 currentError, newError, params.
verbosity);
bool isMultifrontal() const
virtual const Values & optimize()
IterationHook iterationHook
Subgraph Solver from IROS 2010.
virtual GaussianFactorGraph::shared_ptr iterate()=0
size_t iterations() const
return number of iterations in current optimizer state
Verbosity verbosity
The printing verbosity during optimization (default SILENT)
const Values & values() const
return values in current optimizer state
bool isSequential() const
NonlinearFactorGraph graph
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
VectorValues optimize(const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
static const SmartProjectionParams params
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5)
bool checkConvergence(double relativeErrorTreshold, double absoluteErrorTreshold, double errorThreshold, double currentError, double newError, NonlinearOptimizerParams::Verbosity verbosity)
std::unique_ptr< internal::NonlinearOptimizerState > state_
PIMPL'd state.
double errorTol
The maximum total error to stop iterating (default 0.0)
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
void print(const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
std::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Linear Factor Graph where all factors are Gaussians.
IterativeOptimizationParameters::shared_ptr iterativeParams
The container for iterativeOptimization parameters. used in CG Solvers.
virtual const NonlinearOptimizerParams & _params() const =0
GaussianFactorGraph::Eliminate getEliminationFunction() const
virtual VectorValues solve(const GaussianFactorGraph &gfg, const NonlinearOptimizerParams ¶ms) const
VectorValues optimize() const
Optimize from zero.
const Values & optimizeSafely()
virtual ~NonlinearOptimizer()
Private class for NonlinearOptimizer state.
VectorValues optimize(const GaussianFactorGraph &gfg, const KeyInfo &keyInfo, const std::map< Key, Vector > &lambda, const VectorValues &initial) override
Ordering::OrderingType orderingType
The method of ordering use during variable elimination (default COLAMD)
std::optional< Ordering > ordering
The optional variable elimination ordering, or empty to use COLAMD (default: empty) ...
Base class and parameters for nonlinear optimization algorithms.
double error() const
return error in current optimizer state
#define tictoc_finishedIteration()
size_t maxIterations
The maximum iterations to stop iterating (default 100)