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.
Glossary
Affinity Propagation

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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
| Feature | Affinity Propagation | K-Means | DBSCAN | Gaussian 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 |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
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
ito candidate exemplark, quantifying how well-suitedkis to serve as the exemplar fori, accounting for other potential exemplars. - Availability (a(i, k)): Sent from candidate exemplar
kto data pointi, reflecting the accumulated evidence thatishould choosekas 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.
Related Terms
Explore the core algorithms and validation techniques essential for identifying clinically meaningful patient subgroups using Affinity Propagation and related unsupervised learning methods.
Exemplar-Based Clustering
Unlike centroid-based methods like K-Means, Affinity Propagation identifies actual data points as exemplars to represent clusters. This is biologically intuitive for patient stratification, where an archetypal patient profile is more interpretable than a mathematical centroid. The algorithm simultaneously considers all points as potential exemplars, making it less sensitive to initialization but computationally intensive for large cohorts.
Preference Parameter Tuning
The preference value, set on the diagonal of the similarity matrix, is the critical hyperparameter. It controls how many clusters are formed:
- Higher preference: Each point is more likely to become an exemplar, resulting in many fine-grained clusters.
- Lower preference: Fewer points are chosen as exemplars, producing broader groupings. In biomarker discovery, this is often tuned using the Silhouette Score to balance granularity with clinical utility.
Damping Factor for Convergence
To prevent numerical oscillations during message passing, a damping factor (λ) between 0.5 and 1 is applied. This blends new messages with old ones:
new_message = λ * old_message + (1 - λ) * calculated_message
Higher damping ensures stability but slows convergence. In genomic datasets with high noise, a damping factor of 0.9 is often required to achieve a stable molecular taxonomy.
Similarity Matrix Construction
Affinity Propagation operates on a similarity matrix s(i,k) that quantifies how well point k serves as an exemplar for point i. Common metrics include:
- Negative Euclidean Distance: Standard for continuous clinical variables.
- Pearson Correlation: Robust for gene expression data.
- Jaccard Index: For binary mutation profiles. The choice of metric directly shapes the resulting patient similarity networks and downstream endotype discovery.
Comparison to Other Methods
Affinity Propagation vs. K-Means: Does not require pre-specifying the number of clusters and is not sensitive to initial centroid placement. Affinity Propagation vs. DBSCAN: Does not require a density threshold (epsilon) and can handle non-globular clusters, but DBSCAN is better at explicitly identifying outlier patients as noise. Affinity Propagation vs. Hierarchical Clustering: Provides a flat, non-nested partition with exemplars, whereas hierarchical methods produce a dendrogram useful for visualizing nested disease subtypes.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us