跳到内容

检索类igraph的图的随机矩阵。

用法

stochastic_matrix(
  graph,
  column.wise = FALSE,
  sparse = igraph_opt("sparsematrices")
)

参数

graph

输入图。必须是类igraph

column.wise

如果FALSE,则随机矩阵的行之和为 1;否则,为列之和。

sparse

逻辑标量,是否返回稀疏矩阵。 Matrix 包是稀疏矩阵所必需的。

如果 sparse 参数为 TRUE,则为规则矩阵或 Matrix 类的矩阵。

详细信息

设 \(M\) 是一个具有实数非负条目的 \(n \times n\) 邻接矩阵。 让我们定义 \(D = \textrm{diag}(\sum_{i}M_{1i}, \dots, \sum_{i}M_{ni})\)

(行)随机矩阵定义为 $$W = D^{-1}M,$$,假设 \(D\) 是非奇异的。 列随机矩阵以对称方式定义。

作者

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)
#> [1] "dgCMatrix"
#> attr(,"package")
#> [1] "Matrix"

## may not be exactly 1, due to numerical errors
max(abs(rowSums(W)) - 1)
#> [1] 0