`optim` undocumented `err` values?

Hello everyone,

when I use optim and retrieve the err flag, I got values of 12 and 13, about which I didn’t find any information. From the documentation, I have this:

err=1: Norm of projected gradient lower than…
err=2: At last iteration f decreases by less than…
err=3: Optimization stops because of too small variations for x.
err=4: Optim stops: maximum number of calls to f is reached.
err=5: Optim stops: maximum number of iterations is reached.
err=6: Optim stops: too small variations in gradient direction.
err=7: Stop during calculation of descent direction.
err=8: Stop during calculation of estimated hessian.
err=9: End of optimization, successful completion.
err=10: End of optimization (linear search fails).

Please find below a truncated example of console output with the iprint flag set to 2 and a returned value of 12.

 *********** qnbd (with bound cstr) ****************
dimension=         4, epsq=  0.2220446049250313E-15, verbosity level: iprint=         2
max number of iterations allowed: iter=       100
max number of calls to costf allowed: nap=       100
------------------------------------------------
 qnbd : iter=  1  f=  0.1126653D-01
 qnbd : nbre fact  4 defact  0 total var factorisees  4
 qnbd : epsg,difg= 0.2220D-15 0.2162D-01  epsf,diff= 0.0000D+00 0.4108D-02  nap=  8
 qnbd : iter=  2  f=  0.7158237D-02
 qnbd : nbre fact  0 defact  0 total var factorisees  4
 qnbd : epsg,difg= 0.2220D-15 0.1146D-01  epsf,diff= 0.0000D+00 0.7266D-03  nap= 10
...
...
 qnbd : nbre fact  0 defact  0 total var factorisees  4
 qnbd : epsg,difg= 0.2220D-15 0.1818D-03  epsf,diff= 0.0000D+00 0.1151D-08  nap= 33
 qnbd : iter= 21  f=  0.5656227D-02
 qnbd : nbre fact  0 defact  0 total var factorisees  4
 qnbd : epsg,difg= 0.2220D-15 0.1818D-03  epsf,diff= 0.0000D+00 0.8674D-18  nap= 48
 qnbd : iter= 22  f=  0.5656227D-02
 qnbd : nbre fact  0 defact  0 total var factorisees  4
 qnbd : indqn=      12

I tried searching in the source code, but I am not familiar with it and didn’t find anything relevant.

Does anyone know what the err values of 12 and 13 mean?

Hello, welcome to Scilab’s Discourse !

after looking into the sources (see scilab/modules/optimization/src/fortran/zqnbd.f · main · scilab / scilab · GitLab and scilab/modules/optimization/src/fortran/rlbd.f · main · scilab / scilab · GitLab), indqn=12 means that the linear search failed because of a too small step increment and indqn=13 that the maximum number of calls to the user function (cost+gradient) has been exceeded. I do agree that these values should be mapped to err=10 and err=4, respectively.

S.

Thanks a lot Stéphane !