如果您从 R 中使用 igraph,请使用此选项
cohesive_blocks {igraph} | R 文档 |
为 igraph
类的对象计算凝聚块。
cohesive_blocks(graph, labels = TRUE)
## S3 method for class 'cohesiveBlocks'
length(x)
blocks(blocks)
graphs_from_cohesive_blocks(blocks, graph)
## S3 method for class 'cohesiveBlocks'
cohesion(x, ...)
hierarchy(blocks)
parent(blocks)
## S3 method for class 'cohesiveBlocks'
print(x, ...)
## S3 method for class 'cohesiveBlocks'
summary(object, ...)
## S3 method for class 'cohesiveBlocks'
plot(
x,
y,
colbar = rainbow(max(cohesion(x)) + 1),
col = colbar[max_cohesion(x) + 1],
mark.groups = blocks(x)[-1],
...
)
plot_hierarchy(
blocks,
layout = layout_as_tree(hierarchy(blocks), root = 1),
...
)
export_pajek(blocks, graph, file, project.file = TRUE)
max_cohesion(blocks)
图 |
对于 对于 |
labels |
逻辑标量,是否将顶点标签添加到结果对象。这些标签可以在报告和绘制凝聚块时使用。 |
blocks, x, object |
一个 |
... |
附加参数。 |
y |
其凝聚块在 |
colbar |
顶点颜色的颜色条。它的长度应至少为 |
col |
一个顶点颜色向量,采用任何常用格式。(符号颜色名称(例如“red”、“blue”等)、RGB 颜色(例如“#FF9900FF”)、引用当前调色板的整数。默认情况下,使用给定的 |
mark.groups |
要在图上通过环绕标记的顶点集列表。默认情况下,标记所有凝聚块,除了对应于所有顶点的凝聚块。 |
layout |
图的布局,它只是传递给 |
file |
定义 Pajek 文件写入到的文件(或连接)。 如果 如果 另请参见下面的详细信息。 |
project.file |
逻辑标量,是创建包含所有数据的单个 Pajek 项目文件,还是为每个项目创建单独的文件。请参阅下面的详细信息。 |
凝聚块是一种基于图顶点结构凝聚度(或顶点连通性)确定图顶点分层子集的方法。对于给定的图 G
,如果不存在顶点连通性大于或等于 k
的 S
超集,则其顶点子集 S\subset V(G)
被认为是最大 k
-凝聚的。凝聚块是一个过程,通过该过程,给定一个 k
-凝聚的顶点集,以递归方式识别最大 l
-凝聚的子集,其中 l>k
。因此,找到顶点子集的一个层次结构,整个图 G
位于其根部。
函数 cohesive_blocks
实现凝聚块。它返回一个 cohesiveBlocks
对象。cohesiveBlocks
应被视为不透明类,即不应直接访问其内部结构,而是通过此处列出的函数访问。
函数 length
可用于 cohesiveBlocks
对象,它给出块的数量。
函数 blocks
返回存储在 cohesiveBlocks
对象中的实际块。它们以数字向量列表的形式返回,每个数字向量包含顶点 ID。
函数 graphs_from_cohesive_blocks
类似,但将块作为输入图的(诱导)子图返回。各种(图、顶点和边)属性保留在子图中。
函数 cohesion
返回一个数值向量,即不同块的凝聚度。块的顺序与 blocks
和 graphs_from_cohesive_blocks
函数相同。
可以使用 hierarchy
函数查询块层次结构。它返回一个 igraph 图,其顶点 ID 根据 blocks
和 graphs_from_cohesive_blocks
、cohesion
等函数中块的顺序排序。
parent
给出块层次结构中每个块的父顶点,对于根顶点,它给出 0。
plot_hierarchy
通过调用 igraph.plot
在活动图形设备上绘制凝聚块的层次结构树。
export_pajek
函数可用于以 Pajek 格式导出图及其凝聚块。它可以导出包含所有信息的单个 Pajek 项目文件,也可以导出一组文件,具体取决于其 project.file
参数。如果 project.file
为 TRUE
,则将以下信息写入 file
参数中给出的文件(或连接):(1) 输入图及其属性,有关详细信息,请参见 write_graph
;(2) 层次结构图;以及 (3) 每个凝聚块一个二进制分区。如果 project.file
为 FALSE
,则 file
参数必须是字符标量,并用作生成文件的基本名称。如果 file
为 “basename”,则创建以下文件:(1) 原始图的 “basename.net”;(2) 层次结构图的 “basename_hierarchy.net”;(3) 每个凝聚块的 “basename_block_x.net”,其中 “x” 是块的编号,从 1 开始。
max_cohesion
返回每个顶点的最大凝聚度,即顶点的最具凝聚力块的凝聚度。
通用函数 summary
适用于 cohesiveBlocks
对象,它向终端打印一行摘要。
通用函数 print
也在 cohesiveBlocks
对象上定义,如果输入 cohesiveBlocks
对象的名称,它会自动调用。它产生如下输出
Cohesive block structure: B-1 c 1, n 23 '- B-2 c 2, n 14 oooooooo.. .o......oo ooo '- B-4 c 5, n 7 ooooooo... .......... ... '- B-3 c 2, n 10 ......o.oo o.oooooo.. ... '- B-5 c 3, n 4 ......o.oo o......... ...
左侧部分显示块结构,在本例中为五个块。第一个块始终对应于整个图,即使其凝聚度为零。然后显示块的凝聚度和块中顶点的数量。仅当显示器足够宽时才打印最后一部分,并显示块中的顶点,按顶点 ID 排序。“o” 表示包含顶点,点表示不包含顶点,并且顶点以十个为一组显示。
通用函数 plot
绘制图,在其中显示一个或多个凝聚块。
cohesive_blocks
返回一个 cohesiveBlocks
对象。
blocks
返回一个数字向量列表,其中包含顶点 ID。
graphs_from_cohesive_blocks
返回一个 igraph 图列表,对应于凝聚块。
cohesion
返回一个数值向量,即每个块的凝聚度。
hierarchy
返回一个 igraph 图,即凝聚块层次结构的表示。
parent
返回一个数值向量,给出块层次结构中每个凝聚块的父块。层次结构根部的块没有父块,并为其返回 0
。
plot_hierarchy
、plot
和 export_pajek
返回 NULL
,不可见。
max_cohesion
返回一个数值向量,每个顶点一个条目,给出其最具凝聚力块的凝聚度。
print
和 summary
返回 cohesiveBlocks
对象本身,不可见。
length
返回一个数值标量,即块的数量。
Gabor Csardi csardi.gabor@gmail.com 用于当前实现,Peter McMahan (https://socialsciences.uchicago.edu/news/alumni-profile-peter-mcmahan-phd17-sociology) 在 R 中编写了第一个版本。
J. Moody 和 D. R. White。Structural cohesion and embeddedness: A hierarchical concept of social groups。American Sociological Review, 68(1):103–127, Feb 2003。
## The graph from the Moody-White paper
mw <- graph_from_literal(1-2:3:4:5:6, 2-3:4:5:7, 3-4:6:7, 4-5:6:7,
5-6:7:21, 6-7, 7-8:11:14:19, 8-9:11:14, 9-10,
10-12:13, 11-12:14, 12-16, 13-16, 14-15, 15-16,
17-18:19:20, 18-20:21, 19-20:22:23, 20-21,
21-22:23, 22-23)
mwBlocks <- cohesive_blocks(mw)
# Inspect block membership and cohesion
mwBlocks
blocks(mwBlocks)
cohesion(mwBlocks)
# Save results in a Pajek file
## Not run:
export_pajek(mwBlocks, mw, file="/tmp/mwBlocks.paj")
## End(Not run)
# Plot the results
plot(mwBlocks, mw)
## The science camp network
camp <- graph_from_literal(Harry:Steve:Don:Bert - Harry:Steve:Don:Bert,
Pam:Brazey:Carol:Pat - Pam:Brazey:Carol:Pat,
Holly - Carol:Pat:Pam:Jennie:Bill,
Bill - Pauline:Michael:Lee:Holly,
Pauline - Bill:Jennie:Ann,
Jennie - Holly:Michael:Lee:Ann:Pauline,
Michael - Bill:Jennie:Ann:Lee:John,
Ann - Michael:Jennie:Pauline,
Lee - Michael:Bill:Jennie,
Gery - Pat:Steve:Russ:John,
Russ - Steve:Bert:Gery:John,
John - Gery:Russ:Michael)
campBlocks <- cohesive_blocks(camp)
campBlocks
plot(campBlocks, camp, vertex.label=V(camp)$name, margin=-0.2,
vertex.shape="rectangle", vertex.size=24, vertex.size2=8,
mark.border=1, colbar=c(NA, NA,"cyan","orange") )