# Invariant Risk Minimization

Invariant risk minimization learns representations that generalize to new environments

Martin Arjovsky, Léon Bottou, Ishaan Gulrajani, David Lopez-Paz · arXiv · 2019-7-5

- **Problem** Standard training absorbs spurious correlations, like background color, that break when the data distribution shifts. Pooling all training data rewards these shortcuts, so the model fails on new environments.
- **Method** IRM learns a representation where one classifier stays optimal in every training environment. It adds a penalty for classifiers that are not optimal in each environment, instead of minimizing pooled training error.
- **Results** On Colored MNIST, the authors show IRM relies less on color than standard training does, and on synthetic linear setups it is far more accurate on causal weights than ERM.

## Why pooled training data mislead ERM

A model trained to minimize training error takes in every correlation present in its training pool, including ones that reflect the setting rather than the object. Take a cow-or-camel classifier where most cow photos show green pastures and most camel photos show deserts. Such a network can fail on a cow photographed on a sandy beach, because it has learned that green landscapes mean cow.

The background is a spurious correlation, one the authors expect not to hold when the setting changes.

Standard practice shuffles training and test examples together, which assumes both come from one distribution. Shuffling makes the two splits look alike, but it also discards how the data change across sources. That change is exactly the information needed to tell a spurious property from a stable one. So the authors keep the training data split into distinct environments, such as different locations, times or collection conditions.

In the cow example, green pasture appears in 80% of cow pictures in one environment and in 90% in another. Pooling these two sets still rewards the background cue, so the varying link to green pasture has to be discarded. The authors bet that the cow itself carries features that identify it regardless of context.

Earlier work already linked invariance to causation, which points toward a remedy. However, that approach assumes a meaningful causal graph over the observed variables, which is awkward for pixel inputs. It also applies only to linear models and scales exponentially with the number of variables.

## Invariance across environments as the selection rule

The key idea is to keep only the features whose best predictor does not change from one environment to the next. A representation elicits an invariant predictor when a single classifier on top of it is optimal in every training environment. For the squared loss and the cross-entropy, this means the conditional expectation of the label given the representation must match across environments.

The authors draw an analogy with physics, where distinct phenomena that obey the same law suggest the law holds more broadly. Their reading is that a shared invariance across environments is a sign of a real mechanism rather than a shortcut. This is why they phrase the goal as learning representations for which the best classifier stays fixed across environments.

IRM therefore asks for a representation that predicts well and also yields an invariant predictor across the training environments. Written as a constrained problem, it is bi-leveled, because each constraint contains an inner optimization over classifiers.

## Why the obvious alternatives fall short

Example 1 is a linear structural model in which X1 causes Y, Y causes X2, and the noise level of Y can change across environments. Regressing on X1 alone gives the same coefficients in every environment, so it is the one invariant correlation among the candidate regressions. Regressions on X2 or on both inputs produce coefficients that move with the noise level, so they would not generalize to new environments.

Pooling all environments and minimizing training error, which is ERM, would give X2 a large positive weight when the pooled noise is large. Robust learning with environment baselines looks promising, but it reduces to minimizing a weighted average of environment risks. That means it cannot recover the invariance in Example 1 either.

Domain adaptation would match feature distributions across environments, but the distribution of the causal feature X1 shifts in this example. Invariant causal prediction matches regression residuals, which is unsuited here because the noise variance of Y varies across environments.

## IRMv1: a penalty on the dummy classifier's gradient

Solving IRM directly is hard, so the authors first turn its hard constraints into a penalty added to the training risk. A natural penalty for linear classifiers is the distance between a classifier and the optimal least-squares classifier of each environment, written \\(D\_{\\mathrm{dist}}(w,\\Phi,e)=\\\|w-w^e\_\\Phi\\\|\_2\\). In Example 1, this distance jumps at c = 0, the coefficient that gives the invariant predictor, so it is a poor penalty.

Undoing the matrix inversion in the least-squares solution gives a smoother penalty \\(D\_{\\mathrm{lin}}(w,\\Phi,e)=\\\|\\mathbb{E}\_{X^e}\[\\Phi(X^e)\\Phi(X^e)^\\top\]\\,w-\\mathbb{E}\_{X^e,Y^e}\[\\Phi(X^e)Y^e\]\\\|\_2\\). This penalty measures how much the classifier violates the normal equations, and it reaches zero exactly when the classifier is optimal. The authors caution that this penalty is non-convex for general representations.

The representation is over-parametrized, since any invertible rescaling can move weight between the classifier and the representation. So the authors fix the classifier to a scalar 1.0 and optimize only the representation. For general losses, the penalty becomes the squared gradient norm of the risk with respect to this dummy classifier, evaluated at w = 1.0.

The resulting objective is \\(\\min\_{\\Phi}\\sum\_{e\\in\\mathcal{E}\_{tr}}R^e(\\Phi)+\\lambda\\,\\\|\\nabla\_{w\|w=1.0}R^e(w\\cdot\\Phi)\\\|^2\\), where λ in \[0, ∞) balances predictive power against invariance.

In practice the penalty is estimated from two independent mini-batches drawn from the same environment, which gives an unbiased estimate of the squared gradient norm. In the synthetic experiments, λ was chosen by cross-validation on environment e = 5. The derivation only covers linear classifiers, and the authors leave nonlinear invariances for future work.

## When invariance transfers to unseen environments

Theorem 9 considers a setting where Y depends linearly on a latent cause Z1, while the observed X mixes Z1 with a non-causal variable Z2. Simply regressing on all of X would exploit Z2, because Z2 carries extra and spurious information about the noise in Y.

The theorem needs the training environments to lie in linear general position, meaning they are diverse enough that each one removes a degree of freedom from the invariant solutions. If at least d−r+dr training environments are in linear general position of degree r, a rank-r representation that is invariant across training environments is invariant across all environments.

The authors note that this does not require Gaussian data, a causal graph or specific interventions.

The authors call the bound pessimistic, since it scales the number of environments with the number of parameters in Φ. They report that two environments were often enough in their experiments, and leave the nonlinear analogue unproven.

## Synthetic structural experiments

The synthetic setup extends Example 1 to 10-dimensional inputs, adds a hidden 10-dimensional confounder, and sometimes scrambles the observations. These choices give eight setups, depending on whether the graph is fully or partially observed, whether the noise of Y is homoskedastic or heteroskedastic, and whether the observations are scrambled.

Each run draws 1000 samples from three training environments with e in {0.2, 2, 5}, and ERM and ICP serve as baselines.

The authors score each estimate by its error on the causal weights and by the norm of the estimated non-causal weights, which should be zero. IRM was in most cases orders of magnitude more accurate than ERM on the causal and non-causal weights. It also outperformed ICP by a large margin.

The authors attribute ICP's weaker results to its conservative behaviour, rejecting most covariates as direct causes. That choice produces large errors on the causal weights and small errors on the non-causal ones. So the evidence supports IRM's advantage over these two baselines in these eight linear setups with three environments.

## Colored MNIST: avoiding the color shortcut

The authors build three environments from MNIST: the digit gives a preliminary label, which is flipped with probability 0.25. Then the color is set by flipping the label with environment-specific probability, 0.2 and 0.1 for training and 0.9 for testing. Because color predicts the label more strongly than the digit does, a learner that minimizes training error leans on color.

Each number is a mean over ten runs.

Plots of P(y = 1\|h) show that the IRM model is closer to invariant than the ERM model, though it is not perfectly invariant, especially at the tails. The authors suspect finite sample issues at the tails cause this gap.

Conditional domain adaptation that matches P(h\|y,e) could in principle solve this task too, because the digit shapes and P(y\|e) are identical across environments. It would fail, however, if the distribution of digits changed across environments.

## Limitations

The experiments cover one synthetic linear family and one Colored MNIST task. The Colored MNIST experiment uses two training environments and one test environment.

The penalty for nonlinear classifiers is not yet defined, and the authors ask how to build such penalties. The linear objective stays non-convex, so it is sensitive to initialization. Whether a nonlinear general-position condition holds almost everywhere is left for future work.

## Where invariance meets ERM in practice

In the dialogue, the authors argue that ERM is most useful in the realizable case, where some predictor in the hypothesis class reaches zero error. They also argue that many supervised annotation problems are causal, so P(Y\|X) tends to stay stable across environments. Anticausal problems, such as unsupervised learning of causal factors, may instead vary across environments and benefit from invariance.

## Paper info

- **Authors**: Martin Arjovsky, Léon Bottou, Ishaan Gulrajani, David Lopez-Paz
- **Venue**: arXiv · Preprint
- **First published**: 2019-7-5
- **Added**: 2026-11-12
- **Updated**: 2020-3-27
- **Version**: v3
- **arXiv**: 1907.02893
- **Category**: stat.ML · cs.AI · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1907.02893v3) · [PDF ↗](https://arxiv.org/pdf/1907.02893v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Martin Arjovsky, Léon Bottou, Ishaan Gulrajani, David Lopez-Paz (2019). Invariant Risk Minimization. arXiv:1907.02893v3. https://arxiv.org/abs/1907.02893v3

**BibTeX**

```
@misc{arjovsky2019invariant,
  title = {{Invariant Risk Minimization}},
  author = {Martin Arjovsky and Léon Bottou and Ishaan Gulrajani and David Lopez-Paz},
  year = {2019},
  eprint = {1907.02893},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1907.02893v3}
}
```

## Other paper commentary

- [Equality of Opportunity in Supervised Learning](https://refivu.com/en/papers/97e846bf-1b27-4e7b-934a-caa8326bd5e9-equality-of-opportunity-in-supervised-learning.md)
- [Explaining Explanations: An Overview of Interpretability of Machine Learning](https://refivu.com/en/papers/1e2e5cea-7806-41cc-934c-581f9dec0a44-explaining-explanations-an-overview-of-interpretability-of.md)
- [Estimating Continuous Distributions in Bayesian Classifiers](https://refivu.com/en/papers/318decb8-43d0-4596-b25f-944ca636af13-estimating-continuous-distributions-in-bayesian-classifiers.md)
- [Supervised learning with quantum enhanced feature spaces](https://refivu.com/en/papers/3f9e8d98-c1b3-4fa7-89e8-2599add8f4d9-supervised-learning-with-quantum-enhanced-feature-spaces.md)
- [The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo](https://refivu.com/en/papers/e0f0ea3e-b264-41df-ace0-6689f5d123b5-the-no-u-turn-sampler-adaptively-setting-path.md)
- [An Introduction to Deep Learning for the Physical Layer](https://refivu.com/en/papers/f1790a96-c7b5-4b05-9672-d9d222404a87-an-introduction-to-deep-learning-for-the-physical.md)
- [End-to-end Sequence Labeling via Bi-directional LSTM-CNNs-CRF](https://refivu.com/en/papers/ce633cbf-8295-40aa-a4ee-656b431af25f-end-to-end-sequence-labeling-via-bi-directional.md)
- [Occupancy Networks: Learning 3D Reconstruction in Function Space](https://refivu.com/en/papers/ebb91803-99a7-402a-90f0-6aa763fd3e16-occupancy-networks-learning-3d-reconstruction-in-function.md)
- [Predicting Depth, Surface Normals and Semantic Labels with a Common Multi-Scale Convolutional Architecture](https://refivu.com/en/papers/e513ebec-7ee7-41d2-bb2e-ed519797b97d-predicting-depth-surface-normals-and-semantic-labels-with.md)
- [OpenVLA: An Open-Source Vision-Language-Action Model](https://refivu.com/en/papers/3dd15569-8eba-48b1-88e8-a1ca295a743e-openvla-an-open-source-vision-language-action-model.md)
- [Microsoft COCO Captions: Data Collection and Evaluation Server](https://refivu.com/en/papers/1cf4256e-f015-43b3-a7f1-14167d272b8f-microsoft-coco-captions-data-collection-and-evaluation.md)
- [Crowdsourcing a Word-Emotion Association Lexicon](https://refivu.com/en/papers/3b0b67cb-6dd6-4162-9110-cdbb5d2cea2a-crowdsourcing-a-word-emotion-association-lexicon.md)

## Terms in this paper

- [domain adaptation](https://refivu.com/en/terms/dfc6e2afbc1f-domain-adaptation)
- [synthetic data](https://refivu.com/en/terms/d3b9fabe1cf0-synthetic-data)
- [Empirical risk minimization (ERM)](https://refivu.com/en/terms/8cf1778e398e-empirical-risk-minimization-erm)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/7f6a0d34-8d04-4205-b5c5-1e73e1c91b62-invariant-risk-minimization)
