Conformal Prediction API¶
deepuq.methods.conformal ¶
Conformal Prediction methods for distribution-free uncertainty quantification.
AdaptiveConformalPredictor ¶
Online adaptive conformal predictor with coverage guarantees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model | Module | Trained model. | required |
target_coverage | float | Target coverage level (default 0.9). | 0.9 |
gamma | float | Step size for online threshold updates. | 0.01 |
CQRPredictor ¶
Bases: BaseConformalPredictor
Adaptive conformal intervals using quantile regression.
Requires a model that outputs (lower_quantile, upper_quantile) as a tensor of shape (N, 2) or a tuple.
ConformalClassifier ¶
Bases: BaseConformalPredictor
Prediction sets with marginal coverage guarantee.
Supports Adaptive Prediction Sets (APS) and Regularized APS (RAPS).
ConformalUQWrapper ¶
Bases: BaseConformalPredictor
Calibrate intervals from any predict_uq()-compatible method.
Wraps Laplace, Ensembles, MC Dropout, etc. to guarantee coverage.
SplitConformalRegressor ¶
Bases: BaseConformalPredictor
Distribution-free prediction intervals for any regression model.
Guarantees P(Y in [lower, upper]) >= 1 - alpha for exchangeable data.
WeightedConformalPredictor ¶
Conformal predictor with importance-weighted calibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model | Module | Trained model (callable on input tensors). | required |
score_fn | Callable[..., Tensor] | None | Callable | None |
calibrate ¶
Calibrate using weighted nonconformity scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cal_X | Tensor | | required |
cal_y | Tensor | | required |
weights | Tensor | | required |
predict_set ¶
Compute prediction intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Tensor | | required |
alpha | float | | 0.1 |
Returns:
| Type | Description |
|---|---|
Tuple of (lower, upper) bounds. | |
absolute_residual_score ¶
Absolute residual: |y - y_hat|.
check_coverage ¶
Compute empirical coverage fraction.
conformal_quantile ¶
Compute the conformal quantile of nonconformity scores.
Returns the ceil((n+1)*(1-alpha))/n quantile of the scores.
normalized_residual_score ¶
Normalized absolute residual: |y - y_hat| / sigma.
quantile_score ¶
CQR score: max(q_lo - y, y - q_hi).
signed_residual_score ¶
Signed residual: y - y_hat.