CurrentModule = CounterfactualExplanations
The ProbeGenerator
is designed to navigate the trade-offs between costs and robustness in Algorithmic Recourse (Pawelczyk et al. 2022).
The goal of ProbeGenerator is to find a recourse x’ whose prediction at any point y within some set around x’ belongs to the positive class with probability 1 - r, where r is the recourse invalidation rate. It minimizes the gap between the achieved and desired recourse invalidation rates, minimizes recourse costs, and also ensures that the resulting recourse achieves a positive model prediction.
The loss function this generator is defined below. R is a hinge loss parameter which helps control for robustness. The loss and penalty functions can still be chosen freely.
R uses the following formula to control for noise. It generates small perturbations and checks how often the counterfactual explanation flips back to a factual one, when small amounts of noise are added to it.
The above formula is not differentiable. For this reason the generator uses the closed form version of the formula below.
Generating a counterfactual with the data loaded and generator chosen works as follows:
Note: It is important to set the convergence to “:invalidation_rate” here.
M = fit_model(counterfactual_data, :DeepEnsemble)
opt = Descent(0.01)
generator = CounterfactualExplanations.Generators.ProbeGenerator(opt=opt)
conv = CounterfactualExplanations.Convergence.InvalidationRateConvergence(;invalidation_rate=0.5)
ce = generate_counterfactual(x, target, counterfactual_data, M, generator, convergence=conv)
plot(ce)
Choosing different invalidation rates makes the counterfactual more or less robust. The following plot shows the counterfactuals generated for different invalidation rates.
Pawelczyk, Martin, Teresa Datta, Johannes van-den-Heuvel, Gjergji Kasneci, and Himabindu Lakkaraju. 2022. “Probabilistically Robust Recourse: Navigating the Trade-Offs Between Costs and Robustness in Algorithmic Recourse.” arXiv Preprint arXiv:2203.06768.