vectorize lsqnonneg?
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I'm currently working with sequences of images and I'm interested in the temporal dynamics of individual pixels. Typically I have a series of approx. 50 images with 250 000 pixels of interest and I want to fit them to 5-10 time-activity curves of reference. I need to do a non-negative fitting because negative coefficients are physically nonsensical in my problem.
At the moment, I'm basically doing this
nPixels = 250 000;
nRefTACs = 5;
nImages = 50;
% imTS := image time series data [nImages x nPixels]
% refTACs := reference time-activity curves [nImages x nRefTACs]
% nnCoeff := fitting coefficients [nRefTACs x nPixels]
nnCoeff = zeros(nRefTACs, nPixels);
for k = 1:nPixels
nnCoeff(:,k) = lsqnonneg(refTACs, imTS(:,k));
end
I'm wondering if there would be a way to speed this up by vectorization or by using another optimization function. I've been browsing the optimization toolbox documentation for some time, but I'm not very familiar with optimization in general.
Any help would be appreciated.
댓글 수: 0
채택된 답변
Matthias Klemm
2011년 12월 9일
lsqnoneg is written in Matlab code. You can open it with the editor and vectorize it yourself to gain some speed. You can't avoid the loops in there I guess. Still you should get some improvement out of it. The only show stopper is mldivide (\) as it is not vectorized. In your case it should work as you already can use mldivide to compute a (not ideal) solution for your problem (because your problem is not overdetermined I think).
댓글 수: 2
Silas Leavesley
2012년 12월 1일
Hi David,
Would you mind posting your modified lsqnonneg, or at least the modified portion of it? I am currently using lsqnonneg for spectral image analysis and would like to see if this would speed things up. Thanks.
추가 답변 (1개)
Sean de Wolski
2011년 11월 23일
preallocate nnCoeff so that it doesn't change size on each iteration.
nnCoeff = zeros(nRedTACs,nPixels);
for k ...
nnCoeff(:,k) = lsqnonneg(refTACs, imTS);
end
댓글 수: 3
Steve Grikschat
2011년 12월 13일
Can you expand this into one large problem? That may or may not make things slower, but it could be worth a try. Additionally, if you have Parallel Computing Toolbox, you could solve these problems in parallel easily.
The reason that (\) is faster than lsqnonneg is that lsqnonneg has to solve a series of linear systems using (\) in order to satisfy the non-negativity constraint.
FYI: I assume that you are actually changing the RHS (imTS) in the loop as well. Your code snippet doesn't show that.
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!