[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous func
From: |
Denis Sbragion |
Subject: |
[Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling |
Date: |
Tue, 16 Mar 2021 05:26:21 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0 |
Follow-up Comment #4, bug #60237 (project octave):
Hello,
tried with 6.2.1, same behaviour. I took the time to reduce my code to
something self contained, taking the rosenbrock function from the optim
package:
function antest()
# NLOPT Based
ol = 1e-6;
p = 5;
# Initializes the optimization structure
op = struct();
# Set the algorithm to SQP
op.algorithm = NLOPT_LD_SLSQP;
# Set the objective function
# op.min_objective = @rosenbrock; # <-- Works both with 5.2.0 and 6.2.X
# op.min_objective = (@(t)(rosenbrock(t))); # <-- Works both with 5.2.0
and
6.2.X
op.min_objective = (@(t)(rosenbrock(t,p))); # <-- Works with 5.2.0,
doesn't
work with 6.2.X
# Set the tolerances for the optimization
op.ftol_rel = ol;
op.xtol_rel = ol;
# Optimize
sl = zeros(p,1);
[ pl, se ] = nlopt_optimize(op,sl)
endfunction
function [obj_value, gradient] = rosenbrock(x,p = 0);
x = x(:);
dimension = length(x);
obj_value = sum(100*(x(2:dimension)-x(1:dimension-1).^2).^2 +
(1-x(1:dimension-1)).^2);
if nargout > 1
gradient = zeros(dimension, 1);
gradient(1:dimension-1) = -
400*x(1:dimension-1).*(x(2:dimension)-x(1:dimension-1).^2) -
2*(1-x(1:dimension-1));
gradient(2:dimension) = gradient(2:dimension) +
200*(x(2:dimension)-x(1:dimension-1).^2);
endif
endfunction
I hadded a fake unused variable p to rosenbrock just to trigger the error.
When it fails, both on 6.2.0 and 6.2.1 it gives again:
octave:33> antest
error: 'p' undefined near line 16, column 16
error: called from
antest>@<anonymous> at line 16 column 27
antest at line 24 column 13
Now that I know that at least it isn't a problem of my own code I'll dig also
into che NLOpt Octave interface to see if there's something weird and see if I
can trigger the problem with some reduced self contained example not involving
the whoole NLOpt library.
Bye,
Denis Sbragion
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?60237>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Denis Sbragion, 2021/03/15
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Dmitri A. Sergatskov, 2021/03/15
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Markus Mützel, 2021/03/15
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Denis Sbragion, 2021/03/16
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling,
Denis Sbragion <=
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Denis Sbragion, 2021/03/16
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Markus Mützel, 2021/03/17
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Denis Sbragion, 2021/03/17
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Denis Sbragion, 2021/03/18
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Denis Sbragion, 2021/03/18
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, Denis Sbragion, 2021/03/22
- [Octave-bug-tracker] [bug #60237] Differente behaviour in anonymous function handling, John W. Eaton, 2021/03/22