spectrum$vects  Motif-based spectral clustering The overall aim of motifcluster is to use motifs for spectral clustering, so now we see how to extract clusters from the motif-based eigenvector embeddings. The run_motif_clustering function handles the entire process of building an MAM, restricting it to its largest connected component, performing eigenvector embedding, and extracting clusters. We therefore take the opportunity to showcase the ability of motifcluster to recover the blocks of a DSBM, demonstrating all of the methods outlined in this vignette. Let's use a DSBM with three blocks of 10 nodes each. block_sizes = rep(10, 3)  We use strong connections of 0.8 within the blocks, and weaker connections of 0.3 between the blocks. connection_matrix = matrix(c( 0.8, 0.2, 0.2, 0.2, 0.8, 0.2, 0.2, 0.2, 0.8 ), nrow = 3)  We also set the within-block edges to be Poisson-weighted with mean 20, and the between-block edges to be Poisson-weighted with smaller mean 10. weight_matrix = matrix(c( 20, 10, 10, 10, 20, 10, 10, 10, 20 ), nrow = 3) G4 = sample_dsbm(block_sizes, connection_matrix, weight_matrix, sample_weight_type = "poisson")  Now we can run the motif-based spectral clustering algorithm on this network with the 3-cycle motif$\mathcal{M}_1$. We build a functional MAM, weighting the instances by their mean edge weights, using the sparse formulation. We restrict this MAM to its largest connected component. Then we construct a random-walk Laplacian and embed it using the first four eigenvalues and eigenvectors. Finally we extract three clusters. motif_cluster = run_motif_clustering(G4, motif_name = "M1", motif_type = "func", mam_weight_type = "mean", mam_method = "sparse", type_lap = "rw", num_eigs = 4, num_clusts = 3 )  We can evaluate the performance by comparing it to the ground-truth labels using the adjusted Rand index from the mclust package: truth = c(rep(1, 10), rep(2, 10), rep(3, 10)) mclust::adjustedRandIndex(motif_cluster$clusts, truth)


A larger value indicates better recovery of the blocks, with a value of one indicating perfect agreement.

References

options(old_options)


Try the motifcluster package in your browser

Any scripts or data that you put into this service are public.

motifcluster documentation built on April 30, 2022, 1:06 a.m.