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

 
 

bug #63286: [octave forge] (optim) fmincon fails for Rosenbrock example

Submitter:  Liang Tang <lt1234>
Submitted:  Fri 28 Oct 2022 09:01:59 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  lt1234 Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 04 Nov 2022 02:22:12 PM UTC, comment #17: 

To add to the links that nrjank already pointed you to, if you believe that there is a missing feature that Matlab has, you can open a bug report for that and submit a patch there as well. This is especially true for core Octave.

If you're referring to the optim and/or parallel packages, Octave packages are external to Octave core (much like PyPI packages are external to Python), and usually their developers and maintainers are not the same as core maintainers. You can still submit those patches to Savannah using a separate bug report as described above, or you could also reach out to the package maintainers on Github directly and ask if they accept PRs. See https://gnu-octave.github.io/packages/ for the list of packages.

Arun Giridhar <arungiridhar>
Group Member
Fri 04 Nov 2022 12:14:20 PM UTC, comment #16: 

@Liang - as an off topic comment about general contribution questions, that would probably be better posted in the Octave discussion forum at https://octave.discourse.group/

General guidelines on how to get involved contributing to octave can be found at: https://wiki.octave.org/Developer_FAQ



Nicholas Jankowski <nrjank>
Group Member
Fri 04 Nov 2022 11:17:04 AM UTC, comment #15: 

Hi Arun, I have a bug unrelated question.  This item must have been discussed many times in the past.  But to modify a code taken from someone else to work in pararrayfun and paracellfun require significantly lot more work than changing 'for' to 'parfor' plus some array/matrix allocation.  So I am interested in the feasibility. 

This is from the command line help of parfor:

Warning: parallel processing pools are currently unimplemented in
 Octave; 'parfor' currently behaves exactly as a normal 'for' loop.

How can I pull a request to make Octave parfor works like a Matlab parfor? 

Thanks,

Liang Tang <lt1234>
Tue 01 Nov 2022 03:11:00 PM UTC, comment #14: 

Right, that notice is about all the Octave Forge packages at SourceForge. They've been migrated to Github and optim is getting maintained there. That notice is for anyone finding the old SourceForge pages through a web search, but I see how it can be ambiguous in the context of a single package.

Btw, these days when you do "pkg install -forge" it picks up the package from Github not SourceForge.

Arun Giridhar <arungiridhar>
Group Member
Tue 01 Nov 2022 02:38:20 PM UTC, comment #13: 

I used this page: https://octave.sourceforge.io/optim/

I will look into nonlin_min.

Thanks.

Liang Tang <lt1234>
Tue 01 Nov 2022 02:17:45 PM UTC, comment #12: 

I'm not seeing any notice that optim is not being maintained.  Where did you see it?
https://gnu-octave.github.io/packages/optim/

I recall that fmincon was added only to serve as a Matlab-compatible wrapper to nonlin_min. If you can live without Matlab function name compatibility, can you try nonlin_min directly? That is generally more powerful than fmincon. If that works but fmincon doesn't, then at least we'll have localized the problem.

Arun Giridhar <arungiridhar>
Group Member
Tue 01 Nov 2022 10:29:13 AM UTC, comment #11: 

Hi Arun,

optim's web page does indicate that optim is not actively maintained. 

I will add one more item.  It is related to nonlinear constraint input of fmincon.

>>  fun=@(x) x^2;
>>  fun_c=@(x) 1-x^2;  % The assumed constraint is (<=0), i.e., x^2>=1 is the constraint
>> [X, FVAL, CVG]=fmincon (fun,   0, A=[], B=[], AEQ=[], BEQ=[], LB=[], UB=[]);             % converge to 0
>> [X, FVAL, CVG]=fmincon (fun_c, 0, A=[], B=[], AEQ=[], BEQ=[], LB=[], UB=[]);             % diverge as expected
>> [X, FVAL, CVG]=fmincon (fun,   0, A=[], B=[], AEQ=[], BEQ=[], LB=[], UB=[], fun_c);      % x=1 is expected

error: element number 2 undefined in return list
error: called from
    fmincon>out_2_wrapper at line 521 column 12
    fmincon>@<anonymous> at line 309 column 36
    _process_constraints_>tf_gencstr at line 147 column 7
    collect_constraints>@<anonymous> at line 115 column 2
    _process_constraints_>@<anonymous> at line 41 column 36
    _constraints_interface_ at line 35 column 18
    fmincon at line 425 column 16

Liang Tang <lt1234>
Sat 29 Oct 2022 02:28:54 PM UTC, comment #10: 

I see what you mean. Whether it accepts column only or both column and row, it should say so up front, not wait until calculating the fourth output and only then give an error.

Will wait on the optim package maintainers to weigh in.

Since sqp is a core function and fmincon is not, can someone comment on optimization function input aspects, especially whether they should take only column inputs or not?

Arun Giridhar <arungiridhar>
Group Member
Sat 29 Oct 2022 12:53:35 PM UTC, comment #9: 

Hi Arun,

For the row/column inputs, please consider the link below.  Array is a legal input. 

https://www.mathworks.com/help/optim/ug/matrix-arguments.html

I have seen the row vs column inputs causing error message for dimension mismatch.  Fmincon accepts both and sqp accepts only column input.  So there is some confusion on my side for exactly what to expect.  For the specific OUTP issue, I think the optimal solution has been obtained regardless if there is OUTP or not.  The form below did provide the right solution.  Or you might want to document the special column input requirement for fmincon OUTP to work.   Thanks. 

[X, FVAL, CVG]=fmincon (OBJF=fun, [0 0], A=[], B=[], AEQ=[], BEQ=[], LB=[0 0], UB=[1 1])

Liang Tang <lt1234>
Sat 29 Oct 2022 12:22:54 PM UTC, comment #8: 

I am getting completely bizarre results for the Rosenbrock function, so I'm marking this as Confirmed. Also retitling it since it is unrelated to anonymous functions. (I got the same results when I created a standalone fun.m with the same expression as the anonymous function.)

This is all with Octave 8 (hg id ee03da4812fd), optim 1.6.2, statistics 1.5.0, and struct 1.0.18.

Test:


clear all
fun = @(x) 100*(x(2) - x(1)^2) + (1 - x(1))^2;
A = [1 2];
b = 1;
x0 = [1 0]';
x = fmincon (fun, x0, A, b)


This gives the result:

x =
   1.457337448511223e+17
  -7.286687242556115e+16


Changing x0 to [-1 0]' changes the output to:

x =
  -3.19965837099897e+152
  -2.654287402237436e+151


Changing x0 to the example's value of [-1 2]' gives the error as described by the OP:

error: Initial parameters violate constraints.
error: called from
    __lm_feasible__ at line 92 column 5
    fmincon at line 456 column 24


Regarding the output causing an error for the OP, that only causes a problem for me if x0, LB and UB are row vectors, but if they are passed as column vectors then it works properly, so that does not look like a bug:


>> clear all; fun = @(x) 100*(x(2) - x(1)^2) + (1 - x(1))^2; [x,fval,cvg,outp] = fmincon (fun, [0 0]', [],[], [],[], [0 0]', [1 1]')
x =
                       1
                       0

fval =             -100
cvg =                2
outp =
  scalar structure containing the fields:
    user_interaction =
      scalar structure containing the fields:
        stop = [](0x1)
        info = {}(0x1)
    niter =                2
    nobjf =                2
    constrviolation =                0


Arun Giridhar <arungiridhar>
Group Member
Sat 29 Oct 2022 10:05:34 AM UTC, comment #7: 

There are two items below.  One is about the initial value in my prior comment and the other is for the 4th argument in fmincon output, OUTP.  


(1) The url is https://www.mathworks.com/help/optim/ug/fmincon.html.  The exact example is below. 

>> fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
>> x0 = [-1,2];
>> A = [1,2];
>> b = 1;
>> x = fmincon(fun,x0,A,b)

error: Initial parameters violate constraints.
error: called from
    _lm_feasible_ at line 92 column 5
    fmincon at line 451 column 24

>> x = fmincon(fun,x0=[1 0]',A,b)

x =

   0.5022
   0.2489

(2) The 1.6.2 fmincon also continues to have an issue (in Octave 7.1.0) with OUTP argument. Output worked in 1.6.0.  What below is from 1.6.2.  1.6.1 produced the same. 

>> fun=@(x) sum(x.^2)

fun =

@(x) sum (x .^ 2)

>> [X, FVAL, CVG, OUTP]=fmincon (OBJF=fun, [0 0], A=[], B=[], AEQ=[], BEQ=[], LB=[0 0], UB=[1 1])

error: operator *: nonconformant arguments (op1 is 4x2, op2 is 1x2)
error: called from
    _constraints_interface_>@<anonymous> at line 113 column 56
    fmincon at line 466 column 12

>> [X, FVAL, CVG]=fmincon (OBJF=fun, [0 0], A=[], B=[], AEQ=[], BEQ=[], LB=[0 0], UB=[1 1])

X =

   0   0

FVAL = 0
CVG = 2


In Octave 5.3 & optim 1.6.0,

>>  [X, FVAL, CVG, OUTP]=fmincon (OBJF=fun, [1 1], A=[], B=[], AEQ=[], BEQ=[], LB=[0 0]', UB=[1 1]')

X =

   0
   0

FVAL = 0
CVG =  2
OUTP =

  scalar structure containing the fields:

    user_interaction =

      scalar structure containing the fields:

        stop = [](0x1)
        info = {}(0x1)

    niter =  2
    nobjf =  2
    constrviolation = -0
 
Thanks,

Liang Tang <lt1234>
Sat 29 Oct 2022 12:06:47 AM UTC, comment #6: 

Re comment #4: the paths to fmincon are different before and after the update, as are the versions. It looks like the update fixed the bug, whatever its cause. When you restarted Octave, it picked up the most recent location for each package. I believe that's set only once at startup.

Re comment #6: could you post the link when I can find that example and try it? Which version of Matlab?

Arun Giridhar <arungiridhar>
Group Member
Fri 28 Oct 2022 10:13:23 PM UTC, comment #5: 

When we are still on fmincon, could you also look at a possible matlab compatibility issue. 

The fmincon example on matlab web site (fun=100....) does not run in Octave. The error is below: 

error: Initial parameters violate constraints.
error: called from
    _lm_feasible_ at line 92 column 5
    fmincon at line 456 column 24

if I do a different x0: x = fmincon(fun,[1 0],A,b), the matlab result is also derived from Octave fmincon. 

x =

   0.5022   0.2489

Liang Tang <lt1234>
Fri 28 Oct 2022 10:04:33 PM UTC, comment #4: 

I don't know what happen now.  I updated but I still had this:

>> which fmincon

'fmincon' is a function from the file C:\Octave\Octave-7.1.0\mingw64\share\octave\packages\optim-1.6.1\fmincon.m

I then exited Octave & re-enter.  Now it works.  

>> which fmincon

'fmincon' is a function from the file C:\Users\Owner\AppData\Roaming\octave\api-v57\packages\optim-1.6.2\fmincon.m

>> fun = @(x) x^2;
>> x = fmincon(fun, x0=1)

x = 8.0109e-13


Liang Tang <lt1234>
Fri 28 Oct 2022 09:59:14 PM UTC, comment #3: 

Same error.  This is MS window result. 

 optim  |   1.6.2 |

>> fun = @(x) x^2;
>> x = fmincon(fun, x0=1)

error: @<anonymous>: function called with too many inputs
error: called from
    @<anonymous>
    _dfdp_ at line 304 column 15
    fmincon>@<anonymous> at line 385 column 26
    _jacobian_constants_>@<anonymous> at line 135 column 11
    _lm_feasible_ at line 145 column 8
    fmincon at line 451 column 24

>> ver

----------------------------------------------------------------------
GNU Octave Version: 7.1.0 (hg id: 04120d65778a)
GNU Octave License: GNU General Public License
Operating System: MINGW32_NT-6.2 Windows 6.2  x86_64

Liang Tang <lt1234>
Fri 28 Oct 2022 09:35:53 PM UTC, comment #2: 

Works for me with optim 1.6.2.

Could you try "pkg update" and check if the error still happens? It might have been fixed already if it was a problem.

Arun Giridhar <arungiridhar>
Group Member
Fri 28 Oct 2022 09:07:48 PM UTC, comment #1: 

For Octave 6.2 and optim 1.6.1, the example works.

Liang Tang <lt1234>
Fri 28 Oct 2022 09:01:59 PM UTC, original submission:  

The example below gave an unexpected error.  

>> fun = @(x) x^2;
>> x = fmincon(fun, x0=0)


In Octave 5.2.0 and optim 1.6.0, I got the right result:
x = 0

In Octave 7.1.0 and optim  1.6.1, I had an error from the same example. 

error: @<anonymous>: function called with too many inputs
error: called from
    @<anonymous>
    _dfdp_ at line 304 column 15
    fmincon>@<anonymous> at line 385 column 26
    _jacobian_constants_>@<anonymous> at line 135 column 11
    _lm_feasible_ at line 145 column 8
    fmincon at line 451 column 24

Thanks,





Liang Tang <lt1234>

 

(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 nrjank (Posted a comment)
  • -email is unavailable- added by arungiridhar (Posted a comment)
  • -email is unavailable- added by lt1234 (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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-10-29 arungiridhar StatusNeed Info Confirmed
        Release7.1.0 dev
        Operating SystemMicrosoft Windows Any
        Summary[octave forge] (optim) fmincon error with anonymous function [octave forge] (optim) fmincon fails for Rosenbrock example
    2022-10-28 arungiridhar Summaryfmincon error with anonymous function [octave forge] (optim) fmincon error with anonymous function
    2022-10-28 arungiridhar StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code