【问题标题】:igraph error long vectors not supported yet when trying to create adjacency matrix尝试创建邻接矩阵时不支持 igraph 错误长向量
【发布时间】:2020-01-27 20:01:09
【问题描述】:

我正在尝试在 R 中执行社交网络分析,但在使用 igraph 包从非常大的矩阵创建邻接矩阵时遇到了一些麻烦。主要矩阵之一是 10998555876 个大元素 (82 Gb) - 从具有 176881 行的数据集创建。

我在运行时遇到的错误:

adjacency_matrix <- graph.adjacency(one_mode_matrix, mode = "undirected", weighted = TRUE, diag = TRUE)

如下:

Error in graph.adjacency.dense(adjmatrix, mode = mode, weighted = weighted, : 
long vectors not supported yet: ../../src/include/Rinlinedfuns.h:519

数据是双模,所以我不得不转置它以获得具有我感兴趣的单位的单模矩阵。之前用于创建矩阵的代码是:

graph <- graph.data.frame(data, directed = FALSE) # Making a graph object from the dataframe.
types <- bipartite.mapping(graph)$type 
matrix <- as_incidence_matrix(graph, types = type) # Creating a  two-mode matrix.

one_mode_matrix <- tcrossprod(matrix) # Transposing to get one-mode matrix.
diag(matrix) <- 0 
mode(matrix) <- "numeric" 

adjacency_matrix <- graph.adjacency(one_mode_matrix, mode = "undirected", weighted = TRUE, diag = FALSE) # This is where things break down.

做过一些研究,例如在这个线程 https://github.com/igraph/rigraph/issues/255 中,它看起来像是 R 基础中的一个问题。在我看来(不是这些事情的专家)igraph 正试图以 R 无法处理的格式创建一个对象,因为它太大了(?)有人知道如何处理这个问题吗?也许还有其他用于创建邻接矩阵的包可以在大型矩阵上做得更好?

【问题讨论】:

    标签: r matrix igraph adjacency-matrix network-analysis


    【解决方案1】:

    任何可能感兴趣的人的解决方案:

    我发现 igraph 可以处理稀疏矩阵。使用 Matrix 包将矩阵转换为稀疏矩阵,如下所示:

    sparse_matrix <- as(one_mode_matrix, "sparseMatrix")
    

    然后把它做成这样的图形对象:

    g <- graph_from_adjacency(sparse_matrix)
    

    了解 igraph 提供的所有功能。

    【讨论】:

      猜你喜欢
      • 2014-10-19
      • 2014-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      相关资源
      最近更新 更多