43 std::unique_ptr<BlockSolverBase> solver)
45 m_solver{
std::move(solver)} {
64 int iteration,
bool online) {
67 "underlying linear solver operates on different graph");
76 return OptimizationAlgorithm::Fail;
108 double bNormSquared = b.squaredNorm();
109 double alpha = bNormSquared /
_auxVector.dot(b);
112 double hsdNorm =
_hsd.norm();
113 double hgnNorm = -1.;
115 bool solvedGaussNewton =
false;
116 bool goodStep =
false;
122 if (!solvedGaussNewton) {
123 const double minLambda =
cst(1e-12);
124 const double maxLambda =
cst(1e3);
125 solvedGaussNewton =
true;
129 bool solverOk =
false;
156 assert(hgnNorm >= 0. &&
"Norm of the GN step is not computed");
161 }
else if (hsdNorm >
_delta) {
167 double bmaSquaredNorm =
_auxVector.squaredNorm();
170 beta = (-c + sqrt(c * c + bmaSquaredNorm *
174 double hsdSqrNorm =
_hsd.squaredNorm();
177 (c + sqrt(c * c + bmaSquaredNorm * (
_delta *
_delta - hsdSqrNorm)));
179 assert(beta > 0. && beta < 1 &&
"Error while computing beta");
183 "Computed step does not correspond to the trust region");
196 double nonLinearGain = currentChi - newChi;
197 if (fabs(linearGain) < 1e-12) linearGain =
cst(1e-12);
198 double rho = nonLinearGain / linearGain;
213 }
while (!goodStep && numTries < _maxTrialsAfterFailure->value());
base for the block solvers with some basic function interfaces
virtual void multiplyHessian(double *dest, const double *src) const =0
VectorX _hsd
steepest decent step
double _delta
trust region
Property< double > * _initialLambda
int _lastStep
type of the step taken by the algorithm
virtual void printVerbose(std::ostream &os) const
VectorX _hdl
final dogleg step
Property< int > * _maxTrialsAfterFailure
static const char * stepType2Str(int stepType)
convert the type into an integer
Property< double > * _lamdbaFactor
double _currentLambda
the damping factor to force positive definite matrix
virtual ~OptimizationAlgorithmDogleg()
virtual SolverResult solve(int iteration, bool online=false)
OptimizationAlgorithmDogleg(std::unique_ptr< BlockSolverBase > solver)
Property< double > * _userDeltaInit
bool _wasPDInAllIterations
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)
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
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
void discardTop(SparseOptimizer::VertexContainer &vlist)
#define __PRETTY_FUNCTION__
constexpr double cst(long double v)
double get_monotonic_time()
statistics about the optimization
double timeResiduals
residuals
static G2OBatchStatistics * globalStats()
double timeQuadraticForm
construct the quadratic form in the graph
utility functions for handling time related stuff