NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Contrastive Mixture of Posteriors for Counterfactual Inference, Data Integration and Fairness

Adam Foster, Árpi Vezér, Craig A Glastonbury, Páidí Creed, Sam Abujudeh, Aaron Sim

TL;DR

The authors introduce Contrastive Mixture of Posteriors (CoMP), a novel method for training Conditional Variational Autoencoders (CVAEs) that forces latent representations to be independent of a condition variable (like experimental batch or gender). By using a contrastive-inspired penalty based on mixtures of the variational posteriors themselves, CoMP achieves state-of-the-art performance in batch effect correction, counterfactual inference in single-cell genomics, and fair representation learning without requiring external discrepancy measures.

What Problem Does This Paper Address?

In fields like computational biology and machine learning fairness, we often want to learn a low-dimensional representation of data ($z$) that is completely stripped of a specific confounding or sensitive condition variable ($c$).

Consider two major challenges in single-cell genomics:

  1. Data Integration / Batch Correction: Combining datasets from different labs or technologies. Technical variations (batches) obscure the true underlying biology. We want to align the datasets so that cells group by biological type, not by the lab they came from.
  2. Counterfactual Inference: Predicting how a healthy control cell would respond if treated with a drug. To do this via an "encode-swap-decode" approach, the latent space must perfectly align control and treated cells so that the drug's effect is isolated entirely to the decoder.

Standard CVAEs often fail here; they frequently preserve the condition information, leading to distinct, unaligned clusters in the latent space. Existing fixes rely on Maximum Mean Discrepancy (MMD) penalties, which require tedious hyperparameter tuning and suffer from vanishing gradients when clusters are far apart.

Figure 1. Latent representations of a single-cell gene expression dataset under two conditions: stimulated (red) and not stimulated (black). Full details in Section 6.2. From fully disjointed (VAE) to a well-mixed pair of distributions (CoMP).

Methods

CoMP addresses this by enforcing marginal independence ($z \perp \!\!\! \perp c$) directly through the model's own encoder distributions. Inspired by contrastive learning, the CoMP penalty does two things simultaneously:

  • It encourages latent representations from different conditions to overlap (minimizing misalignment).
  • It ensures representations from the same condition remain spread out, preventing the latent space from collapsing into a single tight cluster.

Mathematically, the authors approximate the intractable marginal distributions ($q(z|c)$ and $q(z|\neg c)$) using mixtures of the variational posteriors within each training batch. They prove that this penalty acts as a stochastic upper bound on a weighted sum of Kullback-Leibler (KL) divergences.

Crucially, unlike MMD, CoMP gradients are self-normalizing. This means that even if two condition clusters are far apart in the latent space, CoMP still provides a strong gradient signal to pull them together, making it highly effective at aligning complex global structures.

Datasets

The authors evaluate CoMP across four diverse datasets:

  1. Tumour / Cancer Cell Line: Bulk gene expression profiles of 12,236 tumours and 1,249 cell lines across 39 cancer types, aiming to strip out the "cell line vs. tumour" condition.
  2. Stimulated vs. Untreated Single-Cell PBMCs: 14,053 single-cell RNA-seq profiles of peripheral blood mononuclear cells, where half were stimulated with interferon-beta (IFN-$\beta$).
  3. Single-Cell RNA-Seq Data Integration: 16,077 PBMC cells processed using two different library preparation protocols (3-prime V2 vs. 5-prime) to evaluate batch correction.
  4. UCI Adult Income Dataset: A standard fairness benchmark containing census data where the goal is to predict income while remaining independent of gender.

Key Insights and Ideas

  • Self-Normalizing Gradients: MMD penalties use kernels where gradients drop to zero if clusters are far apart. CoMP's formulation ensures that distant clusters still experience a strong pulling force, which is vital for aligning highly disjointed datasets.
  • The Power of Non-Gaussianity: While standard VAEs assume a Gaussian prior, the authors prove that a non-Gaussian latent distribution is actually a necessary condition for counterfactual identifiability. It breaks the rotational symmetry inherent in isotropic Gaussians, ensuring that counterfactual predictions are unique and identifiable from unpaired data.

Key Results

CoMP consistently achieves state-of-the-art results across all tasks, balancing perfect alignment with the retention of downstream biological information.

Tumour / Cell Line Alignment

CoMP dramatically outperformed baseline models on local mixing metrics (Silhouette score and kBET), achieving a Silhouette score of 0.023 (where closer to 0 is better mixing) compared to trVAE's 0.096 and CVAE's 0.554, while maintaining high cancer-type classification accuracy (57.9%).

Quantitative results on the Tumour / Cell Line dataset.

Counterfactual Prediction

When predicting how cells respond to IFN-$\beta$ stimulation, CoMP accurately reconstructed the expression alterations of highly variable genes, avoiding the systematic underestimation seen in baseline models.

Figure 4. 2D UMAP projection of posterior means of zi. A: Tumour / Cell Line data. Tumours (blue) and cell lines (orange). B: Stimulated and control PBMC scRNA-seq data with colours highlighting immune cell types (top) and the IFN-β condition (bottom). C: PBMC scRNA-seq data processed using different protocols, with colours indicating immune cell type (top) and 5-prime or 3-prime V2 library construction protocol (bottom); D: UCI Adult Income dataset, coloured by gender with male (blue) and female (yellow).

Single-Cell Data Integration

For batch correction, CoMP achieved a kBET score of 0.164 and an m-kBET of 0.120, significantly outperforming popular domain-specific tools like Seurat CCA and Harmony.

Limitations and Future Work

While CoMP delivers excellent empirical results, the formal proof for counterfactual identifiability (Theorem 2) currently assumes a linear decoder. In practice, the authors used non-linear decoders (shallow MLPs) with great success, but extending the theoretical guarantees to fully non-linear neural network decoders remains an open area for future work. Additionally, care must be taken with the penalty weight ($\gamma$) to avoid "over-correcting" true biological differences between populations.

Summary updated

BibTeX
@inproceedings{foster2022contrastive,
  author = {Adam Foster and Árpi Vezér and Craig A Glastonbury and Páidí Creed and Sam Abujudeh and Aaron Sim},
  title = {{Contrastive Mixture of Posteriors for Counterfactual Inference, Data Integration and Fairness}},
  booktitle = {International Conference on Machine Learning},
  year = {2022},
  url = {https://openreview.net/forum?id=MZZRqq_KyS},
}
Figure