用 igraph 消除 clique 集群
Eliminate clique clusters with igraph
我有一个包含多个组件的网络,我想:
- 删除任何完全连接的集群
玩具示例:
g <- graph(c("a","b","b","c","c","a","f","g","h","g"))
result_g <- graph(c("f", "g","h","g"))
- 仅当(除其他条件外)不属于完全连接的组件时,才能仅标记组件的顶点。
为此,您可以先使用 components
函数将图形拆分为连通分量。然后你可以测试每个组件,看看它是否是一个完整的子图。当且仅当边数等于 n(n-1)/2 时,图是满图,其中 n 是节点数。因此,使用您的示例:
CompList = components(g)
NotFull = c()
for(i in 1:CompList$no) {
COMP = induced_subgraph(g, which(CompList$membership==i))
VC = vcount(COMP)
if(ecount(COMP) != VC*(VC-1)/2) {
NotFull = c(NotFull, which(CompList$membership==i)) }
}
result_g = induced_subgraph(g, NotFull)
result_g
IGRAPH 5d61ea5 DN-- 3 2 --
+ attr: name (v/c)
+ edges from 5d61ea5 (vertex names):
[1] f->g h->g
我有一个包含多个组件的网络,我想:
- 删除任何完全连接的集群
玩具示例:
g <- graph(c("a","b","b","c","c","a","f","g","h","g"))
result_g <- graph(c("f", "g","h","g"))
- 仅当(除其他条件外)不属于完全连接的组件时,才能仅标记组件的顶点。
为此,您可以先使用 components
函数将图形拆分为连通分量。然后你可以测试每个组件,看看它是否是一个完整的子图。当且仅当边数等于 n(n-1)/2 时,图是满图,其中 n 是节点数。因此,使用您的示例:
CompList = components(g)
NotFull = c()
for(i in 1:CompList$no) {
COMP = induced_subgraph(g, which(CompList$membership==i))
VC = vcount(COMP)
if(ecount(COMP) != VC*(VC-1)/2) {
NotFull = c(NotFull, which(CompList$membership==i)) }
}
result_g = induced_subgraph(g, NotFull)
result_g
IGRAPH 5d61ea5 DN-- 3 2 --
+ attr: name (v/c)
+ edges from 5d61ea5 (vertex names):
[1] f->g h->g