[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: efficient normalization of matrix columns?
From: |
Joachim De Beule |
Subject: |
Re: efficient normalization of matrix columns? |
Date: |
Tue, 26 Oct 2010 13:42:35 +0200 |
User-agent: |
KMail/1.11.2 (Linux/2.6.28-15-generic; KDE/4.2.2; x86_64; ; ) |
Me again,
It seems that the following function solves my problem:
function Xn = normalizeX (X)
norms = spdiag(1./sqrt(sumsq(X)));
Xn = X*norms;
endfunction
It is fast and relatively cheap on memory.
Best, Joachim.
On Tuesday 26 October 2010 12:25:55 pm Joachim De Beule wrote:
> 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.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave