Skip to content

Symmetric Matrix classes

4 messages · Martin Maechler, Douglas Bates, Gad Abraham

#
Scanning for 'Matrix' in old R-help e-mail, I found
GA> Hi,
    GA> I'd like to store large covariance matrices using Matrix classes.

    GA> dsyMatrix seems like the right one, but I want to specify just the
    GA> upper/lower triangle and diagonal and not have to instantiate a huge
    GA> n^2 vector just for the sake of having half of it ignored:

    GA> Dumb example:
    GA> M <- new("dsyMatrix", uplo="U", x=rnorm(1e4), Dim=as.integer(c(100, 100)))
    GA> diag(M) <- 1

    GA> This doesn't work:
    GA> M <- new("dsyMatrix", uplo="U", x=0, Dim=as.integer(c(100, 100)))
    GA> Error in validObject(.Object) :
    GA> invalid class "dsyMatrix" object: length of x slot != prod(Dim)

    GA> Is there an easier way of doing this?

I think you want a  "dspMatrix"  ("sp" == "symmetric packed")
instead.

Before going into details: Is this topic still interesting to
those involved almost two months ago?

Regards,
Martin

    GA> -- 
    GA> Gad Abraham
    GA> PhD Student, Dept. CSSE and NICTA
    GA> The University of Melbourne
    GA> Parkville 3010, Victoria, Australia
    GA> email: gabraham at csse.unimelb.edu.au
    GA> web: http://www.csse.unimelb.edu.au/~gabraham
#
On Tue, Jan 19, 2010 at 9:26 AM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
Also, I fail to understand the advantage of allocating storage for
roughly half the elements in the matrix instead of the whole matrix
when the matrix is so large.  If dense storage of a symmetric matrix
of size 20000 takes up too much memory (approx 3 GB for each copy) it
is unlikely that the packed symmetric storage form, using about 1.5 GB
per copy, is going to save the day.
[1] 2.980232
[1] 1.490191

If the matrix is sparse, the dsCMatrix class may help.

And there is also the issue of what exactly do you want to do with the
matrix once you have stored it?
#
On Wed, Jan 20, 2010 at 2:26 AM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
Yes, please!
#
On Wed, Jan 20, 2010 at 8:18 AM, Douglas Bates <bates at stat.wisc.edu> wrote:
The difference between 16GB and 32 GB will determine whether I can
store the matrix in RAM or not.
It's a covariance matrix, it's dense.
I'm mainly interested in doing things like partial correlation using
(taking the pseudoinverse of the matrix using SVD or Lanczos).