-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_exp_syn.sh
154 lines (127 loc) · 5.67 KB
/
run_exp_syn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
############################
# #
# default setting for LTR #
# #
############################
LTR_DATA_DIR=out/ranklib_data
LTR_SRC_DIR=src/ranklib
LTR_RANKER=ListNet
LTR_RANKER_ID=7
LTR_OPT_METRIC=NDCG
LTR_OPT_K=500
LTR_LEARNING_RATE=0.000001
LTR_EPOCHS=10000
#########################
# #
# default setting for R #
# #
#########################
R_DATA_DIR=out
R_SRC_DIR=src/rscripts
#################################
# #
# default setting for python #
# #
#################################
PY_SRC_DIR=src/pyscripts
export PY_SRC_DIR="src/pyscripts"
export PY_DATA_SRC_DIR=data
####################################
# #
# default setting for experiment #
# #
####################################
DATA_N=2000 # only validation purpose
COUNT_FILE_NAME="_count"
SPLIT_FLAG=None
EVAL_K=50,100,200
OUT_DATA_DIR="synthetic_data"
SRC_DATA=None
LTR_TRIAL_N=10
DATA_TRIAL_N=20
LTR_SETTINGS=("Full")
###########################################################
# #
# INPUT SETTING for experiment, change based on dataset #
# #
###########################################################
DATA_FLAG="$1"
MODEL_FLAG="$2"
MODEL_DESP="$3"
MEDIATOR_ATT="$4"
#################################################
# #
# Functions for complete routine of experiments #
# #
#################################################
#################################################
# #
# Functions for generate data #
# #
#################################################
python "$PY_SRC_DIR/gen_orig_data.py" --data_dir $OUT_DATA_DIR --data_flag $DATA_FLAG --para_file $MODEL_DESP --run $DATA_TRIAL_N
#########################################################
# #
# Functions for estimate causal model on the data, #
# causal model is specified in 'rscripts' #
# #
#########################################################
Rscript --vanilla "$R_SRC_DIR/${DATA_FLAG}_${MODEL_FLAG}.R" $R_DATA_DIR $DATA_TRIAL_N
############################################################################
# #
# Functions to get counterfactual data from estimated causal model #
# #
############################################################################
if [ $MEDIATOR_ATT == "G" ]
then
COUNTER_G="F"
OTHER_G="M"
HIDDEN_G="B"
echo "MEDIATION ON SINGLE SENSITIVE ATTRIBUTE GENDER"
python "$PY_SRC_DIR/gen_counter_data.py" --data_dir $OUT_DATA_DIR --data_flag $DATA_FLAG --model_flag $MODEL_FLAG --counter_g $COUNTER_G --other_g $OTHER_G --hidden_g $HIDDEN_G --med_s $MEDIATOR_ATT --val_n $DATA_N --counter_run $DATA_TRIAL_N --src_data $SRC_DATA
else
if [ $MEDIATOR_ATT == "R" ]
then
COUNTER_G="B"
OTHER_G="W"
HIDDEN_G="F"
echo "MEDIATION ON SINGLE SENSITIVE ATTRIBUTE RACE"
python "$PY_SRC_DIR/gen_counter_data.py" --data_dir $OUT_DATA_DIR --data_flag $DATA_FLAG --model_flag $MODEL_FLAG --counter_g $COUNTER_G --other_g $OTHER_G --hidden_g $HIDDEN_G --med_s $MEDIATOR_ATT --val_n $DATA_N --counter_run $DATA_TRIAL_N --src_data $SRC_DATA
else
COUNTER_G="FB"
echo "MEDIATION ON MULTIPLE SENSITIVE ATTRIBUTES"
python "$PY_SRC_DIR/gen_counter_data.py" --data_dir $OUT_DATA_DIR --data_flag $DATA_FLAG --model_flag $MODEL_FLAG --counter_g $COUNTER_G --val_n $DATA_N --counter_run $DATA_TRIAL_N --src_data $SRC_DATA
fi
fi
##############################################
# #
# Functions to prepare ranklib inputs #
# ONLY SUPPORT MODEL m1 and m2 NOW #
# #
##############################################
if [ $MODEL_FLAG == "m2" ]
then
EVAL_COUNTER_RANKINGS="Y,Y_count,Y_count_resolve"
EVAL_LTR_RANKINGS="Y__Y__full,Y_count__Y__full,Y_count__Y_count__full,Y_count_resolve__Y__full,Y_count_resolve__Y_count_resolve__full"
echo "EVALUATION ON BOTH RESOLVING AND NON-RESOLVING"
else
EVAL_COUNTER_RANKINGS="Y,Y_count"
EVAL_LTR_RANKINGS="Y__Y__full,Y_count__Y__full,Y_count__Y_count__full"
echo "EVALUATION ON NON-RESOLVING"
fi
# evaluation for selection rate
python "$PY_SRC_DIR/eval_rankings.py" --data_flag $DATA_FLAG --model_flag $MODEL_FLAG --eval_ks $EVAL_K --rankings "$EVAL_COUNTER_RANKINGS,Y_quotas_R,Y_quotas_G,Y_quotas_GR" --measure select_rate --file_n $COUNT_FILE_NAME
# evaluation for rKL
python "$PY_SRC_DIR/eval_rankings.py" --data_flag $DATA_FLAG --model_flag $MODEL_FLAG --eval_ks $EVAL_K --rankings $EVAL_COUNTER_RANKINGS --measure rKL --file_n $COUNT_FILE_NAME
# evaluation for ratio
python "$PY_SRC_DIR/eval_rankings.py" --data_flag $DATA_FLAG --model_flag $MODEL_FLAG --eval_ks $EVAL_K --rankings $EVAL_COUNTER_RANKINGS --measure igf --file_n $COUNT_FILE_NAME
# evaluation for score utility
python "$PY_SRC_DIR/eval_rankings.py" --data_flag $DATA_FLAG --model_flag $MODEL_FLAG --eval_ks $EVAL_K --rankings "$EVAL_COUNTER_RANKINGS,Y_quotas_R,Y_quotas_G,Y_quotas_GR" --measure score_utility --file_n $COUNT_FILE_NAME
#################################
# #
# Functions to generate plots #
# #
#################################
python "$PY_SRC_DIR/gen_plots.py" --data_flag $DATA_FLAG --model_flag $MODEL_FLAG --rankings "$EVAL_COUNTER_RANKINGS,Y_quotas_R,Y_quotas_G,Y_quotas_GR" --plot_ks $EVAL_K --y_col select_rate --y_max 2.2 --file_n $COUNT_FILE_NAME
python "$PY_SRC_DIR/gen_plots.py" --data_flag $DATA_FLAG --model_flag $MODEL_FLAG --rankings $EVAL_COUNTER_RANKINGS --plot_ks $EVAL_K --y_col rKL --y_max 2.1