get_silhouette_mean: Compute Average Silhouette Width with Logging

View source: R/general_tools.R

get_silhouette_meanR Documentation

Compute Average Silhouette Width with Logging

Description

Computes the average silhouette width for a clustering solution using Euclidean distance.

Usage

get_silhouette_mean(X, cluster_assignments, n_threads = 1, verbose = FALSE)

Arguments

X

A numeric matrix where rows are observations and columns are features.

cluster_assignments

An integer vector of cluster assignments, which must be the same length as the number of rows in X.

n_threads

Number of threads to use for parallel processing.

verbose

Logical. If TRUE, prints progress and informational messages. Default is FALSE.

Value

A single numeric value: the average silhouette score.

Note

This process can be very slow for large matrices if single-threaded. Use multiple threads to take advantage of parallel computation for significantly faster results.

Examples

# Preparing the inputs
set.seed(42)
pc_matrix <- matrix(data = rnorm(n = 10000 * 15, sd = 2), nrow = 10000, ncol = 15)
cluster_numbers <- as.integer(runif(n = 10000, min = 1, max = 10))

# Getting the mean silhouette score
n_threads <- parallel::detectCores()
score <- get_silhouette_mean(pc_matrix, cluster_numbers, n_threads)
print(score)


splikit documentation built on May 13, 2026, 9:08 a.m.