Skip to content

Commit 2c38590

Browse files
committed
only findings left now
1 parent 036cdbb commit 2c38590

9 files changed

Lines changed: 526 additions & 323 deletions

File tree

dev/build/paper/paper.html

Lines changed: 96 additions & 67 deletions
Large diffs are not rendered by default.

dev/build/paper/paper.pdf

-13.6 KB
Binary file not shown.

dev/build/paper/www/mitigation.png

53.3 KB
Loading

dev/notebooks/synthetic.qmd

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ results = Serialization.deserialize(joinpath(output_path,"results_strict.jls"))
170170
line_charts = Dict()
171171
errorbar_charts = Dict()
172172
for (data_name, res) in results
173-
line_charts[data_name] = plot(res)
174-
errorbar_charts[data_name] = plot(res,50)
173+
plt = plot(res)
174+
savefig(plt, joinpath(www_path, "line_chart_$(data_name).png"))
175+
line_charts[data_name] = plt
176+
plt = plot(res,maximum(res.output.n))
177+
savefig(plt, joinpath(www_path, "errorbar_chart_$(data_name).png"))
178+
errorbar_charts[data_name] = plt
175179
end
176180
```

dev/paper/paper.tex

Lines changed: 303 additions & 208 deletions
Large diffs are not rendered by default.

dev/paper/sections/empirical.qmd

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
# Experiment Setup {#sec-empirical}
22

3-
## Data {#sec-empirical-data}
3+
This section presents the exact ingredients and parameter choices describing the simulation experiments we ran to produce the findings presented in the next section (@sec-empirical-2). For convenience, we use Algorithm \ref{algo-experiment} as a template to guide us through this section. A few high-level details upfront: each experiment is run for a total of $T=50$ rounds, where in each round we provide recourse to five percent of all individuals in the non-target class, so $B_t=0.05 * N_t^{\mathcal{D}_0}$^[As mentioned in the previous section, we end up providing recourse to a total of $\approx50\%$ by the end of round $T=50$.]. All classifiers and generative models are retrained for 10 epochs in each round $t$ of the experiment. Rather than retraining models from scratch, we initialize all parameters at their previous levels ($t-1$) and compute backpropagate for 10 epochs using the new training data as inputs into the existing model. Evaluation metrics are computed and stored every 10 rounds.
4+
5+
## $M$ -- Classifiers and Generative Models {#sec-empirical-classifiers}
6+
7+
For each dataset and generator we look at three different types of classifiers all of them built and trained using `Flux.jl` [@innes2018fashionable]: firstly, a simple linear classifier - **Logistic Regression** - implemented as single linear layer with sigmoid activation; secondly, a multilayer perceptron (**MLP**); and finally, a **Deep Ensemble** composed of five MLPs following @lakshminarayanan2016simple that serves as our only probabilistic classifier. We have chosen to work with deep ensembles both for their simplicity and effectiveness at modelling predictive uncertainty. They are also the model of choice in @schut2021generating. The actual neural network architectures are kept simple (@tbl-mlp), since we are only marginally concerned with achieving good initial classifier performance. For the real-world datasets we using mini-batch training and dropout regularization.
8+
9+
The Latent Space generators rely on separate generative models. Following the authors of both REVISE and CLUE we use Variational Autoencoders (**VAE**) for this purpose. As with the classifiers, we deliberately choose to work with fairly simple architectures (@tbl-vae). More expressive generative models generally also lead to more meaningful counterfactuals produced by Latent Space generators. But in our view this should simply be considered as a vulnerability of counterfactual generators that rely on surrogate models to learn what realistic representations of the underlying data.
10+
11+
::: {#tbl-panel layout-ncol=1}
12+
13+
| | Hidden Dim. | Hidden Layers | Batch | Dropout |
14+
|------|------|------|-----|-----|
15+
| Synthetic | 32 | 1 | - | - |
16+
| Real-World | 32 | 2 | 50 | 0.25 |
17+
18+
: MLP {#tbl-mlp}
19+
20+
| | Hidden Dim. | Epochs |
21+
|------|------|------|
22+
| Synthetic | 2 | 100 |
23+
| Real-World | 8 | 250 |
24+
25+
: Variational Autoencoder {#tbl-vae}
26+
27+
Model Architectures
28+
:::
29+
30+
## $\mathcal{D}$ -- Data {#sec-empirical-data}
431

532
We have chosen to work with both synthetic and real-world datasets. Using synthetic data allows us to impose distributional properties that may affect the resulting recourse dynamics. Following @upadhyay2021towards, we generate synthetic data in $\mathbb{R}^2$ to also allow for a visual interpretation of the results. Real-world data is used in order to assess if endogenous dynamics also occur in higher-dimensional settings.
633

@@ -34,32 +61,9 @@ As a third dataset we include the **California Housing** dataset derived from th
3461

3562
Since the simulations involve generating counterfactuals for a significant proportion of the entire sample of individuals, we have randomly undersampled each dataset to yield balanced subsamples consisting of 10,000 individuals each. We have also standardized all explanatory features since our chosen classifiers are sensetive to scale.
3663

37-
## Classifiers and Generative Models {#sec-empirical-classifiers}
38-
39-
For each dataset and generator we look at three different types of classifiers all of them built and trained using `Flux.jl` [@innes2018fashionable]: firstly, a simple linear classifier - **Logistic Regression** - implemented as single linear layer with sigmoid activation; secondly, a multilayer perceptron (**MLP**); and finally, a **Deep Ensemble** composed of five MLPs following @lakshminarayanan2016simple that serves as our only probabilistic classifier. We have chosen to work with deep ensembles both for their simplicity and effectiveness at modelling predictive uncertainty. They are also the model of choice in @schut2021generating. The actual neural network architectures are kept simple (@tbl-mlp), since we are only marginally concerned with achieving good initial classifier performance. For the real-world datasets we using mini-batch training and dropout regularization.
40-
41-
The Latent Space generators rely on separate generative models. Following the authors of both REVISE and CLUE we use Variational Autoencoders (**VAE**) for this purpose. As with the classifiers, we deliberately choose to work with fairly simple architectures (@tbl-vae). More expressive generative models generally also lead to more meaningful counterfactuals produced by Latent Space generators. But in our view this should simply be considered as a vulnerability of counterfactual generators that rely on surrogate models to learn what realistic representations of the underlying data.
42-
43-
All classifiers and generative models are retrained for 10 epochs in each round $t$ of the experiment. Rather than retraining models from scratch, we initialize all parameters at their previous levels ($t-1$) and compute backpropagate for 10 epochs using the new training data as inputs into the existing model.
44-
45-
::: {#tbl-panel layout-ncol=1}
46-
47-
| | Hidden Dim. | Hidden Layers | Batch | Dropout |
48-
|------|------|------|-----|-----|
49-
| Synthetic | 32 | 1 | - | - |
50-
| Real-World | 32 | 2 | 50 | 0.25 |
51-
52-
: MLP {#tbl-mlp}
53-
54-
| | Hidden Dim. | Epochs |
55-
|------|------|------|
56-
| Synthetic | 2 | 100 |
57-
| Real-World | 8 | 250 |
58-
59-
: Variational Autoencoder {#tbl-vae}
64+
## $G$ -- Generators
6065

61-
Model Architectures
62-
:::
66+
All generators introduced earlier are included in the experiments: Wachter [@wachter2017counterfactual], REVISE [@joshi2019towards], CLUE [@antoran2020getting], DiCE [@mothilal2020explaining] and Greedy [@schut2021generating]. In addition, we introduce two new generators in @sec-empirical-2-mitigate that directly address the issue of endogenous domain and model shifts. We also test to what extent it may be beneficial to combine ideas underlying the various generators.
6367

6468

6569

dev/paper/sections/empirical_2.qmd

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,87 @@
22

33
## Endogenous Macrodynamics
44

5-
## Potential Mitigation Strategies
65

7-
### Gravitational Counterfactual Explanations {#sec-empirical-2-mitigate}
86

9-
A straight-forward choice simply extends the baseline approach by @wachter2017counterfactual: instead of only penalizing the distance of the individuals' counterfactual to its factual, we propose penalizing its distance to some sensible point in the target domain, for example the sample average: $\bar{\mathbf{x}}$. For such a recourse objective, higher choices of $\lambda_2$ relative to $\lambda_1$ will lead counterfactuals to gravitate towards the specified point in the target domain. In the remainder of this paper we will therefore refer to this approach as **Gravitational** generator, when we investigate its potential usefulness for mitigating endongenous macrodynamics^[Note that despite the naming convention our goal here is not to provide yet another counterfactual generator, but merely investigate the most simple penalty we can think of with respect to its effectiveness.].
7+
## Potential Mitigation Strategies {#sec-empirical-2-mitigate}
108

11-
#### A note on convergence
9+
In the following we explore several ideas for strategies that may help to mitigate those types of endogenous recourse dynamics we observed in the previous subsection. All of them essentially boil down to one simple principle: to avoid substantial domain and model shifts, the generated counterfactuals should comply as much as possible with the true data generating process. This principle is really at the core of Latent Space generators, and hence it is not surprising that we have found these types of generators to perform comparably well in the previous subsection. But as we have mentioned earlier, generators that rely on separate generative models carry an additional computational cost and - perhaps more importantly - their performance hinges on the performance of said generative models. Fortunately, it turns out that we can use a number of other, much simpler strategies, which we will discuss now.
1210

13-
For this simple mitigating strategy underlying the Gravitational generator to work as expected, one needs to ensure that counterfactual search continues, even after a predetermined threshold probability $\gamma$ has potentially already been reached. @fig-convergence illustrates this distinction: if one chooses to terminate search once the desired threshold is reached (left panel) the gravitational pull towards $\bar{\mathbf{x}}$ is never actually satisfied (compare to right panel). More generally, if convergence is defined simply in terms of flipping the predicted label with some desired degree of confidence, this corresponds to essentially ignoring any parts of the counterfactual search objective that do not involve $\ell(M(f(s_k^\prime)),t)$ beyond that point. While this may be appropriate for some applications, in general this seems like an odd convention. Since we nonetheless seen convergence specified simply in terms of reaching the threshold probability in some places^[@joshi2019towards define convergence of Algorithm 1 in this way. The implementation of @wachter2017counterfactual in CARLA is also defined in this way.], we thought it worth making this distinction explicit.
11+
### More Conservative Decision Thresholds
1412

15-
![Comparison of counterfactual search outcome with simple (left) and strict convergence (right).](www/gravitational_generator_comparison.png){#fig-convergence fig.pos="h" width=45%}
13+
The most obvious and trivial mitigation strategy is to simply choose a higher decision threshold $\gamma$. Under $\gamma=0.5$, counterfactuals will end up near the decision boundary by construction. Since this is the region of maximal aleotoric uncertainty, the classifier is bound to be thrown off. By simply setting a more conservative decision threshold, we can avoid this issue to some extent. A potential drawback of this approach is that a classifier with high decisiveness may classify samples with high confidence even far away from the training data.
14+
15+
### Classifier Preserving ROAR
16+
17+
Another potential strategy draws inspiration from ROAR @upadhyay2021towards: to preserve the classifier, we propose to simply explicitly penalize the loss it incurs when evaluated on the counterfactual $x^\prime$ at given parameter values. Recall that $g(\cdot)$ denotes what we had defined as the external cost in @eq-collective. Then formally we let
18+
19+
$$
20+
\begin{aligned}
21+
g(f(s_k^\prime)) = l(M(f(s_k^\prime)),y^\prime)
22+
\end{aligned}
23+
$$ {#eq-clap}
24+
25+
for each counterfactual $k$ where $l$ denotes the loss function used to train $M$. This approach, which we shall refer to as **ClapROAR**, is based on the intuition that (endogenous) model shifts will be triggered by counterfactuals that increase classifier loss. It is closely linked to the idea of choosing higher decision threshold, but likely better at avoiding the potential pitfalls associated with highly decisive classifiers. It also makes the private vs. external cost trade-off more explicit and hence manageable.
26+
27+
### Gravitational Counterfactual Explanations
28+
29+
Yet another strategy simply extends Wachter as follows: instead of only penalizing the distance of the individuals' counterfactual to its factual, we propose penalizing its distance to some sensible point in the target domain, for example the sample average: $\bar{x}$:
30+
31+
$$
32+
\begin{aligned}
33+
g(f(s_k^\prime)) = \text{dist}(f(s_k^\prime),\bar{x})
34+
\end{aligned}
35+
$$ {#eq-clap}
36+
37+
Once again we can putting this in the context of @eq-collective, the former penalty can be thought of here as the private cost incurred by the individual, while the latter reflects the external cost incurred by other individuals. Higher choices of $\lambda_2$ relative to $\lambda_1$ will lead counterfactuals to gravitate towards the specified point $\bar{x}$ in the target domain. In the remainder of this paper we will therefore refer to this approach as **Gravitational** generator, when we investigate its potential usefulness for mitigating endongenous macrodynamics^[Note that despite the naming convention our goal here is not to provide yet another counterfactual generator, but merely investigate the most simple penalty we can think of with respect to its effectiveness.].
38+
39+
@fig-mitigation shows an illustrative example that demonstrates the differences in counterfactual outcomes when using the various mitigation strategies compared to the baseline approach, that is Wachter with $\gamma=0.5$: choosing a higher decision threshold pushes the counterfactual a little further into the target domain; this effect is even stronger for ClapROAR; finally, using the Gravitational generator the counterfactual ends up all the way inside the target domain in the neighbourhood of $\bar{x}$^[In order for the Graviational generator and ClapROAR to work as expected, one needs to ensure that counterfactual search continues, independent of the threshold probability $\gamma$.].
40+
41+
```{julia}
42+
#| eval: false
43+
using Random
44+
Random.seed!(2022)
45+
46+
# Data:
47+
using MLJ
48+
N = 1000
49+
X, ys = make_blobs(N, 2; centers=2, as_table=false, center_box=(-5 => 5), cluster_std=0.5)
50+
ys .= ys.==2
51+
X = X'
52+
xs = Flux.unstack(X,2)
53+
data = zip(xs,ys)
54+
counterfactual_data = CounterfactualData(X,ys')
55+
56+
# Models:
57+
using AlgorithmicRecourseDynamics
58+
M = AlgorithmicRecourseDynamics.Models.FluxModel(counterfactual_data)
59+
M = AlgorithmicRecourseDynamics.Models.train(M, counterfactual_data)
60+
61+
# Generators:
62+
generators = Dict(
63+
"Generic (γ=0.5)" => GenericGenerator(decision_threshold=0.5),
64+
"Generic (γ=0.9)" => GenericGenerator(decision_threshold=0.9),
65+
"Gravitational" => GravitationalGenerator(),
66+
"ClapROAR" => ClapROARGenerator()
67+
)
68+
69+
# Counterfactuals
70+
x = select_factual(counterfactual_data, rand(1:size(X)[2]))
71+
y = round(probs(M, x)[1])
72+
target = ifelse(y==1.0,0.0,1.0) # opposite label as target
73+
T = 50
74+
counterfactuals = Dict([name => generate_counterfactual(x, target, counterfactual_data, M, gen; T=T, latent_space=false) for (name, gen) in generators])
75+
76+
# Plots:
77+
plts = []
78+
for (name,ce) ∈ counterfactuals
79+
plt = plot(ce; title=name, colorbar=false, ticks = false, legend=false)
80+
plts = vcat(plts..., plt)
81+
end
82+
plt = plot(plts..., size=(750,200), layout=(1,4))
83+
savefig(plt, "dev/paper/www/mitigation.png")
84+
```
85+
86+
![The differences in counterfactual outcomes when using the various mitigation strategies compared to the baseline approach, that is Wachter with $\gamma=0.5$](www/mitigation.png){#fig-mitigation fig.pos="h" width=45%}
87+
88+
Our findings ...

0 commit comments

Comments
 (0)