find_threshold_graph

find_threshold_graph#

graph_tool.structure.find_threshold_graph(g)[git][source]#

Return a threshold subgraph of the graph.

Parameters:
gGraph

Graph to be used. Edge directions, self-loops, and parallel edges are ignored.

Returns:
uGraphView

Induced subgraph that is a threshold graph.

See also

is_threshold_graph

Test for threshold graphs

Notes

The vertices of the subgraph are found greedily: starting from the whole graph, its isolated vertices are kept, and its vertex of largest degree (the largest index among ties) is kept, with the search continuing in the subgraph induced by the neighbors of this vertex, which is dominating in the subgraph found there. The induced subgraph of these vertices is a threshold graph (see is_threshold_graph()), although not necessarily the largest one. The time is \(O(VE)\) in the worst case.

Examples

>>> g = gt.collection.data["karate"]
>>> u = gt.find_threshold_graph(g)
>>> print(u.num_vertices(), u.num_edges(), gt.is_threshold_graph(u))
13 21 True

The threshold subgraph can be highlighted in a drawing of the network:

>>> inu = g.new_vp("bool")
>>> inu.a[u.get_vertices()] = True
>>> vcolor = g.new_vp("string", vals=np.where(inu.a, "#f28c8e",
...                                           "#cccccc"))
>>> s = gt.edge_endpoint_property(g, inu, "source")
>>> t = gt.edge_endpoint_property(g, inu, "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="find_threshold_graph-karate.pdf")
<...>
../_images/find_threshold_graph-karate.png

Threshold subgraph of Zachary’s karate club network, with its vertices and edges shown in red.#