如果您从 R 中使用 igraph,请使用此选项
stochastic_matrix {igraph} | R 文档 |
检索类 igraph
的图的随机矩阵。
stochastic_matrix(
graph,
column.wise = FALSE,
sparse = igraph_opt("sparsematrices")
)
图 |
输入图。必须是 |
column.wise |
如果 |
sparse |
逻辑标量,是否返回稀疏矩阵。稀疏矩阵需要 |
设 M
是一个具有实非负条目的 n \times n
邻接矩阵。让我们定义 D = \textrm{diag}(\sum_{i}M_{1i}, \dots, \sum_{i}M_{ni})
(行)随机矩阵定义为
W = D^{-1}M,
其中假定 D
是非奇异的。列随机矩阵以对称方式定义。
如果 sparse
参数为 TRUE
,则为常规矩阵或 Matrix
类的矩阵。
Gabor Csardi csardi.gabor@gmail.com
library(Matrix)
## g is a large sparse graph
g <- sample_pa(n = 10^5, power = 2, directed = FALSE)
W <- stochastic_matrix(g, sparse=TRUE)
## a dense matrix here would probably not fit in the memory
class(W)
## may not be exactly 1, due to numerical errors
max(abs(rowSums(W))-1)