Instruction.txt: How to Run the Spectral Clustering Application
This application demonstrates spectral clustering on different datasets using MATLAB 2024. The code includes interactive prompts for parameter selection and visualizes the clustering results.
-
Launch MATLAB 2024: Ensure you are running MATLAB version 2024 to guarantee compatibility with the code.
-
Load the Application: Save the provided code as a
.mfile (e.g.,SpectralClusteringApp.m). Ensure all required dataset files (Circle.csv,Spiral.csv,Sphere.csv) are in the same directory as the script. -
Run the Code: Open the
.mfile in MATLAB, then click on the Run button or typeSpectralClusteringAppin the MATLAB command window. -
Select a Dataset: The program will prompt you to choose one of the following datasets:
- Circle.csv
- Spiral.csv
- Sphere.csv
Use the menu dialog to select your desired dataset.
-
Set Parameters:
- k (k-nearest neighbors): Enter the number of nearest neighbors (e.g., 10, 20, 40).
- Laplacian Choice: Select the type of Laplacian matrix:
L: Standard LaplacianL_norm: Normalized Laplacian
- Number of Eigenvalues: Enter the number of eigenvalues to compute (e.g., 3, 5, etc.).
-
View Sparsity Pattern: The adjacency matrix's sparsity pattern is displayed in a plot for verification.
-
Eigenvalue Plot: After computing eigenvalues, the program plots them for analysis. Use this plot to identify the eigengap and determine the optimal number of clusters.
- Tip: When prompted, enter the number of clusters based on the largest gap between consecutive eigenvalues.
-
Clustering Results: The script performs clustering using three methods:
- k-means
- DBSCAN
- Hierarchical Clustering
-
Visualize Results: The program displays:
- Clusters in 2D or 3D depending on the dataset.
- Sparsity patterns of adjacency matrices.
- Eigenvalue distributions.
-
Evaluate Silhouette Scores: The program computes and displays silhouette scores for each clustering method. These scores indicate how well-separated the clusters are.
-
Evaluate Adjusted Rand Index (ARI): If you select the
Spiral.csvdataset, the ARI metric evaluates clustering accuracy against true labels.
- You can try different values of
k, eigenvalues, and the number of clusters to see their effects on the results. - Experiment with the DBSCAN epsilon parameter using the
k-Distancegraph generated by the code.
- The datasets should be properly formatted with coordinates (and labels for
Spiral.csv). - Make sure MATLAB has the required permissions to access the datasets.