Code
= splitpath(pwd()) |>
projectdir -> joinpath(ss[1:findall([s == "endogenous-macrodynamics-in-algorithmic-recourse" for s in ss])[1]]...)
ss cd(projectdir)
= splitpath(pwd()) |>
projectdir -> joinpath(ss[1:findall([s == "endogenous-macrodynamics-in-algorithmic-recourse" for s in ss])[1]]...)
ss cd(projectdir)
= [
models :LogisticRegression,
:FluxModel,
:FluxEnsemble
]= Flux.Descent(0.01)
opt = Dict(
generators :Greedy=>GreedyGenerator(),
:Generic=>GenericGenerator(opt = opt),
:REVISE=>REVISEGenerator(opt = opt),
:DICE=>DiCEGenerator(opt = opt),
)
= 5000
max_obs = load_real_world(max_obs)
data_sets = [
choices :cal_housing,
:credit_default,
:gmsc,
]= filter(p -> p[1] in choices, data_sets) data_sets
using CounterfactualExplanations.DataPreprocessing: unpack
= 500
bs function data_loader(data::CounterfactualData)
= unpack(data)
X, y = Flux.DataLoader((X,y),batchsize=bs)
data return data
end
= (batch_norm=false,n_hidden=64,n_layers=3,dropout=true,p_dropout=0.1) model_params
= set_up_experiments(
experiments
data_sets,models,generators; =100, model_params=model_params,
pre_train_models=data_loader
data_loader )
= 5
n_evals = 50
n_rounds = Int(round(n_rounds/n_evals))
evaluate_every = 5
n_folds = 10000
n_samples = 100
T = (epochs=250, latent_dim=8)
generative_model_params = run_experiments(
results
experiments;=output_path,evaluate_every=evaluate_every,n_rounds=n_rounds, n_folds=n_folds, T=T, n_samples=n_samples,
save_path=generative_model_params
generative_model_params
)Serialization.serialize(joinpath(output_path,"results.jls"),results)
= load_real_world_results() results
using Images
= Dict()
line_charts = Dict()
errorbar_charts for (data_name, res) in results
= plot_res(res)
plt save(joinpath(www_path, "line_chart_$(data_name).png"), plt)
Images.save(joinpath(www_paper_path, "line_chart_$(data_name).png"), plt)
Images.= plt
line_charts[data_name] = plot_res(res,maximum(res.output.n))
plt save(joinpath(www_path, "errorbar_chart_$(data_name).png"), plt)
Images.save(joinpath(www_paper_path, "errorbar_chart_$(data_name).png"), plt)
Images.= plt
errorbar_charts[data_name] end
The evolution of the evaluation metrics over the course of the experiment is shown for different datasets in Figure 4.1 to Figure 4.3.
The evaluation metrics at the end of the experiment are shown for different datasets in Figure 4.4 to Figure 4.6.
= 100
n_bootstrap = run_bootstrap(results, n_bootstrap; filename=joinpath(output_path,"bootstrap.csv")) df
Table 4.1 presents the tests for statistical significance of the estimated MMD metrics.
= EMAR.aggregate_bs_real_world()
df write(joinpath(www_path, "bootstrap.csv"), df)
CSV.write(joinpath(www_paper_path, "bootstrap.csv"), df)
CSV.tabulate_bs(df, Val(:html)) EMAR.
Metric | Data | Generator | Model | p-value |
---|---|---|---|---|
MMD | Cal Housing | DICE | Deep Ensemble | 0.0 |
MMD | Cal Housing | DICE | Linear | 0.0 |
MMD | Cal Housing | DICE | MLP | 0.0 |
MMD | Cal Housing | Generic (γ=0.5) | Deep Ensemble | 0.0 |
MMD | Cal Housing | Generic (γ=0.5) | Linear | 0.0 |
MMD | Cal Housing | Generic (γ=0.5) | MLP | 0.0 |
MMD | Cal Housing | Greedy | Deep Ensemble | 0.0 |
MMD | Cal Housing | Greedy | Linear | 0.0 |
MMD | Cal Housing | Greedy | MLP | 0.0 |
MMD | Cal Housing | Latent | Deep Ensemble | 0.0 |
MMD | Cal Housing | Latent | Linear | 0.0 |
MMD | Cal Housing | Latent | MLP | 0.0 |
MMD | Credit Default | DICE | Deep Ensemble | 1.0 |
MMD | Credit Default | DICE | Linear | 1.0 |
MMD | Credit Default | DICE | MLP | 1.0 |
MMD | Credit Default | Generic (γ=0.5) | Deep Ensemble | 1.0 |
MMD | Credit Default | Generic (γ=0.5) | Linear | 1.0 |
MMD | Credit Default | Generic (γ=0.5) | MLP | 1.0 |
MMD | Credit Default | Greedy | Deep Ensemble | 1.0 |
MMD | Credit Default | Greedy | Linear | 1.0 |
MMD | Credit Default | Greedy | MLP | 1.0 |
MMD | Credit Default | Latent | Deep Ensemble | 0.0 |
MMD | Credit Default | Latent | Linear | 1.0 |
MMD | Credit Default | Latent | MLP | 0.0 |
MMD | GMSC | DICE | Deep Ensemble | 0.082 |
MMD | GMSC | DICE | Linear | 0.51 |
MMD | GMSC | DICE | MLP | 0.338 |
MMD | GMSC | Generic (γ=0.5) | Deep Ensemble | 0.306 |
MMD | GMSC | Generic (γ=0.5) | Linear | 0.278 |
MMD | GMSC | Generic (γ=0.5) | MLP | 0.128 |
MMD | GMSC | Greedy | Deep Ensemble | 0.032 |
MMD | GMSC | Greedy | Linear | 0.006 |
MMD | GMSC | Greedy | MLP | 0.0 |
MMD | GMSC | Latent | Deep Ensemble | 0.0 |
MMD | GMSC | Latent | Linear | 0.0 |
MMD | GMSC | Latent | MLP | 0.0 |
PP MMD | Cal Housing | DICE | Deep Ensemble | 0.0 |
PP MMD | Cal Housing | DICE | Linear | 0.0 |
PP MMD | Cal Housing | DICE | MLP | 0.0 |
PP MMD | Cal Housing | Generic (γ=0.5) | Deep Ensemble | 0.0 |
PP MMD | Cal Housing | Generic (γ=0.5) | Linear | 0.0 |
PP MMD | Cal Housing | Generic (γ=0.5) | MLP | 0.0 |
PP MMD | Cal Housing | Greedy | Deep Ensemble | 0.0 |
PP MMD | Cal Housing | Greedy | Linear | 0.0 |
PP MMD | Cal Housing | Greedy | MLP | 0.0 |
PP MMD | Cal Housing | Latent | Deep Ensemble | 0.0 |
PP MMD | Cal Housing | Latent | Linear | 0.0 |
PP MMD | Cal Housing | Latent | MLP | 0.0 |
PP MMD | Credit Default | DICE | Deep Ensemble | 0.0 |
PP MMD | Credit Default | DICE | Linear | 0.0 |
PP MMD | Credit Default | DICE | MLP | 0.0 |
PP MMD | Credit Default | Generic (γ=0.5) | Deep Ensemble | 0.0 |
PP MMD | Credit Default | Generic (γ=0.5) | Linear | 0.0 |
PP MMD | Credit Default | Generic (γ=0.5) | MLP | 0.0 |
PP MMD | Credit Default | Greedy | Deep Ensemble | 0.0 |
PP MMD | Credit Default | Greedy | Linear | 0.044 |
PP MMD | Credit Default | Greedy | MLP | 0.0 |
PP MMD | Credit Default | Latent | Deep Ensemble | 0.0 |
PP MMD | Credit Default | Latent | Linear | 0.436 |
PP MMD | Credit Default | Latent | MLP | 0.0 |
PP MMD | GMSC | DICE | Deep Ensemble | 0.032 |
PP MMD | GMSC | DICE | Linear | 0.0 |
PP MMD | GMSC | DICE | MLP | 0.0 |
PP MMD | GMSC | Generic (γ=0.5) | Deep Ensemble | 0.018 |
PP MMD | GMSC | Generic (γ=0.5) | Linear | 0.0 |
PP MMD | GMSC | Generic (γ=0.5) | MLP | 0.0 |
PP MMD | GMSC | Greedy | Deep Ensemble | 0.02 |
PP MMD | GMSC | Greedy | Linear | 0.0 |
PP MMD | GMSC | Greedy | MLP | 0.0 |
PP MMD | GMSC | Latent | Deep Ensemble | 0.008 |
PP MMD | GMSC | Latent | Linear | 0.0 |
PP MMD | GMSC | Latent | MLP | 0.0 |
PP MMD (grid) | Cal Housing | DICE | Deep Ensemble | 0.0 |
PP MMD (grid) | Cal Housing | DICE | Linear | 0.0 |
PP MMD (grid) | Cal Housing | DICE | MLP | 0.0 |
PP MMD (grid) | Cal Housing | Generic (γ=0.5) | Deep Ensemble | 0.0 |
PP MMD (grid) | Cal Housing | Generic (γ=0.5) | Linear | 0.0 |
PP MMD (grid) | Cal Housing | Generic (γ=0.5) | MLP | 0.004 |
PP MMD (grid) | Cal Housing | Greedy | Deep Ensemble | 0.0 |
PP MMD (grid) | Cal Housing | Greedy | Linear | 0.0 |
PP MMD (grid) | Cal Housing | Greedy | MLP | 0.0 |
PP MMD (grid) | Cal Housing | Latent | Deep Ensemble | 0.006 |
PP MMD (grid) | Cal Housing | Latent | Linear | 0.01 |
PP MMD (grid) | Cal Housing | Latent | MLP | 0.026 |
PP MMD (grid) | Credit Default | DICE | Deep Ensemble | 0.0 |
PP MMD (grid) | Credit Default | DICE | Linear | 0.0 |
PP MMD (grid) | Credit Default | DICE | MLP | 0.0 |
PP MMD (grid) | Credit Default | Generic (γ=0.5) | Deep Ensemble | 0.0 |
PP MMD (grid) | Credit Default | Generic (γ=0.5) | Linear | 0.0 |
PP MMD (grid) | Credit Default | Generic (γ=0.5) | MLP | 0.0 |
PP MMD (grid) | Credit Default | Greedy | Deep Ensemble | 0.164 |
PP MMD (grid) | Credit Default | Greedy | Linear | 0.0 |
PP MMD (grid) | Credit Default | Greedy | MLP | 0.0 |
PP MMD (grid) | Credit Default | Latent | Deep Ensemble | 0.0 |
PP MMD (grid) | Credit Default | Latent | Linear | 0.044 |
PP MMD (grid) | Credit Default | Latent | MLP | 0.0 |
PP MMD (grid) | GMSC | DICE | Deep Ensemble | 0.0 |
PP MMD (grid) | GMSC | DICE | Linear | 0.0 |
PP MMD (grid) | GMSC | DICE | MLP | 0.004 |
PP MMD (grid) | GMSC | Generic (γ=0.5) | Deep Ensemble | 0.002 |
PP MMD (grid) | GMSC | Generic (γ=0.5) | Linear | 0.0 |
PP MMD (grid) | GMSC | Generic (γ=0.5) | MLP | 0.0 |
PP MMD (grid) | GMSC | Greedy | Deep Ensemble | 0.0 |
PP MMD (grid) | GMSC | Greedy | Linear | 0.0 |
PP MMD (grid) | GMSC | Greedy | MLP | 0.0 |
PP MMD (grid) | GMSC | Latent | Deep Ensemble | 0.0 |
PP MMD (grid) | GMSC | Latent | Linear | 0.0 |
PP MMD (grid) | GMSC | Latent | MLP | 0.03 |
Figure 4.7 shows the chart that went into the paper.
load(joinpath(www_artifact_path,"paper_real_world_results.png")) Images.