假设我有一个包含10 ^ 4个节点的大型网络。然后,我想分析与一个随机节点(例如节点10)相关联的邻域。通过查看邻接矩阵的第10行条目,可以看到哪些节点连接到该节点,然后如果有,我可以重复此过程我想看看那些邻居的邻居(第二个外壳),然后我可以根据需要多次重复此过程。
有没有一种有效的方法可以做到这一点-甚至是效率低下但比从头开始编写整件事更好的方法?我拥有的实际网络是随机正则图,并且我对大型网络的树状局部结构感兴趣。
如果我了解您的用例,则有一个很好的方法: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.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句