Skip to content

configurable tolerance for gradient stopping condition (#121) #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/docs/NLopt_Algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ I converted Prof. Luksan's code to C with the help of [f2c](https://en.wikipedia

One of the parameters of this algorithm is the number *M* of gradients to "remember" from previous optimization steps: increasing *M* increases the memory requirements but may speed convergence. NLopt sets *M* to a heuristic value by default, but this can be [changed by the set_vector_storage function](NLopt_Reference.md#vector-storage-for-limited-memory-quasi-newton-algorithms).

The `NLOPT_LD_LBFGS` algorithm supports the following internal parameter, which can be specified using the [`nlopt_set_param` API](NLopt_Reference.md#algorithm-specific-parameters):

* `tolg` (defaults to `1e-8`) "gradient tolerance": the algorithm will stop successfully if either the *maximum absolute value of the negative lagrange multiplier* or the *norm of the transformed gradient* falls below *tolg*.

### Preconditioned truncated Newton

This algorithm in NLopt, is based on a Fortran implementation of a preconditioned inexact truncated Newton algorithm written by Prof. Ladislav Luksan, and graciously posted online under the GNU LGPL at:
Expand All @@ -374,6 +378,10 @@ I converted Prof. Luksan's code to C with the help of [f2c](https://en.wikipedia

One of the parameters of this algorithm is the number *M* of gradients to "remember" from previous optimization steps: increasing *M* increases the memory requirements but may speed convergence. NLopt sets *M* to a heuristic value by default, but this can be [changed by the set_vector_storage function](NLopt_Reference.md#vector-storage-for-limited-memory-quasi-newton-algorithms).

All the `NLOPT_LD_TNEWTON` algorithms support the following internal parameter, which can be specified using the [`nlopt_set_param` API](NLopt_Reference.md#algorithm-specific-parameters):

* `tolg` (defaults to `1e-8`) "gradient tolerance": the algorithm will stop successfully if either the *maximum absolute value of the negative lagrange multiplier* or the *norm of the transformed gradient* falls below *tolg*.

### Shifted limited-memory variable-metric

This algorithm in NLopt, is based on a Fortran implementation of a shifted limited-memory variable-metric algorithm by Prof. Ladislav Luksan, and graciously posted online under the GNU LGPL at:
Expand All @@ -390,6 +398,10 @@ I converted Prof. Luksan's code to C with the help of [f2c](https://en.wikipedia

One of the parameters of this algorithm is the number *M* of gradients to "remember" from previous optimization steps: increasing *M* increases the memory requirements but may speed convergence. NLopt sets *M* to a heuristic value by default, but this can be [changed by the set_vector_storage function](NLopt_Reference.md#vector-storage-for-limited-memory-quasi-newton-algorithms).

The `NLOPT_LD_VAR1` and `NLOPT_LD_VAR2` algorithms support the following internal parameter, which can be specified using the [`nlopt_set_param` API](NLopt_Reference.md#algorithm-specific-parameters):

* `tolg` (defaults to `1e-8`) "gradient tolerance": the algorithm will stop successfully if either the *maximum absolute value of the negative lagrange multiplier* or the *norm of the transformed gradient* falls below *tolg*.

Augmented Lagrangian algorithm
------------------------------

Expand Down
17 changes: 10 additions & 7 deletions src/algs/luksan/luksan.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,30 @@ extern "C"
#endif /* __cplusplus */

nlopt_result luksan_plis(int n, nlopt_func f, void *f_data,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
double *minf,
nlopt_stopping *stop,
int mf);
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
double *minf,
nlopt_stopping *stop,
int mf,
double tolg);

nlopt_result luksan_plip(int n, nlopt_func f, void *f_data,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
double *minf,
nlopt_stopping *stop,
int mf,
int method);
int method,
double tolg);

nlopt_result luksan_pnet(int n, nlopt_func f, void *f_data,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
double *minf,
nlopt_stopping *stop,
int mf,
int mos1, int mos2);
int mos1, int mos2,
double tolg);

typedef struct {
double fl, fu, pl, rl, pu, ru;
Expand Down
4 changes: 2 additions & 2 deletions src/algs/luksan/plip.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,13 @@ nlopt_result luksan_plip(int n, nlopt_func f, void *f_data,
double *minf,
nlopt_stopping *stop,
int mf, /* subspace dimension (0 for default) */
int method) /* 1 or 2, see below */
int method, /* 1 or 2, see below */
double tolg) /* gradient tolerance */
{
int i, *ix, nb = 1;
double *work, *xl, *xu, *gf, *s, *xo, *go, *so, *xm, *xr, *gr;
double gmax, minf_est;
double xmax = 0; /* no maximum */
double tolg = 0; /* default gradient tolerance */
int iest = 0; /* we have no estimate of min function value */
int mit = 0; /* default no limit on #iterations */
int mfv = stop->maxeval;
Expand Down
4 changes: 2 additions & 2 deletions src/algs/luksan/plis.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,13 @@ nlopt_result luksan_plis(int n, nlopt_func f, void *f_data,
double *x, /* in: initial guess, out: minimizer */
double *minf,
nlopt_stopping *stop,
int mf) /* subspace dimension, 0 for default */
int mf, /* subspace dimension, 0 for default */
double tolg) /* gradient tolerance */
{
int i, *ix, nb = 1;
double *work, *xl, *xu, *xo, *gf, *s, *go, *uo, *vo;
double gmax, minf_est;
double xmax = 0; /* no maximum */
double tolg = 0; /* default gradient tolerance */
int iest = 0; /* we have no estimate of min function value */
int mit = 0; /* default no limit on #iterations */
int mfv = stop->maxeval;
Expand Down
4 changes: 2 additions & 2 deletions src/algs/luksan/pnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,14 @@ nlopt_result luksan_pnet(int n, nlopt_func f, void *f_data,
double *minf,
nlopt_stopping *stop,
int mf, /* subspace dimension (0 for default) */
int mos1, int mos2) /* 1 or 2 */
int mos1, int mos2, /* 1 or 2 */
double tolg) /* gradient tolerance */
{
int i, *ix, nb = 1;
double *work;
double *xl, *xu, *gf, *gn, *s, *xo, *go, *xs, *gs, *xm, *gm, *u1, *u2;
double gmax, minf_est;
double xmax = 0; /* no maximum */
double tolg = 0; /* default gradient tolerance */
int iest = 0; /* we have no estimate of min function value */
int mit = 0, mfg = 0; /* default no limit on #iterations */
int mfv = stop->maxeval;
Expand Down
6 changes: 3 additions & 3 deletions src/api/optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf)

case NLOPT_LD_LBFGS:
#ifdef NLOPT_LUKSAN
return luksan_plis(ni, f, f_data, lb, ub, x, minf, &stop, opt->vector_storage);
return luksan_plis(ni, f, f_data, lb, ub, x, minf, &stop, opt->vector_storage, nlopt_get_param(opt, "tolg", 0.));
#else
printf("ERROR - attempting to use NLOPT_LD_LBFGS, but Luksan code disabled\n");
return NLOPT_INVALID_ARGS;
Expand All @@ -724,7 +724,7 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf)
case NLOPT_LD_VAR1:
case NLOPT_LD_VAR2:
#ifdef NLOPT_LUKSAN
return luksan_plip(ni, f, f_data, lb, ub, x, minf, &stop, opt->vector_storage, algorithm == NLOPT_LD_VAR1 ? 1 : 2);
return luksan_plip(ni, f, f_data, lb, ub, x, minf, &stop, opt->vector_storage, algorithm == NLOPT_LD_VAR1 ? 1 : 2, nlopt_get_param(opt, "tolg", 0.));
#else
printf("ERROR - attempting to use NLOPT_LD_VAR*, but Luksan code disabled\n");
return NLOPT_INVALID_ARGS;
Expand All @@ -735,7 +735,7 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf)
case NLOPT_LD_TNEWTON_PRECOND:
case NLOPT_LD_TNEWTON_PRECOND_RESTART:
#ifdef NLOPT_LUKSAN
return luksan_pnet(ni, f, f_data, lb, ub, x, minf, &stop, opt->vector_storage, 1 + (algorithm - NLOPT_LD_TNEWTON) % 2, 1 + (algorithm - NLOPT_LD_TNEWTON) / 2);
return luksan_pnet(ni, f, f_data, lb, ub, x, minf, &stop, opt->vector_storage, 1 + (algorithm - NLOPT_LD_TNEWTON) % 2, 1 + (algorithm - NLOPT_LD_TNEWTON) / 2, nlopt_get_param(opt, "tolg", 0.));
#else
printf("ERROR - attempting to use NLOPT_LD_TNEWTON*, but Luksan code disabled\n");
return NLOPT_INVALID_ARGS;
Expand Down
Loading