使用 igraph:由 decompose.graph() 构建的组件的社区成员资格
我非常感谢使用 decompose.graph
、来自 igraph
和 lapply
的社区检测功能的帮助。
我有一个 igraph 对象 G,其顶点属性“标签”和边缘属性“权重”。我想使用 igraph 中的不同函数来计算社区成员资格,为简单起见,将其设为 walktrap.community
。
该图没有连接,这就是为什么我决定分解它 进入连接的组件并在每个组件上运行 walktrap.community
,然后将社区成员资格顶点属性添加到原始图 G 中。
我当前正在执行以下操作
comps <- decompose.graph(G,min.vertices=2)
communities <- lapply(comps,walktrap.community)
此时我陷入困境,因为我得到了列表具有我无法弄清楚的结构的对象。 decompose.graph 上的文档只告诉它返回列表对象,当我对结果使用 lapply 时,我完全感到困惑。此外,每个组件中的社区从 0 开始编号,我不知道如何将 weights
参数提供给 walktrap.community
函数。
如果不是这些组件,我会执行以下操作:
wt <- walktrap.community(G, modularity=TRUE, weights=E(G)$weight)
wmemb <- community.to.membership(G, wt$merges,steps=which.max(wt$modularity)-1)
V(G)$"walktrap" <- wmemb$membership
有人可以帮我解决这个问题吗?或者提供一些 有帮助的信息/链接吗?
I would appreciate help with using decompose.graph
, community detection functions from igraph
and lapply
.
I have an igraph object G with vertex attribute "label" and edge attribute "weight". I want to calculate community memberships using different functions from igraph, for simplicity let it be walktrap.community
.
This graph is not connected, that is why I decided to decompose it
into connected components and run walktrap.community
on each component, and afterwards add a community membership vertex attribute to the original graph G.
I am doing currently the following
comps <- decompose.graph(G,min.vertices=2)
communities <- lapply(comps,walktrap.community)
At this point I get stuck since I get the list object with the structure I cannot figure out. The documentation on decompose.graph
tells only that it returns list object, and when I use lapply
on the result I get completely confused. Moreover, the communities are numbered from 0 in each component, and I don't know how to supply weights
parameter into walktrap.community
function.
If it were not for the components, I would have done the following:
wt <- walktrap.community(G, modularity=TRUE, weights=E(G)$weight)
wmemb <- community.to.membership(G, wt$merges,steps=which.max(wt$modularity)-1)
V(G)$"walktrap" <- wmemb$membership
Could anyone please help me solve this issue? Or provide some
information/links which could help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用循环:
可以使用
lapply
和mapply
来实现,但可读性较差。You could use a loop:
It is possible to do it with
lapply
andmapply
, but it is less readable.