small bug in fminsearch

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

small bug in fminsearch

Andrea Latina
Hello Olaf (as maintainer of the 'optim' package), hello everyone,

I've found a small bug in fminsearch.m in octave 5.1.0 :

line 168 should be
    fval = feval (fun, x, varargin{:});

and not
    fval = feval (fun, x);

Best,
Andrea
Reply | Threaded
Open this post in threaded view
|

Re: small bug in fminsearch

siko1056
On 8/8/19 12:10 AM, Andrea Latina wrote:

> Hello Olaf (as maintainer of the 'optim' package), hello everyone,
>
> I've found a small bug in fminsearch.m in octave 5.1.0 :
>
> line 168 should be
>     fval = feval (fun, x, varargin{:});
>
> and not
>     fval = feval (fun, x);
>
> Best,
> Andrea


Dear Andrea,

Thank you for the report.  Do you want to enable the following calling
scheme?

  f = @(x,a) x.^2 + a;
  a = 3;
  x0 = 1;
  [x, fval] = fminsearch (f, x0, [], a)

This behavior is no longer documented by Matlab [1] (but still works in
R2019a). The Mathworks encourages to use anonymous functions instead:

  f = @(x,a) x.^2 + a;
  a = 3;
  fun = @(x)f(x,a);
  x0 = 1;
  [x, fval] = fminsearch (fun, x0)

This works perfectly in both Octave and Matlab.  In bug #55742 [2] it
was recently decided not to support undocumented Matlab features, as
they are more likely to change quietly and are difficult to support and
test.

With best wishes,

Kai

[1] https://www.mathworks.com/help/matlab/ref/fminsearch.html
[2] https://savannah.gnu.org/bugs/?55742


Reply | Threaded
Open this post in threaded view
|

Re: small bug in fminsearch

Andrea Latina
Hi Kai,

nice to read you. Yes, I called fminsearch with an extra parameter. fminsearch correctly called the function throughput the full optimisation, but gave an error when evaluating the function for the second return value.

Thank you for the hint on using the anonymous functions!. It looks indeed more elegant.

Best wishes,
Andrea

On Thu, 8 Aug 2019 at 03:39, Kai Torben Ohlhus <[hidden email]> wrote:
On 8/8/19 12:10 AM, Andrea Latina wrote:
> Hello Olaf (as maintainer of the 'optim' package), hello everyone,
>
> I've found a small bug in fminsearch.m in octave 5.1.0 :
>
> line 168 should be
>     fval = feval (fun, x, varargin{:});
>
> and not
>     fval = feval (fun, x);
>
> Best,
> Andrea


Dear Andrea,

Thank you for the report.  Do you want to enable the following calling
scheme?

  f = @(x,a) x.^2 + a;
  a = 3;
  x0 = 1;
  [x, fval] = fminsearch (f, x0, [], a)

This behavior is no longer documented by Matlab [1] (but still works in
R2019a). The Mathworks encourages to use anonymous functions instead:

  f = @(x,a) x.^2 + a;
  a = 3;
  fun = @(x)f(x,a);
  x0 = 1;
  [x, fval] = fminsearch (fun, x0)

This works perfectly in both Octave and Matlab.  In bug #55742 [2] it
was recently decided not to support undocumented Matlab features, as
they are more likely to change quietly and are difficult to support and
test.

With best wishes,

Kai

[1] https://www.mathworks.com/help/matlab/ref/fminsearch.html
[2] https://savannah.gnu.org/bugs/?55742