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
.
expand2
signature(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
.P1
andP1.
arepMatrix
,L1
,L1.
,L
, andL.
aredtCMatrix
, andD
is addiMatrix
.expand2
signature(x = "CHMsuper")
: asCHMsimpl
, but the triangular factors are stored asdgCMatrix
.expand2
signature(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.
aredtrMatrix
ordtpMatrix
, andD
is addiMatrix
.expand2
signature(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 argumentcomplete
isTRUE
, then an unnamed list giving the full expansion with2 b_{U} + 1
or2 b_{L} + 1
matrix factors is returned instead.P_{k}
are represented aspMatrix
,U_{k}
andL_{k}
are represented asdtCMatrix
, andD_{U}
andD_{L}
are represented asdsCMatrix
.expand2
signature(x = "Schur")
: expands the factorizationA = Q T Q'
aslist(Q, T, Q.)
.Q
andQ.
arex@Q
andt(x@Q)
moduloDimnames
, andT
isx@T
.expand2
signature(x = "sparseLU")
: expands the factorizationA = P_{1}' L U P_{2}'
aslist(P1., L, U, P2.)
.P1.
andP2.
arepMatrix
, andL
andU
aredtCMatrix
.expand2
signature(x = "denseLU")
: expands the factorizationA = P_{1}' L U
aslist(P1., L, U)
.P1.
is apMatrix
, andL
andU
aredtrMatrix
if square anddgeMatrix
otherwise.expand2
signature(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
,Q
andQ1
aredgeMatrix
,R
is adgCMatrix
, andR1
is adtCMatrix
.expand
signature(x = "CHMfactor")
: asexpand2
, but returninglist(P, L)
.expand(x)[["P"]]
andexpand2(x)[["P1"]]
represent the same permutation matrixP_{1}
but have oppositemargin
slots and invertedperm
slots. The components ofexpand(x)
do not preservex@Dimnames
.expand
signature(x = "sparseLU")
: asexpand2
, but returninglist(P, L, U, Q)
.expand(x)[["Q"]]
andexpand2(x)[["P2."]]
represent the same permutation matrixP_{2}'
but have oppositemargin
slots and invertedperm
slots.expand(x)[["P"]]
represents the permutation matrixP_{1}
rather than its transposeP_{1}'
; it isexpand2(x)[["P1."]]
with an invertedperm
slot.expand(x)[["L"]]
andexpand2(x)[["L"]]
represent the same unit lower triangular matrixL
, but withdiag
slot equal to"N"
and"U"
, respectively.expand(x)[["L"]]
andexpand(x)[["U"]]
store the permuted first and second components ofx@Dimnames
in theirDimnames
slots.expand
signature(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