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 (nn.Module) – Trained classification model. Defaults to
None.randomized (bool) – Whether to use randomized smoothing in RAPS. Defaults to
True.penalty (float) – Regularization weight. Defaults to
0.1.regularization_rank (int) – Rank threshold for regularization. Defaults to
1.ts_init_val (float, optional) – Initial value for the temperature. Defaults to
1.0.ts_lr (float, optional) – Learning rate for the optimizer. Defaults to
0.1.ts_max_iter (int, optional) – Maximum number of iterations for the optimizer. Defaults to
100.enable_ts (bool) – Whether to scale the logits. Defaults to
False.device (Literal["cpu", "cuda"] | torch.device | None, optional) – device. Defaults to
None.
- Reference:
TODO:
Code inspired by TorchCP.
- conformal(inputs)#
Compute the prediction set for each input.
- fit(dataloader)#
Calibrate the APS threshold q_hat on a calibration set.
- model_forward(inputs)#
Apply the model and return the scores.