def test_edge_cut_clustering_with_edgevals_nx(graph_file, partitions): gc.collect() # Read in the graph and create a NetworkX Graph # FIXME: replace with utils.generate_nx_graph_from_file() NM = utils.read_csv_for_nx(graph_file, read_weights_in_sp=True) G = nx.from_pandas_edgelist(NM, create_using=nx.Graph(), source="0", target="1", edge_attr="weight") # Get the edge_cut score for partitioning versus random assignment df = cugraph.spectralBalancedCutClustering(G, partitions, num_eigen_vects=partitions) pdf = pd.DataFrame.from_dict(df, orient='index').reset_index() pdf.columns = ["vertex", "cluster"] gdf = cudf.from_pandas(pdf) cu_score = cugraph.analyzeClustering_edge_cut(G, partitions, gdf, 'vertex', 'cluster') df = set(gdf["vertex"].to_array()) Gcu = cugraph.utilities.convert_from_nx(G) rand_vid, rand_score = random_call(Gcu, partitions) # Assert that the partitioning has better edge_cut than the random # assignment print(cu_score, rand_score) assert cu_score < rand_score
def cugraph_call(G, partitions): df = cugraph.spectralBalancedCutClustering(G, partitions, num_eigen_vects=partitions) score = cugraph.analyzeClustering_edge_cut(G, partitions, df, 'vertex', 'cluster') return set(df["vertex"].to_array()), score
def cugraph_call(G, partitions): df = cugraph.spectralBalancedCutClustering( G, partitions, num_eigen_vects=partitions ) df = df.sort_values("vertex") score = cugraph.analyzeClustering_edge_cut(G, partitions, df["cluster"]) return set(df["vertex"].to_array()), score
def annotate_nodes(graph, nodes, edges): return nodes.assign( # add node names name=nodes["name"] if "name" in nodes else nodes["id"], # add node sizes size=(nodes["degree"].scale() * 254 + 1).astype(np.uint8), # add node colors color=category_to_color( cugraph.spectralBalancedCutClustering(graph, 9) .sort_values(by="vertex").reset_index(drop=True)["cluster"], color_palette=[ # https://colorbrewer2.org/#type=diverging&scheme=Spectral&n=9 4292165199, 4294208835, 4294815329, 4294893707, 4294967231, 4293326232, 4289453476, 4284924581, 4281501885 ]) )