| expand-methods {Matrix} | R Documentation |
Expand Matrix Factorizations
Description
expand1 and expand2 construct matrix factors from
objects specifying matrix factorizations. Such objects typically
do not store the factors explicitly, employing instead a compact
representation to save memory.
Usage
expand1(x, which, ...)
expand2(x, ...)
expand (x, ...)
Arguments
x |
a matrix factorization, typically inheriting from
virtual class |
which |
a character string indicating a matrix factor. |
... |
further arguments passed to or from methods. |
Details
Methods for expand are retained only for backwards
compatibility with Matrix < 1.6-0. New code
should use expand1 and expand2, whose methods
provide more control and behave more consistently. Notably,
expand2 obeys the rule that the product of the matrix
factors in the returned list should reproduce
(within some tolerance) the factorized matrix,
including its dimnames.
Hence if x is a matrix and y is its factorization,
then
all.equal(as(x, "matrix"), as(Reduce(`%*%`, expand2(y)), "matrix"))
should in most cases return TRUE.
Value
expand1 returns an object inheriting from virtual class
Matrix, representing the factor indicated
by which, always without row and column names.
expand2 returns a list of factors, typically with names
using conventional notation, as in list(L=, U=).
The first and last factors get the row and column names of the
factorized matrix, which are preserved in the Dimnames
slot of x.
Methods
The following table lists methods for expand1 together with
allowed values of argument which.
class(x) | which |
Schur | c("Q", "T", "Q.") |
denseLU | c("P1", "P1.", "L", "U") |
sparseLU | c("P1", "P1.", "P2", "P2.", "L", "U") |
sparseQR | c("P1", "P1.", "P2", "P2.", "Q", "Q1", "R", "R1") |
BunchKaufman, pBunchKaufman | c("U", "DU", "U.", "L", "DL", "L.") |
Cholesky, pCholesky | c("P1", "P1.", "L1", "D", "L1.", "L", "L.") |
CHMsimpl, CHMsimpl | c("P1", "P1.", "L1", "D", "L1.", "L", "L.")
|
Methods for expand2 and expand are described
below. Factor names and classes apply also to expand1.
expand2signature(x = "CHMsimpl"): expands the factorizationA = P_{1}' L_{1} D L_{1}' P_{1} = P_{1}' L L' P_{1}aslist(P1., L1, D, L1., P1)(the default) or aslist(P1., L, L., P1), depending on optional logical argumentLDL.P1andP1.arepMatrix,L1,L1.,L, andL.aredtCMatrix, andDis addiMatrix.expand2signature(x = "CHMsuper"): asCHMsimpl, but the triangular factors are stored asdgCMatrix.expand2signature(x = "p?Cholesky"): expands the factorizationA = L_{1} D L_{1}' = L L'aslist(L1, D, L1.)(the default) or aslist(L, L.), depending on optional logical argumentLDL.L1,L1.,L, andL.aredtrMatrixordtpMatrix, andDis addiMatrix.expand2signature(x = "p?BunchKaufman"): expands the factorizationA = U D_{U} U' = L D_{L} L'whereU = \prod_{k = 1}^{b_{U}} P_{k} U_{k}andL = \prod_{k = 1}^{b_{L}} P_{k} L_{k}aslist(U, DU, U.)orlist(L, DL, L.), depending onx@uplo. If optional argumentcompleteisTRUE, then an unnamed list giving the full expansion with2 b_{U} + 1or2 b_{L} + 1matrix factors is returned instead.P_{k}are represented aspMatrix,U_{k}andL_{k}are represented asdtCMatrix, andD_{U}andD_{L}are represented asdsCMatrix.expand2signature(x = "Schur"): expands the factorizationA = Q T Q'aslist(Q, T, Q.).QandQ.arex@Qandt(x@Q)moduloDimnames, andTisx@T.expand2signature(x = "sparseLU"): expands the factorizationA = P_{1}' L U P_{2}'aslist(P1., L, U, P2.).P1.andP2.arepMatrix, andLandUaredtCMatrix.expand2signature(x = "denseLU"): expands the factorizationA = P_{1}' L Uaslist(P1., L, U).P1.is apMatrix, andLandUaredtrMatrixif square anddgeMatrixotherwise.expand2signature(x = "sparseQR"): expands the factorizationA = P_{1}' Q R P_{2}' = P_{1}' Q_{1} R_{1} P_{2}'aslist(P1., Q, R, P2.)orlist(P1., Q1, R1, P2.), depending on optional logical argumentcomplete.P1.andP2.arepMatrix,QandQ1aredgeMatrix,Ris adgCMatrix, andR1is adtCMatrix.expandsignature(x = "CHMfactor"): asexpand2, but returninglist(P, L).expand(x)[["P"]]andexpand2(x)[["P1"]]represent the same permutation matrixP_{1}but have oppositemarginslots and invertedpermslots. The components ofexpand(x)do not preservex@Dimnames.expandsignature(x = "sparseLU"): asexpand2, but returninglist(P, L, U, Q).expand(x)[["Q"]]andexpand2(x)[["P2."]]represent the same permutation matrixP_{2}'but have oppositemarginslots and invertedpermslots.expand(x)[["P"]]represents the permutation matrixP_{1}rather than its transposeP_{1}'; it isexpand2(x)[["P1."]]with an invertedpermslot.expand(x)[["L"]]andexpand2(x)[["L"]]represent the same unit lower triangular matrixL, but withdiagslot equal to"N"and"U", respectively.expand(x)[["L"]]andexpand(x)[["U"]]store the permuted first and second components ofx@Dimnamesin theirDimnamesslots.expandsignature(x = "denseLU"): asexpand2, but returninglist(L, U, P).expand(x)[["P"]]andexpand2(x)[["P1."]]are identical moduloDimnames. The components ofexpand(x)do not preservex@Dimnames.
See Also
The virtual class MatrixFactorization
of matrix factorizations.
Generic functions Cholesky, BunchKaufman,
Schur, lu, and qr for
computing factorizations.
Examples
showMethods("expand1", inherited = FALSE)
showMethods("expand2", inherited = FALSE)
set.seed(0)
(A <- Matrix(rnorm(9L, 0, 10), 3L, 3L))
(lu.A <- lu(A))
(e.lu.A <- expand2(lu.A))
stopifnot(exprs = {
is.list(e.lu.A)
identical(names(e.lu.A), c("P1.", "L", "U"))
all(sapply(e.lu.A, is, "Matrix"))
all.equal(as(A, "matrix"), as(Reduce(`%*%`, e.lu.A), "matrix"))
})
## 'expand1' and 'expand2' give equivalent results modulo
## dimnames and representation of permutation matrices;
## see also function 'alt' in example("Cholesky-methods")
(a1 <- sapply(names(e.lu.A), expand1, x = lu.A, simplify = FALSE))
all.equal(a1, e.lu.A)
## see help("denseLU-class") and others for more examples