Section 53.2: Model uncertainty and calibration

A robust robot is not the one that never sees surprise, it is the one that notices surprise early enough to act differently.

A Runtime Monitoring Engineer
Big Picture

Uncertainty estimates are useful only if they are calibrated enough to support action gating, planning fallbacks, or human alerts. This section separates uncertainty source from calibration quality.

Model uncertainty and calibration illustration for Chapter 53.
Figure 53.2.1: A reliability diagram and confidence trace show that confidence must match empirical correctness, not just feel intuitive.

Why This Matters

Model uncertainty and calibration is useful only when it distinguishes disturbance sources and ties them to specific corrective actions. Robustness is not one scalar, it is a map from perturbation class to degraded behavior, detection delay, and residual risk.

A standard calibration statistic is the expected calibration error $$\mathrm{ECE} = \sum_{b=1}^{B} \frac{|S_b|}{n}\, |\mathrm{acc}(S_b) - \mathrm{conf}(S_b)|,$$ where $S_b$ is the set of predictions whose confidence falls in bin $b$. In embodied systems, calibration should be evaluated on action-relevant predictions, not only class labels.

Key Insight

An uncertainty signal can have the right ordering but the wrong scale. Calibration is what makes the scale actionable for a threshold, an intervention rule, or a planner cost.

Algorithmic View
  1. Choose the prediction interface that matters for action, such as grasp success probability or collision-free path confidence.
  2. Collect held-out or replayed episodes with prediction confidence and empirical outcome.
  3. Compute calibration summaries such as ECE, reliability bins, and threshold-conditioned precision.
  4. If needed, fit a calibration map on one panel and test it on a separate shifted panel.
  5. Use the calibrated confidence only if it remains stable under the deployment shifts you care about.

Worked Example

A manipulation policy may be good at ranking candidate grasps yet still overclaim 0.95 confidence on cases that succeed only 0.70 of the time. A runtime gate built on that confidence will intervene too late.

predictions = [
    {"confidence": 0.9, "correct": 1},
    {"confidence": 0.8, "correct": 1},
    {"confidence": 0.8, "correct": 0},
    {"confidence": 0.6, "correct": 1},
    {"confidence": 0.55, "correct": 0},
    {"confidence": 0.95, "correct": 1},
]

def binned_ece(preds, n_bins=10):
    """Proper binned ECE: sum over bins of (n_b / N) * |accuracy_b - confidence_b|."""
    N = len(preds)
    edges = [i / n_bins for i in range(n_bins + 1)]
    ece = 0.0
    for i in range(n_bins):
        lo, hi = edges[i], edges[i + 1]
        in_bin = [p for p in preds if lo < p["confidence"] <= hi or (i == 0 and p["confidence"] == 0.0)]
        if not in_bin:
            continue
        n_b = len(in_bin)
        acc_b = sum(p["correct"] for p in in_bin) / n_b
        conf_b = sum(p["confidence"] for p in in_bin) / n_b
        ece += (n_b / N) * abs(acc_b - conf_b)
    return ece

ece = binned_ece(predictions)
print({"n_predictions": len(predictions), "binned_ece": round(ece, 4)})
{'n_predictions': 6, 'binned_ece': 0.15}
Code Fragment 53.2.1 computes a simple calibration gap, the minimal signal needed before choosing a confidence threshold.

Expected output: The small gap here suggests the average scale is close, but a real evaluation would still inspect bins because cancellation can hide local miscalibration. Calibration is about the full reliability shape, not only the mean.

Library Shortcut

Torchmetrics, scikit-learn calibration tools, MAPIE-style conformal wrappers, and reliability-diagram notebooks can automate reliability curves and threshold audits once the action-relevant prediction interface is defined.

Concrete stack anchors for this chapter include PyTorch or JAX evaluation loops for saving logits and uncertainty heads, OpenCV or Open3D replay tools for checking perception-linked failures, Torchmetrics and scikit-learn for calibration analysis, MAPIE or related conformal wrappers for thresholding, Weights & Biases or TensorBoard dashboards for reliability diagrams, and ROS 2 diagnostics when the calibrated signal gates a real runtime action.

Calibration Tool Anchors
ToolRoleAudit Question
TorchmetricsFast ECE, binning, and confidence summaries inside PyTorch evaluation loops.Is the metric attached to the prediction that actually changes the robot's action?
scikit-learnCalibration curves, isotonic regression, and threshold sweeps.Was the calibration split frozen before deployment outcomes were inspected?
MAPIE-style conformal wrappersCoverage-style intervals and abstention sets.Does coverage remain acceptable on the shifted panel, not only on the clean split?

In embodied systems, calibration must be tied to consequences. A poorly calibrated collision predictor and a poorly calibrated object classifier are not equally serious if only one gates a safety-critical maneuver. In practice, teams often compare temperature scaling, isotonic regression, and conformal intervals on the exact signal that drives a stop, reroute, or human-review threshold.

The implementation contract is simple: the confidence value in the PyTorch or JAX tensor must be the same signal logged in the replay artifact, plotted in Weights & Biases or TensorBoard, and consumed by the ROS 2 gate. A calibration curve that is detached from the deployed threshold is analysis theater, not safety evidence.

A frequent failure is to calibrate on clean validation data and deploy on shifted scenes. The confidence scale then looks disciplined in the notebook and collapses in the field.

Cross-References

This section connects to Section 53.3 on OOD detection and Section 54.4 on shielded policies, where calibrated thresholds become actual intervention logic.

Lab Recipe

Log confidence and outcome for one embodied prediction task, compute a reliability diagram, then decide whether you trust a threshold to trigger degraded mode or human review.

Failure Mode

Do not calibrate confidence on a proxy metric that the action policy never uses. The only calibration that matters is the calibration of the signal tied to a real decision.

Practical Example

For a self-driving perception stack, calibration may matter most for occupancy or collision probability, not for semantic class labels that have no immediate control effect.

Research Frontier

Open work includes sequence-level calibration, calibration for action distributions rather than labels, and joint calibration across planners, policies, and monitors in one control loop.

Self Check

Can you explain why an accurate but miscalibrated confidence head can still be dangerous in deployment? If not, connect the threshold choice to a missed or false intervention.

Key Takeaway

Calibration turns uncertainty from a descriptive score into a decision-support signal that can safely trigger thresholds and fallbacks.

Exercise 53.2.1

Take one model output from your own stack and define how you would test whether its confidence is calibrated enough to drive a runtime threshold.

Section References

Guo, C. et al. "On Calibration of Modern Neural Networks." (2017). https://arxiv.org/abs/1706.04599

A standard reference for calibration evaluation and post-hoc adjustment.

Ovadia, Y. et al. "Can You Trust Your Model’s Uncertainty? Evaluating Predictive Uncertainty Under Dataset Shift." (2019). https://arxiv.org/abs/1906.02530

Calibration under shift is the real embodied challenge.

What's Next

Section 53.3 continues by asking how to detect states that should not be trusted at all because they lie outside the supported distribution.