Description Usage Arguments Details Value Author(s) References See Also Examples
Construct list of variables defining a column-sparse matrix used
by the glmmGS.CovarianceModel
function
1 |
... |
can be a dense matrix or the following arguments in order:
(1) a numeric (i.e., double) vector with the non-zero elements of the matrix;
(2) an integer vector with the zero-based row indices of the non-zero elements of the matrix;
(3) an integer vector |
The list returned by this function defines a column-sparse matrix. The data structure
is the same one used by the AMD algorithms written by
Timothy A. Davis, Patrick R. Amestoy, Iain S. Duff, and the LDL algorithms
written by Timothy A. Davis (see Reference). The glmmGS
package
implements the AMD and LDL algorithms to perform sparse LDL decompositions of
sparse precision matrices.
A list with variables named as the arguments, describing a column-sparse matrix.
Michele Morara, Louise Ryan, Subharup Guha, Christopher Paciorek
http://www.cise.ufl.edu/research/sparse/amd/
http://www.cise.ufl.edu/research/sparse/ldl/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # Create dense matrix R
ncols <- 100;
R <- diag(rep(1, ncols));
for (i in 2:ncols)
R[i - 1, i] <- R[i, i - 1] <- 0.5;
# Create sparse matrix from dense matrix R
R.sparse <- glmmGS.SparseMatrix(R);
# Create sparse matrix from vectors of values, indices, and counts
# maximizing performance (requires O(ncols^2) workspace memory)
nz <- R != 0;
values <- c(R[nz]);
indices <- row(R)[nz] - 1L;
counts <- as.integer(c(0, cumsum(colSums(nz))));
R.sparse2 <- glmmGS.SparseMatrix(values, indices, counts);
# Create sparse matrix from vectors of values, indices, and counts
# allocating O(ncols) workspace memory
# 1) Set counts
counts <- integer(ncols + 1L);
count.total <- 0L;
counts[1] <- 0L;
for (j in 1:ncols)
{
nz <- which(R[, j] != 0);
count.total <- count.total + length(nz);
counts[j + 1] <- count.total;
}
# 2) Set values and indices
values <- double(count.total);
indices <- integer(count.total);
index <- 0L;
for (j in 1:ncols)
{
nz <- which(R[, j] != 0);
lnz <- length(nz);
kk <- index + 1:lnz;
values[kk] <- R[nz, j];
indices[kk] <- nz - 1L; # must be zero-based
index <- index + lnz;
}
# Build sparse matrix
R.sparse3 <- glmmGS.SparseMatrix(values, indices, counts);
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.