Inferensys

Glossary

Affinity Propagation

Affinity propagation is an unsupervised clustering algorithm that identifies representative exemplars among data points and forms clusters by iteratively passing real-valued messages between all pairs of samples until a stable set of clusters emerges.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
EXEMPLAR-BASED CLUSTERING

What is Affinity Propagation?

Affinity Propagation is a clustering algorithm that identifies representative data points, called exemplars, and forms clusters by iteratively exchanging real-valued messages between all pairs of data points until a stable set of exemplars and corresponding clusters emerges.

Affinity Propagation is a clustering algorithm that identifies exemplars—actual data points that serve as cluster centers—by passing responsibility and availability messages between all pairs of samples simultaneously. Unlike centroid-based methods such as K-Means, it does not require pre-specifying the number of clusters; instead, a preference parameter controls how many exemplars are selected, with higher values producing more clusters.

The algorithm converges when exemplar assignments stabilize across iterations, forming clusters around the most representative patient profiles. In patient stratification, Affinity Propagation excels at discovering clinically meaningful subgroups from molecular data without imposing arbitrary cluster counts, making it valuable for identifying natural disease subtypes where the underlying taxonomy is unknown.

EXEMPLAR-BASED CLUSTERING

Key Features of Affinity Propagation

Affinity Propagation distinguishes itself from centroid-based methods by identifying actual data points as cluster centers (exemplars) through a democratic message-passing process, eliminating the need to pre-specify the number of clusters.

01

Exemplar Identification

Unlike K-Means which creates synthetic centroids, Affinity Propagation selects real data points as cluster centers. These exemplars are the most representative members of their clusters. In patient stratification, an exemplar might be a patient whose molecular profile best represents a specific disease endotype, providing clinicians with a tangible reference case rather than an abstract average.

02

Message Passing Mechanism

The algorithm converges through two types of messages exchanged between data points:

  • Responsibility (r): Sent from point i to candidate exemplar k, quantifying how well-suited k is to serve as the exemplar for i, accounting for other potential exemplars.
  • Availability (a): Sent from candidate exemplar k to point i, reflecting the accumulated evidence that k would be a good exemplar, considering support from other points. This iterative process continues until cluster assignments stabilize.
03

Preference Parameter

The preference value s(k,k) is the single most critical hyperparameter. It represents the a priori suitability of point k to serve as an exemplar. A higher preference leads to more clusters; a lower preference yields fewer. A common heuristic is to set all preferences to the median of the input similarities, which typically produces a moderate number of clusters. This parameter effectively controls the granularity of patient subgroup discovery.

04

Similarity Matrix Input

Affinity Propagation operates on a similarity matrix s(i,k) rather than raw feature vectors. The similarity s(i,k) indicates how well point k is suited to be the exemplar for point i. Common choices include:

  • Negative squared Euclidean distance: s(i,k) = -||x_i - x_k||²
  • Cosine similarity for high-dimensional omics data
  • Correlation-based measures for gene expression profiles This abstraction allows the algorithm to cluster any data type where pairwise similarities can be defined.
05

Damping Factor for Convergence

To prevent numerical oscillations during message passing, a damping factor λ (typically between 0.5 and 0.9) is applied. Each new message is a weighted combination of the previous value and the newly computed value:

  • r_new = λ·r_old + (1-λ)·r_current
  • a_new = λ·a_old + (1-λ)·a_current Higher damping values increase stability but slow convergence. This is essential when clustering noisy clinical data where oscillations can prevent termination.
06

No Predefined Cluster Count

A defining advantage for exploratory biomarker discovery: the algorithm automatically determines the number of clusters based on the data structure and preference parameter. This is critical when the true number of disease subtypes is unknown. Unlike K-Means, which forces a predetermined k, Affinity Propagation lets the data reveal its natural granularity, making it ideal for unbiased endotype discovery in heterogeneous patient populations.

ALGORITHM SELECTION GUIDE

Affinity Propagation vs. Other Clustering Algorithms

A technical comparison of Affinity Propagation against K-Means, DBSCAN, and Gaussian Mixture Models for patient stratification and biomarker discovery workflows.

FeatureAffinity PropagationK-MeansDBSCANGaussian Mixture Models

Cluster Count Specification

Not required; algorithm determines optimal number automatically

Must be pre-specified by user (k)

Not required; determined by density parameters

Must be pre-specified by user

Cluster Shape Assumption

Arbitrary; exemplar-based

Spherical, isotropic clusters only

Arbitrary; density-connected regions

Elliptical; soft probabilistic boundaries

Outlier Handling

Outliers may form singleton clusters or be absorbed

All points assigned to nearest centroid; no outlier detection

Explicitly identifies outliers as noise points

Assigns low probability membership; no explicit outlier rejection

Input Requirement

Similarity matrix (pairwise affinities)

Feature vectors in Euclidean space

Feature vectors with distance metric

Feature vectors assumed from Gaussian distributions

Soft/Hard Assignment

Hard assignment to single exemplar

Hard assignment to single centroid

Hard assignment; noise points unassigned

Soft assignment; probabilistic membership across clusters

Computational Complexity

O(N²T) where N=samples, T=iterations; memory-intensive

O(NkI) where I=iterations; linear in samples

O(N log N) with spatial indexing; efficient on large data

O(Nk²d) per iteration; covariance matrix estimation costly

Deterministic Output

Deterministic given fixed preference and damping values

Non-deterministic; depends on centroid initialization

Deterministic given fixed minPts and epsilon

Non-deterministic; depends on initialization and EM convergence

Preference Parameter Sensitivity

High; preference value directly controls resulting cluster count

Not applicable

Not applicable; epsilon and minPts control granularity

Not applicable

AFFINITY PROPAGATION CLARIFIED

Frequently Asked Questions

Addressing the most common technical inquiries regarding the mechanics, parameterization, and application of Affinity Propagation for identifying clinically meaningful patient subgroups.

Affinity Propagation is a graph-based clustering algorithm that identifies representative data points, called exemplars, and forms clusters by iteratively exchanging real-valued messages between all pairs of data points until a high-quality set of exemplars and corresponding clusters emerges. Unlike centroid-based methods like K-Means, it does not require pre-specifying the number of clusters.

It operates by viewing each data point as a node in a network. The algorithm simultaneously considers all points as potential exemplars. Two types of messages are passed:

  • Responsibility (r(i, k)): Sent from data point i to candidate exemplar k, quantifying how well-suited k is to serve as the exemplar for i, accounting for other potential exemplars.
  • Availability (a(i, k)): Sent from candidate exemplar k to data point i, reflecting the accumulated evidence that i should choose k as its exemplar, considering the support from other points.

These messages are updated iteratively using specific formulas until convergence, typically when the exemplar decisions remain stable for a set number of iterations. The final exemplars are the points for which the sum of responsibility and availability is positive.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.