Abstract
Learning models whose predictions are invariant under multiple environments is a promising approach for out-of-distribution generalization. Such models are trained to extract features $X_{\text{inv}}$ where the conditional distribution $Y \mid X_{\text{inv}}$ of the label given the extracted features does not change across environments. Invariant models are also supposed to generalize to shifts in the marginal distribution $p(X_{\text{inv}})$ of the extracted features $X_{\text{inv}}$, a type of shift we call an invariant covariate shift. However, we show that proposed methods for learning invariant models underperform under invariant covariate shift, either failing to learn invariant models---even for data generated from simple and well-studied linear-Gaussian models---or having poor finite-sample performance. To alleviate these problems, we propose weighted risk invariance (WRI). Our framework is based on imposing invariance of the loss across environments subject to appropriate reweightings of the training examples. We show that WRI provably learns invariant models, i.e. discards spurious correlations, in linear-Gaussian settings. We propose a practical algorithm to implement WRI by learning the density $p(X_{\text{inv}})$ and the model parameters simultaneously, and we demonstrate empirically that WRI outperforms previous invariant learning methods under invariant covariate shift.
Introduction
The primary goal of Domain Generalization (DG) is to build models that generalize to unseen test data by identifying relationships that remain constant across different training environments. For example, in medical imaging, the relationship between a tumor's shape and its malignancy should be invariant, while lighting or camera type represents a "spurious" correlation.
Current state-of-the-art methods like Invariant Risk Minimization (IRM) and Risk Extrapolation (REx) attempt to find features where the prediction risk is equal across all training environments. However, we identify a critical failure mode: invariant covariate shift. This occurs when the marginal distribution of the invariant features changes across domains. If Environment A contains mostly "easy" examples while Environment B contains "hard" ones, an optimal model should have a higher risk in Environment B. Forcing risks to be equal pushes the model to exploit spurious correlations to "balance" the losses, leading to poor generalization.
Methodology: Weighted Risk Invariance (WRI)
We propose Weighted Risk Invariance (WRI) to address this. Instead of forcing raw risks to be equal, WRI ensures that reweighted risks are invariant across environments.
Density-Based Reweighting
Weights are derived from the density of the invariant features $p(X_{\text{inv}})$. By weighting examples by their inverse density, the model effectively aligns distributions across environments before checking for risk invariance. This prevents the model from being misled by varying difficulty levels or "hard examples" across domains.
Alternating Minimization
Since invariant features are not known upfront, the algorithm alternates between two steps:
- Predictor Step: Update the model to minimize the WRI objective, which includes the standard loss plus a penalty for variance in reweighted risks.
- Density Step: Update environment-specific density models to better estimate the distribution of the current feature representation.
The objective includes a negative log-likelihood penalty to ensure learned densities have high entropy and broad support, preventing the model from collapsing into trivial solutions.
Experimental Evaluation
WRI was evaluated on synthetic linear-Gaussian models and real-world benchmarks from DomainBed, including PACS, OfficeHome, and DomainNet.
Key Results
- Synthetic Benchmarks: On the HCMNIST-CS dataset, which features both color bias and feature shift, WRI achieved ~74.7% accuracy. In contrast, IRM and VREx performance dropped to ~61.3% and ~58.2%, respectively—barely better than a model using only spurious colors.
- Real-World Data: On the DomainNet benchmark, WRI outperformed other invariant learning baselines and matched or exceeded non-causal baselines like CORAL and Mixup.
- OOD Detection: WRI's learned densities proved to be significantly better Out-of-Distribution (OOD) detectors than standard model confidence (max softmax score), showing higher AUROC scores across the board.
Discussion and Conclusion
The core insight of this work is that risk invariance is only a valid proxy for finding invariant features if feature distributions are identical. WRI provides a robust alternative by incorporating density weighting to handle invariant covariate shift. While the alternating minimization scheme is complex, it effectively handles "hard" environments that break traditional methods. Future work could integrate more sophisticated generative models like Normalizing Flows or Diffusion models to improve high-dimensional density estimation within the WRI framework.
Summary updated