微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 igraph 和 NetworkX 中读取缺少数据的 GML 文件时出错

如何解决在 igraph 和 NetworkX 中读取缺少数据的 GML 文件时出错

我有一组网络,其中包含一些缺失的节点属性数据。我需要能够在 igraph、NetworkX 和 Gephi 中访问这些网络。我知道我可以在 GML 中将缺失值记录为 NAN,igraph 会理解它,但 NetworkX 不会(出现此错误消息:networkx.exception.NetworkXError: expected an int,float,string or '[',found 'NAN' at (16,9))。

GML 文件看起来像这样(称为“export.gml”):

graph [
  directed 1
  node [
    id 0
    label "1"
    age 1
  ]
  node [
    id 1
    label "2"
    age 2
  ]
  node [
    id 2
    label "3"
    age "NA"
  ]
  edge [
    source 0
    target 1
  ]
  edge [
    source 1
    target 2
  ]
  edge [
    source 2
    target 0
  ]
]

我可以在 Python 中的 igraph 中打开这个文件,直到最近我还可以在 R 中打开类似的文件。截至今天,这是我得到的,首先是在 Python 中:

>>> import igraph
>>> g = igraph.read("export.gml")
>>> g.vs["age"]
['1','2','NA']

然后在 R 中:

R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos,'help()' for on-line help,or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(igraph)

Attaching package: ‘igraph’

The following objects are masked from ‘package:stats’:

    decompose,spectrum

The following object is masked from ‘package:base’:

    union

> igraph_version()
[1] "1.2.6"
> g <- read_graph("export.gml",format = "gml")

 *** caught segfault ***
address (nil),cause 'memory not mapped'

Traceback:
 1: read.graph.gml(file,...)
 2: read_graph("export.gml",format = "gml")

Possible actions:
1: abort (with core dump,if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 

有没有办法在 R igraph 中打开这个文件?或者,有没有办法让 NetworkX 正确解释 GML 文件中的 NAN

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。