bugGNU Octave - Bugs: bug #57446, fminsearch fails due to...

 
 

bug #57446: fminsearch fails due to undocumented Matlab feature of passing extra parameters

Submitter:  None
Submitted:  Thu 19 Dec 2019 09:52:26 AM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  WTF, Matlab?!?
Status:  Duplicate Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.4.1
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 20 Dec 2019 08:51:21 PM UTC, comment #3: 

Works now (finally figured it out!). For anyone else who stumbles across this the first line needed to be:

f = @(pm0, x, y, xmax, ymax)fssr(pm0,x,y,xmax,ymax);


Nick <nicks>
Fri 20 Dec 2019 08:30:42 PM UTC, comment #2: 

Thanks for the response Kai, very helpful!

My function fssr is contained in it's own file (fssr.m). The function is rather long but takes vectors x,y,xmax and ymax as arguments and then minimises two parameter contained in pm0. I would like to write something like the below with the anonymous function, but it does not work. y is undefined when fssr is called (y is the first argument used in fssr).

I would much appreciate any advice
_____________

f = @(pm0, x, y, xmax, ymax)fssr;

%Define test data
c = magic(5);
y = c(:,2); x = c(:,1); ymax = c(:,4); xmax = c(:,3);
   
%Create anonymous function
fun = @(pm0)f(pm0, x, y, xmax, ymax);

%Define initial guess
pm0 = [-3; -2]; 

%Search for minimum  
[pm, ssr] = fminsearch(fun, pm0)

Nick <nicks>
Thu 19 Dec 2019 03:13:43 PM UTC, comment #1: 

Thank you for the bug report.  According to bug #55742, Octave only supported this undocumented Matlab feature of extra arguments  for a short time in Octave 4.4.0.  Ultimately, it was decided in bug #46807 not to support this undocumented feature, as it can be silently removed at any time in Matlab.

But no worries.  There is a much more consistent way of getting your job done using anonymous functions.  You can find an example in the Matlab manual, section "Minimize with Extra Parameters"

https://www.mathworks.com/help/matlab/ref/fminsearch.html

or if you post your function here, we can easily suggest an appropriate anonymous functions declaration.

As you are on MS Windows, maybe you decide to upgrade to Octave 5.1.0?

I close this bug report as duplicate, but you can post your example function "fssr" here with some idea of the parameters y,x,ymax,xmax to obtain further guidance.


Kai Torben Ohlhus <siko1056>
Group Member
Thu 19 Dec 2019 09:52:26 AM UTC, original submission:  

Hi,

It appears fminsearch fails to exit properly, and instead calls the function that is trying to be minimized again but without the arguments.

Call fminsearch with:

[pm,ssr] = fminsearch(@fssr,pm0,optimset('Display', 'final'),y,x,ymax,xmax);

It iterates through alright, and produces output:

Simplex size 8.2135e-05 <= 1.0000e-04 and step in function value 0.0000e+00 <= 1.0000e-07...quitting

But then immediately after it gives:

error: 'y' undefined near line 6 column 6
error: called from
    fssr at line 6 column 1
    fminsearch at line 105 column 10
    estm_sym_20180507 at line 41 column 13

It appears to me that Stopping Test 3 is met so fminsearch breaks, however it then calls the function fssr again. I am sure there is no second call to fssr within the script that is being run.

Thanks

Anonymous

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Carbon-Copy List
  • -email is unavailable- added by nicks (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  •  

    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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-12-19 siko1056 Item GroupNone WTF, Matlab?!?
        Summaryfminsearch fails to undocumented Matlab feature of passing extra parameters fminsearch fails due to undocumented Matlab feature of passing extra parameters
    2019-12-19 siko1056 Severity3 - Normal 2 - Minor
        Priority5 - Normal 3 - Low
        StatusNone Duplicate
        Open/ClosedOpen Closed
        Summaryfminsearch fails to exit fminsearch fails to undocumented Matlab feature of passing extra parameters
    2019-12-19 siko1056 Dependencies- Depends on bugs #46807
    2019-12-19 siko1056 Dependencies- Depends on bugs #55742

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code