Re: sum of a large covariance matrix
- From: ellieandrogerxyzzy@xxxxxxxxxxxxxxxxxxxxxx (Roger Stafford)
- Date: Wed, 02 Aug 2006 08:11:04 GMT
In article <ef3d34d.-1@xxxxxxxxxxxxxxxxxxxxxxx>, danielle
<danielleblanc2004@xxxxxxxxxxx> wrote:
hi all,----------------------
I have a 155x12000 matrix. I am unable to compute the covariance
matrix since i am running out of memory. is their a neat trick to
compute the sum of the covariance matrix (I don't need to store it.
simply i need the sum of the variance-covariance matrix) i hope
someone could help.
D
Do you have 12000 variables and 155 observations, or is it the other way
around? The matlab function, 'cov', assumes that each row is an
observation, and each column a variable, so 'cov' of a 155 x 12000 matrix
would yield a 12000 x 12000 covariance matrix, one for each possible pair
of variables. Is that your intent? If so, that would account nicely for
your memory problem. If you mean it the other way around, you should take
the transpose of your matrix before applying 'cov' to it and doing the
summation.
In either case, there is a shortcut you can use in your computations if
all you want is the sum of all the covariance values. First, compute the
vector t, where, for each observation, the corresponding element of t is
the sum of all the variables. If N is the number of observations, t will
have N elements. If X is your matrix, this will be either t = sum(X,1) if
the columns of X are observations or t = sum(X,2) if the rows of X are the
observations. Then,
s = 1/(N-1)*(sum(t.^2)-1/N*sum(t)^2);
will give you the desired sum of all covariances without your ever having
to generate the covariances themselves, and you should have no memory
problems with this method. Also this is probably faster than having to
compute each covariance value and then add them.
Roger Stafford
.
- Follow-Ups:
- Re: sum of a large covariance matrix
- From: Roger Stafford
- Re: sum of a large covariance matrix
- References:
- sum of a large covariance matrix
- From: danielle
- sum of a large covariance matrix
- Prev by Date: copy image - bug in matlab???
- Next by Date: Voltage Measurement block (mask) 'v'. Error
- Previous by thread: sum of a large covariance matrix
- Next by thread: Re: sum of a large covariance matrix
- Index(es):
Relevant Pages
|