Skip to content

Clustering, density estimation, and anomaly detection · Deep clustering · UCL066 · Training method

Deep Embedded Clustering (DEC)

Jointly adjust a neural embedding and cluster centers through self-generated soft targets. It replaces fixed-feature clustering with a representation explicitly optimized for cluster separation.

Runs in CodeSplash (Experimental) Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.

Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.

Availability
Runs in CodeSplash (Experimental)
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through discover.deep_cluster. 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

Jointly adjust a neural embedding and cluster centers through self-generated soft targets. It replaces fixed-feature clustering with a representation explicitly optimized for cluster separation.

Question / hypotheses

Can an unlabeled objective improve both representation quality and the stability or usefulness of clusters? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.

Architecture / computational structure

Encoder, trainable cluster centers, Student-t assignment head, and periodically refreshed targets.

Assumptions

Parameters include encoder weights and cluster centers. Self-training can amplify incorrect initial assignments; confident labels are not ground truth. DEC drops the reconstruction objective during clustering, allowing the representation to distort.

Formula / computational definition

With embedding zi=fθ(xi)z_i=f_\theta(x_i), use Student-t assignments qik∝(1+∥zi−μk∥2/α)−(α+1)/2q_{ik}\propto(1+\|z_i-\mu_k\|^2/\alpha)^{-(\alpha+1)/2}. Sharpen and frequency-normalize them as pik∝qik2/∑iqikp_{ik}\propto q_{ik}^2/\sum_iq_{ik}, then minimize KL(P∥Q)=∑ikpiklog⁡(pik/qik)KL(P\|Q)=\sum_{ik}p_{ik}\log(p_{ik}/q_{ik}). Normalize both distributions over clusters for each observation.

Parameters and notation

Learned or fitted quantities: Encoder weights, centers, and resulting soft assignments. User-set hyperparameters/design choices: Choose KK, embedding width, architecture, pretraining, target-refresh interval, optimizer, and stopping based on assignment change. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.

Fitting, fine-tuning, and adaptation

Pretrain the encoder through reconstruction, initialize centers with K-means, then jointly update encoder and centers while periodically refreshing detached targets. For transfer, compare frozen embeddings first; unfreeze gradually with a lower learning rate than newly initialized centers/head. Stop based on stable assignments and independent evaluation rather than self-confidence alone.

How to use and calibrate

Inspect occupancy, target sharpening, stability, and external ARI/NMI only on a held-out evaluation protocol. Compare with clustering the pretrained embedding before joint optimization.

Example application

Refine pretrained embeddings into sharper unlabeled groups. 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

Implement the clustering head and target updates with PyTorch or R torch, or port an author implementation after dependency review. The paired code computes normalized targets and KL divergence; it is a loss-component example, not full neural training.

Component: DEC target sharpening and KL loss. 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 — DEC target sharpening and KL loss. · needs numpy

import numpy as np
Q=np.array([[.8,.2],[.3,.7],[.6,.4]])
P=Q**2/Q.sum(0); P=P/P.sum(1,keepdims=True)
result=np.sum(P*np.log(P/Q))
print(result)
R

Component demo, not a trained model — DEC target sharpening and KL loss.

Q=rbind(c(.8,.2),c(.3,.7),c(.6,.4))
P=sweep(Q^2,2,colSums(Q),'/'); P=P/rowSums(P)
result=sum(P*log(P/Q))
print(result)

Sources

From the CodeSplash reference, entry UCL066.