Can you use Batched partitioned nonlinear least squares to fit 5 parameters?

2 Ansichten (letzte 30 Tage)
Hi,
I've seen people using the batched partitioned nonlinear least squares to solve nonlinear problems of two unknown parameters.
I have a function with 5 unknown parameters and I want to fit it nonlinearly. I fitted my model using the lsqnonlin but is extremely slow.
I was looking for solutions on how to speed It up and I came across with the batched partitioned nonlinear least squares but I am not sure if I can use it in case of 5 unknown parameters.
Thank you in advance.

Akzeptierte Antwort

John D'Errico
John D'Errico am 9 Apr. 2018
As the person who introduced the concept of batched partitioned nonlinear least squares here, I'll assume you are asking about using my BATCHPLEAS utility, found on the file exchange.
Yes, in theory, you can use it to solve problems with any number of parameters. Of course, theory and practice need not always coincide. There is no limit (implicit or explicit) on the number of parameters you can estimate.
But first, are you talking about a problem with 5 NONLINEAR parameters, thus really more variables that that? Or as is common in this arena, if you have 5 total variables, then you might have 2 or 3 nonlinear parameters to estimate, but the remainder linear, so 5 total parameters? Remember that the partitioning reduces the search space for the estimation.
If you have no clue as to what partitioned nonlinear least squares is, or how it works, and the docs provided with BATCHPLEAS and/or FMINSPLEAS do not help you enough, then one of the chapters in the Seber & Wild book on nonlinear regression do cover the concept. And since Bates & Watts were the people who wrote the original papers on the topic as I recall, I'd bet that the book by Bates & Watts on nonlinear regression does so too. I think Seber and Wild called the idea something like separable nonlinear least squares.
Next, remember that regardless of how many nonlinear parameters there are in your problem, that nonlinear regression is often sensitive to starting values. BATCHPLEAS presumes the SAME set of starting values will be used for every member of the set. Problems with many nonlinear parameters might have local solutions that are not the global optimum. Or in some cases, some sub-problems might diverge, again due to sensitivity to the starting values. The more variables you have, the more risk there is in this happening. If partitioning does reduce the search space, so that in reality, you have only 2 or 3 unknowns, then the partitioning typically also increases the robustness of the problem, so it is less sensitive to the need for good starting values.
  5 Kommentare
John D'Errico
John D'Errico am 11 Apr. 2018
No. First, making batchsize to be as large as 1000 will probably not be fast. It may even be slower than a loop that processes each data set separately.
As I explained, batchsize for 4 nonlinear variables will probably be best somewhere between 25 and 200. The code will do the work for you. I might try 50 or 100 to see how it does.
Next, there is only ONE function in funlist here, since there is only ONE linear variable. Also you will pass in ONE array of independent variables. I'll all it xy.
You also need to learn about the use of .* and ./ as operators. You can freely multiply or divide anything by a scalar variable. But if you multiply two vectors, then you need to use .* to do element-wise multiplication. Likewise, ./ is needed if you divide one vector into another element-wise, or if you divide a scalar by the elements of a vector.
xy = [x(:),y(:)];
funlist = {@(p,xy) (p(2) * exp(-xy(:,1)*p(3) - xy(:,2)/p(4))+(1-p(2)).*exp(-xy(:,1)*c1).*(p(5)*exp(-xy(:,2)/c2)+(1-p(5)).*exp(xy(:,2)/c3)))};
I think I got that right. At least, MATLAB accepts it as valid syntax.
Gina Carts
Gina Carts am 18 Apr. 2018
Bearbeitet: Gina Carts am 20 Apr. 2018
The following code performs nonlinear least squares fitting using the Matlab function lsqnonlin.
img = data(:,:,:,:) %4D array consists of 26 images (x-pixels:150, y-pixels:190) and 41 time points
%c1 3D array with dimensions [150 190 26] calculated beforehand.
This array doesn’t change and is used as fixed.
%c2 and c3 are both scalars
%x and y are 1D vectors with 41 measurements
params=zeros(size(img,1),size(img,2),size(img,3),10);
for i=1:size(img,1)
for j=1:size(img,2)
for k=1:size(img,3)
[p,residual]=lsqnonlin(@(p)(s(isfinite(s))-p(1)*(p(2)*exp(-x(isfinite(s))*p(3)-y(isfinite(s))/p(4))+(1-p(2))*exp(-x(isfinite(s))*c1(i,j,k)).*(p(5)*exp(-y(isfinite(s))/c2) + (1-p(5))*exp(-y(isfinite(s))/c3)) )),[p0(1),p0(2),p0(3),p0(4),p0(5),p0(6),p0(7)],[0,0,c1(i,j,k),0,0,0,0],[100,1,1,1,10000,1000,1000],options);
params(i,j,k,1:9)=[p,c1(i,j,k),residual];
end
end
end
To speed it up I tried to use the batchpleas instead but I’m getting errors. One of those “funlist must be a cell array of functions, even if only one fun”
My code looks as follows:
INLPlb = 0;
INLPub = [1 1 0.1 1];
batchsize = 50;
INLPstart = [p0(2), p0(3), p0(4), p0(5)]; %initial values of nonlinear parameters
%Here I defined the Ydata to be my objective function using the initial parameter values
Ydata = p0(1)*(p0(2)*exp(-x*p0(3)-y/p0(4))+(1-p0(2))*exp(-x*c1).*(p0(5)*exp(-y/c2)+ (1-p0(5))*exp(-y/c3)));
xy = [x(:),y(:)];
%Here I defined the Xdata to be the inputs of the Data
Xdata = xy;
funlist = {@(p,xy) (p(2) * exp(-xy(:,1)*p(3) - xy(:,2)/p(5))+(1-p(2)).*exp(-xy(:,1)*c1).*(p(4)*exp(-xy(:,2)/c2)+(1-p(4)).*exp(xy(:,2)/c3)))};
[INLP,ILP] = batchpleas(Xdata,Ydata,funlist,INLPstart,batchsize,INLPlb,INLPub);
One more question I have is where the way I defined the Xdata and Ydata is the correct one to use in the batchpleas function.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by