Help speeding up matrix algebra in loop...

조회 수: 5 (최근 30일)
John
John 2015년 8월 28일
댓글: John 2015년 8월 28일
Hi everyone, I'm simply looking for some suggestions for speeding up the following block of code:
bhat = (X'*X)\(X'*y);
yhat = X*bhat;
resid = y - yhat;
bclu=zeros(size(X,2));
for i=idx.unique
idmat=find(idx.sample==i);
x_g=X(idmat,:);
u_g=resid(idmat,:);
bclu_i=x_g'*u_g*(u_g)'*x_g;
bclu = bclu+bclu_i;
end
vhat=((X'*X)\bclu)/(X'*X);
I suppose there might be some scope for the use of "sparse" here, or perhaps vectorization, but it's not obvious to me how to optimize this. Any suggestions would be great. Thanks!

채택된 답변

Walter Roberson
Walter Roberson 2015년 8월 28일
You could probably use parfor, if you have the Parallel Computing Toolkit.
  댓글 수: 2
John
John 2015년 8월 28일
Oops! Didn't mean to accept so quickly!
This code is part of an optimization routine which itself is run in parallel, so I can't easily use parallel here. Any other suggestions?
John
John 2015년 8월 28일
Did I miss my chance??

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by