def spectralBalancedCutClustering(G, num_clusters, num_eigen_vects=2, evs_tolerance=.00001, evs_max_iter=100, kmean_tolerance=.00001, kmean_max_iter=100): """ Compute a clustering/partitioning of the given graph using the spectral balanced cut method. Parameters ---------- G : cugraph.Graph cuGraph graph descriptor num_clusters : integer Specifies the number of clusters to find num_eigen_vects : integer Specifies the number of eigenvectors to use. Must be lower or equal to num_clusters. evs_tolerance: float Specifies the tolerance to use in the eigensolver Default is 0.00001 evs_max_iter: integer Specifies the maximum number of iterations for the eigensolver Default is 100 kmean_tolerance: float Specifies the tolerance to use in the k-means solver Default is 0.00001 kmean_max_iter: integer Specifies the maximum number of iterations for the k-means solver Default is 100 Returns ------- df : cudf.DataFrame GPU data frame containing two cudf.Series of size V: the vertex identifiers and the corresponding cluster assignments. df['vertex'] : cudf.Series contains the vertex identifiers df['cluster'] : cudf.Series contains the cluster assignments Examples -------- >>> M = cudf.read_csv('datasets/karate.csv', delimiter = ' ', dtype=['int32', 'int32', 'float32'], header=None) >>> G = cugraph.Graph() >>> G.from_cudf_edgelist(M, source='0', destination='1') >>> df = cugraph.spectralBalancedCutClustering(G, 5) """ df = spectral_clustering_wrapper.spectralBalancedCutClustering( G, num_clusters, num_eigen_vects, evs_tolerance, evs_max_iter, kmean_tolerance, kmean_max_iter) return df
def spectralBalancedCutClustering( G, num_clusters, num_eigen_vects=2, evs_tolerance=0.00001, evs_max_iter=100, kmean_tolerance=0.00001, kmean_max_iter=100, ): """ Compute a clustering/partitioning of the given graph using the spectral balanced cut method. Parameters ---------- G : cugraph.Graph or networkx.Graph Graph descriptor num_clusters : integer Specifies the number of clusters to find, must be greater than 1 num_eigen_vects : integer, optional Specifies the number of eigenvectors to use. Must be lower or equal to num_clusters. Default is 2 evs_tolerance: float, optional Specifies the tolerance to use in the eigensolver. Default is 0.00001 evs_max_iter: integer, optional Specifies the maximum number of iterations for the eigensolver. Default is 100 kmean_tolerance: float, optional Specifies the tolerance to use in the k-means solver. Default is 0.00001 kmean_max_iter: integer, optional Specifies the maximum number of iterations for the k-means solver. Default is 100 Returns ------- df : cudf.DataFrame GPU data frame containing two cudf.Series of size V: the vertex identifiers and the corresponding cluster assignments. df['vertex'] : cudf.Series contains the vertex identifiers df['cluster'] : cudf.Series contains the cluster assignments Examples -------- >>> M = cudf.read_csv(datasets_path / 'karate.csv', ... delimiter = ' ', ... dtype=['int32', 'int32', 'float32'], ... header=None) >>> G = cugraph.Graph() >>> G.from_cudf_edgelist(M, source='0', destination='1') >>> df = cugraph.spectralBalancedCutClustering(G, 5) """ # Error checking in C++ code G, isNx = ensure_cugraph_obj_for_nx(G) df = spectral_clustering_wrapper.spectralBalancedCutClustering( G, num_clusters, num_eigen_vects, evs_tolerance, evs_max_iter, kmean_tolerance, kmean_max_iter, ) if G.renumbered: df = G.unrenumber(df, "vertex") if isNx is True: df = df_score_to_dictionary(df, "cluster") return df