简体   繁体   English

二分投影在igraph中不起作用

[英]Bipartite projection not working in igraph

I am trying to get the projections of a bi-partite graph using igraph . 我正在尝试使用igraph获得二部图的投影。 My bi-partite network has 9523 edges, 8313 are of type FALSE and 1210 of type TRUE - as the following two outputs confirm. 我的二分网络具有9523层的边缘,8313是类型FALSE和1210型的TRUE -如下面的两个输出进行确认。

> length(V(bp_network))
[1] 9523
> table(V(bp_network)$type)

FALSE  TRUE 
 8313  1210 

However, when I try to project them using 但是,当我尝试使用

pr_networks = bipartite_projection(bp_network, multiplicity = TRUE)

I get the following error: 我收到以下错误:

Error in bipartite_projection(bp_network, multiplicity = TRUE) : 
  At structure_generators.c:86 : Invalid (negative) vertex id, Invalid vertex id

I have tried changing the type of the vertices to characters from boolean. 我尝试将顶点的类型更改为布尔型的字符。

> table(V(bp_network)$type)

   A    B 
1210 8313 

Now the same code gives another error: 现在,相同的代码给出了另一个错误:

Error in bipartite_projection(bp_network, multiplicity = TRUE) : 
  `NA' is not allowed in vertex types
In addition: Warning message:
In bipartite_projection(bp_network, multiplicity = TRUE) :
  vertex types converted to logical

What might be going on? 可能会发生什么?

EDIT: The network is created from a data frame with two columns of Twitter usernames, each row corresponding to a follow relationship. 编辑:网络是从具有两列Twitter用户名的数据帧创建的,每一行对应一个跟随关系。

> names(elite_following_df)
[1] "user"      "following"    
> nrow(elite_following_df)
[1] 267442
> bp_network = graph_from_edgelist(as.matrix(elite_following_df), directed = FALSE)
> V(bp_network)$type = ifelse(V(bp_network)$name %in% elite_following_df$following, TRUE, FALSE)
> length(E(bp_network))
[1] 267442

The problem was that one of the edges was violating the bipartite property. 问题在于边缘之一违反了二部性质。 In other words, one of the nodes that was meant to be type FALSE had an edge with another FALSE node. 换句话说,一个本应为FALSE类型的节点与另一个FALSE节点相比具有优势。 Leaving this answer instead of deleting the question just in case someone encounters the same error. 保留此答案,而不是删除问题,以防万一有人遇到相同的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM