29 #include <Eigen/Cholesky> 37 PRINT_ERROR(
"LevenbergMarquardtSparse(): cannot handle non-least-squares objectives or LS objectives in non-LS form.");
46 if (obj_value) *obj_value = -1;
52 PRINT_ERROR(
"LevenbergMarquardtSparse(): cannot handle non-least-squares objectives or LS objectives in non-LS form.");
103 constexpr
const double eps1 = 1e-5;
104 constexpr
const double eps2 = 1e-5;
105 constexpr
const double eps3 = 1e-5;
106 constexpr
const double eps4 = 0;
112 constexpr
const double goodStepUpperScale = 2. / 3.;
113 constexpr
const double goodStepLowerScale = 1. / 3.;
122 bool analyze_pattern = new_structure;
125 double chi2_old =
_values.squaredNorm();
126 if (obj_value) *obj_value = chi2_old;
144 analyze_pattern =
false;
151 if (
_delta.norm() <= eps2)
167 double chi2_new =
_values.squaredNorm();
178 if (!stop && k < _iterations - 1)
196 double scaleFactor =
std::max(goodStepLowerScale, alpha);
202 if (obj_value) *obj_value = chi2_old;
215 }
while (rho <= 0 && !stop);
216 stop = (
_values.norm() <= eps3);
303 #ifdef MESSAGE_SUPPORT 304 void LevenbergMarquardtSparse::toMessage(corbo::messages::NlpSolver& message)
const 306 message.mutable_levenberg_marquardt_sparse()->set_iterations(
_iterations);
307 message.mutable_levenberg_marquardt_sparse()->set_weight_eq(
_weight_init_eq);
308 message.mutable_levenberg_marquardt_sparse()->set_weight_ineq(
_weight_init_ineq);
318 void LevenbergMarquardtSparse::fromMessage(
const corbo::messages::NlpSolver& message, std::stringstream* issues)
320 _iterations = message.levenberg_marquardt_sparse().iterations();
virtual int finiteCombinedBoundsDimension()
Dimension of the set of finite bounds (combined such that each ub and lb component define a single di...
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
virtual void backupParameters()=0
Restore parameter set from the last backup and keep backup if desired.
const ConstDiagonalReturnType diagonal() const
Eigen::SparseMatrix< double > _hessian
virtual int getInequalityDimension()=0
Total dimension of general inequality constraints.
void resize(Index rows, Index cols)
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
virtual void computeDistanceFiniteCombinedBounds(Eigen::Ref< Eigen::VectorXd > values)
Compute the distance to finite bound values (combined lower and upper)
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
virtual int computeSparseJacobianInequalitiesNNZ()
void resetWeights()
Reset weights to their original values.
virtual void restoreBackupParameters(bool keep_backup)=0
Discard last backup (or all)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isinf(const half &a)
double _weight_init_bounds
virtual int getEqualityDimension()=0
Total dimension of equality constraints.
double _weight_adapt_max_bounds
Eigen::SimplicialLLT< Eigen::SparseMatrix< double >, Eigen::Upper > _sparse_solver
Eigens sparse solver wrapper. Check http://eigen.tuxfamily.org/dox/group__TopicSparseSystems.html for further information and different solvers. The second template parameter specifies, whether the upper or lower triangular part should be used. If CHOLMOD was found by CMake, the cholmod supernodal llt version is used rathar than Eigens simplicial ldlt. Define FORCE_EIGEN_SOLVER if the default LDLT should sill be used even if CHOLMOD is found.
void factorize(const MatrixType &a)
virtual void applyIncrement(const Eigen::Ref< const Eigen::VectorXd > &increment)
Apply increment to the current parameter set.
virtual int getLsqObjectiveDimension()=0
Total dimension of least-squares objective function terms.
void setWeightAdapation(double factor_eq, double factor_ineq, double factor_bounds, double max_eq, double max_ineq, double max_bounds)
Set parameters for weight adaptation (refer to the class description); set factors to 1 in order to d...
double _weight_adapt_factor_eq
TransposeReturnType transpose()
virtual void computeValuesActiveInequality(Eigen::Ref< Eigen::VectorXd > values, double weight=1.0)
Compute the values of the active inequality constraints (elementwise max(0, c(x))) ...
Generic interface for optimization problem definitions.
void clear() override
Clear internal caches.
double _weight_adapt_factor_ineq
void adaptWeights()
Perform single weight adapation step.
virtual void computeValuesEquality(Eigen::Ref< Eigen::VectorXd > values)=0
Compute the equality constraint values ceq(x) for the current parameter set.
#define PRINT_WARNING_COND(cond, msg)
Print msg-stream only if cond == true.
virtual int computeSparseJacobianEqualitiesNNZ()
double _weight_adapt_max_ineq
virtual int computeSparseJacobianLsqObjectiveNNZ()
Scalar & coeffRef(Index row, Index col)
void computeValues(OptimizationProblemInterface &problem)
Compute overall value vector including constraint approximation.
virtual int computeSparseJacobianFiniteCombinedBoundsNNZ()
virtual bool isLeastSquaresProblem() const =0
Check if the underlying problem is defined in the least squares form.
virtual void computeValuesLsqObjective(Eigen::Ref< Eigen::VectorXd > values)=0
Compute the objective function values f(x) for the current parameter set.
virtual void discardBackupParameters(bool all=false)=0
void reserve(Index reserveSize)
virtual int getParameterDimension()=0
Effictive dimension of the optimization parameter set (changeable, non-fixed part) ...
void analyzePattern(const MatrixType &a)
Eigen::SparseMatrix< double > _jacobian
double _weight_adapt_factor_bounds
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isnan(const half &a)
SolverStatus solve(OptimizationProblemInterface &problem, bool new_structure=true, bool new_run=true, double *obj_value=nullptr) override
Solve the provided optimization problem.
double _weight_adapt_max_eq
void setPenaltyWeights(double weight_eq, double weight_ineq, double weight_bounds)
Define penalty weights (equality constraints, inequality constraints, bounds)
bool initialize(OptimizationProblemInterface *problem=nullptr) override
Initialize the solver w.r.t. a given optimization problem.
#define PRINT_ERROR(msg)
Print msg-stream as error msg.
virtual void computeCombinedSparseJacobian(Eigen::SparseMatrix< double > &jacobian, bool objective_lsq, bool equality, bool inequality, bool finite_combined_bounds, bool active_ineq=false, double weight_eq=1.0, double weight_ineq=1.0, double weight_bounds=1.0, const Eigen::VectorXd *values=nullptr, const Eigen::VectorXi *col_nnz=nullptr)