mixle.inference.uq module¶
Unified uncertainty dispatch for models, predictors, ensembles, and LLM-style callables.
uq(thing, data) inspects the object it receives and routes to a compatible
uncertainty method, returning a UQResult with the method name and the
quantities needed for downstream checks.
a fitted mixle model (has
seq_log_density) -> a Laplace parameter posterior; sample fitted models, read any summary, get a credible interval (epistemic uncertainty over parameters).a torch module / any point predictor callable over arrays -> split-conformal calibration from a held-out
(X, y);interval(x)returns a prediction interval with finite-sample coverage. Give a LIST of predictors instead and it becomes a deep ensemble (epistemic spread + conformal).an LLM-style callable over prompts (returns a string, or samples of strings) -> semantic entropy over meaning classes;
confident(prompt)abstains when the model disagrees with itself.
The method is chosen from observed capability rather than a caller-supplied mode string.
- class UQResult(kind, method, payload)[source]
Bases:
objectThe uncertainty of a predictor, with the method that produced it and receipts to check it.
- kind: str
- method: str
- sample_models(n=200, *, seed=None)[source]
nfitted models drawn from the parameter posterior (epistemic ensemble).
- credible_interval(readout, alpha=0.1, *, n=400, seed=0)[source]
A
1-alphacredible interval onreadout(model)over the parameter posterior.
- interval(x, alpha=None)[source]
Calibrated prediction interval(s) at
x.alphaoverrides the calibrated level.
- epistemic_std(x)[source]
Ensemble disagreement (std across members) at
x– 0.0 for a single predictor.
- semantic_entropy(prompt, *, n=8)[source]
Entropy (nats) over the meaning classes of
nsampled generations forprompt.
- confident(prompt, *, n=8, max_entropy=None)[source]
True when semantic entropy is below the threshold – else the model disagrees with itself.
- uq(thing, data=None, *, alpha=0.1, equivalent=None)[source]
Quantify the uncertainty of
thing, choosing the method from whatthingis.- Parameters:
thing (Any) – a fitted mixle model, a torch module / point-predictor callable (or a list of them for a deep ensemble), or an LLM-style callable that maps a prompt to a generation.
data (Any) – for a mixle model, the fitting data (builds the Laplace posterior); for a point predictor,
(X_cal, y_cal)calibration data; for an LLM, optional example prompts used to calibrate an abstention threshold.alpha (float) – target miscoverage / abstention level (
1 - alphacoverage).equivalent (Callable[[Any, Any], bool] | None) – for the LLM path, an optional meaning-equivalence predicate over generations (default: exact string match after stripping).
- Returns:
A
UQResultexposing the method-appropriate accessors and its own calibration numbers.- Return type:
UQResult