p_cluster: Silhouette-like cluster scores using DC distances

View source: R/disco.R

p_clusterR Documentation

Silhouette-like cluster scores using DC distances

Description

Computes a silhouette coefficient for each non-noise point using the precomputed (or internally derived) DC-distance matrix rather than raw Euclidean distances. This matches the formula used by sklearn.metrics.silhouette_samples with metric="precomputed" (Python reference: disco.py, line 280):

s(i) = \frac{b(i) - a(i)}{\max(a(i),\, b(i))}

where a(i) is the mean DC distance from i to all other points in the same cluster and b(i) is the minimum over other clusters of the mean DC distance from i to that cluster. Points that form a singleton cluster score 0, as defined in the DISCO paper (and as in silhouette_samples); version 0.1.1 incorrectly gave them 1.

Usage

p_cluster(X, labels, min_points = 5, precomputed_dc_dists = FALSE)

Arguments

X

Either (a) a numeric matrix of raw data (n \times p) when precomputed_dc_dists = FALSE, or (b) a precomputed n \times n DC-distance matrix when precomputed_dc_dists = TRUE.

labels

An integer vector of cluster labels of length n. Noise labels (-1) should not be present; pass only the non-noise subset.

min_points

Positive integer; used only when precomputed_dc_dists = FALSE. Default is 5.

precomputed_dc_dists

Logical. If TRUE, X is treated as an already-computed DC-distance matrix; no further distances are computed. Default is FALSE.

Value

A numeric vector of length n with per-point silhouette-style scores in [-1, 1].

See Also

disco_samples, compute_dc_distances

Examples

set.seed(7)
X <- matrix(rnorm(60), ncol = 2)
labels <- rep(c(0L, 1L, 2L), each = 10)
p_cluster(X, labels)

discoCVI documentation built on Oct. 28, 2026, 1:07 a.m.