[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
efficient normalization of matrix columns?
From: |
Joachim De Beule |
Subject: |
efficient normalization of matrix columns? |
Date: |
Tue, 26 Oct 2010 12:25:55 +0200 |
User-agent: |
KMail/1.11.2 (Linux/2.6.28-15-generic; KDE/4.2.2; x86_64; ; ) |
Hi all,
1) I have the following function that normalizes the columns in a sparse
matrix X and returns the result as a sparse matrix Xn:
function Xn = normalizeX (X)
norms = sqrt(sumsq(X));
[i,j,v] = find (X);
[n, m] = size(X);
v = v./full(norms(j'))';
Xn = sparse(i,j,v,n,m);
endfunction
On my computer, this function takes about 0.7 seconds when applied to a random
(sparse) matrix of 1000 by 1000.
It uses a huge amount of memory however, and becomes unfeasible to use on
really large matrices (I need to apply it to matrices of size 3206978 by
18846)
2) On the other hand, the following function performs better on memory, but
takes over 27 seconds to terminate on the same random matrix as mentioned
above:
function Xn = normalizeX (X)
norms = sqrt(sumsq(X));
for c = 1:size(X)(2)
Xn(:,c) = X(:,c)./norms(c);
endfor
endfunction
3) In short, it seems that it is not possible to normalize a large sparse
matrix in octave, either because it requires too much memory or else because
it takes too long too compute. Any ideas?
Thanks, Joachim.
- efficient normalization of matrix columns?,
Joachim De Beule <=