How can I perform a large number of curve fits more efficiently?
11 次查看(过去 30 天)
显示 更早的评论
I have set of MRI images, and I am doing a pixel-by-pixel curve fit to calculate a certain coefficient I want. I then take that coefficient and assign it to a new matrix in its designated position. The images are 128x128, therefor there are 16,384 curve fits that need to be performed. Currently the process takes about an hour and half. I am looking for a way to reduce this time by a drastic amount. Any help is appreciated.
h = waitbar(0,'Wait');
%Curve fitting process
for j = 1:128
waitbar(j/128)
for i = 1:128
%T is a 5x1 vector (ind. variable)
%signal_array is an array with 128x128 5x1 vectors (dep. variable)
[fit,gof] = fit(T,signal_array{i,j},fittype);
coeff = coeffvalues(fit);
%If high correlation between values, plot T value directly
if gof.rsquare > .8
t2map(i,j) = 1/coeff(2);
%If medium correlation between values, plot T value located directly to
%the left of that pixel
elseif (gof.rsquare <= .8) && (gof.rsquare >=.5)
t2map(i,j) = t2map(i,(j-1));
%If there is low correlation, assign the value to 0
else
t2map(i,j) = 0;
end
clear fit coeff gof
end
end
0 个评论
回答(2 个)
John D'Errico
2016-11-9
编辑:John D'Errico
2016-11-9
Because of the nature of the partitioned least squares, you also gain in terms of speed, because it reduces the effective size of the problem. But you will need to learn how to split the variables into conditionally linear versus truly nonlinear sets. I can't help you there, because you don't tell us that model you use.
I don't know of a better solution. It has been a while, but I recall throughput speeds of as much as 250 to 1 compared to a simple loop when I originally developed the idea. That will depend on your problem of course. I see in my comments that a 3 variable example showed a 13-1 speed boost.
You will need to compute the various statistics yourself. But that should be trivial in most cases.
You will also need the optimization toolbox, since I don't believe the curve fitting toolbox has the necessary sparse Jacobian matrix capabilities that I use.
0 个评论
Szu-Yu Lee
2021-4-8
Hi, I guess you are trying to fit a large number of independent equations? MATLAB "fit" function do not support multiple independent curves fitting. I have created a function that takes in a 2D matrix, where each row is a curve to be fitted to some polynomial expression. The function does not use for-loop, so can work on large number of rows in a very short time.
https://www.mathworks.com/matlabcentral/fileexchange/90017-matrix-row-wise-polynomial-fit
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!