Help speeding up matrix algebra in loop...

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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2015 年 8 月 28 日

コメント済み:

2015 年 8 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by