1

假设我有一个包含 10^4 个节点的大型网络。然后我想分析与随机节点相关的邻域,比如节点 10。我可以通过查看邻接矩阵的第 10 行条目来查看哪些节点连接到该节点,然后如果我愿意,我可以重复此操作查看那些邻居的邻居(第二个外壳)等等。

有没有一种有效的方法来做到这一点 - 或者甚至是一种低效但比从头开始编写整个东西更好的方法?我拥有的实际网络是一个随机正则图,我对大型网络的树状局部结构感兴趣。

4

1 回答 1

4

如果我了解您的用例,有一个很好的方法:egonet函数。你给它一个图、一个起始顶点和跳数,它会返回一个从顶点开始并走出那个跳数的图的诱导子图。这是文档字符串:

  egonet(g, v, d, distmx=weights(g))

  Return the subgraph of g induced by the neighbors of v up to distance d, using weights (optionally) provided by distmx. This is equivalent to
  induced_subgraph(g, neighborhood(g, v, d, dir=dir))[1].

  Optional Arguments
  ––––––––––––––––––––

    •    dir=:out: if g is directed, this argument specifies the edge direction

  with respect to v (i.e. :in or :out).

编辑添加:如果您只需要顶点索引,那么neighborhood()就是您想要的:

neighborhood(g, v, d, distmx=weights(g))                                                                                                            
                                                                                                                                                      
  Return a vector of each vertex in g at a geodesic distance less than or equal to d, where distances may be specified by distmx.                     
                                                                                                                                                      
  Optional Arguments                                                                                                                                  
  ––––––––––––––––––––                                                                                                                                
                                                                                                                                                      
    •    dir=:out: If g is directed, this argument specifies the edge direction                                                                       
                                                                                                                                                      
  with respect to v of the edges to be considered. Possible values: :in or :out.                             
于 2020-12-09T17:09:10.910 回答