Graph 光图中的子图-Julia

Graph 光图中的子图-Julia,graph,julia,lightgraphs,Graph,Julia,Lightgraphs,假设我有一个包含10^4个节点的大型网络。然后我想分析与一个随机节点相关的邻域,比如节点10。通过查看邻接矩阵的第10行条目,我可以看到哪些节点连接到该节点,然后如果我想查看这些邻居的邻居(第二个shell),我可以重复这个步骤,以此类推 有没有一种有效的方法可以做到这一点?或者甚至是一种效率低下但比从头开始写整个东西更好的方法?我拥有的实际网络是一个随机规则图,我对大型网络的树状局部结构感兴趣。如果我了解您的用例,有一个很好的方法可以做到这一点:使用egonet函数。你给它一个图,一个起始顶点

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


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

如果我了解您的用例,有一个很好的方法可以做到这一点:使用
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.                             

如果我了解您的用例,有一种很好的方法可以做到这一点:使用
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.                             

非常感谢。这正是我要找的!我只是好奇你是怎么知道的;)我知道是我写的:)非常感谢。这正是我要找的!我只是好奇你是怎么知道的;)我知道是因为我写的:)