Robust Calibration with Multi-domain Temperature Scaling
Anonymous Author(s)
AfﬁliationAddress email
Abstract
Uncertainty quantiﬁcation is essential for the reliable deployment of machinelearning models to high-stakes application domains.
Uncertainty quantiﬁcation isall the more challenging when training distribution and test distribution are different,even the distribution shifts are mild.
Despite the ubiquity of distribution shiftsin real-world applications, existing uncertainty quantiﬁcation approaches mainlystudy the in-distribution setting where the train and test distributions are the same.
In this paper, we develop a systematic calibration model to handle distribution shiftsby leveraging data from multiple domains.
Our proposed method—multi-domaintemperature scaling—uses the heterogeneity in the domains to improve calibrationrobustness under distribution shift.
Through experiments on three benchmark datasets, we ﬁnd our proposed method outperforms existing methods as measured onboth in-distribution and out-of-distribution test sets.
Introduction
To make learning systems reliable and fault-tolerant, predictions must be accompanied by uncertaintyestimates.
A signiﬁcant challenge to accurately codifying uncertainty is the distribution shift thattypically arises over the course of a system’s deployment [35].
For example, suppose health providersfrom 20 different hospitals employ a model to make diagnostic predictions from fMRI data.
Thedistributions across hospitals could be quite different as a result of differing patient populations,machine conditions, and so on.
In such a setting, it is critical to provide uncertainty quantiﬁcation thatis valid for every hospital—not just on average across all hospitals.
Going even further, our uncertaintyquantiﬁcation should be informative when a new 21st hospital goes online, even if the distributionshifts from those already encountered.
In this work, we study calibration in the multi-domain setting.
We ﬁnd that by requiring accurate calibration across all observed domains, our method provides moreaccurate uncertainty quantiﬁcation on unseen domains.
Calibration is a core topic in learning [33, 28, 9, 24, 12, 3], but most techniques are targeted at settingswith no distribution shift.
To see this, we consider a simple experiment on the ImageNet-C [14]dataset, which consists of 76 domains.
Here, each domain corresponds to one type of data corruptionapplied with a certain severity.
We apply the temperature scaling technique [12] on the pooled datafrom all domains.
In Figure 1(a) and 1(b), we display the reliability diagrams for the pooled dataand for one individual domain.
We ﬁnd that even under a relatively mild distribution shift—i.e.,subpopulation shift from the mixture of all domains to the single domain—temperature scaling doesnot produce calibrated conﬁdence estimates on the stand-alone domain.
This behavior is pervasive;in Figure 1(c), we see that the calibration on individual domains is much worse than the the reliabilitydiagram from the pooled data would suggest.
To address this issue, we develop a new algorithm, multi-domain temperature scaling, that leveragesmulti-domain structure in the data.
Our algorithm takes a base model and learns a calibration function [Figure] that maps each input to a different temperature parameter that is used for adjusting conﬁdence in thebase model.
Empirically, we ﬁnd our algorithm signiﬁcantly outperforms temperature scaling onthree real-world multi-domain datasets.
In particular, in contrast to temperature scaling, our proposedalgorithm is able to provide well-calibrated conﬁdence on each domain.
Moreover, our algorithmlargely improves robustness of calibration under distribution shifts.
This is expected, because if thecalibration method performs well on every domain, it is likely to have learned some structure thatgeneralizes to unseen domains.
Theoretically, we analyze the multi-domain calibration problem inthe regression setting, providing guidance about the conditions under which robust calibration ispossible.
Contributions.
The main contributions of our work are as follows: Algorithmically, we develop anew calibration method that generalizes the widely used temperature scaling concept from singledomain to multi-domain.
The proposed new method exploits multi-domain structure in the datadistribution, which enables model calibration on every domain.
We conduct detailed experiments onthree real-world multi-domain datasets and demonstrate that our method signiﬁcantly outperformsexisting calibration methods on both in-distribution domains and unseen out-of-distribution domains .
Theoretically, we study multi-domain calibration in the regression setting and develop a theoreticalunderstanding of robust calibration in this setting.
Related Work
Calibration methods.
There is a large literature on calibrating the well-trained machine learningmodels, including histogram binning [45], isotonic regression [46], conformal prediction [39], Plattscaling [33], and temperature scaling [12].
These calibration methods apply a validation set and postprocess the model outputs.
As shown in Guo et al.
[12], temperature scaling, a simple method that usesa single (temperature) parameter for rescaling the logits, performs surprisingly well on calibratingconﬁdences for deep neural networks.
We focus on this approach in our work.
More broadly,there has been much recent work develop methods to improve calibration for deep learning models,including augmentation-based training [37, 17], calibration for neural machine translation [23], neuralstochastic differential equation [22], self-supervised learning [16], ensembling [24], and Bayesianneural networks [9, 10], as well as statistical guarantees for calibration with black-box models [1].
Calibration under distribution shifts.
Ovadia et al.
[29] conduct an empirical study on modelcalibration under distribution shifts and ﬁnd that models are much less calibrated under distributionshifts.
Minderer et al.
[26] revisit calibration of recent state-of-the-art image classiﬁcation modelsunder distribution shifts and study the relationship between calibration and accuracy.
Wald et al.[40] study model calibration and out-of-distribution generalization.
Other works consider providinguncertainty estimates under structured distribution shifts, such as covariate shift [38, 31], labelshift [34], and f -divergence balls [6].
Another line of work studies calibration in the domainadaptation setting [41, 30], which require unlabeled samples from the target domain.
Problem setup
Notation.
We denote the input space and the label set by X ✓ R d and Y = { 1 , . . .
, J } .
We let [ x ] idenote the i -th element of vector x .
We use P ( X ) to denote the marginal feature distribution on input space X , P ( Y | X ) to denote the conditional distribution, and P ( X, Y ) to denote the joint distribution.
For the multiple domains scenario, we let P k ( X ) and P k
( Y | X ) denote the feature distribution andconditional distribution for the k -th domain.
We let f : X !
R J denote the base model, e.g., a deepneural network, where J is the total number of classes.
We assume f returns an (unnormalized) vectorof logits.
Throughout the paper, the base model is trained with training data and will not be modiﬁed.
The class prediction of model f on input x 2 X is denoted by ˆ y =
argmax
j 2 { 1 ,...,J } [ f ( x ; ✓ )] j .
Weuse 1 {·} to represent the indicator function.
We use h ( · ; f,  ) :
X ! [0 , 1] to denote a calibration 82 map (parameterized by  ) that takes an input x 2 X and returns a conﬁdence score—this is a 83 post-processing of the base model f .
We let ˆ ⇡ = h ( x ; f,  ) 2 [0 , 1] denote the conﬁdence estimatefor sample x when using model f .
For instance, if we have 100 predictions { ˆ y 1 , . . .
, ˆ y 100 } withconﬁdence ˆ ⇡ 1 = · · · = ˆ ⇡ 100 = 0 .
7 , then the accuracy of f is expected to be 70% on these 100samples (if the conﬁdence estimate is well calibrated).
Data from the domains P 1 , . .
, P K are usedfor learning the calibration models, and we call the in-distribution (InD) domains.
We use e
P to denotethe unseen out-of-distribution (OOD) domain which is not used for calibrating the base model.
Ourgoal is to learn a calibration map h that is well calibrated on the OOD domain e
P .
To do this, we willlearn a calibration map that does well on all InD domains simultaneously.
To measure calibration, we ﬁrst review the deﬁnition of approximate expected calibration error.
Deﬁnition 2.1 (ECE) .
For a set of samples D = { ( x i , y i ) } ni =1 with ( x i , y i ) i .
i .
d .
⇠ P ( X, Y ) , the(empirical) expected calibration error (ECE) with M bins evaluated on D is deﬁned as
[Equation]
and B m , acc( B m ) , conf( B m ) are deﬁned as
[Equation]
where ˆ ⇡ i and ˆ y i are the conﬁdence and predicted label of sample x i .
The empirical ECE deﬁned in Eq.
(1) approximates the expected calibration error (ECE) E [ | p  P (ˆ y =
y
| ˆ ⇡ = p ) | ] with bin size equal to M [28, 12]; see [25] for statistical results about about the empirical
ECE as an estimator.
The perfect calibrated map corresponds to the case when P (ˆ y =
y
| ˆ ⇡ = p ) =
pholds for all p 2 [0 , 1] .
Multi-domain calibration.
Although the standard ECE measurement in Eq.
(1) provides informativeevaluations for various calibration methods in the single-domain scenario, it does not provide ﬁnegrained evaluations when the dataset consists of multiple domains, P 1 , . .
, P K .
It is possible that the
ECE evaluated on the pooled data D pool K
= D 1 [ · · · [ D K is small while the ECE evaluated on one 104 of the domains is large.
For example, as shown in Figure 1(c), there may exist a domain, k 2 [ K ] , 105 such that the ECE evaluated on domain k is much higher than the ECE evaluated on the pooleddataset, i.e., ECE( D k )  ECE( D pool K ) .
In the fMRI application mentioned in Section 1, producingwell-calibrated conﬁdence on data from every hospital is a more desirable property compared to onlybeing calibrated on the pooled data from all hospitals.
Therefore, it is natural to consider the ECEevaluated on every domain, which we refer to as “per-domain ECE.”
Next, we introduce the notion of
Multi-domain ECE to formalize per-domain calibration.
Deﬁnition 2.2 (Multi-domain ECE) .
For a dataset D pool K = D 1 [ · · · [ D K consisting of samplesfrom K domains, where D k = { ( x i,k , y i,k ) } n k i
=
and ( x i,k , y i,k ) i .
i .
d .
⇠ P k
( X, Y ) , the (empirical)multi-domain expected calibration error (Multi-domain ECE) with M bins evaluated on D pool K isdeﬁned as MDECE ( D pool K )
= 1 K
P
Kk =1 ECE ( D k ) .
Compared with the standard ECE evaluated on the pooled dataset, multi-domain ECE providesinformation about per-domain model calibration.
In the multi-domain setting, we aim to learn acalibration map ˆ h that can produce calibrated conﬁdence estimates on every InD domain.
Intuitively,if the unseen OOD domain e
D is similar to one or multiple InD domains, ˆ h can still provide reliableconﬁdence estimates on the new domain.
We formally study the connection between “well-calibratedon each InD domain” and “robust calibration on the OOD domain” in Section 5.
Temperature scaling.
Next, we review a simple and effective calibration method, named temperaturescaling (TS) [33, 12], that is widely used in single-domain model calibration.
Temperature scalingapplies a single parameter T > 0 and produces the conﬁdence prediction for the base model f as
[Equation]
where [Softmax( z )]
j = exp([ z ] j ) /
P
Ji =1 exp([ z ] i ) .
The parameter T is the so-called temperature ,with larger temperature yielding more diffuse probability estimates.
To learn the temperatureparameter T from dataset D
= { ( x i , y i ) } ni =1 , Guo et al.
[12] propose to ﬁnd T by solving thefollowing convex optimization problem,
[Equation]
which optimizes the temperature parameter such that the negative log likelihood is minimized.
We use
TS-Alg to denote the temperature scaling learning algorithm; given inputs dataset D and base modelf , TS-Alg outputs the learned temeperature parameter by solving Eq.
e.g., ˆ T = TS-Alg ( D , f ) .
Multi-domain temperature scaling
We propose our algorithm—multi-domain temperature scaling—that aims to improve the calibrationon each domain.
One key observation is that if we apply temperature scaling to each domainseparately, then TS is able to produce calibrated conﬁdence on every domain.
Therefore, the questionbecomes how to “aggregate” these temperature scaling models and learn one calibration model,denoted by ˆ h , that has similar performance to the k -th calibration model ˆ h k evaluated on domain kfor
every k 2 [ K ] .
At a high level, we propose to learn a calibration model that maps samples from the input space X tothe temperature space R + .
To start with, we learn the temperature parameter ˆ T k for the base modelon every domain k by applying temperature scaling on D k .
Next, we apply the base deep model tocompute feature embeddings of samples from different domains, 1 and label feature embeddings fromthe k -th domain with ˆ T k .
In particular, we construct K new datasets, ˆ D 1 , . . .
, ˆ D K , where each datasetcontains feature embeddings and temperature labels from one domain, i.e., ˆ D k
= { ( ( x i,k ) , ˆ T k ) } n k i =1 .
Finally, we apply linear regression on these labeled datasets.
In detail, our algorithm is as follows:
Learn temperature scaling model for each domain.
For every domain k , we learn
temperature ˆ T k by applying temperature scaling on validation data D k
= { ( x i,k , y i,k ) } n k i =
from k -th domain, i.e., ˆ T k = TS-Alg ( D k , f ) and TS-Alg denotes the TS algorithm.
Learn linear regression of temperatures.
Extract the feature embeddings of the base deep
model f on each domain.
Use ( x i,k ) 2 R p to denote the feature embedding of the i -th sample from k -th domain.
Then we learn ˆ ✓ by solving the following optimization problem,
[Equation]
Predict temperature on unseen test samples.
Given an unseen test sample e x , we ﬁrst
compute the predicted temperature e T using the learned linear model e
T =
h ( x i,k ) , ˆ ✓ i
Then we output the conﬁdence estimate for sample e x as
[Equation]
We denote our proposed method by MD-TS (
M ult- D omain T emperature S caling).
A presentation ofthe algorithm in pseudocode can be found in Algorithm 1, Appendix A.
We pause to consider the basic concept in more detail.
The goal of our proposed algorithm is topredict the best temperature for samples from different several domains.
In an ideal setting where the learned linear model ˆ ✓ results in good calibration on every InD domain, we can expect that ˆ ✓will continue to yield good calibration on the OOD domain e
P when e
P is close to one or several InDdomains.
For example, e
P will work well if e
P is a mixture of the K domains, i.e., e
P =
P
Kk =1 ↵ k P kand ↵ 2  K  1 .
Regarding the algorithmic design, linear regression is one of the simplest modelsfor solving the regression problem.
It is computationally fast to learn such linear models as well asmake predictions on new samples, making it attractive.
We test alternative, more ﬂexible, regressionalgorithms in Section 4 but do not observe signiﬁcant gains over linear regression.
To illustrate how our proposed algorithm MD-TS performs differently from standard TS, we return to the
ImageNet-C dataset.
We compare the predicted temperature of our algorithm on new samples from domaink with the temperature that results from running TSon domain k alone.
The results are summarized in
Figure 2, where each circle corresponds to the meanpredicted temperature on one InD domain.
For eachdomain, we also visualize the standard deviation of thepredicted temperatures for samples from that domain(the horizontal bar around each point).
We ﬁnd that ouralgorithm predicts the temperature quite well.
Note thatit does not have access to the domain index informationof the fresh samples.
By contrast, TS always uses thesame temperature, regardless of the input point.
Experiments
In this section, we present experimental results evaluating our proposed method, demonstrating itseffectiveness on both in-distribution and out-of-distribution calibration.
We focus on three real-worlddatasets, including ImageNet-C [14]—a widely used robustness benchmark image classiﬁcationdataset, [-WILDS-RxRx
-]WILDS-RxRx1 [20]—an image of cells (by ﬂuorescent microscopy) dataset in the domain
benchmark, and GLDv2 [42]—a landmark recognition dataset in federated learning.
Additional experimental results and implementation details can be found in Appendix B.
Datasets.
We evaluate different calibration methods on three datasets, ImageNet-C, WILDS-RxRx1,and GLDv2.
ImageNet-C contains 15 types of common corruptions where each corruption includesﬁve severity levels.
Each corruption with one severity is one domain, and there are 76 domains intotal (including the standard ImageNet validation dataset).
We partition the 76 domains into disjointin-distribution domains and out-of-distribution by severity level or corruption type.
WILDS-RxRx1 isa domain generalization dataset, and we treat each experimental domain as one domain.
We adopt thedefault val/test split in Koh et al.
[20]: use the four validation domains as in-distribution domains andthe 14 test domains as the out-of-distribution domains.
We also provide experimental results of otherrandom splits in Appendix B. For GLDv2, each client corresponds to one domain, and there are 823domains in total.
We randomly select 500 domains for training the model, and then use the remaining323 domains for evaluation denoted by validation domains.
We further screen the validation domainsby removing the domains with less than 300 data points.
There are 44 domains after screening, andwe use 30 domains as in-distribution domains and the remaining 14 domains as out-of-distributiondomains.
For all datasets, we randomly sample half of the data from in-distribution domains forcalibrating models and use the remaining samples for InD ECE evaluation.
We use all the samplesfrom OOD domains for ECE evaluation.
Models and training setup.
We consider multiple network architectures for evaluation, including
ResNet-50 [13], ResNext-50 [44], DenseNet-121 [19], BiT-M-50 [21], Efﬁcientnet-b1 [36], ViTSmall, and ViT-Base [8].
To evaluate on ImageNet-C, we directly evaluate models that are pre-trainedon ImageNet [7].
For WILDS-RxRx1 and GLDv2, we use the ImageNet pre-trained models asinitialization and apply SGD optimizer to training the models on training datasets.
Evaluation metrics.
We use the Expected Calibration Error (ECE) as the main evaluation metric.
We set the bin size as 100 for ImageNet-C, and set bin size as 20 for WILDS-RxRx1 and GLDv2.
We evaluate ECE on both InD domains and OOD domains.
Speciﬁcally, we evaluate the ECE ofeach InD/OOD domain.
Meanwhile, we also evaluate the ECE of the pooled InD/OOD domains, i.e., [Table] [Figure] the ECE evaluated on all samples from InD/OOD domains.
We use unseen samples from the InDdomain to measure the per-domain ECE.
We also measure the averaged per-domain ECE results (i.e.,per-domain ECE averaged across domains)
4.1 Main results
We summarize the ECE results of different methods on three datasets in Table 1 and Figure 3.
Weuse TS to denote temperature scaling [12], and use MSP to denote applying the maximum softmaxprobability [15] of the model output (i.e., without calibration).
In Table 1, we use the ImageNetvalidation dataset and ImageNet-C datasets with severity level s 2 { 1 , 5 } as the InD domains and usethe remaining datasets as OOD domains.
We present the averaged per-domain ECE results in Table 1,and visualize the ECE of each domain in Figure 3.
As shown in Table 1 and Figure 3(a)-3(c), weﬁnd that our proposed approach achieves much better InD per-domain calibration compared with [Table]
baselines. Also, TS does not signiﬁcantly improve over MSP on ImageNet-C InD domains in Table 1,but our proposed method largely improve the ECE compared with MSP and TS.
For instance, the
ECE results of MSP and TS on Efﬁcientnet-b1 are 6.93 and 6.99, and our method achieves 3.84.
Intuitively, when there are a diverse set of domains in the calibration dataset, a single temperaturecannot provide well-calibrated conﬁdences.
In contrast, our proposed method is able to producemuch better InD conﬁdence estimates by leveraging the multi-domain structure of the data.
Next we study the performance of different methods on out-of-distribution domains.
From Table 1,we
ﬁnd that MD-TS achieves the best performance on OOD domains arcoss all the settings.
On
ImageNet-C with BiT-M-R50, MD-TS improves the ECE from 6.54 (MSP) to 4.05, while theperformance of TS is similar to MSP.
Moreover, MD-TS signiﬁcantly outperforms MSP and TS on
WILDS-RxRx1, where MD-TS improves over TS by around 5.00 measured in ECE.
Figure 3(d)-3(f)display the per-domain ECE performance on out-of-distribution domains.
MD-TS improves over TSon more than half of the domains in all three datasets.
For the remaining domains, MD-TS performsslightly worse than TS.
Furthermore, on those domains that TS performs poorly (ECE > 8), MD-TSlargely improves over TS by large margins.
Further comparisons in Appendix B.7 show that theseimprovements continue to hold when relative to two other calibration techniques: MC dropout [9]and deep ensembles [24].
4.2 Predicting generalization
Suppose a model can produce calibrated conﬁdences on unseen samples, in which case we couldleverage the calibrated conﬁdence to predict the model performance.
Speciﬁcally, based on thedeﬁnition of ECE in Eq.
(1), when the model is well-calibrated, the average of the calibratedconﬁdence is close to the average accuracy, i.e., Conf ( D ) ⇡
Acc ( D ) .
Meanwhile, predicting modelperformance accurately is an essential ingredient in developing reliable machine learning systems,especially under distributional shifts [11].
As shown in Table 1, we ﬁnd that our proposed methodproduces well-calibrated conﬁdence values on both InD and OOD domains.
We now measure itsperformance on predicting model performance and compare with existing methods.
We measurethe performance using mean absolute error (MAE), MAE =
(1 /K ) ·
[Equation]
| 250 where S k is the dataset from the k -th domain.
We show the predicting model accuracy results in Table 2.
MD-TS signiﬁcantly improves over existingmethods on predicting model performance across all three datasets.
For example, on ImageNet-C,calibrated conﬁdence of MD-TS produces fairly accurate predictions on both InD and OOD domains(less than 2% measured in MAE), which largely outperforms MSP and TS.
In Figure 4, we comparedthe prediction performance of TS and MD-TS on every OOD domain.
We ﬁnd that MD-TS achievesbetter prediction performance compared to TS on most of the domains.
Refer to Appendix B.1 formore results in which other architectures are tested.
4.3 MD-TS ablations
To learn a calibration model that performs well per-domain, we apply linear regression on featurerepresentations  ( x k ) such that h  ( x k ) , ✓ i ⇡ ˆ T k , where x k is from domain k and ˆ T k is the tem-
[Figure]
[Table]
perature parameter for domain k .
We investigate other methods for learning the map from featurerepresentations to temperatures in a regression framework.
Speciﬁcally, beside the ordinary leastsquares (OLS) used in Algorithm 1, we consider ridge regression (Ridge), robust regression with
Huber loss (Huber), kernel ridge regression (KRR) [Table] and K -nearest neighbors regression (KNN).
Theimplementations are mainly based on scikit-learn [32].
We use grid search (on InD domains) toselect hyperparameters for Ridge, Huber, KRR, and KNN.
We summarize the comparative results for different regression algorithms in Table 3.
Compared to
OLS, other regression algorithms do not achieve signiﬁcant improvement.
Speciﬁcally, KRR achievesslightly better performance on OOD domains, while other algorithms have similar performancecompared to OLS.
Moreover, there are no hyperparameter in OLS, which makes it more practical inreal-world problems.
Meanwhile, the results suggest that our proposed MD-TS is stable to the choiceof speciﬁc regression algorithms.
Theoretical analysis
In this section, we provide theoretical analysis to support our understanding of our proposed algorithmin the presence of distribution shifts.
We use h ? k
( · ) = h ( · ; f,  ? k ) :
X ! [0 , 1] to denote the bestcalibration map for the base model f on the k -th domain; this map minimizes the expected calibrationerror (ECE) E [ | p  P (ˆ y = y
| ˆ ⇡ = p ) | ] over distribution P k .
We also call h ?
k a hypothesis in thehypothesis class H .
Next, given the ﬁxed base model f , we aim to learn ˆ h ( · ) =
h ( · ; f, ˆ  ) suchthat " (ˆ h, P k,X ) =
E X ⇠ P k,X [ | h ?
k ( X )  ˆ h ( X ) | ] is small for every domain k , where " k (ˆ h ) denotes therisk of ˆ h w.r.t.
the the best calibration map h ?
k under domain P k .
In addition, we are interested ingeneralizing to new domains: suppose there is an unseen OOD domain e
P and its marginal featuredistribution is different from existing domains, i.e., e
{+P X 
+}
= P k,X for k 2 [ K ] .
Our goal is to understand the conditions under which ˆ h can have similar calibration on OOD domainsas the InD domains.
For example, if the OOD domain is similar to the mixture distribution of InDdomains, we would expect ˆ h performs similarly on InD and OOD domains.
To quantify the distance between two distributions, we ﬁrst introduce the H -divergence [4] to measure the distance betweentwo distributions:
Deﬁnition 5.1 ( H -divergence) .
Given an input space X and two probability distributions P X and 289 P 0 X on X , let H be a hypothesis class on X , and denote by A the collection of subsets of X which 290 are the support of hypothesis h 2 H ,
i.e., A H = { h  1 (1) | h 2 H } .
The distance between P X and 291 P 0 X is deﬁned as
[Equation]
The H -divergence reduces to the standard total variation (TV) distance when H contains all measurable functions on X , which implies that the H -divergence is upper bounded by the TV-distance,i.e., d H ( P X , P 0 X )  d TV ( P X , P 0 X ) .
On the other hand, when the hypothesis class H has a ﬁnite VCdimension or pseudo-dimension, the H -divergence can be estimated using ﬁnite samples from P Xand P 0 X [4].
Next, we deﬁne the mixture distribution of the K in-distribution domains P ↵ K,X on inputspace X as follows:
[Equation]
where
[Equation]
Given multiple domains { P 1 , . . .
, P K } , we can optimize the combination parameters ↵ such that
P ↵ K,X minimizes the H -divergence between P ↵ K,X and e
P X .
More speciﬁcally, we deﬁne ˆ ↵ asˆ ↵ = argmin ↵
[Equation]
, P ↵ K
[Equation]
X ) + " ( h ? [Equation] e P X ) , (3) where h ? :
= argmin h 2 H { " ( h, P ↵ K,X )+ " ( h, e
P X ) } and ¯ H is deﬁned as ¯ H :
= { sign( | h ( x )  h 0 ( x ) | t ) | h, h 0 2 H , 0  t  1 } .
We now give an upper bound on the risk on the unseen OOD domain.
This 302 result follows very closely those of Blitzer et al.
[5], Zhao et al.
[47], instantiated in our calibrationsetup.
Details can be found in Appendix E.
Theorem 5.2.
Let H be a hypothesis class that contains functions h : X ! [0 , 1] with pseudodimension Pdim( H ) =
d . Let { D k,X } Kk =1 denote the empirical distributions generated from{ P k,X } Kk =1 , where D k,X contains n i.i.d.
samples from the marginal feature distribution P k,X of 307 domain k .
Then for  2 (0 , 1) , with probability at least 1   , we have
[Equation]
where ˆ ↵ and  ( P ˆ ↵ K,X , e
P X ) are deﬁned in Eq.
(3) , e
P X denotes the marginal distribution of the
OOD domain, Pdim( H ) is the pseudo-dimension of the hypothesis class H , and ˆ " (ˆ h, D k,X ) is theempirical risk of the hypothesis ˆ h on D k,X .
This result means that if we can learn a hypothesis ˆ h that achieves small empirical risk ˆ " ( ˆ h, D k,X )on every domain, then ˆ h is able to achieve good performance on the OOD domain if distribution ofthe OOD domain is similar to the mixture distribution of InD domains measured by H -divergence.
In this case, if the learned calibration map ˆ h is well-calibrated on every domain P k , then ˆ h is likelyto provide calibrated conﬁdence for the OOD domain e
P .
Recall from Section 4, we proposed analgorithm that performs well across InD domains.
The upper bound in Eq.
(4) provides insight intounderstanding why this algorithm is effective.
Discussion
We have developed an algorithm for robust calibration that exploits multi-domain structure in datasets.
Experiments on real-world domains indicate that multi-domain calibration is an effective way toimprove the robustness of calibration under distribution shifts.
One interesting direction for futurework would be to extend our algorithm to a scenario where no domain information is available.
Wehope the multi-domain calibration perspective in this paper can motivate further work to close thegap between in-distribution and out-of-distribution calibration.