简体   繁体   English

R中的中间性和最短路径

[英]Betweenness and shortest paths in R

I've been reviewing this interesting article: 我一直在评论这篇有趣的文章:

http://kieranhealy.org/blog/archives/2013/06/09/using-metadata-to-find-paul-revere/ http://kieranhealy.org/blog/archives/2013/06/09/using-metadata-to-find-paul-revere/

As an exercise, I've been picking through the various steps taken to convict Mr. Revere of treason. 作为练习,我一直在仔细研究采取各种步骤,以定罪叛逆者里维尔先生。 At one point, the author uses the betweenness function of the igraph library , which is described as: 一方面,作者使用igraph库interweenness函数 ,其描述为:

"The vertex and edge betweenness are (roughly) defined by the number of geodesics (shortest paths) going through a vertex or an edge." “顶点和边之间的距离(大致)由经过顶点或边的测地线(最短路径)的数量定义。”

So, in the case of the article, how many shortest communication paths between pairs of people go through each of the 254 people being considered? 因此,就本文而言,正在考虑的254个人中的每对之间有多少条最短的通信路径? I diverted a little from the article, though, and I'm wondering if I'm thinking naively. 不过,我从这篇文章中挪了些头,我想知道我是否在幼稚地思考。

A 254 x 254 matrix has 64516 elements. 254 x 254矩阵具有64516个元素。 However, trivial elements (those on the diagonal-- a person talking to herself is obviously the shortest path from X to X) can be discounted, leaving (it seems) 254 * 254 - 254 = 64262 total nontrivial ordered pairings. 但是,可以忽略琐碎的元素(对角线上的那些人-一个与自己说话的人显然是从X到X的最短路径),从而使254 * 254-254 = 64262总非琐碎的有序配对成为可能。 But, these are not directional-- that is, the shortest path between a particular pair X and Y is the same, regardless of which of X or Y is the sender and which is the receiver. 但是,这些不是定向的,也就是说,特定X对和Y对之间的最短路径是相同的,而不管X或Y中的哪个是发送方,哪个是接收方。

So, we can reduce our number of pairings: (254 * 254 - 254) / 2 = 32131 . 因此,我们可以减少配对的数量: (254 * 254 - 254) / 2 = 32131

Since this also happens to be the number of combinations of 2 selected from 254, even better-- a fine coincidence! 由于这也恰好是从254个中选择的2个组合的数量,甚至更好-巧合! ;-) ;-)

Then, just for fun, I did: 然后,只是为了好玩,我做了:

((254 * 254 - 254) / 2) - sum(betweenness(person.g)) = 10061

What does this number mean? 这个数字是什么意思? It almost seems to say that there are 10,061 pairings for whom no path exists, but I don't see how that can be. 几乎可以说,有10,061个配对不存在任何路径,但我不知道该怎么做。 Do I misunderstand betweenness? 我会误会两者之间吗? Many thanks in advance. 提前谢谢了。

If you check what happens on a simpler graph, you will notice that shortest paths of length 1 do not enter the computation. 如果检查简单图上发生的情况,您会注意到长度为1的最短路径不会进入计算。

betweenness( graph.lattice( 3 ) )
# [1] 0 1 0

Shortest paths of length 2 will be used once (for the point in the middle), but shortest paths of length 3 or more will be used several times: once for each point in the middle. 长度为2的最短路径将被使用一次(用于中间的点),但是长度为3或更长的最短路径将被使用几次:对于中间的每个点将使用一次。

betweenness( graph.lattice( 5 ) )
# [1] 0 3 4 3 0

In this example, the shortest paths are 在此示例中,最短路径是

length 1: 1-2, 2-3, 3-4, 4-5  (not used)
length 2: 1-3, 2-4, 3-5       (each used once, for the betweenness of 2, 3 and 4)
length 3: 1-4, 2-5            (each used twice, for 2,3 and 2,4)
length 4: 1-5                 (each used 3 times, for 2, 3 and 4)

In other words, a shortest path of length k is counted k-1 times. 换句话说,长度为k的最短路径被计算为k-1次。

p <- shortest.paths(person.g)
sum( p[upper.tri(p)] - 1 )
# [1] 22070
sum( betweenness( person.g ) )
# [1] 22070

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM