Counterfactual Explanations via Riemannian Latent Space Traversal

Paraskevas Pegios, Aasa Feragen, Andreas Abildtrup Hansen, Georgios Arvanitidis

TL;DR

Standard counterfactual explanations generated via latent space optimization often produce unrealistic recourse recommendations because they ignore the nonlinear distortions introduced by generative decoders. By equipping the latent space with a Riemannian pull-back metric derived from both a well-calibrated stochastic decoder and the downstream classifier, this work ensures counterfactual trajectories curve naturally along the true data manifold rather than cutting through impossible, low-density regions.

What Problem Does This Paper Address?

Counterfactual explanations (CEs) show users how to minimally modify their features to alter a machine learning model's prediction (e.g., “How must my financial profile change to be approved for a loan?”). When optimizing directly in input space, gradient descent frequently yields nonsensical or off-manifold samples.

To keep explanations realistic, prior methods search the latent space of generative models like Variational Autoencoders (VAEs) or Normalizing Flows. However, latent spaces typically have simplified geometries (such as standard Gaussians), while the complex data distribution is encoded in the nonlinear decoder. Optimizing with naive Euclidean Stochastic Gradient Descent (SGD) in latent space ignores this distortion, taking straight-line paths that inadvertently jump across holes or data-sparse voids in the original manifold.

Methods

The authors propose Riemannian Latent Space Traversal, replacing Euclidean steps with Riemannian Stochastic Gradient Descent (RSGD):

  • Basic Pull-back Metric (RSGD): The latent space is endowed with a pull-back metric $M_Z(z)$ induced by a stochastic decoder $x = \mu(z) + \sigma(z) \odot \epsilon$. By modeling uncertainty $\sigma(z)$ with a Radial Basis Function (RBF) network calibrated to explode when moving away from training data, the expected pull-back metric penalizes paths entering low-density regions: $$M_Z(z) = J_\mu(z)^\top J_\mu(z) + J_\sigma(z)^\top J_\sigma(z)$$
  • Classifier-Guided Pull-back Metric (RSGD-C): Rather than treating the classifier independently from the manifold, the authors pull back the metric of the classifier’s penultimate representation space $H$ into input space ($M_X(x) = J_h(x)^\top J_h(x)$), and then pull it back through the generator into latent space ($\hat{M}_Z^c$). This accounts for both data topology and classifier decision boundary curvature.
  • RSGD Optimization: Counterfactual search follows normalized Riemannian gradients: $$z' = z - \eta \frac{r}{\|r\|_2}, \quad \text{where } r = M_Z^{-1}(z) \nabla_z \ell(c(\hat{g}(z)), y)$$

Datasets

  • Synthetic 2D Manifold in $\mathbb{R}^3$: A non-linear surface featuring a central hole to visualize whether optimization trajectories respect topological voids.
  • Adult Census Dataset: 13 mixed-type demographic and employment features predicting whether income exceeds \$50K/year, with immutable constraints on age, race, and sex.
  • Give Me Some Credit (GMC): 10 continuous features predicting financial distress within two years, with age marked as immutable.

Key Insights and Ideas

  • Manifold awareness without ad-hoc penalties: Standard latent CE methods require handcrafted proximity regularizers (fidelity constraints) to avoid straying from the factual point. The Riemannian metric acts as an intrinsic preconditioner, softly enforcing manifold adherence purely through geometric curvature.
  • Flows and Euclidean VAEs take invalid shortcuts: Even when latent representations look continuous, Euclidean lines cross unpopulated topological holes. In contrast, Riemannian paths follow the contour of high-density support.
  • Boundary smoothing via classifier pull-back: Incorporating the classifier’s hidden representation into the metric pulls the trajectory toward paths that traverse regions of smoother classification transitions.

Key Results

  • Avoiding Topological Holes: On the synthetic manifold, both Euclidean VAE and Normalizing Flow trajectories cut directly through the central data-sparse hole. RSGD and RSGD-C successfully navigate around it.
  • Closer to Real Data: On the Adult dataset without fidelity regularization ($\alpha = 0$), Riemannian traversal dramatically reduced distance to the closest training data point ($L_D$) from $0.20 \pm 0.29$ (SGD) down to $0.04 \pm 0.05$ (RSGD) and $0.04 \pm 0.07$ (RSGD-C) at 50 iterations.
  • Higher Fidelity to Factual Input: On Adult, RSGD reduced factual feature distortion ($L_2$ distance dropped from $2.22$ with SGD to $0.40$ with RSGD at 50 steps) and maintained lower violation rates of immutable attributes ($0.97$ vs. $1.06$).
  • Fidelity Across Confidence: While RSGD requires more gradient steps to achieve very high confidence thresholds, the counterfactuals it discovers consistently maintain lower manifold distance ($L_D$) and smaller perturbation magnitude ($L_2$) across all confidence levels.

Limitations and Future Work

  • Scalability of Decoder Uncertainty: Well-calibrated uncertainty networks (such as RBF-parameterized variances) currently struggle to scale beyond low- to moderate-dimensional latent representations.
  • Computational Cost: Tracking and inverting decoder and classifier Jacobians at each step increases memory and computational runtime compared to simple Euclidean SGD.
  • Future Directions: Scaling Riemannian trajectory concepts to modern generative backbones such as decoder ensembles, Laplacian autoencoders, and Riemannian Diffusion Models.

Summary updated

BibTeX
@inproceedings{pegios2024counterfactual,
  author = {Paraskevas Pegios and Aasa Feragen and Andreas Abildtrup Hansen and Georgios Arvanitidis},
  title = {{Counterfactual Explanations via Riemannian Latent Space Traversal}},
  booktitle = {NeurReps @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=wskfAkRK8M},
}
Figure