bugGNU Octave - Bugs: bug #55742, fminsearch does not pass extra...

 
 

bug #55742: fminsearch does not pass extra arguments to objective function, undocumented old Matlab behavior

Submitter:  None
Submitted:  Wed 20 Feb 2019 04:21:48 AM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  Unexpected Error or Warning
Status:  Duplicate Assigned to:  None
Originator Name:  AlanStr Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.4.1
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 21 Feb 2019 12:52:05 AM UTC, comment #6: 

I removed the old documentation in this changeset (https://hg.savannah.gnu.org/hgweb/octave/rev/d6325ba174dd).

Rik <rik5>
Group administrator
Wed 20 Feb 2019 11:06:43 PM UTC, comment #5: 

(This might be essentially a duplicate-- I am having some problems with the system.)

Ok, I don't agree with the decision, but you are the bosses, and thanks for all of your great work.

If you still get this even though this bug is now closed, be sure to update the Octave documentation that describes this syntax. Type "help fminsearch" to view it, at least in Release 4.4.1.

Anonymous
Wed 20 Feb 2019 08:54:08 PM UTC, comment #4: 

Thanks for the pointer to bug #46807, does indeed look like this has already been discussed and decided a couple times now. Closing this as a duplicate.

Mike Miller <mtmiller>
Group Member
Wed 20 Feb 2019 08:41:53 PM UTC, comment #3: 

Besides bug #41888, see bug #46807 where it was decided not to implement parameter passing because it is undocumented and the anonymous function approach is documented and prefered by Matlab itself.

Rik <rik5>
Group administrator
Wed 20 Feb 2019 04:09:56 PM UTC, comment #2: 

Thanks for the quick response and the diligent testing on different releases. And thanks for the work-around example using the anonymous function syntax. And I can hardly find words to express my appreciation for all of the work that so many people are doing to make Octave so beautiful.

I am trying to port a large and complex system from Matlab to Octave. It is not too bad if only a few changes are required, especially if those changes are well-contained, straight-forward, and well-documented. But if the number and complexity of required changes gets too large, then we users will become overwhelmed, throw our hands into the air and declare that Octave code and Matlab code are not compatible.

At some point it might be good to leave Matlab in the dust, and abandon the goal of compatibility. The problem is that Matlab has done a very good job of infiltrating colleges and universities, with their temporary licenses (subsidized rentals) for students. What is needed here is a big push to promote Octave to universities and colleges. Then following Matlab compatibility would become unnecessary.

There is Matlab documentation that describes the syntax of adding extra parameters to the fminsearch call. Octave documentation also describes this syntax, if you type “help fminsearch” in the command prompt.

For these reasons, I recommend fixing it, unless the fix is complex and is not easy to propagate to future releases. If you choose not to fix it, then I suggest changing the Octave documentation and also adding a comment that explains that this Matlab syntax is not supported, and pointing to a separate page on how to use the anonymous function call to pass extra parameters to the function.

Anonymous
Wed 20 Feb 2019 06:23:58 AM UTC, comment #1: 

Confirmed, this is because of the final call to 'fun' for the 'fval' second return value. So in Octave 4.4, confirmed that this error occurs when calling fminsearch with two output arguments and an optional argument passed to the function.

As documented elsewhere, the best way to pass auxiliary arguments to your objective function is to use an anonymous function, for example in the attached fminsearchBugTest2.m.

Moreover, in the changes made for Octave 5 since 4.4, it looks to me like the functionality added in bug #41888 has been broken in revision a00379f6f8c4 (https://hg.savannah.gnu.org/hgweb/octave/rev/a00379f6f8c4), probably accidentally. So this is a bigger bug, but is it worth fixing (again)? As mentioned earlier on bug #41888, this calling syntax is not documented Matlab behavior, do we need to continue supporting this when anonymous functions works far better and more flexibly?

(file #46311)

Mike Miller <mtmiller>
Group Member
Wed 20 Feb 2019 04:21:48 AM UTC, original submission:  

It is wonderful that you acted on bug #41888 and added the matlab feature to fminsearch, where you can pass additional parameters to the function that can then be passed through fminsearch as additional arguments at the end of the call.

My application is quite complex, but here I have boiled it down to a fairly short example.

Main script file, which I called fminsearchBugTest1


% We will minimize the function f(x)=2+(x-2.0)^2+(y-3.0)^2
% but we will pass the 2.0 and 3.0 through an additional
% parameter called dataStructure.

dataStructure{1}=2.0;
dataStructure{2}=3.0;

beta0=[1.5 2.8];

[beta,fval] = fminsearch('fminsearchBugTestFunction',beta0, ...
   optimset('TolX',1e-6,'TolFun',1e-6,'Display','iter','MaxIter',20000,'MaxFunEvals',40000),dataStructure);


Next we define the function that we will minimize. I called it fminsearchBugTestFunction:




function [s]=fminsearchBugTestFunction(beta, dataStructure)
  %dataStructure is a paramter of the function

  s=2.0+(beta(1)-dataStructure{1})^2+(beta(2)-dataStructure{2})^4;

  fprintf('%9.6f\t%9.6f\n',beta);

endfunction


Test this in Release 4.4.1. For me it shows the search proceeding all the way to the end, and then at the end it crashes and reports


error: 'dataStructure' undefined near line 3 column 18
error: called from
    fminsearchBugTestFunction at line 3 column 4
    fminsearch at line 105 column 10
    fminsearchBugTest1 at line 10 column 12


Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #46311:  fminsearchBugTest2.m added by mtmiller (432B - text/x-objcsrc)
file #46309:  fminsearchBugTest1.m added by None (797B - application/octet-stream)
file #46310:  fminsearchBugTestFunction.m added by None (223B - application/octet-stream)

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -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 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-12-19 siko1056 Dependencies- bugs #57446 is dependent
    2019-02-20 mtmiller StatusConfirmed Duplicate
        Open/ClosedOpen Closed
        Dependencies- Depends on bugs #46807
    2019-02-20 mtmiller Attached File- Added fminsearchBugTest2.m, #46311
        Severity3 - Normal 2 - Minor
        Priority5 - Normal 3 - Low
        StatusNone Confirmed
        SummaryRelated to bug #41888, fix not quite working yet-- crashes at the very end of the search. fminsearch does not pass extra arguments to objective function, undocumented old Matlab behavior
    2019-02-20 None Attached File- Added fminsearchBugTest1.m, #46309
        Attached File- Added fminsearchBugTestFunction.m, #46310

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code