即使对于 128 GB 的内存,图形聚类也会出现内存错误。为什么?

Getting memory error for graph clustering even for 128 GB of memory. Why?

我在具有 128 GB 内存 的 Linux 服务器上使用 python 语言。我正在使用 马尔可夫算法 进行图聚类。详细过程如下:

Graphtype = nx.Graph()
G = nx.from_pandas_edgelist(df, 'source','target', edge_attr='weight', create_using=Graphtype)

图表详细信息:

Name: 
Type: Graph
Number of nodes: 4533801
Number of edges: 10548751
Average degree:   4.6534

图是否连通?

nx.is_connected(G)
False

连通分量数

print(nx.number_connected_components(G))
7254

马尔可夫聚类

import markov_clustering as mc
import networkx as nx

matrix = nx.to_scipy_sparse_matrix(Gc) # build the matrix
result = mc.run_mcl(matrix)            # run MCL with default parameters
clusters = mc.get_clusters(result)     # get clusters

MemoryError

为什么我在尝试提取集群时仍然收到 内存错误 消息? 问题是什么?我该如何解决这个问题?

更新:

报告结果考虑了给出的意见。

根据您的代码,我假设您使用的是 32 位 Python,这意味着无论硬件如何,您都无法使用超过 4GB 的 RAM。

升级到 64 位 Python 将允许您使用最多 16EB 的 RAM,这将允许您使用服务器上的额外 space。

您可以通过不存储不必要的变量并让 python 清除丢弃的信息来节省 一些 内存。从我在这些代码行中看到的内容:

matrix = nx.to_scipy_sparse_matrix(Gc) # build the matrix
result = mc.run_mcl(matrix)            # run MCL with default parameters
clusters = mc.get_clusters(result)     # get clusters

'matrix' 和 'result' 变量仅用于到达 'clusters' 所以理论上不需要保存。此代码应授予 python 清除一点内存的权限:

clusters = mc.get_clusters(mc.run_mcl(nx.to_scipy_sparse_matric(Gc)))

显然,您牺牲了代码的易读性和优雅性,这不太可能释放足够的空间 space 来解决您的问题,但值得您注意以防万一。