如何手动分配社区和衡量模块化?

时间:2021-10-06 12:50:20

I have a network for which I would like to compare the modularity scores that are derived from various algorithms, e.g. walktrap, with the modularity scores that are derived by community membership of my own choosing (assigned by hand). For example, I would like to be able to assign every node a "commmunity" of 1 or 2. So far, I have used various means to try to achieve this and they typically crash the R environment when I run modularity(graph1, assigned_communities).

我有一个网络,我想比较从各种算法得到的模块性分数,例如: walktrap,具有由我自己选择的社区成员资格(手工分配)派生的模块化分数。例如,我希望能够为每个节点分配1或2的“社区”。到目前为止,我已经使用各种方法来尝试实现这一点,并且当我运行模块化时它们通常会崩溃R环境(graph1,assigned_communities) )。

library(igraph)
raw1 <- read.csv("C:\\edge list directed weighted.csv")
graph1 <- graph.data.frame(raw1, directed=TRUE, vertices=NULL)

attrib <- read.csv("C:\\vertex_groups.csv")

"attrib" is the object holding my assigned groups. The .csv file contains four columns - "vertex" which is the sorted list of unique vertices contained in graph1, and other columns with the communities I would like to be able to assign to those vertices, in this example "group1" "group2" etc.

“attrib”是持有我指定组的对象。 .csv文件包含四列 - “顶点”,它是graph1中包含的唯一顶点的排序列表,以及其他具有我希望能够分配给这些顶点的社区的列,在此示例中为“group1”“group2”等等

##method1: communities object type clone
members <- as.double(attrib$group1)
nam <- as.character(attrib$vertex)
comms <- list(membership=members, vcount=vcount(graph1), names=nam, algorithm="by.hand")
class(comms) <- "communities"
modularity(graph1, membership(comms) )

This first attempt is to clone a "communities" object. I extract the column from the attrib object corresponding to group1, the group i want to assign as a community. Running that modularity command crashes the environment.

第一次尝试是克隆“社区”对象。我从对应于group1的attrib对象中提取列,我想将该组指定为社区。运行该模块化命令会导致环境崩溃。

v = attrib$group1
names(v) = attrib$vertex
modularity(graph1,v)

Here, v extracts the group1 values as a column but also names the rows to match the style of a commmunity object. This also crashes the environment.

这里,v将group1值提取为列,但也将行命名为与commmunity对象的样式匹配。这也会破坏环境。

Thanks for your help.

谢谢你的帮助。

1 个解决方案

#1


The crashing was caused by running this code on 64 bit R, I changed to 32 bit and the crashing stopped. Go figure.

崩溃是由于在64位R上运行此代码引起的,我更改为32位并且崩溃停止。去搞清楚。

#1


The crashing was caused by running this code on 64 bit R, I changed to 32 bit and the crashing stopped. Go figure.

崩溃是由于在64位R上运行此代码引起的,我更改为32位并且崩溃停止。去搞清楚。