bugGNU Octave - Bugs: bug #65535, (optim) lsqnonlin, lsqcurvefit:...

 
 

bug #65535: (optim) lsqnonlin, lsqcurvefit: non-scalar resnorm, missing lagrange multipliers for both l

Submitter:  A.R. Burgers <arb>
Submitted:  Fri 29 Mar 2024 02:30:02 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 30 Mar 2024 10:09:55 AM UTC, comment #3: 

CC'ing package maintainer.

Markus M├╝tzel <mmuetzel>
Group administrator
Fri 29 Mar 2024 08:22:13 PM UTC, comment #2: 

and similarly for lsqcurvefit


diff -r 0a88bfac372f inst/lsqcurvefit.m
--- a/inst/lsqcurvefit.m        Thu Mar 28 09:00:55 2024 +0100
+++ b/inst/lsqcurvefit.m        Fri Mar 29 21:20:02 2024 +0100
@@ -293,6 +293,7 @@
     outp.iterations = outp.niter;
     outp = rmfield (outp, "niter");
     varargout{5} = outp;
+    outp = curvefit_out{4};
   endif


A.R. Burgers <arb>
Fri 29 Mar 2024 08:15:46 PM UTC, comment #1: 

this seems to fix empty the lambda issue for this case:


diff -r 0a88bfac372f inst/lsqnonlin.m
--- a/inst/lsqnonlin.m  Thu Mar 28 09:00:55 2024 +0100
+++ b/inst/lsqnonlin.m  Fri Mar 29 21:13:35 2024 +0100
@@ -286,6 +286,7 @@
       outp = rmfield (outp, "user_interaction");
     endif
     varargout{5} = outp;
+    outp = residmin_out{4};
   endif

   if (out_args >= 6)


A.R. Burgers <arb>
Fri 29 Mar 2024 02:30:02 PM UTC, original submission:  

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


A.R. Burgers <arb>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by mmuetzel
  • -email is unavailable- added by arb (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.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-03-30 mmuetzel Carbon-Copy- Added i7tiol

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code