[R] Binary Matrices
Martin Maechler
maechler at stat.math.ethz.ch
Wed Apr 13 17:17:13 CEST 2005
>>>>> "Mark" == Mark Edmondson-Jones <Mark.Edmondson-jones at nottingham.ac.uk>
>>>>> on Wed, 13 Apr 2005 15:40:26 +0100 writes:
Mark> 1000x1000 is only indicative. I need to generate
Mark> larger (adjacency) matrices using a variety of models.
Mark> Most are sparse, with a high proportion of zeros and
Mark> so SparseM sounds very promising. I will investigate.
As others have said, you can use either 'SparseM' or 'Matrix'.
The latter has also good code for sparse matrices, and actually
I know that Doug Bates was going to implement sparse logical
matrices in the next few days.
Those actually need (quite) a bit less space than sparse double
matrices, since you only need to store the indices of the TRUE
entries.
Martin
>>>> "Liaw, Andy" <andy_liaw at merck.com> 13/04/2005 >>>
>> -----Original Message-----
>> From: Uwe Ligges
>>
>> Mark Edmondson-Jones wrote:
>>
>> > I'm wanting to perform analysis (e.g. using eigen()) of
>> binary matrices - i.e. matrices comprising 0s and 1s.
>> >
>> > For example:
>> >
>> > n<-1000
>> > test.mat<-matrix(round(runif(n^2)),n,n)
>> > eigen(test.mat,only.values=T)
>> >
>> > Is there a more efficient way of setting up test.mat, as
>> each cell only requires a binary digit? I imagine R is
>> setting up a structure which could contain n^2 floats.
>>
>> No. In principle you could use logicals,
Mark> ... but that doesn't save any memory:
>> object.size(integer(1e6))
Mark> [1] 4000028
>> object.size(logical(1e6))
Mark> [1] 4000028
>> but that does not help for further calculations in eigen().
Mark> Besides, if the problem size is really 1000 x 1000, one matrix in
Mark> double precision is only 8MB. As Reid said, if the matrix is sparse,
Mark> there's probably a lot more saving in both memory and computation
Mark> by using SparseM and Matrix packages.
Mark> Cheers,
Mark> Andy
>> Uwe Ligges
>>
>>
>> > Thanks in advance for any help.
>> >
>> > Regards,
>> > Mark
>> >
>> >
>> > This message has been checked for viruses but the contents
>> of an attachment
>> > may still contain software viruses, which could damage your
>> computer system:
>> > you are advised to perform your own checks. Email
>> communications with the
>> > University of Nottingham may be monitored as permitted by
>> UK legislation.
>> >
>> > ______________________________________________
>> > R-help at stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>>
>>
Mark> ------------------------------------------------------------------------------
Mark> ------------------------------------------------------------------------------
Mark> This message has been checked for viruses but the contents of an attachment
Mark> may still contain software viruses, which could damage your computer system:
Mark> you are advised to perform your own checks. Email communications with the
Mark> University of Nottingham may be monitored as permitted by UK legislation.
Mark> ______________________________________________
Mark> R-help at stat.math.ethz.ch mailing list
Mark> https://stat.ethz.ch/mailman/listinfo/r-help
Mark> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list