coo2mat | R Documentation |
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:
coo2mat(coomat,
n = max(max(coomat[, 1]), max(coomat[, 2])),
transpose_needed = FALSE)
coomat |
a 3-column matrix or data.frame (basically
|
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) |
https://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.
outmat
Nicholas J. Matzke nickmatzke.ncse@gmail.com
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.