contingency_graph#
- graph_tool.inference.contingency_graph(x, y)[source]#
Returns the contingency graph between both partitions.
- Parameters:
- xiterable of
int
values orPropertyMap
First partition.
- yiterable of
int
values orPropertyMap
Second partition.
- xiterable of
- Returns:
- g
Graph
Contingency graph, containing an internal edge property map
mrs
with the weights, an internal vertex property maplabel
with the label values, and an internal boolean vertex property mappartition
indicating the partition membership.
- g
Notes
The contingency graph is a bipartite graph with the labels of \(\boldsymbol x\) and \(\boldsymbol y\) as vertices, and edge weights given by
\[m_{rs} = \sum_i\delta_{x_i,r}\delta_{y_i,s}.\]This algorithm runs in time \(O(N)\) where \(N\) is the length of \(\boldsymbol x\) and \(\boldsymbol y\).
Examples
>>> x = np.random.randint(0, 10, 1000) >>> y = np.random.randint(0, 10, 1000) >>> g = gt.contingency_graph(x, y) >>> g.ep.mrs.a PropertyArray([ 8, 10, 4, 11, 8, 11, 15, 12, 14, 11, 8, 12, 9, 9, 11, 14, 10, 9, 16, 8, 12, 16, 15, 13, 12, 7, 11, 13, 18, 9, 9, 9, 14, 10, 11, 8, 6, 7, 11, 11, 8, 11, 14, 12, 8, 7, 7, 8, 8, 12, 10, 11, 8, 15, 6, 13, 14, 14, 8, 10, 8, 11, 7, 6, 10, 13, 10, 13, 6, 11, 15, 5, 4, 10, 13, 8, 8, 9, 14, 8, 6, 11, 7, 8, 15, 10, 9, 7, 8, 11, 10, 11, 9, 8, 8, 10, 7, 8, 3, 9], dtype=int32)