开发者

How to accelerate/avoid multiplication for large matrices in Matlab?

The setting is here.

X: 6000x8000 non-sparse matrix

B: 8000x1 sparse vect开发者_如何学运维or with only tens of non-zeros

d: positive number

M: is sparsified X'X, i.e. thresholding the elements smaller than d in magnitude to be 0. Only hundreds of elements are left. So (X' * X - M) have many small elements and is not sparse.

I want to compute the vector y=(X' * X - M)* B and can rewrite as y=X' * (X * B) - M*B. The first part is fast enough, but the second part involves X'*X, and is very very slow.

Could any one help me to accelerate this computation?

Thanks a million!


You explain that B is very sparse: tens of non-zero values in a column array of length 8000. As a result, I think you can speed up your multiplications by B as follows. Firstly, you can find the indices of the non-zero values in B:

nzIndex = find(B);

Then you can change your computation of y as follows:

Bnz = B(nzIndex);  %# Non-zero values in B
y = X.'*(X(:,nzIndex)*Bnz) - M(:,nzIndex)*Bnz;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜