generate_triadic_closure#
- graph_tool.generation.generate_triadic_closure(g, t, probs=True, curr=None, ego=None)[source]#
Closes open triads in a graph, according to an ego-based process.
- Parameters:
- g
Graph
Graph to be modified.
- t
VertexPropertyMap
or scalar Vertex property map (or scalar value) with the ego closure propensities for every node.
- probs
boolean
(optional, default:True
) If
True
, the values oft
will be interpreted as the independent probability of connecting two neighbors of the respective vertex. Otherwise, it will determine the integer number of pairs of neighbors that will be closed.- curr
EdgePropertyMap
(optional, default:None
) If given, this should be a boolean-valued edge property map, such that triads will only be closed if they contain at least one edge marged with the value
True
.- ego
EdgePropertyMap
(optional, default:None
) If given, this should be an integer-valued edge property map, containing the ego vertex for each closed triad, which will be updated with the new generation.
- g
- Returns:
- ego
EdgePropertyMap
Integer-valued edge property map, containing the ego vertex for each closed triad. A value of
-1
marks original edges that were not created by triadic closure.
- ego
Notes
This algorithm [peixoto-disentangling-2022] consist in, for each node
u
, connecting all its neighbors with probability given byt[u]
. In caseprobs == False
, thent[u]
indicates the number of random pairs of neighbors ofu
that are connected. This algorithm may generate parallel edges.This algorithm has a complexity of \(O(N\left<k^2\right>)\), where \(\left<k^2\right>\) is the second moment of the degree distribution.
References
[peixoto-disentangling-2022]Tiago P. Peixoto, “Disentangling homophily, community structure and triadic closure in networks”, Phys. Rev. X 12, 011004 (2022), DOI: 10.1103/PhysRevX.12.011004 [sci-hub, @tor], arXiv: 2101.02510
Examples
>>> g = gt.collection.data["karate"].copy() >>> gt.generate_triadic_closure(g, .5) <...> >>> gt.graph_draw(g, g.vp.pos, output="karate-triadic.png") <...>