【问题标题】:Transforming directed network into undirected while preserving degree distribution在保留度分布的同时将有向网络转换为无向网络
【发布时间】:2014-02-12 03:52:48
【问题描述】:

我有一个有向网络,其中 50 个节点的度数为 3,另外 50 个节点的度数为 10。

source("http://bioconductor.org/biocLite.R")
biocLite("graph")

#load graph and make the specified graph
library(graph)
degrees=c(rep(3,50),rep(10,50))
names(degrees)=paste("node",seq_along(degrees)) #nodes must be names
x=randomNodeGraph(degrees)

#verify graph
edges=edgeMatrix(x)
edgecount=table(as.vector(edges))
table(edgecount)

这是一个有向网络,其中总度数由入度和出度组成。

我想要一个网络,其中每个入度也是一个出度,反之亦然

例如,如果node 1node 5 有边,那么node 5 也需要与node 1 有边。我的主要目标是保留度数分布,即 50 度为 3 和 50 度为 10。

【问题讨论】:

    标签: r graph bioconductor


    【解决方案1】:

    只需将图形设置为无向似乎就可以做到:

    x2 <- x
    edgemode(x2) <- "undirected"
    edges<-edgeMatrix(x)
    edgecount <- table(as.vector(edges))
    table(edgecount)
    

    提供与您的代码相同的结果。 此外,如果存在从 1 到 5 的边,则无向图将始终具有从 5 到 1 的边。单边满足此属性。

    【讨论】:

    • 你的代码第三行好像有错误,你的意思是edge
    • 糟糕。我会尽力为您找到更好的答案。
    【解决方案2】:

    Paul Shannon 提出以下建议:

    library(graph)
    library(igraph)
    degrees=c(rep(3,50),rep(10,50))
    g <- igraph.to.graphNEL(degree.sequence.game(degrees))
    table(graph::degree(g))
    

    这给出了与您的代码相同的结果。

    【讨论】:

      猜你喜欢
      • 2021-01-29
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      相关资源
      最近更新 更多