ConformalClsRAPS#
- class torch_uncertainty.post_processing.ConformalClsRAPS(alpha, model=None, randomized=True, penalty=0.1, regularization_rank=1, ts_init_val=1.0, ts_lr=0.1, ts_max_iter=100, enable_ts=False, device=None)[source]#
Conformal prediction with RAPS scores.
- Parameters:
alpha (
float) – The confidence level meaning we allow \(1-\alpha\) error.model (
Module|None) – Trained classification model. Defaults toNone.randomized (
bool) – Whether to use randomized smoothing in RAPS. Defaults toTrue.penalty (
float) – Regularization weight. Defaults to0.1.regularization_rank (
int) – Rank threshold for regularization. Defaults to1.ts_init_val (
float) – Initial value for the temperature. Defaults to1.0.ts_lr (
float) – Learning rate for the temperature scaling optimizer. Defaults to0.1.ts_max_iter (
int) – Maximum number of iterations for the temperature scaling optimizer. Defaults to100.enable_ts (
bool) – Whether to scale the logits. Defaults toFalse.device (
Union[Literal['cpu','cuda'],device,None]) – device. Defaults toNone.
Warning
This implementation only works in the multiclass setting. Raise an issue if binary is needed.
- Reference:
TODO:
Code inspired by TorchCP.
- conformal(inputs)#
Compute the prediction set for each input.
- Return type:
Tensor
- fit(dataloader)#
Calibrate the APS threshold q_hat on a calibration set.
- Return type:
None
- model_forward(inputs)#
Apply the model and return the scores.
- Return type:
Tensor