Skip to content

Clustering, density estimation, and anomaly detection · Hierarchical clustering · UCL019 · Algorithm

ROCK

Cluster categorical or set-like records using shared-neighbor links rather than only raw pairwise similarity. Objects may be linked strongly when they have many common neighbors even if their direct similarity is modest.

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Cluster categorical or set-like records using shared-neighbor links rather than only raw pairwise similarity. Objects may be linked strongly when they have many common neighbors even if their direct similarity is modest.

Question / hypotheses

Which nested divisions or merges summarize the specified dissimilarity structure? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.

Architecture / computational structure

A thresholded similarity graph, shared-neighbor link counts, and normalized merge scores.

Assumptions

Threshold selection changes graph density and thus the link evidence. High-frequency attributes can create broad shared-neighbor hubs. A link count is neither a posterior probability nor a statistical significance level.

Formula / computational definition

Define neighbors by a similarity threshold θ\theta. Their link count is L(i,j)=∣N(i)∩N(j)∣L(i,j)=|N(i)\cap N(j)|. Cluster merging compares aggregated links against an expected size-dependent normalization; in the original formulation the denominator involves (∣A∣+∣B∣)1+2f(θ)−∣A∣1+2f(θ)−∣B∣1+2f(θ)(|A|+|B|)^{1+2f(\theta)}-|A|^{1+2f(\theta)}-|B|^{1+2f(\theta)}.

Parameters and notation

Learned or fitted quantities: Graph partition and merged cluster memberships. User-set hyperparameters/design choices: Choose KK, similarity, neighbor threshold, and sampling design. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.

Fitting, fine-tuning, and adaptation

Neural fine-tuning is not applicable. A changed distance or linkage generally requires rebuilding the hierarchy. A cut can be changed without rebuilding the tree; assigning new cases to a fixed tree needs a separately stated rule and is not identical to refitting.

How to use and calibrate

Plot neighbor and link distributions, inspect disconnected cases, assess cluster stability across thresholds, and review attribute profiles. Compare with direct-distance methods on the same representation.

Example application

Cluster categorical records linked by shared neighbors. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.

Interpretation / pitfalls

Watch out

The reported result is conditional on the representation and objective. A stable partition can reflect nuisance structure such as batch, collection site, or missingness. Confirm the interpretation in original variables and an independent sample.

Python and R code examples

Python's pyclustering documentation includes ROCK. R needs a custom link-based agglomeration routine or bridge. The component example computes shared-neighbor links; it does not implement the complete normalized merge algorithm.

Component: ROCK shared-neighbor link matrix. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — ROCK shared-neighbor link matrix. · needs numpy

import numpy as np
A=np.array([[0,1,1],[1,0,1],[1,1,0]])
result=A@A.T; np.fill_diagonal(result,0)
print(result)
R

Component demo, not a trained model — ROCK shared-neighbor link matrix.

A=matrix(c(0,1,1,1,0,1,1,1,0),3,3)
result=A%*%t(A); diag(result)=0
print(result)

Sources

From the CodeSplash reference, entry UCL019.