expand-methods 位於 Matrix 包(package)。 說明
expand1 和 expand2 從指定矩陣分解的對象構造矩陣因子。此類對象通常不會顯式存儲因子,而是采用緊湊表示來節省內存。
用法
expand1(x, which, ...)
expand2(x, ...)
expand (x, ...)
參數
x |
矩陣分解,通常繼承自虛擬類 |
which |
表示矩陣因子的字符串。 |
... |
傳入或傳出方法的更多參數。 |
細節
保留 expand 的方法隻是為了向後兼容 Matrix < 1.6-0 。新代碼應使用 expand1 和 expand2 ,它們的方法提供更多控製並且行為更一致。值得注意的是, expand2 遵循以下規則:返回列表中矩陣因子的乘積應重現(在一定容差範圍內)因式分解矩陣,包括其 dimnames 。
因此,如果 x 是一個矩陣,而 y 是它的分解,那麽
all.equal(as(x, "matrix"), as(Reduce(`%*%`, expand2(y)), "matrix"))
在大多數情況下應該返回 TRUE 。
值
expand1 返回一個繼承自虛擬類 Matrix 的對象,表示 which 指示的因子,始終沒有行名稱和列名稱。
expand2 返回因子列表,通常使用常規表示法進行名稱,如 list(L=, U=) 中。第一個和最後一個因子獲取因式分解矩陣的行名稱和列名稱,這些名稱保存在 x 的 Dimnames 槽中。
方法
下表列出了 expand1 的方法以及參數 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.")
|
下麵說明expand2和expand的方法。因子名稱和類別也適用於 expand1 。
expand2-
signature(x = "CHMsimpl"):將分解 擴展為list(P1., L1, D, L1., P1)(默認)或list(P1., L, L., P1),具體取決於可選邏輯參數LDL。P1和P1.是pMatrix、L1、L1.、L和L.是dtCMatrix,D是ddiMatrix. expand2-
signature(x = "CHMsuper"):與CHMsimpl相同,但三角因子存儲為dgCMatrix。 expand2-
signature(x = "p?Cholesky"):將分解 擴展為list(L1, D, L1.)(默認)或list(L, L.),具體取決於可選邏輯參數LDL。L1、L1.、L和L.是dtrMatrix或dtpMatrix,D是ddiMatrix。 expand2-
signature(x = "p?BunchKaufman"):將 展開分解,其中 和 為list(U, DU, U.)或list(L, DL, L.),具體取決於x@uplo。如果可選參數complete是TRUE,則返回一個未命名列表,給出 或 矩陣因子的完整擴展。 表示為pMatrix,和表示為dtCMatrix,和表示為dsCMatrix。 expand2-
signature(x = "Schur"):將分解 展開為list(Q, T, Q.)。Q和Q.是x@Q和t(x@Q)模Dimnames,T是x@T。 expand2-
signature(x = "sparseLU"):將分解 展開為list(P1., L, U, P2.)。P1.和P2.是pMatrix,L和U是dtCMatrix。 expand2-
signature(x = "denseLU"):將分解 展開為list(P1., L, U)。P1.是pMatrix,如果是正方形,L和U是dtrMatrix,否則是dgeMatrix。 expand2-
signature(x = "sparseQR"):將分解 擴展為list(P1., Q, R, P2.)或list(P1., Q1, R1, P2.),具體取決於可選邏輯參數complete。P1.和P2.是pMatrix,Q和Q1是dgeMatrix,R是dgCMatrix,R1是dtCMatrix。 expand-
signature(x = "CHMfactor"):與expand2相同,但返回list(P, L)。expand(x)[["P"]]和expand2(x)[["P1"]]表示相同的置換矩陣,但具有相反的margin槽和倒置的perm槽。expand(x)的組件不保留x@Dimnames。 expand-
signature(x = "sparseLU"): 作為expand2,但返回list(P, L, U, Q).expand(x)[["Q"]]和expand2(x)[["P2."]]表示相同的置換矩陣但有相反的margin插槽和倒置perm插槽。expand(x)[["P"]]表示置換矩陣而不是它的轉置;這是expand2(x)[["P1."]]與倒立的perm投幣口。expand(x)[["L"]]和expand2(x)[["L"]]表示同一個單位下三角矩陣,但與diag插槽等於"N"和"U", 分別。expand(x)[["L"]]和expand(x)[["U"]]存儲排列後的第一和第二分量x@Dimnames在他們的Dimnames插槽。 expand-
signature(x = "denseLU"):與expand2相同,但返回list(L, U, P)。expand(x)[["P"]]和expand2(x)[["P1."]]與模Dimnames相同。expand(x)的組件不保留x@Dimnames。
例子
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
也可以看看
可分解矩陣的虛擬類compMatrix。
矩陣分解的虛擬類MatrixFactorization。
用於計算因式分解的通用函數 Cholesky 、 BunchKaufman 、 Schur 、 lu 和 qr 。
相關用法
- R expm-methods 矩陣指數
- R externalFormats 讀寫外部矩陣格式
- R dtrMatrix-class 三角形稠密數值矩陣
- R facmul-methods 乘以矩陣因式分解的因數
- R solve-methods 函數求解矩陣包中的方法
- R updown-methods 更新和降級稀疏 Cholesky 分解
- R bdiag 構建分塊對角矩陣
- R printSpMatrix 靈活格式化和打印稀疏矩陣
- R symmetricMatrix-class 包矩陣中對稱矩陣的虛擬類
- R all.equal-methods 函數 all.equal() 的矩陣封裝方法
- R boolmatmult-methods 布爾算術矩陣乘積:%&% 和方法
- R ltrMatrix-class 三角密集邏輯矩陣
- R Hilbert 生成希爾伯特矩陣
- R nearPD 最近正定矩陣
- R lsyMatrix-class 對稱密集邏輯矩陣
- R CHMfactor-class 稀疏 Cholesky 分解
- R symmpart-methods 矩陣的對稱部分和偏斜(對稱)部分
- R sparseMatrix 從非零項構建一般稀疏矩陣
- R dgCMatrix-class 壓縮、稀疏、麵向列的數值矩陣
- R Cholesky-methods Cholesky 分解方法
- R Subassign-methods “[<-”的方法 - 分配給“矩陣”的子集
- R ldenseMatrix-class 密集邏輯矩陣的虛擬類“ldenseMatrix”
- R norm-methods 矩陣範數
- R ngeMatrix-class 一般密集非零模式矩陣的“ngeMatrix”類
- R CAex 阿爾伯斯的示例矩陣與“困難”特征分解
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Expand Matrix Factorizations。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
