29 #include <Eigen/Cholesky> 37 PRINT_ERROR(
"LevenbergMarquardtDense(): cannot handle non-least-squares objectives or LS objectives in non-LS form.");
46 if (obj_value) *obj_value = -1;
52 PRINT_ERROR(
"LevenbergMarquardtDense(): cannot handle non-least-squares objectives or LS objectives in non-LS form.");
66 PRINT_WARNING(
"LevenbergMarquardtDense: problem has zero dimension");
97 constexpr
const double eps1 = 1e-5;
98 constexpr
const double eps2 = 1e-5;
99 constexpr
const double eps3 = 1e-5;
100 constexpr
const double eps4 = 0;
106 constexpr
const double goodStepUpperScale = 2. / 3.;
107 constexpr
const double goodStepLowerScale = 1. / 3.;
111 double mu = tau *
_hessian.diagonal().maxCoeff();
117 double chi2_old =
_values.squaredNorm();
118 if (obj_value) *obj_value = chi2_old;
132 if (
_delta.norm() <= eps2)
146 double chi2_new =
_values.squaredNorm();
157 if (!stop && k < _iterations - 1)
174 double scaleFactor =
std::max(goodStepLowerScale, alpha);
180 if (obj_value) *obj_value = chi2_old;
193 }
while (rho <= 0 && !stop);
194 stop = (
_values.norm() <= eps3);
307 #ifdef MESSAGE_SUPPORT 308 void LevenbergMarquardtDense::toMessage(corbo::messages::NlpSolver& message)
const 310 message.mutable_levenberg_marquardt_dense()->set_iterations(
_iterations);
311 message.mutable_levenberg_marquardt_dense()->set_weight_eq(
_weight_init_eq);
322 void LevenbergMarquardtDense::fromMessage(
const corbo::messages::NlpSolver& message, std::stringstream* issues)
324 _iterations = message.levenberg_marquardt_dense().iterations();
double _weight_adapt_factor_eq
virtual int finiteCombinedBoundsDimension()
Dimension of the set of finite bounds (combined such that each ub and lb component define a single di...
SolverStatus solve(OptimizationProblemInterface &problem, bool new_structure=true, bool new_run=true, double *obj_value=nullptr) override
Solve the provided optimization problem.
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
void adaptWeights()
Perform single weight adapation step.
void resetWeights()
Reset weights to their original values.
Eigen::MatrixXd _jacobian
virtual void backupParameters()=0
Restore parameter set from the last backup and keep backup if desired.
#define PRINT_WARNING(msg)
Print msg-stream.
virtual int getInequalityDimension()=0
Total dimension of general inequality constraints.
virtual void computeDenseJacobianEqualities(Eigen::Ref< Eigen::MatrixXd > jacobian, const double *multipliers=nullptr)
Compute the equality constraint Jacobian Jceq(x) for the current parameter set.
virtual void computeDenseJacobianFiniteCombinedBounds(Eigen::Ref< Eigen::MatrixXd > jacobian, double weight=1.0)
Compute the Jacobian for finite combined bounds.
virtual void computeDenseJacobianActiveInequalities(Eigen::Ref< Eigen::MatrixXd > jacobian, double weight=1.0)
Compute the Jacobian Jc(x) with non-zeros for active constraints c(x)>= 0 and zeros for inactive ones...
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
void computeJacobian(OptimizationProblemInterface &problem)
Compute overall jacobian including constraint approximation.
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...
virtual void restoreBackupParameters(bool keep_backup)=0
Discard last backup (or all)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isinf(const half &a)
virtual int getEqualityDimension()=0
Total dimension of equality constraints.
bool initialize(OptimizationProblemInterface *problem=nullptr) override
Initialize the solver w.r.t. a given optimization problem.
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.
double _weight_adapt_factor_ineq
void clear() override
Clear internal caches.
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.
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.
double _weight_init_bounds
void setPenaltyWeights(double weight_eq, double weight_ineq, double weight_bounds)
Define penalty weights (equality constraints, inequality constraints, bounds)
double _weight_adapt_max_ineq
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
virtual int getParameterDimension()=0
Effictive dimension of the optimization parameter set (changeable, non-fixed part) ...
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isnan(const half &a)
double _weight_adapt_max_eq
double _weight_adapt_factor_bounds
virtual void computeDenseJacobianLsqObjective(Eigen::Ref< Eigen::MatrixXd > jacobian, const double *multipliers=nullptr)
Compute the objective Jacobian Jf(x) for the current parameter set.
double _weight_adapt_max_bounds
void computeValues(OptimizationProblemInterface &problem)
Compute overall value vector including constraint approximation.
#define PRINT_ERROR(msg)
Print msg-stream as error msg.