densest_subgraph#
- graph_tool.structure.densest_subgraph(g, iterations=1, method='greedy++')[git][source]#
Return an approximately densest subgraph.
- Parameters:
- g
Graph Graph to be used. Edge directions, self-loops, and parallel edges are ignored.
- iterations
int(optional, default:1) Number of iterations.
- method
str(optional, default:"greedy++") Algorithm:
"greedy++"or"fista".
- g
- Returns:
- density
float The density \(E(S)/|S|\) of the subgraph found.
- vertices
numpy.ndarray Its vertices.
- density
See also
kcore_subgraphK-core of the graph
maximal_cliquesMaximal cliques
graph_tool.stats.densityDensity of a graph
Notes
The densest subgraph is induced by the set of vertices \(S\) that maximizes the density
\[\rho(S) = \frac{|E(S)|}{|S|},\]where \(E(S)\) is the set of edges with both endpoints in \(S\) of the simple undirected graph underlying
g. Both methods remove (“peel”) the vertices one at a time, and return the set of remaining vertices of largest density found along the way. With one iteration, Greedy++ [boob-flowless-2020] is Charikar’s greedy peeling [charikar-greedy-2000], which removes each time a vertex of smallest degree in the remaining subgraph, and is a 2-approximation, i.e. \(\rho(S) \ge \max_{S'}\rho(S')/2\); further iterations peel by the remaining degree plus a load, which accumulates the degree of every vertex at its removal in the previous iterations, and the density converges to the optimum. FISTA [harb-faster-2022] solves the dual linear program, in which every edge splits a unit load between its endpoints so that the sum of the squares of the total loads of the vertices is minimized, by an accelerated projected gradient method, starting from equal shares; the fractional solution is then rounded by peeling, which removes each time a vertex of smallest remaining load, i.e. of the smallest sum of its shares of the edges to the vertices not yet removed. Each iteration takes time \(O(E\log V)\) (Greedy++) or \(O(E)\) (FISTA, which is followed by a single peeling in time \(O(E\log V)\)).References
[charikar-greedy-2000]Moses Charikar, “Greedy approximation algorithms for finding dense components in a graph”, APPROX 2000, Lecture Notes in Computer Science 1913, 84-95 (2000), DOI: 10.1007/3-540-44436-X_10 [sci-hub, @tor]
[boob-flowless-2020]Digvijay Boob, Yu Gao, Richard Peng, Saurabh Sawlani, Charalampos Tsourakakis, Di Wang and Junxing Wang, “Flowless: Extracting densest subgraphs without flow computations”, Proceedings of The Web Conference 2020, 573-583 (2020), DOI: 10.1145/3366423.3380140 [sci-hub, @tor]
[harb-faster-2022]Elfarouk Harb, Kent Quanrud and Chandra Chekuri, “Faster and scalable algorithms for densest subgraph and decomposition”, Advances in Neural Information Processing Systems 35 (2022), arXiv: 2206.02942
Examples
>>> g = gt.collection.data["karate"] >>> d, vs = gt.densest_subgraph(g, iterations=10) >>> print(d, len(vs)) 2.625 16
The subgraph can be highlighted in a drawing of the network:
>>> ind = g.new_vp("bool") >>> ind.a[vs] = True >>> vcolor = g.new_vp("string", vals=np.where(ind.a, "#f28c8e", ... "#cccccc")) >>> s = gt.edge_endpoint_property(g, ind, "source") >>> t = gt.edge_endpoint_property(g, ind, "target") >>> ecolor = g.new_ep("string", vals=np.where(s.a & t.a, "#e41a1c", ... "#999999")) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor, ... edge_color=ecolor, output="densest_subgraph-karate.pdf") <...>
Densest subgraph of Zachary’s karate club network found by Greedy++, with its vertices and edges shown in red.#