跳到内容

基于不同顶点类型的随机图生成。

用法

sample_pref(
  nodes,
  types,
  type.dist = rep(1, types),
  fixed.sizes = FALSE,
  pref.matrix = matrix(1, types, types),
  directed = FALSE,
  loops = FALSE
)

pref(...)

sample_asym_pref(
  nodes,
  types,
  type.dist.matrix = matrix(1, types, types),
  pref.matrix = matrix(1, types, types),
  loops = FALSE
)

asym_pref(...)

参数

节点

图中的顶点数。

types

不同顶点类型的数量。

type.dist

顶点类型的分布,一个长度为 ‘types’ 的数值向量,包含非负数。该向量将被归一化以获得概率。

fixed.sizes

固定具有给定顶点类型标签的顶点数量。在这种情况下,type.dist 参数给出组大小(即具有不同标签的顶点数量)。

pref.matrix

一个正方形矩阵,给出顶点类型的偏好。该矩阵有 ‘types’ 行和列。当生成一个无向图时,它必须是对称的。

directed

逻辑常量,是否创建有向图。

loops

逻辑常量,是否允许图中的自环。

...

传递给构造函数,sample_pref()sample_asym_pref()

type.dist.matrix

入顶点和出顶点的联合分布。

一个 igraph 图。

详细信息

两种模型都生成具有给定顶点类型的随机图。对于 sample_pref(),两个顶点连接的概率取决于它们的类型,由 ‘pref.matrix’ 参数给出。该矩阵应该是对称的才有意义,但这一点没有被检查。不同顶点类型的分布由 ‘type.dist’ 向量给出。

对于 sample_asym_pref(),每个顶点都有一个入类型和一个出类型,并创建一个有向图。从具有给定出类型的顶点到具有给定入类型的顶点实现有向边的概率在 ‘pref.matrix’ 参数中给出,该参数可以是非对称的。入类型和出类型的联合分布在 ‘type.dist.matrix’ 参数中给出。

生成的顶点的类型可以从 sample_pref()type 顶点属性以及 sample_asym_pref()intypeouttype 顶点属性中检索。

作者

Tamas Nepusz ntamas@gmail.com 和 Gabor Csardi csardi.gabor@gmail.com 为 R 接口

示例


pf <- matrix(c(1, 0, 0, 1), nrow = 2)
g <- sample_pref(20, 2, pref.matrix = pf)
if (FALSE) { # rlang::is_installed("tcltk") && rlang::is_interactive()
# example code

tkplot(g, layout = layout_with_fr)
}

pf <- matrix(c(0, 1, 0, 0), nrow = 2)
g <- sample_asym_pref(20, 2, pref.matrix = pf)
if (FALSE) { # rlang::is_installed("tcltk") && rlang::is_interactive()
tkplot(g, layout = layout_in_circle)
}