假设我有一个有10^4个节点的大型网络。然后我想分析与随机节点相关联的邻居,比如节点10。我可以通过查看邻接矩阵的第10行条目来查看哪些节点连接到该节点,然后如果我想查看这些邻居的邻居(第二个shell),则可以重复此操作,依此类推。
有没有一种有效的方法来做到这一点--或者甚至是一种低效但比从头开始编写整个事情更好的方法?我实际拥有的网络是一个随机规则图,我对大型网络的树状本地结构很感兴趣。
发布于 2020-12-10 01:09:11
如果我理解您的用例,有一个很好的方法可以做到这一点: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. https://stackoverflow.com/questions/65219848
复制相似问题