zzz_coo2mat: Convert a COO-formated matrix to standard square format

Description Usage Arguments Details Value Author(s) Examples

Description

EXPOKIT's dmexp-type functions deal with sparse matrices. These have a lot of zeros, and thus can be compressed into COO (coordinated list) format, which is described here:

Usage

1
2
3
  coo2mat(coomat,
    n = max(max(coomat[, 1]), max(coomat[, 2])),
    transpose_needed = FALSE)

Arguments

coomat

a 3-column matrix or data.frame (basically cbind(ia, ja, a))

n

the order of the matrix

transpose_needed

If TRUE (default), matrix will be transposed (apparently EXPOKIT needs the input matrix to be transposed compared to normal)

Details

http://en.wikipedia.org/wiki/Sparse_matrix#Coordinate_list_.28COO.29

In EXPOKIT and its wrapper functions, a COO-formated matrix is input as 3 vectors (first two integer, the third double):

ia = row number
ja = column number
a = value of that cell in the matrix (skipping 0 cells)

This function takes a 3-column matrix or data.frame (basically cbind(ia, ja, a)) and the order of the matrix, n (n = the order of the matrix, i.e. number of rows/columns) and converts back to standard square format.

Value

outmat

Author(s)

Nicholas J. Matzke [email protected]

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Example use:
ia = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4)
ja = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)
a  = c(-1.218, 0.126, 0.168, 0.126, 0.504, -0.882, 0.504,
0.672, 0.336, 0.252, -1.050, 0.252, 0.378, 0.504, 0.378, -1.050)
coomat = cbind(ia, ja, a)
print(coomat)
n = 4
Qmat = coo2mat(coomat, n)
print(Qmat)

rexpokit documentation built on Aug. 16, 2017, 1:04 a.m.