Counterfactual Maps: Theory & Applications
- Counterfactual Maps are mathematical constructs that define the minimally sufficient changes to inputs required to alter model outcomes in causal inference and machine learning.
- They employ techniques such as optimal transport, neural flows, and piecewise-constant methods to ensure properties like uniqueness, monotonicity, and model consistency.
- Algorithmic strategies enable fast recourse discovery across diverse applications, though challenges remain in scalability, interpretability, and extending methods to complex outputs.
A counterfactual map is a mathematical construct or visual explanation that, given a factual instance and a model, prescribes the minimally sufficient changes to inputs required to alter the model’s output to a specified counterfactual state. The form, theoretical guarantees, and implementation of counterfactual maps depend intricately on the context: causal inference, interpretable machine learning, visual explanation in deep networks, or geometric recourse analysis for structured models. Empirical and theoretical contributions over the past decade have resulted in highly technical toolkits for constructing, interpreting, and algorithmically optimizing these maps.
1. Mathematical Formulations and Core Definitions
Counterfactual maps are formalized differently across contexts.
- Causal inference (SCM perspective): For an endogenous variable with parents $\PA$ and exogenous noise in a structural causal model $X = f(\PA, U)$, the counterfactual map for an intervention $\PA \rightarrow \PA^*$ is
$T^*(\pa^*, \pa, x) = f( \pa^*, f^{-1}(\pa, x) ),$
which deterministically pushes $(\pa, x)$ to its counterfactual realization under new $\pa^*$ (Ribeiro et al., 9 Oct 2025).
- Piecewise-constant predictors (tree ensembles): For piecewise constant on hyperrectangles , a counterfactual map for class $\PA$0 is
$\PA$1
where $\PA$2 is the chosen norm to $\PA$3. The output $\PA$4 is the nearest point in $\PA$5 (Khouna et al., 9 Feb 2026).
- Interpretable deep vision: For a given input $\PA$6 and desired class $\PA$7,
$\PA$8
with $\PA$9 constrained for minimality and the map generator conditioned on 0 such that the classifier’s output flips accordingly (Oh et al., 2020, Mertes et al., 2020).
In all cases, a counterfactual map is not merely a single point but defines a function or operator mapping factual instances to counterfactuals according to a model and target specification.
2. Theoretical Guarantees and Properties
The identifiability, monotonicity, and representational uniqueness of counterfactual maps depend on structural assumptions.
- Uniqueness via Optimal Transport (OT): In Markovian SCMs—i.e., no unobserved confounding and invertible mechanisms—the dynamic optimal transport map 1 exists, is unique, and is (vector-)monotone. The induced counterfactual map 2 is strictly monotone and rank-preserving, avoiding pathologies such as defiers (Ribeiro et al., 9 Oct 2025).
- Counterfactual Maps as Deterministic Transports: In the context of measure coupling, three canonical maps arise: cyclically monotone (gradient of convex potential/OT), quantile-preserving, and triangular-monotone (Knothe–Rosenblatt). Path-independence and triangular comonotonicity are required for SCM-generated counterfactual maps to coincide with OT or quantile-based matches (Lara et al., 19 Sep 2025).
- Compositionality and Identity: SCM-derived counterfactual maps satisfy 3, path-independence 4, and invertibility 5 (Lara et al., 19 Sep 2025).
Significance: These properties enable global reasoning about recourse and explainability, ensuring that counterfactuals are consistent, compositional, and unambiguous in the presence of sufficient model and data regularity.
3. Algorithmic Construction and Optimization
The construction of counterfactual maps is highly context-dependent.
- Piecewise-constant Models (Tree Ensembles):
- Hyperrectangle partitioning: Extract all distinct, labeled hyperrectangles from the ensemble (Born-Again Trees).
- Indexing: Build volumetric k-d trees over all regions for fast, amortized nearest-region queries.
- Branch-and-bound search: For a query 6, perform optimal nearest-region search to determine the minimal sufficient change for class recourse, with explicit optimality certificates (Khouna et al., 9 Feb 2026).
- Causal Models (Flow-Matching):
- Fit continuous-time neural flows matching a fixed prior to observed conditionals given parent 7.
- At inference, abduce the value 8 given 9 and predict $X = f(\PA, U)$0 under intervention $X = f(\PA, U)$1 via two ODE passes (Ribeiro et al., 9 Oct 2025).
- Engineering Visual Counterfactual Maps:
- Deep Structurally-Constrained Generators: Such as BIN’s conditional GANs with shared classifier encoders (Oh et al., 2020), CycleGANs with classifier-steering losses (GANterfactual) (Mertes et al., 2020), or latent diffusion models with classifier/distance guidance and local patch-wise refinement (DocVCE) (Saifullah et al., 6 Aug 2025).
- Saliency-based optimization for time series: Perturbation masks learned with composite sparsity, validity, and temporal regularization objectives (M-CELS) (Li et al., 2024).
- Attribution combination strategies: Discriminant explanations as fast, closed-form, non-iterative map combinations (SCOUT) (Wang et al., 2020).
A summary table of principal algorithmic strategies:
| Method Context | Map Construction | Optimality/Scope |
|---|---|---|
| Tree ensembles (Khouna et al., 9 Feb 2026) | Nearest-region (Voronoi cell) | Global, exact |
| SCM via OT (Ribeiro et al., 9 Oct 2025, Lara et al., 19 Sep 2025) | Neural flows/transport maps | Global, unique (settings) |
| Counterfactual GANs (Oh et al., 2020, Mertes et al., 2020) | Conditional generative mapping | Model-consistent, learned |
| Saliency approaches (Li et al., 2024, Wang et al., 2020) | Learned/re-weighted masks | Local, generally fast |
4. Extensions: Temporal, Spatial, and Multi-Agent Settings
Counterfactual maps have been extended to accommodate highly structured or dynamical systems.
- Spatio-temporal graphical models: A spatio-temporal Bayesian network defines random variables $X = f(\PA, U)$2 over spatial ($X = f(\PA, U)$3) and temporal ($X = f(\PA, U)$4) indices, with edges encoding spatial, temporal, and cross-lag dependencies (Kang et al., 2024). Counterfactual queries involve dynamic $X = f(\PA, U)$5-computation and adjustment for spatio-temporal confounding, leading to counterfactual maps $X = f(\PA, U)$6 for visualization or policy analysis.
- Time series classification: M-CELS computes a mask $X = f(\PA, U)$7 to identify which spatiotemporal points, if swapped with a nearest unlike neighbor, are minimally sufficient for a class change, balancing validity, proximity, and sparsity (Li et al., 2024).
- Multi-agent game-theoretic systems: The counterfactual map is a function $X = f(\PA, U)$8, mapping belief $X = f(\PA, U)$9 about agents' types and an intervention in rules $\PA \rightarrow \PA^*$0 to a predicted equilibrium outcome distribution, subject to (possibly relaxed) rationality and identification conditions (Peysakhovich et al., 2019).
5. Geometric and Path-Based Perspectives
Recent work elevates counterfactual maps from pointwise recourse to the geometry of paths.
- Explanatory Multiverse: Counterfactual paths $\PA \rightarrow \PA^*$1 define trajectories in feature space from $\PA \rightarrow \PA^*$2 (factual) to $\PA \rightarrow \PA^*$3 (counterfactual). The multiverse is the set of all such admissible paths (Sokol et al., 2023).
- Metrics on Paths: Affinity, path-length, branching/divergence points, and opportunity potential $\PA \rightarrow \PA^*$4 quantify the structure and diversity of recourse trajectories. The latter encodes how well an initial counterfactual path remains compatible with alternative targets, trading path length against downstream flexibility.
- Graph-based implementations: For discrete data, counterfactuals are extracted as shortest paths on a $\PA \rightarrow \PA^*$5-nearest neighbor directed graph, with branching and opportunity potential computed by walking along the graph path and measuring distance evolution to alternative targets.
Significance: This perspective supports recourse planning beyond minimal perturbations, facilitates the exploration of competing (and potentially degenerate) recourse solutions, and endows users with agency over which counterfactual journey to select in applications.
6. Empirical Validation and Applications
Counterfactual maps support tasks including visualization interpretation, model debugging, policy analysis, and recourse in clinical, tabular, and high-dimensional domains:
- Tree ensembles: Millisecond-level exact recourse discovery and visualization of global recourse regions on high-stakes tabular datasets (e.g., recidivism, FICO scoring) (Khouna et al., 9 Feb 2026).
- Medical imaging: GANterfactual and BIN yield model-consistent visual explanations that outperform saliency methods on interpretability, trust, and self-efficacy in controlled user studies (Mertes et al., 2020, Oh et al., 2020).
- Document analysis: DocVCE delivers valid, realistic, and crisp counterfactual maps localizing semantic fields (headers, document numbers) critical for class flips in document classification (Saifullah et al., 6 Aug 2025).
- Time series and spatio-temporal policy analysis: M-CELS produces minimal, temporally coherent counterfactuals in multivariate time series classification (Li et al., 2024); graphical counterfactual maps support dynamic treatment effect estimation and policy visualization in spatio-temporal settings (Kang et al., 2024).
- Multi-agent market design: RMAC quantifies the robustness and identifiability of counterfactual inference under weak identification and equilibrium multiplicity (Peysakhovich et al., 2019).
7. Limitations, Open Problems, and Research Directions
- Non-uniqueness: Without strong structural or causal assumptions, deterministic counterfactual maps may not be identifiable; infinite families of transports exist between marginals (Lara et al., 19 Sep 2025).
- Complexity: While tree ensemble maps yield sublinear query complexity (Khouna et al., 9 Feb 2026), scaling generative approaches with high-dimensional, non-axis-aligned regions or many classes remains challenging.
- Compatibility and Path-independence: Only certain classes of SCM and transport maps guarantee path-independence and compositionally consistent counterfactuals (Lara et al., 19 Sep 2025, Ribeiro et al., 9 Oct 2025).
- Extensions to highly structured outputs: Research continues in higher-dimensional, correlated outputs (e.g., graphs, videos), and recourse planning in discrete and hybrid spaces.
- Visualization and human factors: Interpreting and communicating the geometry of counterfactual maps and their path-based properties—in particular, opportunity potential and branching points—remains an active intersection of human-computer interaction, visualization, and XAI research (Sokol et al., 2023, Kaul et al., 2021).
Counterfactual maps thus constitute a rigorous, model-aware foundation for recourse, causal inference, and interpretable learning, with a rich interplay among geometry, optimization, causal semantics, and practical usability across domains.