Skip to content

Clustering, density estimation, and anomaly detection · Deep clustering · UCL068 · Model

Variational Deep Embedding (VaDE)

Build a generative clustering model with a Gaussian-mixture latent prior and neural decoder. Unlike attaching clustering after an ordinary VAE, mixture structure participates in probabilistic training.

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.vae. 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

Build a generative clustering model with a Gaussian-mixture latent prior and neural decoder. Unlike attaching clustering after an ordinary VAE, mixture structure participates in probabilistic training.

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

Variational encoder, Gaussian-mixture latent prior, and likelihood-specific decoder.

Assumptions

Learned mixture parameters coexist with encoder/decoder weights. Posterior collapse, inactive components, and mismatch between likelihood and data can undermine both density and clustering. Component labels are exchangeable.

Formula / computational definition

Sample c∼Cat(π)c\sim Cat(\pi), then z∣c∼N(μc,Σc)z\mid c\sim\mathcal N(\mu_c,\Sigma_c), and finally x∣z∼pθ(x∣z)x\mid z\sim p_\theta(x\mid z). An encoder approximates latent inference. The ELBO is Eq[log⁡pθ(x∣z)]−KL(q(z,c∣x)∥p(z,c))E_q[\log p_\theta(x\mid z)]-KL(q(z,c\mid x)\|p(z,c)); its exact tractable expression depends on the variational factorization.

Parameters and notation

Learned or fitted quantities: Encoder/decoder weights, mixture weights, means, covariances, and approximate posteriors. User-set hyperparameters/design choices: Choose KK, latent dimension, decoder likelihood, covariance structure, network capacity, initialization, and optimization schedule. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.

Fitting, fine-tuning, and adaptation

Initialize encoder/decoder and mixture parameters to avoid inactive components, then optimize the mixture-prior ELBO. For a new domain, compare refitting only latent mixture parameters against partial encoder/decoder unfreezing at a lower learning rate; monitor component usage, reconstruction likelihood, and posterior collapse. Revalidate likelihood assumptions after adaptation.

How to use and calibrate

Check held-out reconstruction or likelihood estimates, posterior responsibilities, component usage, generated samples, and clustering stability. A good generative score does not guarantee labels match human categories.

Example application

Generate and cluster observations through a multimodal latent prior. 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

A custom probabilistic PyTorch or R torch implementation is appropriate; both need the actual mixture-prior ELBO, not a generic standard-normal VAE loss. The paired component computes a Gaussian-mixture prior log density on supplied latent samples.

Component: VaDE Gaussian-mixture latent-prior log density. 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 — VaDE Gaussian-mixture latent-prior log density. · needs numpy, scipy

import numpy as np
from scipy.special import logsumexp
z=np.array([-.5,1.,3.]); means=np.array([-1.,2.]); var=np.array([.5,1.]); pi=np.array([.4,.6])
log_component=np.log(pi)-.5*np.log(2*np.pi*var)-.5*(z[:,None]-means)**2/var
result=logsumexp(log_component,axis=1)
print(result)
R

Component demo, not a trained model — VaDE Gaussian-mixture latent-prior log density.

z=c(-.5,1,3); means=c(-1,2); variance=c(.5,1); pi=c(.4,.6)
result=sapply(z,function(q) log(sum(pi*dnorm(q,means,sqrt(variance)))))
print(result)

Sources

From the CodeSplash reference, entry UCL068.