-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
419 lines (350 loc) · 14.3 KB
/
Snakefile
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
from os.path import splitext, basename, dirname
from src.util.makeutils import (
find_input_files,
find_manim_sections,
find_opened_files,
find_quarto_images,
find_videos
)
SESSION_CODES = ["ykdzfw2h", "5r4374w0", "v0bpsxm2", "m7xcm95f"]
PAPERS = ["theory", "application", "experiment"]
PRESENTATIONS = ["defense"]
rule prepare_to_publish:
input:
dissertation = "out/paper/dissertation.pdf",
papers = expand("out/paper/{paper}.pdf", paper=PAPERS),
presentations = expand(
"out/presentation/{presentation}.html",
presentation=PRESENTATIONS
),
output:
dissertation = "dist/dissertation.pdf",
papers = expand("dist/{paper}.pdf", paper=PAPERS),
presentations = expand("dist/{presentation}.html", presentation=PRESENTATIONS),
nojekyll = "dist/.nojekyll"
run:
from shutil import copy2
from pathlib import Path
for file in input.papers + input.presentations + [input.dissertation]:
copy2(file, "dist")
Path(output.nojekyll).touch()
rule papers:
input:
papers = expand("out/paper/{paper}.pdf", paper=PAPERS)
rule dissertation:
input:
dissertation = "out/paper/dissertation.pdf"
rule presentations:
input:
expand("out/presentation/{presentation}.html", presentation=PRESENTATIONS)
rule update_latex_deps:
input:
deps = expand("out/paper/{paper}.dep", paper=PAPERS + ["dissertation"]),
output:
dep_file = "tl_packages.txt"
shell:
"python src/util/makeutils.py collect-latex-packages \
--add-biber --add-latexmk --add-manim-deps --add-matplotlib-deps \
--check-against-tl --output-file tl_packages.txt --force-add ms \
{input.deps}"
rule paper:
input:
tex = "src/paper/{paper}.tex",
bib = "src/paper/references.bib",
inputs = lambda wildcard: find_input_files(
f"src/paper/{wildcard.paper}.tex", recursive=True
),
util_script = "src/util/makeutils.py"
output:
pdf = "out/paper/{paper}.pdf",
dep = "out/paper/{paper}.dep"
params:
pdf_wo_ext = lambda wildcards, output: splitext(basename(output.pdf))[0],
outdir = lambda wildcards, output: dirname(output.pdf)
shell:
"latexmk -pdf -synctex=1 -file-line-error \
-outdir={params.outdir} \
-jobname={params.pdf_wo_ext} \
-interaction=nonstopmode {input.tex}"
rule presentation:
input:
qmd = "src/presentation/{presentation}.qmd",
python_input = lambda wildcard: find_opened_files(
f"src/presentation/{wildcard.presentation}.qmd"
),
images = lambda wildcard: find_quarto_images(
f"src/presentation/{wildcard.presentation}.qmd"
),
manim_videos = lambda wildcards: find_videos(
f"src/presentation/{wildcards.presentation}.qmd", remove_prefix="../.."
),
bib = "src/paper/references.bib",
css = "src/presentation/include/custom.scss",
marhjax_js = "src/presentation/include/mathjax-settings.html",
section_js = "src/presentation/include/sections-in-footer.html",
output:
"out/presentation/{presentation}.html",
shell:
"quarto render {input.qmd}"
rule manim_corollary_comparative:
input:
script = "src/manim_figures/corollary_comparative.py"
output:
videos = expand(
"out/manim_figures/videos/corollary_comparative/{height}p{fps}/sections/{section}.mp4",
section = find_manim_sections("src/manim_figures/corollary_comparative.py"),
allow_missing=True
)
params:
width = lambda wildcards: wildcards.height,
shell:
"manim render -qh {input.script} --save_sections --media_dir out/manim_figures \
-r {params.width},{wildcards.height} --fps {wildcards.fps} && \
python src/util/makeutils.py rename-manim-sections \
out/manim_figures/videos/corollary_comparative/{wildcards.height}p{wildcards.fps}/sections"
rule manim_proposition_main:
input:
script = "src/manim_figures/proposition_main.py"
output:
videos = expand(
"out/manim_figures/videos/proposition_main/{height}p{fps}/sections/{section}.mp4",
section = find_manim_sections("src/manim_figures/proposition_main.py"),
allow_missing=True
)
params:
width = lambda wildcards: wildcards.height,
shell:
"manim render -qh {input.script} --save_sections --media_dir out/manim_figures \
-r {params.width},{wildcards.height} --fps {wildcards.fps} && \
python src/util/makeutils.py rename-manim-sections \
out/manim_figures/videos/proposition_main/{wildcards.height}p{wildcards.fps}/sections"
rule manim_shapley_value:
input:
script = "src/manim_figures/shapley_value_demo.py"
output:
videos = expand(
"out/manim_figures/videos/shapley_value_demo/{height}p{fps}/sections/{section}.mp4",
section = find_manim_sections("src/manim_figures/shapley_value_demo.py"),
allow_missing=True
)
params:
width = lambda wildcards: int(wildcards.height) * 4 // 3,
shell:
"manim render -qh {input.script} --save_sections --media_dir out/manim_figures \
-r {params.width},{wildcards.height} --fps {wildcards.fps} && \
python src/util/makeutils.py rename-manim-sections \
out/manim_figures/videos/shapley_value_demo/{wildcards.height}p{wildcards.fps}/sections"
rule manim_comparative_equilibrium_entry:
input:
script = "src/manim_figures/comparative_equilibrium_entry.py"
output:
videos = expand(
"out/manim_figures/videos/comparative_equilibrium_entry/{height}p{fps}/sections/{section}.mp4",
section = find_manim_sections("src/manim_figures/comparative_equilibrium_entry.py"),
allow_missing=True
)
params:
width = lambda wildcards: wildcards.height,
shell:
"manim render -qh {input.script} --save_sections --media_dir out/manim_figures \
-r {params.width},{wildcards.height} --fps {wildcards.fps} && \
python src/util/makeutils.py rename-manim-sections \
out/manim_figures/videos/comparative_equilibrium_entry/{wildcards.height}p{wildcards.fps}/sections"
rule figure_two_sided:
output:
fig = "out/figures/two_sided_lambda2-{lambda_2}.{ext}"
script:
"src/figures/two_sided_value.py"
rule figure_weighting_functions:
output:
fig = "out/figures/weighting_functions_{type}-p{par_list}.{ext}"
script:
"src/figures/weighting_functions.py"
rule figure_equilibrium_presentation:
input:
csv = "out/figures/equilibrium_{value_function}_{bargaining}_scale-{n_c}_lambda-{lambda_P}.csv"
output:
fig = "out/figures/equilibrium_{var}_{add_bargaining}-bargaining_{value_function}_{bargaining}_scale-{n_c}_lambda-{lambda_P}.{ext}"
script:
"src/figures/equilibrium_presentation.py"
rule figure_equilibrium:
input:
script = "src/figures/equilibrium_symbolic.py"
output:
csv = "out/figures/equilibrium_{value_function}_{bargaining}_scale-{n_c}_lambda-{lambda_P}.csv"
shell:
"python {input.script} {output.csv} \
--mu 1 --v-p 1 --v-f 1 --i-f 0.05 --n-p-range 0 4.5 --num-obs 200 \
--n-c {wildcards.n_c} --lambda-p {wildcards.lambda_P} \
--value-function {wildcards.value_function} --bargaining {wildcards.bargaining}"
rule figure_equilibrium_entry:
input:
script = "src/figures/equilibrium_nf.py"
output:
fig = "out/figures/equilibrium_entry.pdf"
shell:
"python {input.script} {output.fig} \
--mu 1 --v-p 1 --v-f 1 --i-f 0.2 --n-p 0 --n-p 0.2 --n-f-range 0 1 \
--num-obs 500 --width 5 --height 3.8 --dpi 300"
rule nonparametric_table:
input:
mann_whitney = "out/analysis/mann_whitney.json",
output:
table = "out/tables/nonparametric_table.tex",
script:
"src/tables/nonparametric_table.py"
rule regression_table:
input:
regression = "out/analysis/regression.pkl",
regression_dummies = "out/analysis/regression_dummies.pkl",
output:
table = "out/tables/regression_table.tex",
script:
"src/tables/regression_table.py"
rule run_analysis:
input:
outcomes = "data/clean/_collected/outcomes.csv",
output:
summary = "out/analysis/analysis_results.txt",
mann_whitney = "out/analysis/mann_whitney.json",
regression = "out/analysis/regression.pkl",
regression_dummies = "out/analysis/regression_dummies.pkl",
mse = "out/analysis/mse.json",
axiom_results = "out/analysis/axiom_test_results.pkl",
script:
"src/analysis/analysis.py"
rule create_chat_plot:
input:
outcomes = "data/clean/_collected/outcomes.csv",
actions = "data/clean/_collected/actions.csv",
chat = "out/analysis/chat_classified.csv",
output:
figure = "out/figures/chat_topics_{sample}.{ext}",
script:
"src/figures/chat_plots.py"
rule classify_chat_messages:
input:
actions = "data/clean/_collected/actions.csv",
output:
chat_classified = "out/analysis/chat_classified.csv",
params:
cache_dir = "data/cached/chat_classified",
script:
"src/analysis/classify_chat.py"
rule create_values_theory_plot:
output:
figure = "out/figures/values_theory.{ext}",
script:
"src/figures/values_theory_plot.py"
rule create_chat_excerpt:
input:
actions = "data/clean/_collected/actions.csv",
output:
figure = "out/figures/chat_excerpt-{rows}.{ext}",
script:
"src/figures/chat_excerpts.py"
rule create_survey_plot:
input:
outcomes = "data/clean/_collected/outcomes.csv",
personal = "data/clean/_collected/personal.csv",
output:
figure = "out/figures/survey_{plot}.{ext}",
script:
"src/figures/survey_plots.py"
rule create_axiom_survey_plot:
input:
outcomes = "data/clean/_collected/outcomes.csv",
wildcard_constraints:
ncol = r"\-?.*",
axiom = r"\w+"
output:
figure = "out/figures/axioms_survey_{axiom}{ncol}.{ext}",
script:
"src/figures/axiom_plots.py"
rule create_axiom_outcomes_plot:
input:
outcomes = "data/clean/_collected/outcomes.csv",
output:
figure = "out/figures/axioms_outcomes_{axiom}.{ext}",
script:
"src/figures/axiom_outcomes_plots.py"
rule create_proposal_plot:
input:
actions = "data/clean/_collected/actions.csv",
output:
figure = "out/figures/proposal_{plot}.{ext}",
script:
"src/figures/proposal_plots.py"
rule create_timing_plot:
input:
outcomes = "data/clean/_collected/outcomes.csv",
actions = "data/clean/_collected/actions.csv",
output:
figure = "out/figures/timing_{plot}.{ext}",
script:
"src/figures/timing_plots.py"
rule create_allocation_plot:
input:
outcomes = "data/clean/_collected/outcomes.csv",
actions = "data/clean/_collected/actions.csv",
output:
figure = "out/figures/allocations_{type}.{ext}",
script:
"src/figures/allocation_scatterplots.py"
rule create_payoff_plot:
input:
outcomes = "data/clean/_collected/outcomes.csv",
output:
figure = "out/figures/payoff_{plot}_rounds_{rounds}.{ext}",
script:
"src/figures/payoff_plots.py"
rule create_datasets:
input:
actions = "data/clean/_collected/actions.csv",
outcomes = "data/clean/_collected/outcomes.csv",
rule concatenate_sessions:
input:
actions = expand("data/clean/session_{session_code}/actions.csv", session_code=SESSION_CODES),
outcomes = expand("data/clean/session_{session_code}/outcomes.csv", session_code=SESSION_CODES),
personal = expand("data/clean/session_{session_code}/survey_data_personal.csv", session_code=SESSION_CODES),
session_details = expand("data/clean/session_{session_code}/session_details.txt", session_code=SESSION_CODES),
output:
actions = "data/clean/_collected/actions.csv",
outcomes = "data/clean/_collected/outcomes.csv",
personal = "data/clean/_collected/personal.csv",
script:
"src/data/concatenate_sessions.py"
rule merge_session_data:
input:
chat_data = "data/clean/session_{session_code}/chat.csv",
acceptances = "data/clean/session_{session_code}/acceptances.csv",
proposals = "data/clean/session_{session_code}/proposals.csv",
bargaining_data = "data/clean/session_{session_code}/bargaining.csv",
slider_data = "data/clean/session_{session_code}/slider_data.csv",
survey_data = "data/clean/session_{session_code}/survey_data_nonpersonal.csv",
output:
actions = "data/clean/session_{session_code}/actions.csv",
outcomes = "data/clean/session_{session_code}/outcomes.csv",
script:
"src/data/merge_session_data.py"
rule collect_session_data:
input:
wide_data = "data/raw/wide_data_nonpersonal.csv",
bargaining_data = "data/raw/bargaining_data.csv",
live_data = "data/raw/live_data.csv",
chat_data = "data/raw/chat_data.csv",
slider_data = "data/raw/slider_data.csv",
survey_data_nonpersonal = "data/raw/survey_data_nonpersonal.csv",
survey_data_personal = "data/raw/survey_data_personal.csv",
output:
session_details = "data/clean/session_{session_code}/session_details.txt",
chat = "data/clean/session_{session_code}/chat.csv",
page_loads = "data/clean/session_{session_code}/page_loads.csv",
proposals = "data/clean/session_{session_code}/proposals.csv",
acceptances = "data/clean/session_{session_code}/acceptances.csv",
bargaining_data = "data/clean/session_{session_code}/bargaining.csv",
slider_data = "data/clean/session_{session_code}/slider_data.csv",
survey_data_nonpersonal = "data/clean/session_{session_code}/survey_data_nonpersonal.csv",
survey_data_personal = "data/clean/session_{session_code}/survey_data_personal.csv",
script:
"src/data/collect_session_data.py"