Spectral, distribution-aware, and dynamic-programming clustering in R.
clusta provides a family of clustering methods built
around dynamic programming. When observations can be placed on an
ordered axis, the package finds the best contiguous partition for the
stated objective. It also provides structured methods for multivariate
data.
The main method is S-MPDP, or Spectral Mathematical Programming Dynamic Programming clustering. It is designed for multivariate groups with complex shapes, including rings, spirals, and crescents.
install.packages("clusta_1.0-1.tar.gz", repos = NULL, type = "source")The core package requires fitdistrplus. Optional
packages provide extra figures, metrics, comparison methods, and the
Shiny app.
library(clusta)
data(ceramic)
X <- ceramic[, setdiff(names(ceramic), "class")]
res <- spectral_mpdp(X, h = 2, k_neighbors = 41)
res
summary(res)
cluster_metrics(X, ceramic$class, res$cluster_results$cluster)Six standard figures are available in base graphics. Matching
ggplot2 figures are also available when
ggplot2 is installed.
plot(res, "clusters")
plot(res, "signal")
plot(res, "confidence")
plot(res, "eigengap")
plot(res, "similarity")
plot(res, "profile")
ggplot2::autoplot(res, "clusters")Stage 1 builds a locally scaled mutual k-nearest-neighbour graph. It uses the normalised Laplacian and its leading eigenvectors to unfold the data. PCA then reduces this representation to one ordered signal.
Stage 2 fits candidate distributions to that signal. It selects a distribution by AIC, then uses dynamic programming to place the cluster boundaries.
The optimality statement applies to the one-dimensional signal and fitted model. It does not claim a global optimum for the original multivariate clustering problem.
The main setting is k_neighbors. Use
smpdp_sensitivity() to assess a range of values. S-MPDP
also checks graph connectivity and reports isolated points. These checks
help identify neighbourhood settings that are too small.
| Task | Function |
|---|---|
| Suggest the number of clusters | suggest_k() |
| Measure bootstrap stability | cluster_stability() |
| Evaluate selected clustering metrics | cluster_metrics() |
| Compare selected methods, including optional MSC | run_clustering_benchmarks() |
| Compare methods across datasets | friedman_ranks() |
| Study tuning sensitivity | smpdp_sensitivity() |
| Cluster one variable | mpdp() |
| Use the broader method family | clusta() |
| Compare candidate values of k | clusta_elbow() |
clusta() supports the "wcss",
"projection", "estvar",
"parametric", "spectral",
"exact2d", "sweep", "sequence",
and "graph" methods. WCSS results include a lower bound and
an optimality gap when these quantities are available.
The package includes seven real benchmark datasets:
glass, breast_cancer, raisin,
rice, ceramic,
image_segmentation, and waveform. It also
includes v_shape, cassini, and
smpdp_toy, the worked example used in the S-MPDP paper.
Generators are provided for two moons, a V-shape, concentric circles, a smiley shape, three spirals, and a Cassini shape.
The bundled Shiny app provides an interactive interface to the package. It can load data, run S-MPDP, select comparison methods and metrics, display diagnostics, and export results. The app uses package functions, so its analyses can also be reproduced from the R console.
For uploaded data, the selected true-label column is excluded from the feature matrix automatically. This is important when labels are stored as numbers, because clustering on the label itself leaks the answer into the fit. Constant features are retained for clustering, but are omitted from standardised PCA diagnostics and reported in the interface.
shiny::runApp(system.file("app", package = "clusta"))vignette("smpdp", package = "clusta")
vignette("clusta", package = "clusta")citation("clusta")karuna.reddy@auckland.ac.nzgabiriele.bulivou@usp.ac.fjmgm.khan@usp.ac.fjGPL (>= 3).