How can I perform a large number of curve fits more efficiently?

조회 수: 10 (최근 30일)
Alex Magsam
Alex Magsam 2016년 11월 9일
답변: Szu-Yu Lee 2021년 4월 8일
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

답변 (2개)

John D'Errico
John D'Errico 2016년 11월 9일
편집: John D'Errico 2016년 11월 9일
One way yo do it is to use a batched nonlinear regression.
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.

Szu-Yu Lee
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

카테고리

Help CenterFile Exchange에서 Support Vector Machine Regression에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by