42 std::unique_ptr<Solver> solver)
44 _currentLambda(
cst(-1.)),
46 _goodStepLowerScale(
cst(1. / 3.)),
47 _goodStepUpperScale(
cst(2. / 3.)),
49 _levenbergIterations(0),
50 m_solver{
std::move(solver)} {
60 int iteration,
bool online) {
63 "underlying linear solver operates on different graph");
70 return OptimizationAlgorithm::Fail;
122 if (!ok2) tempChi = std::numeric_limits<double>::max();
124 rho = (currentChi - tempChi);
130 double alpha = 1. - pow((2 * rho - 1), 3);
136 currentChi = tempChi;
145 }
while (rho < 0 && qmax < _maxTrialsAfterFailure->value() &&
156 double maxDiagonal = 0;
161 for (
int j = 0; j < dim; ++j) {
162 maxDiagonal = std::max(fabs(v->
hessian(j, j)), maxDiagonal);
165 return _tau * maxDiagonal;
A general case Vertex for optimization.
virtual const double & hessian(int i, int j) const =0
get the element from the hessian matrix
int dimension() const
dimension of the estimated state belonging to this node
Property< double > * _userLambdaInit
void setMaxTrialsAfterFailure(int max_trials)
double _goodStepUpperScale
Property< int > * _maxTrialsAfterFailure
double computeLambdaInit() const
OptimizationAlgorithmLevenberg(std::unique_ptr< Solver > solver)
double _goodStepLowerScale
virtual void printVerbose(std::ostream &os) const
virtual SolverResult solve(int iteration, bool online=false)
virtual ~OptimizationAlgorithmLevenberg()
void setUserLambdaInit(double lambda)
double computeScale() const
Base for solvers operating on the approximated Hessian, e.g., Gauss-Newton, Levenberg.
SparseOptimizer * _optimizer
the optimizer the solver is working on
P * makeProperty(const std::string &name_, const typename P::ValueType &v)
void setValue(const T &v)
double * b()
return b, the right hand side of the system
virtual void restoreDiagonal()=0
virtual bool buildStructure(bool zeroBlocks=false)=0
size_t vectorSize() const
return the size of the solution vector (x) and b
double * x()
return x, the solution vector
virtual bool setLambda(double lambda, bool backup=false)=0
virtual bool buildSystem()=0
virtual bool schur()=0
should the solver perform the schur complement or not
SparseOptimizer * optimizer() const
the optimizer (graph) on which the solver works
void push(SparseOptimizer::VertexContainer &vlist)
push the estimate of a subset of the variables onto a stack
void computeActiveErrors()
void pop(SparseOptimizer::VertexContainer &vlist)
pop (restore) the estimate a subset of the variables from the stack
void update(const double *update)
double activeRobustChi2() const
const VertexContainer & indexMapping() const
the index mapping of the vertices
void discardTop(SparseOptimizer::VertexContainer &vlist)
bool terminate()
if external stop flag is given, return its state. False otherwise
#define __PRETTY_FUNCTION__
constexpr double cst(long double v)
double get_monotonic_time()
statistics about the optimization
double timeLinearSolution
double timeResiduals
residuals
static G2OBatchStatistics * globalStats()
double timeUpdate
time to apply the update
int levenbergIterations
number of iterations performed by LM
double timeQuadraticForm
construct the quadratic form in the graph
utility functions for handling time related stuff