Modern deep neural networks routinely output high softmax probabilities even when they are completely wrong or evaluated on inputs far outside their training support. In my research on reliable machine learning and clinical decision support, I treat predictive uncertainty not as an afterthought metric, but as a structural signal that governs whether a model's prediction can be trusted, routed to a deeper network branch, or deferred to a human specialist. This note formalizes the distinction between maximum softmax confidence, predictive Shannon entropy, aleatoric vs. epistemic uncertainty via mutual information decomposition, and probabilistic calibration measured through Expected Calibration Error (\(\text{ECE}\)) and corrected via post-hoc Temperature Scaling.
Note Information
| Field | Value |
|---|---|
| Note Title | Understanding Predictive Uncertainty: Entropy, Confidence, and Calibration |
| Topic / Area | Probabilistic Deep Learning / Uncertainty Quantification |
| Main Focus | Entropy, confidence, calibration |
| Note Type | Mathematical Synthesis & Implementation Note |
| Date Created | January 12, 2025 |
| Last Updated | March 02, 2025 |
| Status | Evergreen |
| Confidence Level | High — Validated across medical imaging & tabular risk pipelines |
| Tags | Predictive Uncertainty, Shannon Entropy, Calibration, ECE, Temperature Scaling |
Source or Context
- Primary References:
- 1Guo, C., Pleiss, G., Sun, Y., & Weinberger, K. Q. (2017). On Calibration of Modern Neural Networks. In Proceedings of the 34th International Conference on Machine Learning (ICML), PMLR 70:1321–1330.
- 2Kendall, A., & Gal, Y. (2017). What Uncertainties Do We Need in Bayesian Deep Learning for Computer Vision? In Advances in Neural Information Processing Systems (NeurIPS 2017).
- 3Depeweg, S., Hernandez-Lobato, J. M., Doshi-Velez, F., & Udluft, S. (2018). Decomposition of Uncertainty in Bayesian Deep Learning for Efficient and Risk-Sensitive Learning. In ICML 2018.
- 4Niculescu-Mizil, A., & Caruana, R. (2005). Predicting Good Probabilities with Supervised Learning. In ICML 2005.
- Why I Wrote This Note: When we trained convolutional classifiers for tuberculosis screening from chest radiographs and early hospital readmission prediction for diabetes patients, I noticed that standard cross-entropy training pushes logits to extreme magnitudes. A raw softmax score of \(0.96\) does not mean the patient has a \(96\%\) empirical probability of readmission. I compiled this note to establish a clean mathematical and PyTorch foundation that separates confidence, dispersion (entropy), knowledge uncertainty (epistemic), and calibration.
Quick Summary
- Confidence is Pointwise; Entropy is Distributional: Maximum softmax probability \(\hat{p} = \max_c p(y=c\mid x)\) only looks at the winning class, whereas predictive Shannon entropy \(\mathcal{H}[p(y\mid x)]\) integrates dispersion across all \(C\) classes.
- Total Uncertainty Decomposes Cleanly: Under a posterior distribution over parameters \(p(\theta \mid \mathcal{D})\), total predictive entropy decomposes additively into Aleatoric Uncertainty (expected data entropy) and Epistemic Uncertainty (mutual information \(\mathcal{I}[y; \theta \mid x, \mathcal{D}]\)).
- Modern Deep Nets Are Overconfident by Construction: Negative log-likelihood (NLL) continues to decrease even after classification error hits \(0\%\) on the training set, driving weight norms and logit magnitudes upward and causing severe miscalibration.
- Calibration \(\neq\) OOD Detection: Post-hoc Temperature Scaling optimizes a single scalar \(T > 0\) on a validation split to dramatically lower \(\text{ECE}\) in-distribution, while leaving the relative class ranking \(\arg\max_c z_c\) strictly invariant.
Key Content
4.1 Confidence vs. Predictive Entropy
Let \(f_\theta: \mathcal{X} \to \mathbb{R}^C\) denote a neural network mapping an input \(x \in \mathcal{X}\) to a logit vector \(\mathbf{z} = f_\theta(x) = (z_1, \dots, z_C)^\top\). The categorical predictive distribution is obtained via the softmax transformation:
From this probability simplex \(\Delta^{C-1}\), we extract two distinct scalar summaries:
- 1Maximum Softmax Confidence (\(\hat{p}\)):
- 1Predictive Shannon Entropy (\(\mathcal{H}\)):
To compare entropy across tasks with different class cardinalities \(C\), I normalize entropy by the uniform distribution bound \(\log C\), yielding \(\tilde{\mathcal{H}}(x) = \mathcal{H}[p_\theta(y\mid x)] / \log C \in [0, 1]\). Consider a \(10\)-class problem where Model A predicts \((0.50, 0.50, 0, \dots, 0)\) and Model B predicts \((0.50, 0.055, \dots, 0.055)\). Both share identical confidence \(\text{Conf}(x) = 0.50\), yet Model A exhibits two-class ambiguity (\(\mathcal{H} \approx 0.693\text{ nats}\)) while Model B spreads its remaining mass across nine classes (\(\mathcal{H} \approx 1.792\text{ nats}\)). Entropy captures the full geometry of the tail.
4.2 Information-Theoretic Decomposition of Uncertainty
A single deterministic network cannot distinguish between an intrinsically ambiguous input (e.g., an occluded chest X-ray boundary) and an unfamiliar input from an underrepresented subpopulation. When we maintain a distribution over parameters \(q(\theta) \approx p(\theta \mid \mathcal{D})\) (via an ensemble of \(M\) models or \(M\) stochastic forward passes), the posterior predictive distribution is:
Taking the Shannon entropy of \(\bar{p}(y \mid x)\) and subtracting the expected entropy of individual models yields the Mutual Information (\(\text{BALD}\) objective):
flowchart LR
X["Input Sample x"] --> ENS["Posterior Samples {θ₁, ..., θ_M}"]
ENS --> PBAR["Posterior Predictive p̄(y|x)"]
PBAR --> TU["Total Entropy H[p̄(y|x)]"]
TU --> AU["Aleatoric: E_θ[H[p(y|x,θ)]]<br/>Irreducible Data Noise"]
TU --> EU["Epistemic: I[y; θ | x]<br/>Model Ignorance / OOD"]4.3 Probabilistic Calibration and ECE
A classifier is perfectly calibrated if its predicted confidence matches its true empirical accuracy at every confidence level \(p \in [0, 1]\):
Because \(\hat{P}\) is a continuous random variable, we approximate this expectation in practice by partitioning predictions on \(N\) test samples into \(B\) equally spaced confidence bins \(\{I_1, \dots, I_B\}\) where \(I_b = (\frac{b-1}{B}, \frac{b}{B}]\). Letting \(B_b\) denote the indices of samples whose confidence falls into bin \(I_b\), the Expected Calibration Error (\(\text{ECE}\)) is:
where empirical bin accuracy and mean bin confidence are defined as:
For safety-critical clinical settings, I also track Maximum Calibration Error (\(\text{MCE}\)):
4.4 Post-Hoc Calibration via Temperature Scaling
The simplest and most effective parametric post-hoc calibration method is Temperature Scaling (Guo et al., 2017). Given frozen validation logits \(\mathbf{z}_i\), we rescale by a single positive scalar temperature \(T > 0\):
We optimize \(T^\star\) by minimizing the Negative Log-Likelihood on a held-out calibration split \(\mathcal{D}_{\text{val}}\) via L-BFGS:
As \(T \to \infty\), \(\hat{\mathbf{q}}_i\) approaches the uniform distribution \((1/C, \dots, 1/C)\) with maximum entropy \(\log C\). When \(T > 1\) (typical for overconfident ResNets and Vision Transformers), Temperature Scaling softens the probability distribution and increases predictive entropy without altering top-\(1\) accuracy.
import torch
import torch.nn as nn
import torch.nn.functional as F
class TemperatureScaler(nn.Module):
# Post-hoc temperature scaling module optimized via L-BFGS on validation logits
def __init__(self, init_temp: float = 1.5):
super().__init__()
self.log_temperature = nn.Parameter(torch.tensor([init_temp]).log())
@property
def temperature(self) -> torch.Tensor:
return self.log_temperature.exp()
def forward(self, logits: torch.Tensor) -> torch.Tensor:
return logits / self.temperature
def fit(self, val_logits: torch.Tensor, val_labels: torch.Tensor) -> float:
optimizer = torch.optim.LBFGS([self.log_temperature], lr=0.05, max_iter=60)
criterion = nn.CrossEntropyLoss()
def closure():
optimizer.zero_grad()
loss = criterion(self.forward(val_logits), val_labels)
loss.backward()
return loss
optimizer.step(closure)
return float(self.temperature.item())
def compute_ece_and_uncertainty(probs: torch.Tensor, labels: torch.Tensor, n_bins: int = 15):
# Compute Expected Calibration Error (ECE) and normalized Shannon entropy
confidences, predictions = probs.max(dim=-1)
accuracies = predictions.eq(labels).float()
# Normalized predictive Shannon entropy in [0, 1]
num_classes = probs.size(-1)
entropy = -(probs * probs.clamp_min(1e-12).log()).sum(dim=-1) / torch.log(torch.tensor(float(num_classes)))
bin_boundaries = torch.linspace(0.0, 1.0, n_bins + 1, device=probs.device)
ece = torch.zeros(1, device=probs.device)
for b in range(n_bins):
in_bin = (confidences > bin_boundaries[b]) & (confidences <= bin_boundaries[b + 1])
prop_in_bin = in_bin.float().mean()
if prop_in_bin.item() > 0:
acc_in_bin = accuracies[in_bin].mean()
conf_in_bin = confidences[in_bin].mean()
ece += torch.abs(acc_in_bin - conf_in_bin) * prop_in_bin
return float(ece.item()), entropyCritical Analysis
| Dimension | Strengths | Weaknesses / Failure Modes | Hidden Assumptions |
|---|---|---|---|
| Shannon Entropy \(\mathcal{H}(\hat{p})\) | Captures full-simplex dispersion across all \(C\) classes; continuous and differentiable. | Single deterministic forward pass conflates epistemic ignorance with aleatoric noise. | Assumes the logit features have not collapsed onto an in-distribution manifold on OOD inputs. |
| Expected Calibration Error (\(\text{ECE}\)) | Intuitive scalar summary of reliability diagram alignment. | Sensitive to bin count \(B\), sample size \(N\), and class imbalance; only evaluates top-1 confidence (not full-class marginal calibration). | Assumes static evaluation distribution matching the deployment domain. |
| Temperature Scaling (\(T\)) | \(1\)-parameter convex optimization in NLL; preserves top-1 accuracy exactly; zero inference overhead once folded into final linear layer. | Calibration degrades rapidly under covariate shift (Ovadia et al., 2019); assigns identical temperature \(T\) to all regions of input space \(\mathcal{X}\). | Assumes validation set \(\mathcal{D}_{\text{val}}\) is i.i.d. with test deployment data. |
Relevance to My Research
In my published work on diabetes patient early readmission risk minimization (IEEE BECITHCON 2024) and tuberculosis screening from chest X-rays (IEEE ICEEICT 2024), raw classifier probabilities cannot be handed directly to clinicians as risk percentages.
- In clinical risk scoring, an uncalibrated model with \(\text{ECE} > 0.12\) systematically distorts downstream expected utility thresholds.
- Furthermore, in TIG-UNet++ lung region segmentation (ICICT 2025), pixel-wise predictive entropy maps highlight boundary ambiguity along the costophrenic angles and diaphragm, giving us a spatial uncertainty mask that explains where the segmentation backbone needs thresholded guidance.
- Finally, calibrated predictive entropy serves as the halting signal in my ongoing experiments on Early-Exit Neural Networks and Risk-Constrained Selective Prediction.
Observations and Insights
- Label Smoothing vs. Temperature Scaling: Training with Label Smoothing (\(\epsilon = 0.1\)) implicitly prevents logit explosion and reduces pre-scaling \(\text{ECE}\), but it often erases subtle epistemic distance signals in logit space. I have found that training with standard cross-entropy + L2 weight decay followed by post-hoc Temperature Scaling preserves better out-of-distribution separability.
- Adaptive Binning (ACE): Standard fixed-width \(\text{ECE}\) leaves mid-confidence bins (\([0.4, 0.7]\)) nearly empty for high-accuracy classifiers, introducing high variance. Using equal-mass (quantile) bins via Adaptive Calibration Error (\(\text{ACE}\)) provides a much more stable diagnostic on small medical validation cohorts (\(N < 1,000\)).
Actionable Follow-Ups
- Verified
- Verified
- Pending
- Pending
Quotes, Equations, Figures, or Snippets
"A neural network that achieves 99% accuracy on a test benchmark can still be dangerously uncalibrated if its 99% confidence predictions are only correct 80% of the time."
Core Calibration & Decomposition Identity Card:
Links and Connections
- Connected Research Notes:
- Deep Ensembles vs MC Dropout — How to instantiate \(q(\theta)\) in practice to compute the epistemic mutual information \(\mathcal{I}[y; \theta \mid x]\) derived above.
- Distribution Shift: A Practical Introduction — Why post-hoc Temperature Scaling breaks down when \(p_{\text{test}}(x) \neq p_{\text{train}}(x)\).
- Early-Exit Neural Networks — Using normalized predictive entropy \(\tilde{\mathcal{H}}(x) < \tau_m\) as a dynamic halting criterion.
- Risk-Constrained AI Decision-Making — Converting calibrated predictive probabilities into selective prediction abstention rules.
Revision History
| Version | Date | Changes Made |
|---|---|---|
| v1.0 | 2025-01-12 | Initial mathematical synthesis of confidence, Shannon entropy, and ECE. |
| v2.0 | 2025-02-08 | Added mutual information decomposition (\(\text{BALD}\)) and PyTorch TemperatureScaler L-BFGS module. |
| v2.4 | 2025-03-02 | Added clinical imaging connections (TIG-UNet++ boundary entropy) and ACE vs. ECE analysis. |