bugGNU Octave - Bugs: bug #61801, [octave forge] (optim) lsqnonlin...

 
 

bug #61801: [octave forge] (optim) lsqnonlin and fmincon test failures

Submitter:  None
Submitted:  Wed 12 Jan 2022 11:07:46 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Ready For Test Assigned to:  None
Originator Name:  MSpo Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 7.1.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 22 Apr 2022 06:18:04 PM UTC, comment #14: 

I cherry-picked that patch to MXE Octave here:
https://hg.octave.org/mxe-octave/rev/8df7db467c66

Should be in the next minor release of Octave (or the nightlies).

Markus Mützel <mmuetzel>
Group administrator
Fri 15 Apr 2022 09:10:40 AM UTC, comment #13: 

Thanks Olaf. It would be great if the fix in 197b5a882a41 were also included in the next release of the MXE installer.

Sébastien Villemot <svillemot>
Fri 15 Apr 2022 08:59:23 AM UTC, comment #12: 

The problem described by the previous post should be fixed now, in 197b5a882a41 (but not in relases 1.6.2 made just now).

Olaf Till <i7tiol>
Group Member
Wed 13 Apr 2022 03:39:03 PM UTC, comment #11: 

Many problems with Octave 7.1.0 have indeed been fixed in the mercurial repository.

However, I still experience one (as of 83eefe952baa):


octave:1> pkg load optim
octave:2> function [v, d] = optimf(x)
>   v = x^2;
>   d = 2*x;
> end
octave:3> optim_options = optimset('GradObj','on');
octave:4> fmincon(@optimf, 3, [], [], [], [], 2, 4, [], optim_options)
error: @<anonymous>: function called with too many inputs
error: called from
    fmincon>@<anonymous>
    __jacobian_constants__>@<anonymous> at line 135 column 11
    __lm_feasible__ at line 145 column 8
    fmincon at line 456 column 24


It is apparently triggered by the combination of explicit gradient with optimization bounds.

Sébastien Villemot <svillemot>
Mon 11 Apr 2022 08:33:45 PM UTC, comment #10: 

works for me now on 8.0.0 and current mercurial of struct (8fcb2a90702c) and optim (83eefe952baa) packages.


octave:1> pkg load optim
octave:2> test fmincon
PASSES 6 out of 6 tests
octave:3> test lsqnonlin
PASSES 2 out of 2 tests
octave:4> pkg list
Package Name  | Version | Installation directory
--------------+---------+-----------------------
          io *|   2.6.4 | /home/arburgers/octave_8/io-2.6.4
       optim *|   1.6.2 | /home/arburgers/octave_8/optim-1.6.2
  statistics *|   1.4.3 | /home/arburgers/octave_8/statistics-1.4.3
      struct *|  1.0.18 | /home/arburgers/octave_8/struct-1.0.18


A.R. Burgers <arb>
Sat 09 Apr 2022 10:35:18 PM UTC, comment #9: 

I confirm that as well. For some reason my struct package was broken internally but was reporting itself as being good. I reinstalled it manually and added mmuetzel's patch in bug #61582 and now I get the same error that you're getting, for both 7.1.0 and 8.0 dev.


octave:5> test fmincon
***** test
 ## equality constraint
 objective_function = @ (p) p(1)^2 + p(2)^2;
 pin = [-2; 5];
 constraint_function = @ (p) - (p(1)^2 + 1 - p(2));
 [p, objf, cvg, outp] = fmincon (objective_function, pin, [], [], [], [], [], [], @ (p) {[], constraint_function(p)}{:}, optimset ("Algorithm", "lm_feasible"));
 assert (p, [0; 1], 1e-6)
!!!!! test failed
@<anonymous>: function called with too many inputs


octave:6> test lsqnonlin
***** test
 t = [0 .3 .8 1.1 1.6 2.3];
 y = [.82 .72 .63 .60 .55 .50];
 yhat = @(c,t) c(1) + c(2)*exp(-t);
 opt = optimset('TolFun',1e-10);
 [c,resnorm,residual] = lsqnonlin(@(c)yhat(c,t)-y,[1 1],[0 0],[],opt);
 assert (c, [ 0.47595; 0.34132], 1e-5)
 assert (resnorm, 3.2419e-004, 1e-8)
 assert(residual, [-2.7283e-003, 8.8079e-003, -6.8307e-004, -1.0432e-002, -5.1366e-003, 1.0172e-002], 1e-5)
!!!!! test failed
@<anonymous>: function called with too many inputs


Arun Giridhar <arungiridhar>
Group Member
Sat 09 Apr 2022 08:51:56 PM UTC, comment #8: 

I confirm that fmincon and lsqnonlin are broken on 7.1.0.

Sébastien Villemot <svillemot>
Sat 09 Apr 2022 08:48:41 PM UTC, comment #7: 

was unable to compile the struct package (current mercurial) with the default branch.

A.R. Burgers <arb>
Sat 09 Apr 2022 12:21:44 PM UTC, comment #6: 

Yes, when I do "pkg load optim" it also loads io 2.6.4, optim 1.6.1, statistics 1.4.3 and struct 1.0.17.

The struct package does have a fields2cell.oct inside it but there is no fields2cell in the path. Something looks broken with the struct package for me. Reinstalling it with "pkg install -forge struct" gave a list of errors about "verror". I'll have to debug that separately.

Do "test lsqnonlin" and "test fmincon" work for you on Octave 7.1.0 or later?

Arun Giridhar <arungiridhar>
Group Member
Sat 09 Apr 2022 11:01:53 AM UTC, comment #5: 

fields2cell seems to be a function in the struct package, a pre-requisite for the optim package. Is the struct package installed?

A.R. Burgers <arb>
Fri 08 Apr 2022 10:17:47 PM UTC, comment #4: 

Retitling this bug and setting it to 7.1.0.

Also, for Octave 8 and optim 1.6.1 the tests still fail but the error is different, referring to "fields2cell".


octave:2> test fmincon
***** test
 ## equality constraint
 objective_function = @ (p) p(1)^2 + p(2)^2;
 pin = [-2; 5];
 constraint_function = @ (p) - (p(1)^2 + 1 - p(2));
 [p, objf, cvg, outp] = fmincon (objective_function, pin, [], [], [], [], [], [], @ (p) {[], constraint_function(p)}{:}, optimset ("Algorithm", "lm_feasible"));
 assert (p, [0; 1], 1e-6)
!!!!! test failed
'fields2cell' undefined near line 75, column 14


octave:4> test lsqnonlin
***** test
 t = [0 .3 .8 1.1 1.6 2.3];
 y = [.82 .72 .63 .60 .55 .50];
 yhat = @(c,t) c(1) + c(2)*exp(-t);
 opt = optimset('TolFun',1e-10);
 [c,resnorm,residual] = lsqnonlin(@(c)yhat(c,t)-y,[1 1],[0 0],[],opt);
 assert (c, [ 0.47595; 0.34132], 1e-5)
 assert (resnorm, 3.2419e-004, 1e-8)
 assert(residual, [-2.7283e-003, 8.8079e-003, -6.8307e-004, -1.0432e-002, -5.1366e-003, 1.0172e-002], 1e-5)
!!!!! test failed
'fields2cell' undefined near line 75, column 14


Arun Giridhar <arungiridhar>
Group Member
Mon 17 Jan 2022 03:26:06 PM UTC, comment #3: 

Note that fmincon is affected by the same issue:


octave:1> pkg load optim
octave:2> test fmincon
***** test
 ## equality constraint
 objective_function = @ (p) p(1)^2 + p(2)^2;
 pin = [-2; 5];
 constraint_function = @ (p) - (p(1)^2 + 1 - p(2));
 [p, objf, cvg, outp] = fmincon (objective_function, pin, [], [], [], [], [], [], @ (p) {[], constraint_function(p)}{:}, optimset ("Algorithm", "lm_feasible"));
 assert (p, [0; 1], 1e-6)
!!!!! test failed
: function called with too many inputs


Sébastien Villemot <svillemot>
Wed 12 Jan 2022 01:54:49 PM UTC, comment #2: 

The issue seems to be that __dfdp__ is defined with a fixed number of 3 input arguments, but handles stuff differently depending on the actual value of nargin. However, with Octave 7.0.90 it must be 3 arguments or the error is thrown.

Anonymous
Wed 12 Jan 2022 12:42:38 PM UTC, comment #1: 

I initially thought this was a broader issue with `varargin` in anonymous functions. But that seems to be working as it should.

As far as I can tell, `func` in line 304 of _dfdp_.m corresponds to the first argument of `lsqnonlin`. It does indeed take only one argument. But `func` is called with two arguments in that line.

CC'ing package maintainer.

Markus Mützel <mmuetzel>
Group administrator
Wed 12 Jan 2022 11:07:46 AM UTC, original submission:  

This minimal example works under Octave 6.4.0 but throws an error in Octave 7.0.90 (plus, there are a couple of warnings when loading the optim package):


pkg load optim

x = (0:0.01:10).';
y = @(p) p(1) + p(2)*sin(2*pi*p(3)*x);

p0 = [0.3 0.5 0.2];
y0 = y([0.37 0.63 0.21]) + (rand(size(x))-0.5);

p_fit = lsqnonlin(@(p) y(p) - y0,p0);
plot(x,[y0,y(p_fit)])


I get this error:


error: : function called with too many inputs
error: called from
    @<anonymous>
    __dfdp__ at line 304 column 15
    __nonlin_residmin__>@<anonymous> at line 329 column 26
    __jacobian_constants__>@<anonymous> at line 121 column 11
    __lm_svd__ at line 196 column 9
    __nonlin_residmin__ at line 452 column 25
    nonlin_residmin at line 98 column 25
    lsqnonlin at line 264 column 21
    optim_bug at line 9 column 7


It seems to boil down to line 316 in \_\_nonlin_residmin\_\_


f.f = @ (varargin) f.f (varargin{:}) - obs;


which doesn’t seem to be allowed anymore.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by i7tiol (Posted a comment)
  • -email is unavailable- added by arb (Posted a comment)
  • -email is unavailable- added by arungiridhar (Posted a comment)
  • -email is unavailable- added by svillemot (Posted a comment)
  • -email is unavailable- added by svillemot
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by mmuetzel
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-22 mmuetzel StatusConfirmed Ready For Test
    2022-04-08 arungiridhar Release7.0.90 7.1.0
        Summary[octave forge] (optim) lsqnonlin doesn't work under Octave 7.0.90 [octave forge] (optim) lsqnonlin and fmincon test failures
    2022-01-17 svillemot Carbon-Copy- Added svillemot
    2022-01-12 mmuetzel StatusNone Confirmed
        Operating SystemMicrosoft Windows Any
        Summarylsqnonlin from optim package doesn't work under Octave 7.0.90 [octave forge] (optim) lsqnonlin doesn't work under Octave 7.0.90
        Carbon-Copy- Added i7tiol

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code