igraph - 如何计算 iGraph 中断开连接的图形的接近度方法
igraph - How to calculate closeness method in iGraph to disconnected graphs
我在 R 中使用 igraph 来计算图形度量,我的图形在 PIN 中创建,该 PIN 不是连接图而是断开连接的图。
连通图的closeness 方法很好,计算正确,而对于Disconnected graph 不好!
library(igraph)
# Create of Graph Matrix for Test Closeness Centrality
g <- read.table(text="A B
1 2
2 4
3 4
3 5", header=TRUE)
gadj <- get.adjacency(graph.edgelist(as.matrix(g), directed=FALSE))
igObject <- graph.adjacency(gadj) # convert adjacency matrix to igraph object
gCloseness <- closeness(igObject,weights = NULL) # Assign Closeness to Variable for print
输出:
[1] 0.1000000 0.1428571 0.1428571 0.1666667 0.1000000
我的断开连接图:
library(igraph)
# Create of Graph Matrix for Test Closeness Centrality
g <- read.table(text="A B
1 2
3 4
3 5", header=TRUE)
gadj <- get.adjacency(graph.edgelist(as.matrix(g), directed=FALSE))
igObject <- graph.adjacency(gadj) # convert adjacency matrix to igraph object
gCloseness <- closeness(igObject,weights = NULL) # Assign Closeness to Variable for print
输出:
[1] 0.06250000 0.06250000 0.08333333 0.07692308 0.07692308
这个输出是对的?如果正确,如何计算?
请阅读closeness
函数的documentation;它清楚地说明了 igraph 如何处理断开连接的图:
If there is no (directed) path between vertex v
and i
then the total number of vertices is used in the formula instead of the path length.
然后计算对我来说似乎是正确的,虽然我会说紧密中心性本身对于断开连接的图形没有明确定义,并且 igraph 在这里使用的更多是 hack(尽管是非常标准的 hack)而不是严格对待问题。我会避免在断开连接的图上使用接近中心性。
我在 R 中使用 igraph 来计算图形度量,我的图形在 PIN 中创建,该 PIN 不是连接图而是断开连接的图。 连通图的closeness 方法很好,计算正确,而对于Disconnected graph 不好!
library(igraph)
# Create of Graph Matrix for Test Closeness Centrality
g <- read.table(text="A B
1 2
2 4
3 4
3 5", header=TRUE)
gadj <- get.adjacency(graph.edgelist(as.matrix(g), directed=FALSE))
igObject <- graph.adjacency(gadj) # convert adjacency matrix to igraph object
gCloseness <- closeness(igObject,weights = NULL) # Assign Closeness to Variable for print
输出:
[1] 0.1000000 0.1428571 0.1428571 0.1666667 0.1000000
我的断开连接图:
library(igraph)
# Create of Graph Matrix for Test Closeness Centrality
g <- read.table(text="A B
1 2
3 4
3 5", header=TRUE)
gadj <- get.adjacency(graph.edgelist(as.matrix(g), directed=FALSE))
igObject <- graph.adjacency(gadj) # convert adjacency matrix to igraph object
gCloseness <- closeness(igObject,weights = NULL) # Assign Closeness to Variable for print
输出:
[1] 0.06250000 0.06250000 0.08333333 0.07692308 0.07692308
这个输出是对的?如果正确,如何计算?
请阅读closeness
函数的documentation;它清楚地说明了 igraph 如何处理断开连接的图:
If there is no (directed) path between vertex
v
andi
then the total number of vertices is used in the formula instead of the path length.
然后计算对我来说似乎是正确的,虽然我会说紧密中心性本身对于断开连接的图形没有明确定义,并且 igraph 在这里使用的更多是 hack(尽管是非常标准的 hack)而不是严格对待问题。我会避免在断开连接的图上使用接近中心性。