Affinity propagation

On this page 7

Affinity propagation is a clustering algorithm that groups data by exchanging messages between pairs of points until a set of representative points, called exemplars, emerges, with every other point assigned to its most suitable exemplar. In machine learning, it stands out because it does not require the number of clusters in advance and because each cluster center is an actual data point, not an average.

The method was introduced in 2007 by Brendan Frey and Delbert Dueck. It works on a similarity matrix of any kind, which makes it useful when only pairwise similarities are available, but its quadratic memory and time cost limits it to small and medium datasets.

How affinity propagation passes messages

Affinity propagation treats clustering as a search for the best exemplars and solves it by iteratively exchanging two kinds of messages between all pairs of points. The input is a similarity value s(i, k) for every pair, commonly the negative squared Euclidean distance, and a diagonal value s(k, k) called the preference.

The responsibility r(i, k), sent from point i to candidate k, measures how well k suits i as an exemplar compared with the best alternative candidate. The availability a(i, k), sent from k back to i, measures how appropriate it would be for i to choose k, given the support k already receives from other points. Each iteration updates both matrices, and a point k becomes an exemplar when the sum r(k, k) + a(k, k) is positive.

The table below summarizes the quantities that drive the algorithm.

QuantityDirectionWhat it expresses
Similarity s(i, k)Input, fixedHow well k represents i
Preference s(k, k)Input, fixedPrior willingness of k to be an exemplar
Responsibility r(i, k)Point to candidateEvidence that k is the best exemplar for i
Availability a(i, k)Candidate to pointCollective support for k as an exemplar
Damping factorUpdate ruleBlend of old and new messages for stability
Core quantities in affinity propagation

Formally, the procedure is an instance of loopy belief propagation on a factor graph that maximizes the total similarity of points to their exemplars, subject to the constraint that an exemplar must choose itself. Loopy propagation is not guaranteed to find the global optimum, but in practice it usually reaches high-quality solutions quickly.

Key parameters and their effects

Affinity propagation has few parameters, but the preference and the damping factor decide most of its behavior. A higher preference makes more points willing to serve as exemplars and therefore yields more clusters; a lower preference yields fewer.

ParameterCommon settingEffect when increased
PreferenceMedian of input similaritiesMore clusters
Damping factor0.5 to 0.9Slower but more stable convergence
Maximum iterations200 to 1,000More time to settle on exemplars
Convergence window15 to 50 unchanged iterationsStricter stopping criterion
Main affinity propagation parameters

Setting the preference to the median similarity typically produces a moderate number of clusters, while the minimum similarity produces a small number. Because the cluster count reacts nonlinearly to the preference, practitioners often run a short sweep and inspect the results. If messages oscillate without converging, raising the damping factor toward 0.9 is the usual first remedy.

Affinity propagation compared with other clustering methods

Affinity propagation sits between centroid-based and graph-based clustering. Like k-medoids, it selects real data points as centers; like spectral clustering, it operates on a similarity matrix rather than raw coordinates. The comparison below highlights the practical differences.

AlgorithmNumber of clustersCluster centersScalability
Affinity propagationDetermined by preferenceReal data pointsQuadratic in samples
k-means clusteringFixed in advanceComputed meansNear linear in samples
k-medoidsFixed in advanceReal data pointsQuadratic or worse
DBSCANDetermined by densityNo centersNear linear with indexing
Spectral clusteringUsually fixedNo explicit centersCostly eigendecomposition
Affinity propagation versus related clustering algorithms

Unlike density-based methods such as DBSCAN, affinity propagation assigns every point to a cluster and does not label outliers as noise. It also tends to favor clusters of roughly similar extent, so it handles elongated or nested shapes poorly compared with density or spectral approaches.

When to use affinity propagation

The algorithm is most valuable when representative examples matter and when the number of groups is genuinely unknown. The decision table below summarizes typical situations.

SituationRecommendationReason
Only pairwise similarities availableUse affinity propagationWorks directly on any similarity matrix
Need real exemplars for reviewUse affinity propagationCenters are actual items
More than about 10,000 pointsPrefer k-means or HDBSCANMemory grows with the square of samples
Noisy data with outliersPrefer DBSCAN or HDBSCANNo explicit noise label
Known, fixed cluster countPrefer k-means or k-medoidsSimpler and faster to tune
Choosing affinity propagation by situation

A useful property is that the similarity matrix need not be symmetric or metric. Similarities can come from edit distances between strings, alignment scores between protein sequences or learned embedding scores, which makes the method attractive in bioinformatics, document grouping and image retrieval. Sparse variants that keep only the strongest similarities per point reduce memory, although they may change the result.

Before clustering, teams should standardize features when using Euclidean similarities and check the cluster count over several preference values. Evaluation with the silhouette coefficient or domain review of the exemplars helps confirm that the chosen preference reflects real structure in the data.

Limitations and common mistakes

  • Quadratic complexity: a dense similarity matrix for 20,000 points already needs several gigabytes of memory.
  • Unscaled features: without feature scaling, one large-range feature dominates Euclidean similarities.
  • Ignoring nonconvergence: results from runs that hit the iteration limit can be arbitrary.
  • Treating the preference as minor: it is the main control of cluster count and needs deliberate tuning.
  • Assuming determinism: ties in similarities can produce different exemplars; small noise is often added to break them.

In simple terms

Affinity propagation sorts items into groups by letting them vote for a representative. Every item compares itself with every other item. Items then send short messages back and forth. One message says, “You would represent me well.” The reply says, “Others also support me, so choose me.”

After many rounds, a few items collect strong support. They become the leaders of the groups, and everyone else joins the leader that suits them best. Nobody has to decide the number of groups beforehand. A single setting makes items more or less eager to lead.

A practical example

A product analytics team at an online retailer has 4,000 customer support tickets and wants to find recurring complaint types without guessing their number. The team converts each ticket into a sentence embedding and computes cosine similarity between all pairs, producing a 4,000 by 4,000 matrix.

With the preference set to the median similarity and a damping factor of 0.8, affinity propagation converges in about 300 iterations and returns 37 exemplar tickets. Because each exemplar is a real ticket, support managers read the 37 examples directly and name the categories in a single meeting. Several small clusters reveal a previously unnoticed shipping label defect, which the team escalates to the warehouse.