MATLAB Answers

Lsqnonlin optimization unexpected behavior

1 view (last 30 days)
OD
OD on 11 May 2021
Answered: Alan Weiss on 11 May 2021
Hello,
I am experimenting with lsqnonlin, first with a very simple problem: make lsqnonlin find translation params. I have an "original" image I, appy translations and then try to make lsqnonlin find them: results of lsqnonlin are in txy_sol_lsqnonlin.
The problem is that it almost immediately stops and always gives me useless results i.e. the same init values that I give it + maybe 0.5 or something like if it can't do more than a few steps and immediately stop searching anymore... Please help me find the problem.
The full code is :
I = phantom(256);
tx=22;
ty=5;
I_tr = imtranslate(I,[tx ty]);
fun = @(txy) [reshape( imtranslate(I,[txy(1) txy(2)])-I_tr,[],1) ];
lsqnonlinoptions=optimset('Algorithm','Levenberg-Marquardt','MaxIter',1000,'Display','iter');
tx_init = 0;
ty_init = 0;
[txy_sol_lsqnonlin,resnorm,residual,exitflag,output] = lsqnonlin(fun,[tx_init, ty_init],[],[],lsqnonlinoptions);
% the Output in Matlab console is:
%
% First-Order Norm of
% Iteration Func-count Residual optimality Lambda step
% 0 3 5058.12 410 0.01
% 1 6 4752.75 58.7 0.001 0.572352
% 2 9 4738.31 1.21 0.0001 0.177726
% 3 12 4738.3 0.00463 1e-05 0.00236374
% 4 15 4738.3 2.41e-05 1e-06 1.27094e-05
%
% So it seems clear that it thinks it has reached an optimum but why?
  1 Comment
OD
OD on 11 May 2021
I tried to change tolerance values with 'TolX' but it does not seem to be related to this ...

Sign in to comment.

Answers (1)

Alan Weiss
Alan Weiss on 11 May 2021
lsqnonlin is a gradient-based solver. It first attempts to estimate the local gradient by small finite difference steps. If your function is locally constant, such as a step function, then lsqnonlin sees zero gradient and stops.
To have your function not look like a step function, perhaps you can interpolate it using interp2, for example.
Alan Weiss
MATLAB mathematical toolbox documentation

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by