rsparsematrix
位於 Matrix
包(package)。 說明
有效地生成隨機稀疏矩陣。默認情況下具有舍入高斯非零條目,並且 rand.x = NULL
生成隨機模式矩陣,即繼承自 nsparseMatrix
。
用法
rsparsematrix(nrow, ncol, density, nnz = round(density * maxE),
symmetric = FALSE,
rand.x = function(n) signif(rnorm(n), 2), ...)
參數
nrow , ncol |
行數和列數,即矩陣維度 ( |
density |
|
nnz |
非零條目的數量,對於稀疏矩陣通常比 |
symmetric |
邏輯指示結果是否應該是類 |
rand.x |
|
... |
可選地將更多參數傳遞給 |
細節
該算法首先通過一維索引對 “encoded” symmetric
sample.int(nrow*ncol, nnz)
,則 — 如果 rand.x
不是 NULL
— 獲取 x <- rand.x(nnz)
並調用 sparseMatrix(i=i, j=j, x=x, ..)
。當 rand.x=NULL
時,sparseMatrix(i=i, j=j, ..)
將返回一個模式矩陣(即繼承自 nsparseMatrix
)。 進行無放回采樣,如果不是
值
a sparseMatrix
,例如維度 (nrow, ncol) 的 M
,即,如果 symmetric
不為 true,則使用 dim(M) == c(nrow, ncol)
,而 nzM <- nnzero(M)
滿足 nzM <= nnz
,並且通常滿足 nzM == nnz
。
例子
set.seed(17)# to be reproducible
M <- rsparsematrix(8, 12, nnz = 30) # small example, not very sparse
M
M1 <- rsparsematrix(1000, 20, nnz = 123, rand.x = runif)
summary(M1)
## a random *symmetric* Matrix
(S9 <- rsparsematrix(9, 9, nnz = 10, symmetric=TRUE)) # dsCMatrix
nnzero(S9)# ~ 20: as 'nnz' only counts one "triangle"
## a random patter*n* aka boolean Matrix (no 'x' slot):
(n7 <- rsparsematrix(5, 12, nnz = 10, rand.x = NULL))
## a [T]riplet representation sparseMatrix:
T2 <- rsparsematrix(40, 12, nnz = 99, repr = "T")
head(T2)
作者
Martin Maechler
相關用法
- R replValue-class 虛擬類“replValue” - 子分配值的簡單類
- R rep2abI 將向量複製到“abIndex”結果中
- R rleDiff-class rle(diff(.)) 存儲向量的“rleDiff”類
- R rcond-methods 估計條件數的倒數
- R rankMatrix 矩陣的秩
- 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-devel大神的英文原創作品 Random Sparse Matrix。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。