| Type: | Package |
| Title: | Spectral, Distribution-Aware and Dynamic-Programming Clustering |
| Version: | 1.0-1 |
| Date: | 2026-10-28 |
| Description: | Provides dynamic-programming clustering methods for one or more variables. For one variable, the package finds the globally optimal contiguous partition for the stated objective. Multivariate methods use projection, separating directions, sequence order, graph structure, or spectral unfolding. The main method is Spectral Mathematical Programming Dynamic Programming clustering, or S-MPDP. It unfolds non-convex data into one ordered signal and places cluster boundaries with a distribution-aware dynamic program. The package also provides cluster diagnostics, stability analysis, evaluation metrics, comparison methods, benchmark datasets, and base or 'ggplot2' figures. The distribution-aware dynamic-programming component follows Khan, Khan and Ahsan (2002) <doi:10.1177/0008068320020518>, Reddy and Khan (2018) <doi:10.1080/03610926.2018.1473609>, and Reddy and Khan (2020) <doi:10.1111/anzs.12301>. The exact one-dimensional clustering comparison follows Wang and Song (2011) <doi:10.32614/RJ-2011-015>. The spectral graph component builds on Shi and Malik (2000) <doi:10.1109/34.868688>, Ng, Jordan and Weiss (2002) https://papers.nips.cc/paper/2092-on-spectral-clustering-analysis-and-an-algorithm, and Zelnik-Manor and Perona (2004) https://papers.nips.cc/paper/2619-self-tuning-spectral-clustering. |
| License: | GPL (≥ 3) |
| URL: | https://github.com/karunaredz/clusta |
| BugReports: | https://github.com/karunaredz/clusta/issues |
| Encoding: | UTF-8 |
| LazyData: | true |
| Depends: | R (≥ 4.1.0) |
| Imports: | stats, graphics, grDevices, utils, fitdistrplus |
| Suggests: | FitVerse (≥ 1.0-2), shiny, bslib, ggplot2, DT, cluster, clue, mclust, dbscan, mlbench, sClust, MASS, testthat (≥ 3.0.0), knitr, rmarkdown |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Author: | Karuna G. Reddy [aut, cre], Gabiriele Bulivou [aut], M. G. M. Khan [aut] |
| Maintainer: | Karuna G. Reddy <karuna.reddy@auckland.ac.nz> |
| Config/roxygen2/version: | 8.0.0 |
| Packaged: | 2026-11-13 02:48:30 UTC; karunareddy |
| Repository: | CRAN |
| Date/Publication: | 2026-12-05 15:10:02 UTC |
Spectral, Distribution-Aware and Dynamic-Programming Clustering
Description
clusta provides dynamic-programming clustering for one or more variables. For one variable, it finds the globally optimal contiguous partition for the stated objective. Multivariate methods use projection, geometry, sequence order, graph structure, or spectral unfolding.
The headline method
spectral_mpdp implements S-MPDP. Stage 1 unfolds multivariate data
into one ordered signal. It uses a locally scaled k-nearest-neighbour graph, the
normalised Laplacian, and PCA. Stage 2 fits candidate distributions and places
the boundaries with dynamic programming. The optimality statement applies to
the one-dimensional signal and fitted model.
The dynamic-programming family
clusta provides the "wcss", "projection",
"estvar", "parametric", "spectral",
"exact2d", "sweep", "sequence", and "graph"
methods. WCSS results include an optimality gap when it is available.
Diagnostics, evaluation and figures
suggest_k uses the spectral gap to suggest a cluster count.
cluster_stability runs a Jaccard bootstrap.
cluster_metrics returns external and internal scores.
run_clustering_benchmarks compares a selected set of clustering
methods, including optional multi-level spectral clustering.
friedman_ranks compares methods across datasets.
smpdp_sensitivity studies tuning sensitivity.
plot.smpdp draws six standard views.
Data
Seven real benchmark datasets are included: glass,
breast_cancer, raisin, rice, and
ceramic, plus image_segmentation and
waveform. The package also includes smpdp_toy,
the v_shape and cassini benchmark data, and six
simulated-data generators.
Vignettes
Use vignette("smpdp", package = "clusta") for S-MPDP.
Use vignette("clusta", package = "clusta") for the broader method
family.
Author(s)
Karuna G. Reddy (maintainer), Gabiriele Bulivou, M. G. M. Khan.
References
Reddy, K. G., Bulivou, G. and Khan, M. G. M. Spectral Mathematical Programming Dynamic Programming Clustering: A Distribution-Aware Multivariate Clustering Algorithm with Optimal Boundary Selection.
Exact and structure-guided Dynamic-Programming clustering
Description
clusta() provides Dynamic Programming (DP) clustering methods. The
one-dimensional methods partition an ordered axis into contiguous segments.
A method can be selected automatically or supplied by the user.
Usage
clusta(
data,
k,
method = NULL,
objective = c("neyman", "gaussian", "wcss"),
score = NULL,
direction = NULL,
order = NULL,
adjacency = NULL,
scale = FALSE,
k_neighbors = 15L,
fit_engine = c("fitdistrplus", "fitverse", "best"),
fit_dists = "all"
)
Arguments
data |
Numeric vector, matrix, or data.frame. Rows are observations,
columns are variables. Rows with |
k |
Integer |
method |
One of |
objective |
Objective for |
score |
Optional numeric vector (one value per row) giving a custom
1-D score for |
direction |
Optional numeric vector (length = number of variables)
giving a custom projection direction for |
order |
Optional vector defining the row ordering for |
adjacency |
Reserved for a user-supplied graph in |
scale |
Logical. Standardise columns before projection (default FALSE). Constant columns are given zero loading and omitted from the standardised PCA calculation because they contain no projection information. |
k_neighbors |
Integer neighbourhood size used by
|
fit_engine |
Which engine fits the candidate distributions in
|
fit_dists |
Families offered to |
Details
"wcss"One variable. Exact, globally optimal 1-D clustering.
"projection"Two or more variables. Project to a single score (first principal component by default, or your own
score/direction) and run the exact 1-D DP on it. Exact on the projection axis. This is a fast approximation for the full-space objective."estvar"Exact DP on the data using an estimation-variance criterion.
objective = "neyman"(sum of Wh*Sh, the variance under Neyman allocation) has a global solution. It is the default."gaussian"(a Gaussian negative log-likelihood) and"wcss"are also available. No distribution is fitted. Runs on one variable or on the PC1 score for several."parametric"The model-fitting method: fits the best parametric distribution by AIC, then places boundaries by a DP on the fitted MODEL's Wh*Sh cost. The candidate families are fitted by fitdistrplus by default. Set
fit_engineto widen the search to the 52 families of FitVerse."spectral"The S-MPDP method, and the one the paper proposes. Stage 1 unfolds the data to a single 1-D signal through a locally scaled k-nearest-neighbour graph and the normalised Laplacian. Stage 2 places the boundaries on that signal with a distribution-fitting DP. This is the method to reach for when the clusters are non-convex (rings, spirals, crescents). Tuned with
k_neighbors. Seespectral_mpdpfor the full interface."exact2d"Exactly two variables and
k = 2. Enumerates all separating directions and returns the global optimum in the full two-dimensional space."sweep"Two variables, any
k. Generalisesexact2d. It is global fork = 2. Fork >= 3, it finds the best clustering that parallel lines can separate."sequence"Ordered/sequential data (time, position, a trajectory). Exact multivariate segment DP along the given
order."graph"Contiguity-constrained clustering on a neighbourhood graph (minimum spanning tree plus SKATER-style greedy edge removal). This heuristic respects spatial or graph structure. It is not globally optimal.
Value
An object of class "clusta": a list with cluster,
centers, size, withinss, tot.withinss,
totss, betweenss, bic, avg.silwidth, plus
method-specific fields (scores, boundaries, direction,
line, order). Works with print, summary,
plot, fitted, predict and fviz_clusta.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
Examples
set.seed(1)
# one variable -> exact global
x <- c(rnorm(60, 0), rnorm(60, 6), rnorm(60, 13))
print(clusta(x, k = 3))
# two variables, k = 2 -> global optimum in full space
X <- rbind(matrix(rnorm(100, 0), 50, 2), matrix(rnorm(100, 5), 50, 2))
cl <- clusta(X, k = 2, method = "exact2d")
plot(cl)
# many variables -> projection to PC1, exact DP on the score
clusta(iris[, 1:4], k = 3, method = "projection")
Real and toy benchmark datasets used in the S-MPDP paper
Description
Data frames bundled for reproducing the clustering benchmarks. Each has numeric
feature columns and a factor class of ground-truth labels.
glassGlass Identification. 214 observations, 9 chemical features (RI, Na, Mg, Al, Si, K, Ca, Ba, Fe) and
class(6 glass types). Source: UCI Machine Learning Repository.breast_cancerWisconsin Diagnostic Breast Cancer (WDBC). 569 observations, 30 numeric features and
class(M = malignant, B = benign). Source: UCI.raisinRaisin Grains. 900 observations, 7 morphological features and
class(2 varieties). Source: UCI.riceRice (Cammeo and Osmancik). 3810 observations, 7 features and
class(2 varieties). Source: UCI.ceramicChemical Composition of Ceramic Samples. 88 observations, 17 oxide-composition features and
class(2 body parts). Source: UCI.smpdp_toyThe 8-point, two-crescent toy dataset from the paper's numerical example (columns
x1,x2,class).image_segmentationImage Segmentation. 2310 observations, 19 numeric image features and
class(7 balanced image classes).waveformWaveform. 5000 observations, 21 numeric features and
class(3 waveform classes).v_shapeThe 400-point, two-class V-shape simulated dataset used in the paper (columns
x,y,class).cassiniThe 2000-point, three-class Cassini simulated dataset used in the paper (columns
x,y,class).
Usage
data(glass)
data(breast_cancer)
data(raisin)
data(rice)
data(ceramic)
data(smpdp_toy)
data(image_segmentation)
data(waveform)
data(v_shape)
data(cassini)
Format
Data frames; the last column class is a factor of labels.
Examples
data(ceramic)
str(ceramic)
Compare clusta against k-means on the same data
Description
Runs clusta() with the chosen method and stats::kmeans() on
the same data and reports the total within-cluster sum of squares (WCSS) of
each, plus the gap. For "wcss"/"exact2d" the clusta value is
a certified optimum, so its WCSS is \leq k-means.
Usage
clusta_compare(data, k, method = NULL, nstart = 1L, seed = NULL, ...)
Arguments
data, k, method |
Passed to |
nstart |
|
seed |
Optional seed for reproducible k-means starts. |
... |
Further arguments passed to |
Value
A data frame with one row per method.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
Examples
set.seed(1); x <- c(rnorm(50, 0), rnorm(50, 5), rnorm(50, 12))
clusta_compare(x, k = 3, seed = 1)
Scan a range of k and plot model-selection diagnostics
Description
Fits clusta() for every k in k_range and returns a
table of total within-cluster SS (for the elbow), BIC, average silhouette
width, and the certified optimality gap. With plot = TRUE it draws a
three-panel diagnostic figure.
Usage
clusta_elbow(
data,
k_range = 2:8,
method = NULL,
objective = "neyman",
plot = TRUE,
...
)
Arguments
data, method, objective, ... |
Passed to |
k_range |
Integer vector of cluster counts to try (default |
plot |
Logical. Draw the diagnostic panel (default TRUE). |
Value
A data frame (invisibly if plotting) with one row per k.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
Examples
x <- c(rnorm(80, 0), rnorm(80, 6), rnorm(80, 13))
clusta_elbow(x, k_range = 1:8)
Evaluate a clustering, with or without ground-truth labels
Description
Computes eight standard scores in one call. The five external metrics
reported in the paper compare the partition to known classes: Adjusted Rand
Index (ARI), Normalised Mutual Information (NMI), Purity and label-matched
Accuracy, plus the average Silhouette width. Three internal indices score
the partition from the feature space alone and so are still returned when no
labels are available: Calinski-Harabasz (CH), Davies-Bouldin
(DB) and the Dunn index.
Usage
cluster_metrics(
X,
true_labels,
pred_labels,
metrics = c("ARI", "NMI", "Silhouette", "Purity", "Accuracy", "CH", "DB", "Dunn")
)
Arguments
X |
Numeric matrix or data.frame of features (used for Silhouette, CH, DB and Dunn). |
true_labels |
Vector of ground-truth class labels, or |
pred_labels |
Vector of predicted cluster labels. |
metrics |
Character vector naming the metrics to compute. The default
computes all eight. Unselected entries remain |
Details
Direction of improvement differs: ARI, NMI, Silhouette, Purity, Accuracy, CH
and Dunn are better when large. DB is better when small.
ARI, NMI, Purity, CH, DB and Dunn are computed in base R. Silhouette uses
cluster and Accuracy uses clue when installed (otherwise
NA).
Value
A named numeric vector: ARI, NMI, Silhouette,
Purity, Accuracy, CH, DB, Dunn. Every
entry is NA when the prediction is missing or has fewer than two
clusters.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
Examples
set.seed(1)
pred <- kmeans(iris[, 1:4], centers = 3, nstart = 10)$cluster
cluster_metrics(iris[, 1:4], iris$Species, pred)
# unlabelled data: the three internal indices are still returned
cluster_metrics(iris[, 1:4], NULL, pred)
Bootstrap stability of S-MPDP clusters
Description
Resamples the observations with replacement, re-runs the whole S-MPDP
pipeline on each resample, and measures how well each of the original
clusters reappears. For every original cluster the score is its best Jaccard
overlap with any cluster found in the resample, so a cluster that dissolves
or merges scores low. This is the Jaccard bootstrap used to validate
clusterings in the style of fpc::clusterboot.
Usage
cluster_stability(
data,
h,
k_neighbors = 15,
B = 25,
mutual = TRUE,
seed = NULL,
progress = NULL
)
Arguments
data |
Numeric matrix or data.frame of features. |
h |
Number of clusters. |
k_neighbors |
Neighbourhood size for Stage 1 (default 15). |
B |
Number of bootstrap resamples (default 25). |
mutual |
Logical. Graph rule used by |
seed |
Optional seed so the resampling is reproducible. |
progress |
Optional callback used by interactive front ends. When
supplied, it is called after the reference fit and after every bootstrap
resample as |
Details
A common reading of the per-cluster mean: above 0.85 highly stable, 0.75–0.85 stable, 0.60–0.75 doubtful, below 0.60 unstable (treat such a cluster as an artefact of the sample rather than a finding).
Each resample is a complete run of both stages, so cost scales with
B times the cost of one spectral_mpdp call.
Value
An object of class "smpdp_stability": a list with
jaccard (an h by B matrix of best overlaps),
stability (the per-cluster mean), overall (the mean over
clusters), B and h. Has print and plot methods.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
See Also
Examples
data(ceramic)
X <- ceramic[, setdiff(names(ceramic), "class")]
cs <- cluster_stability(X, h = 2, k_neighbors = 41, B = 20, seed = 12345)
cs
plot(cs)
Pareto Type II (Lomax) distribution
Description
Density, distribution and quantile functions for the Pareto Type II (Lomax)
distribution, parameterised so the survival function is
S(x) = (scale / (x + scale))^{shape}. Provided so that
fitdistrplus::fitdist(., "pareto") works as one of the S-MPDP candidate
families without requiring the actuar package.
Usage
dpareto(x, shape, scale)
ppareto(q, shape, scale)
qpareto(p, shape, scale)
Arguments
x, q |
Vector of quantiles ( |
shape |
Shape parameter ( |
scale |
Scale parameter ( |
p |
Vector of probabilities. |
Value
Density (dpareto), distribution function (ppareto) or quantiles
(qpareto).
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
Examples
dpareto(0:3, shape = 2, scale = 1)
ppareto(0:3, shape = 2, scale = 1)
qpareto(c(0.25, 0.5, 0.75), shape = 2, scale = 1)
Friedman average-rank comparison of clustering methods
Description
Summarises a datasets-by-methods table of scores the way a benchmarking study does: rank the methods within each dataset (rank 1 = best), average each method's rank over datasets, and test with Friedman's rank test whether the methods differ at all. Average ranks are the fair way to combine datasets whose scores live on different scales.
Usage
friedman_ranks(scores, higher_better = TRUE)
Arguments
scores |
A numeric matrix or data.frame with one row per dataset and one column per method (row and column names are used as labels). |
higher_better |
Logical. Use |
Details
The Iman-Davenport F statistic is reported alongside the Friedman chi-squared, as it is the less conservative of the two and is the one usually quoted in method comparisons.
Value
An object of class "clusta_ranks": a list with ranks
(the per-dataset rank matrix), avg_rank (sorted, best first),
best, statistic and p.value (Friedman chi-squared),
iman_f and iman_p, n_datasets and n_methods.
Has print and plot methods.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
Examples
scores <- rbind(
iris = c(`S-MPDP` = 0.773, `K-Means` = 0.730, Spectral = 0.716),
glass = c(0.281, 0.248, 0.231),
ceramic = c(1.000, 0.909, 0.909)
)
friedman_ranks(scores)
Publication-quality visualisation of an clusta clustering (ggplot2)
Description
type = "clusters" draws the clusters: a shaded density along the axis
for one-variable/projection results, or a coloured scatter (with the
separating line for exact2d) for two or more variables. type =
"silhouette" draws the silhouette bar plot. Returns a ggplot object.
Usage
fviz_clusta(
object,
type = c("clusters", "silhouette"),
palette = NULL,
bins = 30,
base_size = 13
)
Arguments
object |
An |
type |
|
palette |
Optional cluster colours (default colour-blind-safe). |
bins |
Histogram bins for the 1-D view (default 30). |
base_size |
Base font size (default 13). |
Value
A ggplot object.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
Examples
if (requireNamespace("ggplot2", quietly = TRUE)) {
X <- rbind(matrix(rnorm(40, 0), 20, 2), matrix(rnorm(40, 5), 20, 2))
cl <- clusta(X, k = 2, method = "exact2d")
fviz_clusta(cl)
}
Univariate distribution-aware dynamic-programming clustering (MP-DP)
Description
mpdp() clusters a single numeric variable by the Mathematical
Programming - Dynamic Programming method. It fits the best of ten candidate
distributions (by AIC), then uses the closed form of that distribution in a
dynamic-programming recurrence to place the cluster boundaries that minimise
the total weighted within-cluster spread, \sum_h W_h \sigma_h. On one
dimension the split is globally optimal for the fitted model. This is Stage 2
of spectral_mpdp and can also be used on its own.
Usage
mpdp(data, h, verbose = FALSE)
## S3 method for class 'mpdp'
print(x, ...)
## S3 method for class 'mpdp'
summary(object, ...)
Arguments
data |
Numeric vector to cluster (for example the 1-D signal produced by Stage 1). Values should be non-negative for the positive-support families. |
h |
Integer number of clusters. |
verbose |
Logical; print a progress note and the boundary summary
(default |
x |
An object of class |
object |
An object of class |
... |
Further arguments (ignored). |
Value
A list of class "mpdp" with, among others: distr (chosen
distribution), OSB (optimum cluster boundaries on the data scale),
cluster_membership (integer label per observation), Wh,
Vh, WhSh per cluster, and fit_percent (the Akaike weight
of the winning distribution).
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
See Also
Examples
set.seed(1)
x <- c(rnorm(80, 5, 1), rnorm(80, 15, 1))
fit <- mpdp(x, h = 2)
fit$OSB
Plot an clusta clustering (base graphics)
Description
Plot an clusta clustering (base graphics)
Usage
## S3 method for class 'clusta'
plot(
x,
which = c("clusters", "silhouette"),
col = NULL,
main = NULL,
xlab = NULL,
ylab = NULL,
...
)
Arguments
x |
An |
which |
|
col |
Optional cluster colours (default colour-blind-safe palette). |
main, xlab, ylab |
Labels (sensible defaults chosen per method). |
... |
Passed to the underlying plotting call. |
Value
x, invisibly.
Standard figures for an S-MPDP clustering
Description
Draws one of the six views of a "smpdp" object returned by
spectral_mpdp. plot() uses base graphics and needs no
extra package. autoplot() returns the same figure as a ggplot2
object you can theme or save.
Usage
## S3 method for class 'smpdp'
plot(
x,
which = c("clusters", "signal", "confidence", "eigengap", "similarity", "profile"),
col = NULL,
max_show = 15L,
max_points = 600L,
...
)
autoplot.smpdp(
object,
which = c("clusters", "signal", "confidence", "eigengap", "similarity", "profile"),
palette = NULL,
max_show = 15L,
max_points = 600L,
...
)
Arguments
x, object |
An object of class |
which |
One of |
col, palette |
Optional cluster colours (default colour-blind-safe Okabe-Ito). |
max_show |
Largest number of eigenvalues to draw for
|
max_points |
Similarity matrices larger than this are thinned for display (default 600). The block structure is unchanged. |
... |
Passed to the underlying plotting call. |
Details
"clusters"The cluster map: the two features, or the first two principal components when there are more, coloured by cluster.
"signal"The 1-D spectral signal with the optimum boundaries placed by the Stage 2 dynamic program.
"confidence"The cluster map again, with each point faded and shrunk in proportion to how close it sits to a boundary. Pale points are the ones that would switch first if the settings changed.
"eigengap"The normalised-Laplacian spectrum with the largest gap marked. This is a spectral guide to the number of clusters.
"similarity"The Stage 1 affinity matrix with rows and columns ordered by cluster. Clear diagonal blocks support separation in the graph.
"profile"Standardised feature means for each cluster.
Value
plot returns x invisibly. autoplot returns a
ggplot object.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
See Also
Examples
data(ceramic)
res <- spectral_mpdp(ceramic[, setdiff(names(ceramic), "class")],
h = 2, k_neighbors = 41)
plot(res, "clusters")
plot(res, "signal")
plot(res, "eigengap")
Benchmark selected clustering methods
Description
Runs a selected set of algorithms on the same data and returns their cluster
labels: S-MPDP, k-means, normalised-cut spectral clustering, HDBSCAN,
agglomerative clustering, and multi-level spectral clustering (MSC). HDBSCAN
and MSC are skipped with a warning when their optional packages are
unavailable. MSC receives L through its Kmax argument, but may
return a different final number of groups because the algorithm splits clusters
over several levels. A warning reports the difference.
Usage
run_clustering_benchmarks(
X,
L,
k_neb = 15,
mutual = TRUE,
seed = 12345,
methods = c("S-MPDP", "K-Means", "Spectral", "HDBSCAN", "Agglomerative")
)
Arguments
X |
Numeric matrix or data.frame of features. |
L |
Integer number of clusters. |
k_neb |
Neighbourhood size passed to S-MPDP (default 15). |
mutual |
Logical; use a mutual k-NN graph for S-MPDP when TRUE, or the union graph when FALSE (default TRUE). |
seed |
Random seed for the methods that use one (default 12345). |
methods |
Character vector selecting methods. Valid names are
|
Value
A named list of integer label vectors, one per successfully fitted method.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
Examples
preds <- run_clustering_benchmarks(iris[, 1:4], L = 3, k_neb = 50)
t(sapply(preds, function(p) cluster_metrics(iris[, 1:4], iris$Species, p)))
Simulated benchmark datasets for clustering
Description
A family of generators for the non-convex two-dimensional datasets used to
evaluate S-MPDP: two moons, a V-shape, concentric circles, a smiley face,
three spirals, and (optionally) the Cassini shape. Each returns a data.frame
with columns x, y and a factor class.
Usage
gen_two_moons(n = 500)
gen_v_shape(n = 400)
gen_concentric_circles(n = 2000)
gen_smiley(n = 400)
gen_three_spirals(n = 1200, noise = 0.02, cycles = 1.4)
gen_cassini(n = 2000)
gen_non_convex(n = 2000)
Arguments
n |
Total number of points (where applicable). |
noise |
Standard deviation of the Gaussian jitter (spirals). |
cycles |
Number of turns each spiral arm makes. |
Value
A data.frame with numeric columns x, y and factor
class.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
Examples
d <- gen_two_moons()
plot(d$x, d$y, col = d$class)
Sensitivity of S-MPDP to its neighbourhood size and cluster count
Description
Runs spectral_mpdp over a grid of k_neighbors and
h values and scores every cell. This is the sensitivity analysis
reported in the paper. It shows the values for which the method is stable.
Usage
smpdp_sensitivity(
data,
truth = NULL,
k_grid = c(5, 10, 15, 20, 30, 40),
h_grid = 2:4,
mutual = TRUE,
seed = NULL,
progress = NULL
)
Arguments
data |
Numeric matrix or data.frame of features. |
truth |
Optional vector of ground-truth labels. |
k_grid |
Integer vector of |
h_grid |
Integer vector of cluster counts to try. |
mutual |
Logical. Graph rule used by |
seed |
Optional seed for reproducibility. |
progress |
Optional callback used by interactive front ends. When
supplied, it is called after every fitted grid cell as
|
Details
Without truth, the grid uses average silhouette width. With
truth, the grid also reports ARI and NMI.
Value
An object of class "smpdp_sensitivity": a list with
grid, a data frame of one row per cell holding k_neighbors,
h, ARI, NMI and Silhouette, plus the grids
used. Has print and plot (heatmap) methods.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
See Also
Examples
d <- gen_two_moons(300)
s <- smpdp_sensitivity(d[, c("x", "y")], d$class,
k_grid = c(5, 10, 15, 20), h_grid = 2:3)
s
plot(s)
Spectral Mathematical Programming Dynamic Programming clustering (S-MPDP)
Description
spectral_mpdp() is the proposed distribution-aware, spectral clustering
method. Stage 1 unfolds multivariate data into a single ordered 1-D signal
using a locally scaled mutual k-nearest-neighbour graph, a normalised
Laplacian, cumulative variance scaling of the leading eigenvectors, NJW row
normalisation and a PCA projection. Stage 2 clusters that 1-D signal with
mpdp, which fits the best distribution and places globally
optimal boundaries on that 1-D signal by dynamic programming.
Usage
spectral_mpdp(data, h = 4, k_neighbors = 15, verbose = FALSE, mutual = TRUE)
Arguments
data |
Numeric matrix or data.frame of features (rows = observations, columns = variables). |
h |
Integer number of clusters (the target number of groups). |
k_neighbors |
Integer neighbourhood size for the local scaling and mutual k-NN graph in Stage 1 (default 15). This is the main tuning setting. Larger values connect more of the graph. Smaller values keep it local. |
verbose |
Logical. Print Stage 2 progress (default |
mutual |
Logical. Graph rule in Stage 1. |
Details
The optimality is of the boundary placement on the 1-D signal for the fitted distribution. S-MPDP does not claim a global optimum of the original multivariate clustering problem.
Value
An object of class "smpdp": a list whose
cluster_results element is a data frame with the original data
columns, the 1-D score, the integer cluster label and the
per-point confidence (0 = the point sits on a cluster boundary,
1 = the point furthest from any boundary). Stage 1 and Stage 2 details are
carried as attributes: "mpdp" (the fitted Stage 2 object),
"signal" (the 1-D signal), "affinity" (the locally scaled
k-NN affinity matrix), "eigenvalues" (the normalised-Laplacian
spectrum), "boundaries" (the internal cuts) and "settings".
Works with print, summary, plot
and autoplot.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
References
Reddy, K. G., Bulivou, G. and Khan, M. G. M. Spectral Mathematical Programming Dynamic Programming Clustering: A Distribution-Aware Multivariate Clustering Algorithm with Optimal Boundary Selection.
See Also
Examples
data(iris)
res <- spectral_mpdp(iris[, 1:4], h = 3, k_neighbors = 50)
table(res$cluster_results$cluster, iris$Species)
Suggest the number of clusters from the spectral gap
Description
Builds the Stage 1 graph of spectral_mpdp once and reads its
normalised-Laplacian spectrum. The standard eigengap heuristic looks for a
clear separation after the first k eigenvalues. The largest drop
suggests a value of k.
Usage
suggest_k(data, k_neighbors = 15, k_max = 10, mutual = TRUE)
Arguments
data |
Numeric matrix or data.frame of features. |
k_neighbors |
Neighbourhood size for the Stage 1 graph (default 15),
matching the argument of the same name in |
k_max |
Largest number of clusters to consider (default 10). |
mutual |
Logical. Use |
Details
This diagnostic does not use silhouette or reference labels. The graph is
built once. A clear, isolated gap supports a candidate value of k.
A flat spectrum does not strongly support any single value.
Value
An object of class "smpdp_k": a list with k (the
suggested number of clusters), eigenvalues (the leading spectrum),
gaps (the drop after each eigenvalue) and k_max. Has
print and plot methods.
Author(s)
Karuna G. Reddy, Gabiriele Bulivou, M. G. M. Khan
See Also
spectral_mpdp, cluster_stability
Examples
data(ceramic)
X <- ceramic[, setdiff(names(ceramic), "class")]
sk <- suggest_k(X, k_neighbors = 41)
sk
plot(sk)