r""" This function contracts the clusters of the graph, under the assumption that it was given a full clustering, i.e., all vertices have exactly one cluster in clustering Returns: a graph in which: - each vertex is a cluster from the clustering, - each origi
(
edges: pw.Table[Edge | Weight], clustering: pw.Table[Clustering]
)
| 34 | |
| 35 | |
| 36 | def _contract_weighted( |
| 37 | edges: pw.Table[Edge | Weight], clustering: pw.Table[Clustering] |
| 38 | ) -> WeightedGraph: |
| 39 | r""" |
| 40 | This function contracts the clusters of the graph, |
| 41 | under the assumption that it was given a full clustering, |
| 42 | i.e., all vertices have exactly one cluster in clustering |
| 43 | |
| 44 | Returns: |
| 45 | a graph in which: |
| 46 | - each vertex is a cluster from the clustering, |
| 47 | - each original edge now points to clusters containing the original endpoints |
| 48 | |
| 49 | """ |
| 50 | |
| 51 | new_vertices = ( |
| 52 | clustering.groupby(clustering.c) |
| 53 | .reduce(v=clustering.c) |
| 54 | .with_id(pw.this.v) |
| 55 | .select() |
| 56 | ) |
| 57 | new_edges = edges.select(u=clustering.ix(edges.u).c, v=clustering.ix(edges.v).c) |
| 58 | return WeightedGraph.from_vertices_and_weighted_edges(new_vertices, new_edges) |
| 59 | |
| 60 | |
| 61 | def _extended_to_full_clustering( |
no test coverage detected