This is the official code repository for "A Consistent and Differentiable Lp Canonical Calibration Error Estimator", published in NeurIPS 2022.
The paper proposes
The weight
Additionally, the estimator can be used as a metric to evaluate canonical (distribution), marginal (classwise) and top-label (confidence) calibration.
Copy the file ece_kde.py
to your repo. You can obtain the estimate of CE with the method get_ece_kde
. The bandwidth
of the kernel can either be manually set, or chosen by maximizing the leave-one-out likelihood with the method
get_bandwidth
.
For example, an estimate of canonical CE as defined in Equation 9 in the paper can be obtained with:
# Generate dummy probability scores and labels
f = torch.rand((50, 3))
f = f / torch.sum(f, dim=1).unsqueeze(-1)
y = torch.randint(0, 3, (50,))
get_ece_kde(f, y, bandwidth=0.001, p=1, mc_type='canonical', device='cpu')
The code is still in its preliminary version. A demo will be available soon.
If you found this work or code useful, please cite:
@inproceedings{Popordanoska2022b,
title={A Consistent and Differentiable $L_p$ Canonical Calibration Error Estimator},
AUTHOR = {Popordanoska, Teodora and Sayer, Raphael and Blaschko, Matthew B.},
YEAR = {2022},
booktitle = {Advances in Neural Information Processing Systems},
}
Everything is licensed under the MIT License.