Counterfactual inference asks how an observed outcome might have differed under different circumstances, such as whether a patient would have recovered had they received a different treatment. Such questions arise whenever decisions depend on the outcomes of alternatives that were not observed. Answering counterfactual queries generally requires knowledge of the underlying causal structure, which is often unavailable in practice. A common approach is therefore to first estimate the causal graph from observational data and then perform counterfactual inference. However, errors in the estimated causal graph can propagate to downstream counterfactual predictions. To address this challenge, we introduce the Counterfactual Graph Neural Process (CFGNP), an end-to-end approach that answers counterfactual queries directly from observational data without first estimating a causal graph. CFGNP uses Graph Neural Networks (GNNs) to exploit the dual-graph structure by restricting cross-world message passing to corresponding factual--counterfactual variables. Across synthetic and image-based benchmarks, CFGNP achieves stronger predictive performance than existing approaches, including on the German Loan benchmark, where it reduces MSE from 4.51×10−2 to 0.19×10−2. Furthermore, on synthetic causal graphs, a model trained only on 10-node graphs maintains strong predictive performance on graphs with up to 30 nodes, without retraining.
Figures & tables
Figure 1: Overview of the task solved by CFGNP. Unknown variables are in light grey and known variables in dark grey. Blue edges represent missing knowledge about the causal graph. The counterfactual is predicted based on the counterfactual query and additional observational samples.
Figure 2: Example of the dual graph for a counterfactual query with a causal graph of four nodes. Light grey nodes are unknown.
Figure 3: Overview of CFGNP. Observational samples are first aggregated into node-wise context representations, which are combined with the observed factual unit. Message passing between factual and counterfactual unit then produces parameters of the counterfactual predictive distribution.
Dataset
Variant
BGM
VACA
CFM
CFGNP (Ours)
MSE ↓
Triangle
LIN
(3.71±0.08)×10−3
(23.52±1.83)×10−2
(3.32±0.05)×10−3
(2.59±2.13)×10−7
NLIN
(4.78±0.97)×10−6
(13.24±1.93)×10−2
(1.35±0.24)×10−5
(2.14±0.34)×10−7
NADD
(1.80±1.80)×10−6
(22.50±2.61)×10−2
(1.54±0.40)×10−6
(2.81±1.11)×10−7
M-shape
LIN
(1.46±0.40)×10−5
(12.83±0.69)×10−2
(2.73±0.17)×10−5
(3.60±7.00)×10−5
NLIN
(1.97±0.50)×10−5
(16.26±0.95)×10−2
(4.67±1.14)×10−5
(2.50±0.47)×10−6
Table 1: Mean MSE ± standard deviation achieved by BGM, VACA, CFM, and CFGNP (ours) across the Triangle, M-shape, and German Loan datasets. Lower values indicate better performance. Best scores are marked in bold.
Figure 4: Performance (MSE) of models with regard to size of the causal graph. Models are compared on causal graphs with Linear (1.), Sum-sine (2.), Log-sum-exp (3.), Sqrt-sum (4.), and Sum-sqrt (5.) structural equations. MSE mean over distinct causal graphs. Vertical lines show 25th and 75th quantiles.
Feature
Metric
CFGNP (Ours)
DeepBC
VCI
Sex
Accuracy ↑
0.8452±0.0608
0.8222±0.1220
0.5173±0.0296
ROC-AUC ↑
0.9155±0.0540
0.9204±0.0752
0.5238±0.0122
Age
MAE ↓
2.7136±0.7326
10.8750±0.8732
66.8172±62.1769
AP/PA
Accuracy ↑
0.9664±0.0140
0.9572±0.0552
0.8597±0.0000
ROC-AUC ↑
0.9787±0.0136
0.9658±0.0584
0.5741±0.0342
Disease
Accuracy ↑
0.8830±0.0368
0.8720±0.0240
0.8548±0.0667
Table 2: Performance of CFGNP, VCI, and DeepBC on the CheXpert dataset. MAE is reported for the continuous feature, while accuracy and ROC-AUC are reported for categorical features. Arrows indicate whether higher or lower values are preferred. Best values marked in bold.
Feature
Metric
OOD Sex
OOD Age
OOD AP/PA
OOD Disease
Sex
Accuracy ↑
0.9516±0.0108
0.9634±0.0157
0.9692±0.0084
0.9627±0.0029
ROC-AUC ↑
0.9927±0.0037
0.9941±0.0039
0.9965±0.0017
0.9964±0.0005
Age
MAE ↓
10.7037±1.5283
11.5291±0.0950
9.2965±1.9205
8.1875±0.4218
AP/PA
Accuracy ↑
0.9917±0.0069
0.9904±0.0085
0.9995±0.0008
0.9996±0.0005
ROC-AUC ↑
0.9998±0.0004
0.9998±0.0003
1.0000±0.0000
1.0000±0.0000
Disease
Accuracy ↑
0.6560±0.0176
0.6678±0.0119
0.6690±0.0073
0.6579±0.0212
Table 3: OOD generalization on CheXpert. Each column indicates the feature excluded during training; evaluation is performed on the full test set containing all features. Best results in bold.
Appendix figures & tables21 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 5: The training curves of the classifiers and regression models used for the classification of the generated CheXpert images.
Figure 6: The causal graph of the triangle dataset. The causal graph has three nodes and three edges.
Figure 7: The causal graph of the M-shape data. It has five nodes and four edges.
Figure 8: The causal graph of the German loan data. The nodes are real attributes used for German credit rating system. they are connected based on the real-world connections.
Figure 9: Example counterfactual of a CheXpert image. Observed factual unit (left) has age 80 and the intervention value is 58 in the counterfactual (middle). The difference between the pixels is on the right.
Figure 10: Example counterfactual of a CheXpert image. Observed factual unit (left) has AP/PA as 1 and the intervention value is 0 in the counterfactual (middle). The difference between the pixels is on the right.
Figure 11: An image where the observed factual unit of age is 74 and the counterfactual intervention is 85 .
Figure 12: An image where the observed factual unit of age is 65 and the counterfactual intervention is 72 . The model was trained with OOD index sex.
Figure 13: An image where the observed factual unit of AP/PA is 0 and the counterfactual intervention is 1. The model was trained with OOD index sex.
Figure 14: An image where the observed factual unit is age 30 and the counterfactual intervention is age 52 . The model was trained with OOD index age.
Figure 15: An image where the observed factual unit of sex is 1 and the counterfactual intervention is 0. The model was trained with OOD index age.
Figure 16: n image where the observed factual unit of sex is 0 and the counterfactual intervention is 1. The model was trained with OOD index AP/PA.
Figure 17: An image where the observed factual unit is age 26 and the counterfactual intervention is age 64 . The model was trained with OOD index AP/PA.
Figure 18: An image where the observed factual unit of AP/PA is 0 and the counterfactual intervention is 1. The model was trained with OOD index disease.
Figure 19: An image where the observed factual unit is age 67 and the counterfactual intervention is age 37 . The model was trained with OOD index disease.
Figure 20: Performance (MSE) of models with regard to the size of the causal graph for sqrt-sum (left) and sum-sqrt (right) structural equations. The MSE is averaged over distinct causal graphs. Vertical lines show the 25th and 75th quantiles.
Figure 21: Performance (MSE) of models with regard to the size of the causal graph for geometric-mean (left) and sum-tanh (right) structural equations. The MSE is averaged over distinct causal graphs. Vertical lines show the 25th and 75th quantiles.
Dataset
CFGNP (Ours)
BGM
CFM
VACA
German Loan
31.5719s
5.2537s
115.1188s
5.3015s
Triangle LIN
8.1853s
2.9878s
26.3716s
3.7258s
Triangle NLIN
7.9175s
3.0323s
26.2195s
3.7365s
Triangle NADD
7.9084s
3.0364s
26.3470s
3.7963s
M-Shape LIN
12.9088s
3.3865s
41.5352s
3.8361s
M-Shape NLIN
12.9274s
3.3941s
41.8969s
3.8385s
Appendix
Table 4: Runtime comparison of CFGNP (Ours), BGM, CFM, and VACA across (semi-) synthetic datasets. The datasets were used throughout the results section.
Dataset
CFGNP (Ours)
VCI
DeepBC
CheXpert
47.7369s
3.8506s
6032.4057s
Appendix
Table 5: Runtime comparison of CFGNP (Ours), VCI, and DeepBC on the CheXpert dataset.
Figure 22: KL divergences for the two-node experiments across different numbers Nobs of observations supplied to each sample. Vertical lines show the 10th and 90th quantiles. Results are shown for the identifiable (left) and non-identifiable (right) settings.
Dataset
Variant
CFGNP (Ours)
Transformer
MSE ↓
Triangle
LIN
(2.59±2.13)×10−7
(8.33±0.25)×10−4
NLIN
(2.14±0.34)×10−7
(8.37±0.46)×10−4
NADD
(2.81±1.11)×10−7
(5.02±0.03)×10−4
M-shape
LIN
(3.60±7.00)×10−5
(4.79±0.12)×10−3
NLIN
(2.50±0.47)×10−6
(6.04±0.19)×10−3
Appendix
Table 6: Mean MSE ± standard deviation of the full CFGNP model and the Transformer ablation across the Triangle, M-shape, and German Loan datasets. Lower values indicate better performance. Best scores are marked in bold.