[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #65535] (optim) lsqnonlin, lsqcurvefit: non-sc
From: |
A.R. Burgers |
Subject: |
[Octave-bug-tracker] [bug #65535] (optim) lsqnonlin, lsqcurvefit: non-scalar resnorm, missing lagrange multipliers for both l |
Date: |
Fri, 29 Mar 2024 10:30:02 -0400 (EDT) |
URL:
<https://savannah.gnu.org/bugs/?65535>
Summary: (optim) lsqnonlin, lsqcurvefit: non-scalar resnorm,
missing lagrange multipliers for both l
Group: GNU Octave
Submitter: arb
Submitted: Fri 29 Mar 2024 03:30:02 PM CET
Category: Octave Package
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Incorrect Result
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Release: dev
Discussion Lock: Any
Operating System: Any
Fixed Release: None
Planned Release: None
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Fri 29 Mar 2024 03:30:02 PM CET By: A.R. Burgers <arb>
There are inconsistencies between matlab and optim in the lsqnonlin and
lsqcurvefit functions.
The 1st issue is that for multi-column ydata a non-scalar resnorm is
returned.
The 2nd issue is that the Lagrange multiplier output lambda is empty.
octave 10, optim-1.6.2 output:
lsqnonlin
resnorm = 0.020000 0.048223
lambda = [](0x0)
lsqcurvefit
resnorm = 0.020000 0.048223
lambda = [](0x0)
matlab R2019b output
resnorm = 0.1759
lambda = struct with fields:
lower: 0
upper: 5.2781e-05
lsqcurvefit
resnorm = 0.1759
lambda = struct with fields:
lower: 0
upper: 5.2781e-05
test script:
if exist('OCTAVE_VERSION', 'builtin') > 0
pkg load optim;
end
rng('default'); % for reproducibility
xdata = reshape(linspace(0,3,40), [], 2);
ydata = exp(-1.3*xdata) + 0.05*randn(size(xdata));
x0 = 2; lb = 1; ub = 3;
opts.Display='off';
fprintf('lsqnonlin\n');
fun_lsqnonlin = @(r)exp(-xdata*r) -ydata;
[x,resnorm,residual,exitflag,output,lambda] = ...
lsqnonlin(fun_lsqnonlin,x0, lb, ub, opts);
resnorm
lambda
fprintf('lsqcurvefit\n');
fun_lsqcurvefit = @(r, x) exp(-x*r);
[x,resnorm,residual,exitflag,output,lambda] = ...
lsqcurvefit(fun_lsqcurvefit, x0, xdata, ydata, lb, ub, opts);
resnorm
lambda
The lambda field is correctly calculated, but unintentionally cleared because
I think the user_interaction detection in this snippet around line 283 is
incorrect, since there is no use_interaction in this example to my
understanding.
if (out_args >= 5)
outp = residmin_out{4};
if (isfield (outp, "user_interaction")) # not set if stopped by
user_interaction
outp = rmfield (outp, "lambda");
endif
if (isfield (outp, "user_interaction"))
outp = rmfield (outp, "user_interaction");
endif
varargout{5} = outp;
endif
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?65535>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #65535] (optim) lsqnonlin, lsqcurvefit: non-scalar resnorm, missing lagrange multipliers for both l,
A.R. Burgers <=
- [Octave-bug-tracker] [bug #65535] (optim) lsqnonlin, lsqcurvefit: non-scalar resnorm, missing lagrange multipliers for both l, A.R. Burgers, 2024/03/29
- [Octave-bug-tracker] [bug #65535] (optim) lsqnonlin, lsqcurvefit: non-scalar resnorm, missing lagrange multipliers for both l, A.R. Burgers, 2024/03/29
- [Octave-bug-tracker] [bug #65535] (optim) lsqnonlin, lsqcurvefit: non-scalar resnorm, missing lagrange multipliers for both l, Markus Mützel, 2024/03/30