hrg_predict#
- graph_tool.inference.hrg_predict(g, vertex_pairs=None, niter=100, nsamples=100, burnin=None, start=None)[git][source]#
Predict missing edges with the hierarchical random graph.
- Parameters:
- g
Graph Graph to be used. Edge directions, self-loops, and parallel edges are ignored.
- vertex_pairsiterable of pairs of
int(optional, default:None) The pairs of vertices to score. If not given, all non-adjacent pairs are scored and returned in decreasing order of probability.
- niter
int(optional, default:100) Number of sweeps between samples.
- nsamples
int(optional, default:100) Number of sampled dendrograms.
- burnin
int(optional, default:None) Number of initial sweeps discarded; if not given,
10 * niter.- start
Graph(optional, default:None) Initial dendrogram (see
hrg_fit()).
- g
- Returns:
- pairs
numpy.ndarray The scored pairs (only if
vertex_pairsisNone).- prob
numpy.ndarray The average connection probability of every pair.
- pairs
See also
hrg_fitFit of a hierarchical random graph
MeasuredBlockStateNetwork reconstruction from noisy measurements
graph_tool.structure.vertex_similaritySimilarity between pairs of vertices
Notes
The dendrograms \(T_1, \dots, T_S\) are sampled from the posterior distribution, proportional to the likelihood \(\mathcal{L}\) given in
hrg_fit(), with the Markov chain of that function at \(\beta = 1\), one everynitersweeps afterburninsweeps, where \(S\) isnsamples, and the probability of a pair \((i, j)\) is averaged over them [clauset-hierarchical-2008],\[\hat p_{ij} = \frac{1}{S}\sum_{s=1}^S p^{(s)}_{r_s(i,j)},\]where \(r_s(i,j)\) is the lowest common ancestor of \(i\) and \(j\) in \(T_s\) and \(p^{(s)}_r = E_r/(L_rR_r)\) its maximum likelihood connection probability. Scoring all non-adjacent pairs takes memory \(O(V^2)\). A principled alternative is the edge prediction with the stochastic block model described in the inference documentation.
References
[clauset-hierarchical-2008]Aaron Clauset, Cristopher Moore and M. E. J. Newman, “Hierarchical structure and the prediction of missing links in networks”, Nature 453, 98-101 (2008), DOI: 10.1038/nature06830 [sci-hub, @tor], arXiv: 0811.0484
Examples
>>> g = gt.collection.data["karate"] >>> pairs, prob = gt.hrg_predict(g) >>> print(len(pairs), prob[0] >= prob[-1]) 483 True
The ten most probable missing edges, shown in the figure below, can be drawn by adding them to a copy of the graph, as follows:
>>> h = g.copy() >>> new = h.new_ep("bool") >>> h.add_edge_list(np.column_stack((pairs[:10], np.ones(10))), ... eprops=[new]) >>> color = h.new_ep("string", ... vals=np.where(new.a, "#e41a1c", "#bbbbbb")) >>> width = h.new_ep("double", vals=np.where(new.a, 2.5, 1)) >>> gt.graph_draw(h, pos=g.vp.pos, vertex_fill_color="#cccccc", ... edge_color=color, edge_pen_width=width, ... output="hrg-predict-karate.pdf") <...>
Karate club network, with the ten non-adjacent pairs of vertices of largest predicted probability drawn as red edges.#