Skip to content

Clustering, density estimation, and anomaly detection · Density and exemplar clustering · UCL026 · Algorithm

Affinity propagation

Select exemplar observations by passing messages among candidate point pairs. The number of clusters emerges from exemplar preferences rather than being supplied directly.

Runs in CodeSplash 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.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
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.affinity_prop. 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

Select exemplar observations by passing messages among candidate point pairs. The number of clusters emerges from exemplar preferences rather than being supplied directly.

Question / hypotheses

Which dense groups, modes, or exemplars persist under a defensible similarity scale? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.

Architecture / computational structure

Responsibility and availability matrices exchange damped messages over candidate exemplars.

Assumptions

Similarity must reflect the desired relation, and dense pairwise messages require quadratic memory. Convergence is not guaranteed merely because a maximum iteration count is reached. Preference settings are not equivalent to a guaranteed KK.

Formula / computational definition

Given similarities s(i,k)s(i,k), responsibilities update as r(i,k)=s(i,k)−max⁡k′≠k[a(i,k′)+s(i,k′)]r(i,k)=s(i,k)-\max_{k'\ne k}[a(i,k')+s(i,k')]. Availabilities accumulate positive support for candidate exemplar kk, with a separate diagonal rule. Positive a(k,k)+r(k,k)a(k,k)+r(k,k) supports choosing kk as an exemplar.

Parameters and notation

Learned or fitted quantities: Exemplar indices and their assignments. User-set hyperparameters/design choices: Diagonal preferences control willingness to create exemplars; damping helps stabilize oscillations. 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. Refit or rebuild neighborhoods when the reference distribution changes. Recalibrate neighborhood and extraction settings using stable density structure; verify whether the implementation supports genuine new-point assignment before deployment.

How to use and calibrate

Inspect convergence diagnostics, exemplar count over a preference grid, total assignment similarity, and stability. Compare actual exemplars and group sizes rather than reporting only one objective value.

Example application

Select representative exemplars from a similarity matrix. 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 provides sklearn.cluster.AffinityPropagation; R provides apcluster::apcluster. Ensure both receive similarities rather than accidentally passing positive distances. Negative squared Euclidean distance is a common similarity choice, with preferences on the same scale.

Component: One affinity-propagation responsibility update. 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 — One affinity-propagation responsibility update. · needs numpy

import numpy as np
S=np.array([[-1.,-.2,-2.],[-.2,-1.,-1.],[-2.,-1.,-1.]])
A=np.zeros_like(S); result=np.empty_like(S)
for i in range(3):
    for k in range(3): result[i,k]=S[i,k]-np.max(np.delete(A[i]+S[i],k))
print(result)
R

Component demo, not a trained model — One affinity-propagation responsibility update.

S=rbind(c(-1,-.2,-2),c(-.2,-1,-1),c(-2,-1,-1)); A=0*S; result=0*S
for(i in 1:3) for(k in 1:3) result[i,k]=S[i,k]-max((A[i,]+S[i,])[-k])
print(result)

Sources

From the CodeSplash reference, entry UCL026.