|
1 | 1 |
|
2 | | -[](https://pat-alt.github.io/CounterfactualExplanations.jl/stable) [](https://pat-alt.github.io/CounterfactualExplanations.jl/dev) [](https://github.com/pat-alt/CounterfactualExplanations.jl/actions/workflows/CI.yml?query=branch%3Amain) [](https://codecov.io/gh/pat-alt/CounterfactualExplanations.jl) [](https://github.com/invenia/BlueStyle) [](https://github.com/SciML/ColPrac) [](https://twitter.com/paltmey) |
| 2 | +[](https://pat-alt.github.io/AlgorithmicRecourseDynamics.jl/stable) [](https://pat-alt.github.io/AlgorithmicRecourseDynamics.jl/dev) [](https://github.com/pat-alt/AlgorithmicRecourseDynamics.jl/actions/workflows/CI.yml?query=branch%3Amain) [](https://codecov.io/gh/pat-alt/AlgorithmicRecourseDynamics.jl) [](https://github.com/invenia/BlueStyle) [](https://github.com/SciML/ColPrac) [](https://twitter.com/paltmey) |
3 | 3 |
|
4 | 4 | # AlgorithmicRecourseDynamics |
5 | 5 |
|
6 | | -`AlgorithmicRecourseDynamics.jl` is a Julia package for modeling Algorithmic Recourse Dynamics. |
| 6 | +`AlgorithmicRecourseDynamics.jl` is a small package for modeling Algorithmic Recourse Dynamics. It builds on `CounterfactualExplanations`, a package for generating counterfactual explanations. |
7 | 7 |
|
8 | | -## Related Research Paper 📝 |
| 8 | +## Basic Usage |
| 9 | + |
| 10 | +### Data and Model |
| 11 | + |
| 12 | +``` julia |
| 13 | +N = 1000 |
| 14 | +xmax = 2 |
| 15 | +X, ys = make_blobs( |
| 16 | + N, 2; |
| 17 | + centers=2, as_table=false, center_box=(-xmax => xmax), cluster_std=0.1 |
| 18 | +) |
| 19 | +ys .= ys.==2 |
| 20 | +X = X' |
| 21 | +counterfactual_data = CounterfactualData(X,ys') |
| 22 | +``` |
| 23 | + |
| 24 | +``` julia |
| 25 | +n_epochs = 100 |
| 26 | +model = Chain(Dense(2,1)) |
| 27 | +mod = FluxModel(model) |
| 28 | + |
| 29 | +generator = GenericGenerator() |
| 30 | +``` |
| 31 | + |
| 32 | +``` julia |
| 33 | +data_train, data_test = Data.train_test_split(counterfactual_data) |
| 34 | +Models.train(mod, data_train; n_epochs=n_epochs) |
| 35 | +plt_original = plot(mod, counterfactual_data; zoom=0, colorbar=false) |
| 36 | +display(plt_original) |
| 37 | +``` |
| 38 | + |
| 39 | + |
9 | 40 |
|
10 | | -In this work we investigate what happens if Algorithmic Recourse is actually implemented by a large number of individuals. The chart below illustrates what we mean by Endogenous Macrodynamics in Algorithmic Recourse: (a) we have a simple linear classifier trained for binary classification where samples from the negative class (y=0) are marked in blue and samples of the positive class (y=1) are marked in orange; (b) the implementation of AR for a random subset of individuals leads to a noticable domain shift; (c) as the classifier is retrained we observe a corresponding model shift; (d) as this process is repeated, the decision boundary moves away from the target class. |
| 41 | +### Simulation |
| 42 | + |
| 43 | +``` julia |
| 44 | +models = Dict(:mymodel => mod) |
| 45 | +generators = Dict(:wachter => generator) |
| 46 | +experiment = set_up_experiment(data_train, data_test, models, generators) |
| 47 | +``` |
| 48 | + |
| 49 | +``` julia |
| 50 | +run!(experiment) |
| 51 | +``` |
| 52 | + |
| 53 | +``` julia |
| 54 | +new_data = experiment.recourse_systems[1][1].data |
| 55 | +new_model = experiment.recourse_systems[1][1].model |
| 56 | +plt_original = plot(new_model, new_data; zoom=0, colorbar=false) |
| 57 | +``` |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +## Related Research Paper 📝 |
11 | 62 |
|
12 | | - |
| 63 | +The package was developed for a research project that investigates the dynamics of various counterfactual generators. |
0 commit comments