Help speeding up matrix algebra in loop...
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
John
el 28 de Ag. de 2015
Comentada: John
el 28 de Ag. de 2015
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!
0 comentarios
Respuesta aceptada
Walter Roberson
el 28 de Ag. de 2015
You could probably use parfor, if you have the Parallel Computing Toolkit.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!