hrg_consensus#
- graph_tool.inference.hrg_consensus(g, niter=100, nsamples=100, burnin=None, start=None)[git][source]#
Return the majority consensus tree of the dendrograms of the hierarchical random graph.
- Parameters:
- g
Graph Graph to be used. Edge directions, self-loops, and parallel edges are ignored.
- 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:
- tree
Graph The consensus tree, directed from parents to children, whose leaves \(0, \dots, V-1\) are the vertices of
g(in the order ofget_vertices()) and whose internal vertices may have more than two children.- freq
VertexPropertyMap Fraction of the samples in which the cluster of leaves of every internal vertex appears (one for the leaves and the root).
- tree
See also
hrg_fitFit of a hierarchical random graph
hrg_predictPrediction of missing edges with the hierarchical random graph
get_hierarchy_treeHierarchy tree of a nested stochastic block model
Notes
The dendrograms are sampled as in
hrg_predict(), and the clusters (sets of leaves below an internal node) that appear in more than half of the sampled dendrograms are mutually compatible, and form the majority consensus tree [clauset-hierarchical-2008]: every such cluster becomes an internal vertex, whose parent is the smallest of these clusters that contains it, and every leaf is attached to the smallest cluster that contains it.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"] >>> tree, freq = gt.hrg_consensus(g) >>> print(tree.num_vertices() > g.num_vertices()) True
The consensus tree, shown in the figure below, can be drawn with
tree_layout(), starting from its root, as follows:>>> from matplotlib.colors import LinearSegmentedColormap >>> cmap = LinearSegmentedColormap.from_list("f", ["#d9d9d9", ... "#ed6a6b"]) >>> leaf = tree.get_out_degrees(tree.get_vertices()) == 0 >>> vs = tree.get_vertices() >>> root = np.flatnonzero(tree.get_in_degrees(vs) == 0)[0] >>> shape = tree.new_vp("string", ... vals=np.where(leaf, "square", "circle")) >>> label = tree.new_vp("string", vals=[str(v) if l else "" ... for v, l in enumerate(leaf)]) >>> gt.graph_draw(tree, pos=gt.tree_layout(tree, root), ... vertex_fill_color=freq, vcmap=cmap, ... vertex_shape=shape, vertex_text=label, ... vertex_font_size=8, edge_end_marker="none", ... output_size=(700, 300), ... output="hrg-consensus-karate.pdf") <...>
Majority consensus tree of the dendrograms of the hierarchical random graph sampled for the karate club network, with the root at the top. The leaves (squares) are labeled with the vertex indices, and the vertices are colored by the fraction of the samples in which their clusters appear, from gray (the smallest value) to red (one).#