SlowGuess/NeurIPS_2023_OCR huggingface dataset:
where the sigmoid  $\sigma : \mathbb{R} \to [0,1]$  is continuous, by the continuous mapping theorem and the assumption that  $\widehat{\eta}_{U,1}(x_U) \to \widetilde{\eta}(x_U)$ , to prove both of these, it suffices to show:
(i)  $\widehat{\epsilon}_0\to \epsilon_0$  and  $\widehat{\epsilon}_1\rightarrow \epsilon_1$  almost surely as  $n\to \infty$
(ii)  $\widehat{\beta}_{1,n}\to \beta_1\in (-\infty ,\infty)$  almost surely as  $n\to \infty$
(iii) The mapping  $(a,b,c)\mapsto \mathrm{logit}\left(\frac{a + b - 1}{b + c - 1}\right)$  is continuous at  $(\widetilde{\eta} (x_U),\epsilon_0,\epsilon_1)$
We now prove each of these in turn.
Proof of (i) Since  $\widehat{Y}_i \perp \perp Y_i|X_S$  and  $0 < \operatorname*{Pr}[\widehat{Y} = 1]$ , by the strong law of large numbers and the continuous mapping theorem,
$$
\widehat {\epsilon} _ {1} = \frac {1}{n _ {1}} \sum_ {i = 1} ^ {n} \widehat {Y} _ {i} \sigma (f _ {S} (X _ {i})) = \frac {\frac {1}{n} \sum_ {i = 1} ^ {n} \widehat {Y} _ {i} \sigma (f _ {S} (X _ {i}))}{\frac {1}{n} \sum_ {i = 1} ^ {n} \widehat {Y} _ {i}} \to \frac {\mathbb {E} [ \sigma (f _ {S} (X)) 1 \{\widehat {Y} = 1 \} ]}{\operatorname * {P r} [ \widehat {Y} = 1 ]} = \mathbb {E} [ \sigma (f _ {S} (X)) | \widehat {Y} = 1 ] = \epsilon_ {1},
$$
almost surely as  $n\to \infty$  . Similarly, since  $\operatorname *{Pr}[\widehat{Y} = 0] = 1 - \operatorname *{Pr}[\widehat{Y} = 1] > 0,\widehat{\epsilon}_0\rightarrow \epsilon_0$  almost surely.
Proof of (ii) Recall that
$$
\widehat {\beta} _ {1, n} = \operatorname {l o g i t} \left(\frac {1}{n} \sum_ {i = 1} ^ {n} \widehat {Y} _ {i}\right).
$$
By the strong law of large numbers,  $\frac{1}{n}\sum_{i=1}^{n}\widehat{Y}_i\to \operatorname*{Pr}[\widehat{Y} = 1|E = 1] = \operatorname*{Pr}[Y = 1|E = 1]$ . Since we assumed  $\operatorname*{Pr}[Y = 1|E = 1]\in (0,1)$ , it follows that the mapping  $a\mapsto \mathrm{logit}(a)$  is continuous at  $a = \operatorname*{Pr}[Y = 1|E = 1]$ . Hence, by the continuous mapping theorem,  $\widehat{\beta}_{1,n}\rightarrow$  logit  $(\operatorname*{Pr}[Y = 1|E = 1]) = \beta_1$  almost surely.
Proof of (iii) Since the logit function is continuous on the open interval  $(0,1)$  and we assumed  $\epsilon_0 + \epsilon_1 > 1$ , it suffices to show that  $0 < \widetilde{\eta}(x_U) + \epsilon_0 - 1 < \epsilon_0 + \epsilon_1 - 1$ . Since, according to Thm. 4.4,
$$
\tilde {\eta} \left(x _ {U}\right) = \left(\epsilon_ {0} + \epsilon_ {1} - 1\right) \eta^ {*} \left(x _ {U}\right)) + 1 - \epsilon_ {0},
$$
this holds as long as  $0 < \eta^{*}(x_{U}) < 1$ , as we assumed for  $P_{X_U}$ -almost all  $x_{U} \in \mathcal{X}_{U}$ .
Infinite case We now address the case where either  $\operatorname*{Pr}[Y|X_S = x_S] \in \{0,1\}$  or  $\operatorname*{Pr}[Y|X_U = x_U] \in \{0,1\}$ . By Lemma B.2, only one of these can happen at once,  $P_{X_S,X_U}$ -almost surely. Hence, since  $\lim_{n\to \infty}\widehat{\beta}_{1,n}$  is also finite almost surely, if  $\operatorname*{Pr}[Y|X_S = x_S] \in \{0,1\}$ , then  $\widehat{\eta}(x_S,x_U) = \sigma(\operatorname*{logit}(\operatorname*{Pr}[Y|X_S = x_S])) = \eta(x_S,x_U)$ , while, if  $\operatorname*{Pr}[Y|X_U = x_U] \in \{0,1\}$ , then  $\widehat{\eta}(x_S,x_U) \rightarrow \sigma(\operatorname*{logit}(\operatorname*{Pr}[Y|X_U = x_U])) = \eta(x_S,x_U)$ , in probability or almost surely, as appropriate.
C Multiclass Case
In the main paper, to simplify notation, we presented our unsupervised test-domain adaptation method in the case of binary labels  $Y$ . However, in many cases, including several of our experiments in Section 6, the label  $Y$  can take more than 2 distinct values. Hence, in this section, we show how to generalize our method to the multiclass setting and then present the exact procedure (Alg. 2) used in our multiclass experiments in Section 6.
Suppose we have  $K \geq 2$  classes. We "one-hot encode" these classes, so that  $Y$  takes values in the set
$$
\mathcal {Y} = \{(1, 0, \dots , 0), (0, 1, 0, \dots , 0), \dots , (0, \dots , 0, 1) \} \subseteq \{0, 1 \} ^ {K}.
$$
Let  $\epsilon \in [0,1]^{\mathcal{Y}\times \mathcal{Y}}$  with
$$
\epsilon_ {y, y ^ {\prime}} = \Pr [ \widehat {Y} = y | Y = y ^ {\prime} ]
$$
denote the class-conditional confusion matrix of the pseudo-labels. Then, we have
$$
\begin{array}{l} \mathbb {E} [ \widehat {Y} | X _ {U} ] = \sum_ {y \in \mathcal {Y}} \mathbb {E} [ \widehat {Y} | Y = y, X _ {U} ] \Pr [ Y = y | X _ {U} ] \quad (\text {L a w o f T o t a l E x p e c t a t i o n}) \\ = \sum_ {y \in \mathcal {Y}} \mathbb {E} [ \widehat {Y} | Y = y ] \Pr [ Y = y | X _ {U} ] \quad (\text {C o m p l e m e n t a r y}) \\ = \epsilon \mathbb {E} [ Y | X _ {U} ]. \quad (\text {D e f i n i t i o n} \epsilon) \\ \end{array}
$$
When  $\epsilon$  is non-singular, this has the unique solution  $\mathbb{E}[Y|X_U] = \epsilon^{-1}\mathbb{E}[\widehat{Y} |X_U]$ , giving a multiclass equivalent of Eq. (4.3) in Thm. 4.4. In practice, however, it is numerically more stable to estimate  $\mathbb{E}[Y|X_U]$  by the least-squares solution
$$
\underset {p \in \Delta^ {\mathcal {Y}}} {\arg \min } \left\| \epsilon p - \mathbb {E} [ \widehat {Y} | X _ {U} ] \right\| _ {2},
$$
which is what we will do in Algorithm 2. To estimate  $\epsilon$  without observing the label  $Y$  in the test domain, note that
$$
\begin{array}{l} \epsilon_ {y, y ^ {\prime}} = \Pr [ \widehat {Y} = y | Y = y ^ {\prime} ] = \frac {\Pr [ \widehat {Y} = y , Y = y ^ {\prime} ]}{\Pr [ Y = y ^ {\prime} ]} \\ = \frac {\mathbb {E} \left[ \Pr [ \widehat {Y} = y , Y = y ^ {\prime} | X _ {S} ] \right]}{\mathbb {E} \left[ \Pr [ Y = y ^ {\prime} | X _ {S} ] \right]} \\ = \frac {\mathbb {E} \left[ \Pr [ \widehat {Y} = y | X _ {S} ] \Pr [ Y = y ^ {\prime} | X _ {S} ] \right]}{\mathbb {E} \left[ \Pr [ Y = y ^ {\prime} | X _ {S} ] \right]} \\ = \frac {\mathbb {E} \left[ f _ {1 , y} \left(X _ {S}\right) f _ {1 , y ^ {\prime}} \left(X _ {S}\right) \right]}{\mathbb {E} \left[ f _ {1 , y ^ {\prime}} \left(X _ {S}\right) \right]}. \\ \end{array}
$$
This suggests the estimate
$$
\widehat {\epsilon} _ {y, y ^ {\prime}} = \frac {\sum_ {i = 1} ^ {n} \widehat {f} _ {S , y} (X _ {S , i}) \widehat {f} _ {S , y ^ {\prime}} (X _ {S , i})}{\sum_ {i = 1} ^ {n} \widehat {f} _ {S , y ^ {\prime}} (X _ {S , i})} = \sum_ {i = 1} ^ {n} \widehat {f} _ {S, y} (X _ {S, i}) \frac {\widehat {f} _ {S , y ^ {\prime}} (X _ {S , i})}{\sum_ {i = 1} ^ {n} \widehat {f} _ {S , y ^ {\prime}} (X _ {S , i})}
$$
of each  $\epsilon_{y,y'}$ , or, in matrix notation,
$$
\widehat {\epsilon} = f _ {S} ^ {\top} \left(X _ {S}\right) \text {N o r m a l i z e} \left(f _ {S} \left(X _ {S}\right)\right),
$$
where  $\mathrm{Normalize}(X)$  scales each column of  $X$  to sum to 1. This gives us a multiclass equivalent of Line 3 in Alg. 1.
The multiclass versions of Eq. (4.4) and Line 6 of Alg. 1 are slightly less straightforward. Specifically, whereas, in the binary case, we used the fact that  $\operatorname*{Pr}[X_S,X_U|Y\neq 1] = \operatorname*{Pr}[X_S,X_U|Y = 0] =$ $\operatorname*{Pr}[X_S|Y = 0]\operatorname*{Pr}[X_U|Y = 0] = \operatorname*{Pr}[X_S|Y\neq 1]\operatorname*{Pr}[X_U|Y\neq 1]$  (by complementarity), in the multiclass case, we do not have  $\operatorname*{Pr}[X_S,X_U|Y\neq 1] = \operatorname*{Pr}[X_S|Y\neq 1]\operatorname*{Pr}[X_U|Y\neq 1]$ . However, following similar reasoning as in the proof of Thm. 4.4, we have
$$
\begin{array}{l} \frac {\Pr \left[ Y = y \mid X _ {S} , X _ {U} , E \right]}{\Pr \left[ Y \neq y \mid X _ {S} , X _ {U} , E \right]} = \frac {\Pr \left[ Y = y \mid X _ {S} , X _ {U} , E \right]}{\sum_ {y ^ {\prime} \neq y} \Pr \left[ Y = y ^ {\prime} \mid X _ {S} , X _ {U} , E \right]} \\ = \frac {\Pr \left[ X _ {S} , X _ {U} \mid Y = y , E \right] \Pr \left[ Y = y \mid E \right]}{\sum_ {y ^ {\prime} \neq y} \Pr \left[ Y \neq y \mid X _ {S} , X _ {U} , E \right] \Pr \left[ Y = y ^ {\prime} \mid E \right]} \quad (\text {B a y e s} ^ {\prime} \text {R u l e}) \\ = \frac {\Pr \left[ X _ {S} \mid Y = y , E \right] \Pr \left[ X _ {U} \mid Y = y , E \right] \Pr \left[ Y = y \mid E \right]}{\sum_ {y ^ {\prime} \neq y} \Pr \left[ X _ {S} \mid Y = y ^ {\prime} , E \right] \Pr \left[ X _ {U} \mid Y = y ^ {\prime} , E \right] \Pr \left[ Y = y ^ {\prime} \mid E \right]} (X _ {S} \perp X _ {U} | Y) \\ = \frac {\Pr [ Y = y | X _ {S} , E ] \Pr [ Y = y | X _ {U} , E ]}{\sum_ {y ^ {\prime} \neq y} \Pr [ Y = y ^ {\prime} | X _ {S} , E ] \Pr [ Y = y ^ {\prime} | X _ {U} , E ] \cdot \frac {\Pr [ Y = y | E ]}{\Pr [ Y = y ^ {\prime} | E ]}}. \quad (\text {B a y e s} ^ {\prime} \text {R u l e}) \\ \end{array}
$$
$$
\begin{array}{l} \operatorname {l o g i t} (\Pr [ Y = y | X _ {S}, X _ {U}, E ]) = \log \left(\frac {\Pr [ Y = y | X _ {S} , E ] \Pr [ Y = y | X _ {U} , E ]}{\sum_ {y ^ {\prime} \neq y} \Pr [ Y = y ^ {\prime} | X _ {S} , E ] \Pr [ Y = y ^ {\prime} | X _ {U} , E ] \cdot \frac {\Pr [ Y = y | E ]}{\Pr [ Y = y ^ {\prime} | E ]}}\right) \\ = \log \left(\frac {Q _ {y}}{\sum_ {y ^ {\prime} \neq y} Q _ {y ^ {\prime}}}\right) = \log \left(\frac {\frac {Q _ {y}}{\| Q \| _ {1}}}{\sum_ {y ^ {\prime} \neq y} \frac {Q _ {y ^ {\prime}}}{\| Q \| _ {1}}}\right) = \operatorname {l o g i t} \left(\frac {Q _ {y}}{\| Q \| _ {1}}\right), \\ \end{array}
$$
for  $Q\in \mathbb{R}^{\mathcal{V}}$  defined by
$$
Q _ {y} = \frac {f _ {S , y} \left(X _ {S}\right) f _ {U , y} \left(X _ {U}\right)}{\Pr [ Y = y ]} \quad \text {f o r e a c h} y \in \mathcal {Y}.
$$
In particular, applying the sigmoid function to each side, we have
$$
\operatorname * {P r} [ Y | X _ {S}, X _ {U} ] = \frac {Q}{\| Q \| _ {1}}.
$$
We can estimate  $Q_{\nu}$  by
$$
\widehat {Q} _ {y} = \frac {f _ {S , y} (X _ {S}) f _ {U , y} (X _ {U})}{\frac {1}{n} \sum_ {i = 1} ^ {n} f _ {S , y} (X _ {S , i})}.
$$
In matrix notation, this is
$$
\widehat {Q} = \frac {f _ {S} (X _ {S}) \circ f _ {U} (X _ {U})}{\frac {1}{n} \sum_ {i = 1} ^ {n} f _ {S} (X _ {S , i})},
$$
where  $\circ$  denotes element-wise multiplication. It follows that, for  $p \in \Delta^{\mathcal{V}}$  (we will use  $p_{y} = \operatorname*{Pr}[Y = y]$ ), we can use the multiclass combination function  $C: \Delta^{\mathcal{V}} \times \Delta^{\mathcal{V}} \to \Delta^{\mathcal{V}}$  with
$$
C _ {p} \left(p _ {S}, p _ {U}\right) = \text {N o r m a l i z e} \left(\frac {p _ {S} p _ {U}}{p}\right), \tag {C.1}
$$
where the multiplication and division are performed element-wise and  $\mathrm{Normalize}(x) = \frac{x}{\|x\|_1}$ , to generalize Eq. (4.5). Putting these derivations together gives us our multiclass version of Alg. 1, presented in Alg. 2, where  $\Delta^{\mathcal{Y}} = \{z\in [0,1]^K:\sum_{y\in \mathcal{Y}}z_y = 1\}$  denotes the standard probability simplex over  $\mathcal{Y}$ .
Algorithm 2: Multiclass bias-corrected adaptation procedure.
Input: Calibrated stable classifier  $f_{S}:\mathcal{X}\to \Delta^{\mathcal{Y}}$  with  $f_{S,y}(x_S) = \operatorname*{Pr}[Y = y|X_S = x_S]$ ,  $n$  unlabeled samples  $\{(X_{S,i},X_{U,i})\}_{i = 1}^{n}$
Output: Joint classifier  $\widehat{f}:\mathcal{X}_S\times \mathcal{X}_U\to \Delta^{\mathcal{Y}}$  estimating  $\operatorname *{Pr}[Y = y|X_s = x_s,X_U = x_U]$
1 Compute soft pseudo-labels  $\{\widehat{Y}_i\}_{i = 1}^n$  with  $\widetilde{Y}_i = f_S(X_{S,i})$
2 Compute soft class counts  $\widehat{n} = \sum_{i=1}^{n} \widehat{Y}_i$
3 Estimate class-conditional pseudo-label confusion matrix  $\widehat{\epsilon} \gets f_S^{\mathsf{T}}(X_S)$  Normalize  $(f_S^{\mathsf{T}}(X_S))$
4 Fit unstable classifier  $\tilde{f}_U(x_U)$  to pseudo-labelled data  $\{(X_{U,i},\widehat{Y}_i)\}_{i = 1}^n$
$$
/ / \approx \Pr [ \widehat {Y} = y | X _ {U} ]
$$
5 Bias-correction  $\widehat{f}_U(x_U)\mapsto \arg \min_{p\in \Delta^y}\| \epsilon p - \widetilde{f}_U(x_U)\| _2$
$$
/ / \approx \Pr [ Y = y | X _ {U} ]
$$
6 return  $\widehat{f} (x_S,x_U)\mapsto C_{\widehat{n} /n}(f_S(x_S),\widehat{f}_U(x_U))$
$$
/ / \quad E q. (C. 1), \approx \Pr [ Y = y | X _ {S}, X _ {U} ]
$$
D Supplementary Results
D.1 Trivial solution to joint-risk minimization
In Prop. D.1 below, we assume that the stable  $f_{S}(X)$  and unstable  $f_{U}(X)$  predictors output logits. In contrast, throughout the rest of the paper, we assume that  $f_{S}(X)$  and  $f_{U}(X)$  output probabilities in [0, 1].
Proposition D.1. Suppose  $\widehat{Y} | f_S(X) \sim \text{Bernoulli}(\sigma(f_S(X)))$ , such that  $\widehat{Y} \perp f_U(X) | f_S(X)$ . Then,
$$
0\in \operatorname *{arg  min}_{f_{U}:\mathcal{X}\to \mathbb{R}}\mathbb{E}[\ell (\widehat{Y},\sigma (f_{S}(X) + f_{U}(X)))],
$$
where  $\ell(x, y) = -x \log y - (1 - x) \log (1 - y)$  denotes the cross-entropy loss.
Proof. Suppose  $\widehat{Y} | f_S(X) \sim \text{Bernoulli}(\sigma(f_S(X)))$ , such that  $\widehat{Y} \perp f_U(X) | f_S(X)$ . Then,
$$
\begin{array}{l} - \mathbb {E} [ \ell (\widehat {Y}, \sigma (f _ {S} (X) + f _ {U} (X))) ] \\ = \mathbb {E} [ \mathbb {E} [ \ell (\widehat {Y}, \sigma (f _ {S} (X) + f _ {U} (X)) ] ] \\ = \mathbb {E} [ \mathbb {E} [ \widehat {Y} \log \sigma (f _ {S} (X) + f _ {U} (X)) \\ + (1 - Y) \log (1 - \sigma (f _ {S} (X) + f _ {U} (X))) | f _ {S} (X) ] ] \\ = \mathbb {E} [ \mathbb {E} [ \widehat {Y} | f _ {S} (X _ {S}) ] \mathbb {E} [ \log \sigma (f _ {S} (X) + f _ {U} (X)) | f _ {S} (X _ {S}) ] \\ + \mathbb {E} [ (1 - \widehat {Y}) | f _ {S} (X _ {S}) ] \mathbb {E} [ \log (1 - \sigma (f _ {S} (X) + f _ {U} (X))) | f _ {S} (X) ] ] \qquad (\widehat {Y} \perp \perp f _ {U} (X) | f _ {S} (X)) \\ = \mathbb {E} [ \sigma (f _ {S} (X)) \log \sigma (f _ {S} (X) + f _ {U} (X)) \\ + \left(1 - \sigma \left(f _ {S} (X)\right)\right) \log \left(1 - \sigma \left(f _ {S} (X) + f _ {U} (X)\right)\right) ]. \quad (\widehat {Y} | f _ {S} (X) \sim \operatorname {B e r n o u l l i} (\sigma \left(f _ {S} (X)\right))). \\ \end{array}
$$
Since the cross-entropy loss is differentiable and convex, any  $f_{U}(X)$  satisfying  $0 = \frac{d}{df_{U}(X)}\mathbb{E}[\ell (\widehat{Y},f_{S}(X) + f_{U}(X))]$  is a minimizer. Indeed, under the mild assumption that the expectation and derivative commute, for  $f_{U}(X) = 0$ ,
$$
\begin{array}{l} \frac {d}{d f _ {U} (X)} \mathbb {E} [ \ell (\widehat {Y}, \sigma (f _ {S} (X) + f _ {U} (X))) ] = - \mathbb {E} \left[ \frac {\sigma (f _ {S} (X))}{\sigma (f _ {S} (X) + f _ {U} (X))} + \frac {1 - \sigma (f _ {S} (X))}{1 - \sigma (f _ {S} (X) + f _ {U} (X))} \right] \\ = - \mathbb {E} \left[ \frac {\sigma (f _ {S} (X))}{\sigma (f _ {S} (X))} + \frac {1 - \sigma (f _ {S} (X))}{1 - \sigma (f _ {S} (X))} \right] = 0. \\ \end{array}
$$
D.2 Causal perspectives
The stability, complementarity, and informativeness assumptions in Thm. 4.4 can be interpreted as constraints on the causal relationships between the variables  $X_{S}$ ,  $X_{U}$ ,  $Y$ , and  $E$ . We conclude this section with a result with a characterization of causal, directed acyclic graphs (DAGs) that are consistent with these assumptions. In particular, this result shows that our assumptions are satisfied in the "anti-causal" and "cause-effect" settings assumed in prior work [49, 68, 31], as well as work assuming only covariate shift (i.e., changes in the distribution of  $X$  without changes in the conditional  $P_{Y|X}$ ).
Figure 3: Causal DAGs over the environment  $E$ , three types of stable features (causes  $X_{S,C}$ , effects  $X_{S,E}$ , and spouses  $X_{S,S}$ ), unstable features  $X_U$ , and label  $Y$ , under conditions 1)-6). At least one, and possibly both, of the dashed edges  $E \to X_{S,C}$  and  $E \to X_U$  must be included. The dotted edge  $E \to X_{S,S}$  may or may not be included.
Proposition D.2 (Possible Causal DAGs). Consider an environment variable  $E$ , two covariates  $X_U$  and  $X_S$ , and a label  $Y$ . Assume there are no other hidden confounders (i.e., causal sufficiency). First, assume:
1)  $E$  is a root (i.e., none of  $X_U$ ,  $X_S$ , and  $Y$  is an ancestor of  $E$ ).
2)  $X_{S}$  is informative of  $Y$  (i.e.,  $X_{S} \nsubseteq Y|E$ ).
3)  $X_{S}$  and  $X_{U}$  are complementary predictors of  $Y$ ; i.e.,  $X_{S} \perp X_{U}|(Y,E)$ .
4)  $X_{S}$  is stable (i.e.,  $E \perp Y|X_{S}$ ).
These are the four structural assumptions under which Theorems 4.4 and 4.6 show that the SFB algorithm learns the conditional distribution  $P_{Y|X_S,X_U}$  in the test domain. Additionally, suppose
5)  $X_U$  is unstable (i.e.,  $E \nsubseteq Y|X_U$ ), This is the case in which empirical risk minimization [ERM; 65] may suffer bias due to distribution shift, and hence when SFB may outperform ERM.
6)  $X_U$  contains some information about  $Y$  that is not included in  $X_S$  (i.e.,  $\bar{X}_U \nsubseteq Y|X_S$ ). This is information we expect invariant risk minimization [IRM; 1] is unable to learn, and hence when we expect SFB to outperform IRM.
Then,  $X_U$  consists of causal descendants ("effects") of  $Y$ , while three types of stable features are possible:
1. causal ancestors  $X_{S,C}$  of  $Y$
2. causal descendants  $X_{S,E}$  of  $Y$  that are not also descendants of  $E$ ,
3. causal spouses  $X_{S,S}$  of  $Y$  (i.e., causal ancestors of  $X_{S,E}$ ).
Notable special cases of the DAG in Figure 3 include:
1. the "cause-effect" settings, studied by Rojas-Carulla et al. [49], von Kugelgen et al. [68, 69], where  $X_{S}$  is a cause of  $Y$ ,  $X_{U}$  is an effect of  $Y$ , and  $E$  may affect both  $X_{S}$  and  $X_{U}$  but may affect  $Y$  only indirectly through  $X_{S}$ . Note that this generalizes the commonly used "covariate shift" assumption, as not only the covariate distribution  $P_{X_{S},X_{U}}$  but also the conditional distribution  $P_{Y|X_{U}}$  can change between environments.
2. the "anti-causal" setting, studied by Jiang and Veitch [31], where  $X_S$  and  $X_U$  are both effects of  $Y$ , but  $X_S$  is unaffected by  $E$ .
3. the widely studied "covariate shift" setting [62, 23, 6, 61], which corresponds (see Sections 3 and 5 of Scholkopf [55]) to a causal factorization  $P(X,Y) = P(X)P(Y|X)$  (i.e., in which the only stable components  $X_{S}$  are causes  $X_{S,C}$ ) of  $Y$  or unconditionally independent (e.g., causal spouses  $X_{S,S}$ ) of  $Y$ .
However, this model is more general than these special cases. Also, for sake of simplicity, we assumed causal sufficiency here; however, in the presence of unobserved confounders, other types of stable features are also possible; for example, if we consider the possibility of unobserved confounders  $U$  influencing  $Y$  that are independent of  $E$  (i.e., invariant across domains), then our method can also utilize stable features that are descendants of  $U$  (i.e., "siblings" of  $Y$ ).
In our experiments, we consider five datasets: two (synthetic) numerical datasets and three image datasets. We now describe each dataset.
Synthetic: Anti-causal (AC). We consider an anti-causal synthetic dataset based on that of Jiang and Veitch [31, §6.1] where data is generated according to the following structural equations:
$$
X _ {U} \leftarrow Y \cdot \operatorname {R a d} \left(\beta^ {e}\right),
$$
where the input  $X = (X_S, X_U)$  and  $\operatorname{Rad}(\beta)$  denotes a Rademacher random variable that is  $-1$  with probability  $1 - \beta$  and  $+1$  with probability  $\beta$ . Following Jiang and Veitch [31, §6.1], we create two training domains with  $\beta_e \in \{0.95, 0.7\}$ , one validation domain with  $\beta_e = 0.6$  and one test domain with  $\beta_e = 0.1$ .
Synthetic: Cause-effect with a direct  $X_{S} - X_{U}$  dependence (CE-DD). We also consider a synthetic cause-effect dataset in which there is a direct dependence between  $X_{S}$  and  $X_{U}$ . In particular, following Jiang and Veitch [31, App. B], data is generated according to the following structural equations:
where the input  $X = (X_S, X_U)$  and  $\operatorname{Bern}(\beta)$  denotes a Bernoulli random variable that is 1 with probability  $\beta$  and 0 with probability  $1 - \beta$ . Note that  $X_S \not\perp X_U|Y$ , since  $X_S$  directly influences  $X_U$ . Following Jiang and Veitch [31, App. B], we create two training domains with  $\beta_e \in \{0.95, 0.8\}$ , one validation domain with  $\beta_e = 0.2$ , and one test domain with  $\beta_e = 0.1$ .
ColorMNIST. We next consider the ColorMNIST dataset [1]. This transforms the original MNIST dataset into a binary classification task (digit in 0-4 or 5-9) and then: (i) flips the label with probability 0.25, meaning that, across all 3 domains, digit shape correctly determines the label with probability 0.75; and (ii) colorizes the digit such that digit color (red or green) is a more informative but spurious feature (see Fig. 4).
PACS. We next consider the PACS dataset [37]—a 7-class image-classification dataset consisting of 4 domains: photos (P), art (A), cartoons (C) and sketches (S), with examples shown in Fig. 4. Model performances are reported for each domain after training on the other 3 domains.
Camelyon17. Finally, in the additional experiments of App. F2, we consider the Camelyon17 [3] dataset from the WILDS benchmark [33]: a medical dataset with histopathology images from 5 hospitals which use different staining and imaging techniques (see Fig. 4). The goal is to determine whether or not a given image contains tumor tissue, making it a binary classification task across 5 domains (3 training, 1 validation, 1 test).
Figure 4: Examples from ColorMNIST [1], PACS [37] and Camelyon17 [3]. Figure and examples based on Gulrajani and Lopez-Paz [24, Table 3] and Koh et al. [33, Figure 4]. For ColorMNIST, we follow the standard approach [1] and use the first two domains for training and the third for testing. For PACS [37], we follow the standard approach [37, 24] and use each domain in turn for testing, using the remaining three domains for training. For Camelyon17 [3], we follow WILDS [33] and use the first three domains for training, the fourth for validation, and the fifth for testing.
F Further Experiments
This appendix provides further experiments which supplement those in the main text. In particular, it provides: (i) an ablation on the ColorMNIST dataset showing the effects of bias correction, post-hoc calibration and multiple rounds of pseudo-labelling on SFB's performance (F.1.1); (ii) the
performance of SFB on the ColorMNIST dataset when using different stability penalties (F.1.2); and (iii) results on a real-world medical dataset, Camelyon17 [3], where we find that all methods perform similarly when properly tuned (F.2).
F.1 ColorMNIST
We now provide ablations on the ColorMNIST dataset to illustrate the effectiveness of the different components of SFB. In particular, we focus on bias correction and calibration, while also showing how multiple rounds of pseudo-labeling can improve performance in practice.
F.1.1 Ablations
Bias correction. To adapt the unstable classifier in the test domain, SFB employs the bias-corrected adaptation algorithm of Alg. 1 (or Alg. 2 for the multi-class case) which corrects for biases caused by possible disagreements between the stable-predictor pseudo-labels  $\widehat{Y}$  and the true label  $Y$ . In this (sub)section, we investigate the performance of SFB with and without bias correction (BC).
Calibration. As discussed in § 4.2, correctly combining the stable and unstable predictions post-adaptation requires them to be properly calibrated. In particular, it requires the stable predictor  $f_{S}$  to be calibrated with respect to the true labels  $Y$  and the unstable predictor  $f_{U}$  to be calibrated with respect to the pseudo-labels  $\widehat{Y}$ . In this (sub)section, we investigate the performance of SFB with and without post-hoc calibration (in particular, simple temperature scaling [25]). More specifically, we investigate the effect of calibrating the stable predictor (CS) and calibrating the unstable predictor (CU).