2#include "optimization_algorithm_with_hessian.h"
49 if (iteration == 0 && !online)
60 g_type tempChi = currentChi;
62 g_type iniChi = currentChi;
95 tempChi = std::numeric_limits<g_type>::max();
97 rho = (currentChi - tempChi);
99 scale += g_type(1e-3);
102 if (rho >
gs_epsilon && std::isfinite(tempChi))
104 g_type alpha = g_type(1. - pow((2 * rho - 1), 3));
110 currentChi = tempChi;
125 if ((iniChi - currentChi) * 1e3 < iniChi)
145 for (
uint04 i = 0; i < iterations; i++)
187 g_type maxDiagonal = 0.;
188 for (
uint04 k = 0; k < OptimizationAlgorithmWithHessian<t_type>::optimizer().indexMapping().size(); k++) {
192 for (
int j = 0; j < dim; ++j) {
193 maxDiagonal = std::max(fabs(v->
hessian(j, j)), maxDiagonal);
196 return _tau * maxDiagonal;
203 for (
size_t j = 0; j < OptimizationAlgorithmWithHessian<t_type>::solver.vectorSize(); j++) {
209 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
A general case Vertex for optimization.
virtual sint04 dimension() const =0
dimension of the estimated state belonging to this node
virtual const g_type & hessian(int i, int j) const =0
get the element from the hessian matrix
Implementation of the Levenberg-Marquardt optimization algorithm.
OptimizationAlgorithmLevenberg()
construct the Levenberg algorithm, which will use the given Solver for solving the linearized system.
void setUserLambdaInit(g_type lambda)
Sets a user-specified initial damping factor.
g_type currentLambda() const
return the currently used damping factor
int _nBad
Counter for consecutive bad (non-improving) iterations.
g_type _tau
Scaling factor for initial lambda computation.
void clear()
Resets all Levenberg-Marquardt state to initial values.
void optimize(uint04 iterations, bool online, IndexScratch &scratch)
Runs Levenberg-Marquardt optimization for the given number of iterations.
int levenbergIteration()
return the number of levenberg iterations performed in the last round
g_type _currentLambda
Current damping factor.
g_type _ni
Multiplicative increase factor for lambda on bad steps.
OptimizationAlgorithm::SolverResult solve(int iteration, bool online, IndexScratch &scratch)
Performs a single Levenberg-Marquardt iteration with adaptive damping.
g_type _lambdaInit
User-specified initial lambda (0 = auto-compute).
g_type computeLambdaInit() const
helper for Levenberg, this function computes the initial damping factor, if the user did not specify ...
g_type computeScale() const
Computes the predicted reduction scale for the trust-region ratio.
g_type _goodStepLowerScale
Lower bound for lambda decrease if a good LM step.
int _levenbergIterations
The number of Levenberg iterations performed to accept the last step.
g_type _goodStepUpperScale
Upper bound for lambda decrease if a good LM step.
OptimizationAlgorithmWithHessian()
bool init(bool online=false)
Initializes the solver, detecting whether Schur complement should be used.
void clear()
Clears the solver state.
t_solver solver
The underlying solver instance.
SparseOptimizer & optimizer()
Returns a mutable reference to the underlying sparse optimizer.
SolverResult
Result codes returned by the solver after each iteration.
@ Fail
Iteration failed (e.g., singular matrix).
@ OK
Iteration succeeded, continue.
@ Terminate
Optimization should stop (converged or no improvement).
const VertexContainer & indexMapping() const
the index mapping of the vertices
void update(const g_type *update)
update the estimate of the active vertices
void computeActiveErrors()
computes the error vectors of all edges in the activeSet, and caches them
g_type activeRobustChi2() const
Returns the total robustified chi-squared error of all active edges.
The primary namespace for the NDEVR SDK.
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator The only requirement is that t_type have > ...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr g_type gs_epsilon
Convergence threshold for Levenberg-Marquardt.
Scratch buffers for block index assignments during structure building.