-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
659 lines (519 loc) · 17.5 KB
/
Makefile
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# Makefile for Memorization Experiments
#
# Author: G.J.J. van den Burg
# Copyright (c) 2021, The Alan Turing Institute
# License: See the LICENSE file.
#
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
MAKEFLAGS += --no-builtin-rules
SCRIPT_DIR=./scripts
SUMMARY_DIR=./summaries
OUTPUT_DIR=./output
RESULT_DIR=./results
PAPER_IMG_DIR=../../../paper/images/
RESULT_DIR_BMNIST_LR3=$(RESULT_DIR)/binarized_mnist_extra_lr3/results
RESULT_DIR_BMNIST_LR4=$(RESULT_DIR)/binarized_mnist_extra_lr4/results
RESULT_DIR_CIFAR10=$(RESULT_DIR)/cifar10/results
RESULT_DIR_CELEBA=$(RESULT_DIR)/celeba/results
CKPT_DIR_BMNIST_LR3=$(RESULT_DIR)/binarized_mnist_extra_lr3/checkpoints
CKPT_DIR_BMNIST_LR4=$(RESULT_DIR)/binarized_mnist_extra_lr4/checkpoints
CKPT_DIR_CIFAR10=$(RESULT_DIR)/cifar10/checkpoints
CKPT_DIR_CELEBA=$(RESULT_DIR)/celeba/checkpoints
# dependencies of memorization.py
MEM_FILES=\
$(SCRIPT_DIR)/constants.py \
$(SCRIPT_DIR)/dataset.py \
$(SCRIPT_DIR)/models.py \
$(SCRIPT_DIR)/trainer.py \
$(SCRIPT_DIR)/seed_generator.py
##########
# #
# GLOBAL #
# #
##########
.PHONY: all
all: memorization summaries analysis
############################
# #
# MEMORIZATION EXPERIMENTS #
# #
############################
.PHONY: memorization
memorization: \
mem_mnist_lr3 \
mem_mnist_lr4 \
mem_cifar10 \
mem_celeba
############################
# BinarizedMNIST lr = 1e-3 #
############################
BMNIST_LR3_CV_TARGETS=
BMNIST_LR3_FULL_TARGETS=
define make_targets_cv_bmnist_lr3
BMNIST_LR3_CV_TARGETS += $(RESULT_DIR_BMNIST_LR3)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed$(1)_cv_repeat$(2)_fold$(3).json.gz
endef
define make_targets_full_bmnist_lr3
BMNIST_LR3_FULL_TARGETS += $(RESULT_DIR_BMNIST_LR3)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed$(1)_full_repeat$(2).json.gz
endef
$(foreach repeat,$(shell seq 0 9),\
$(foreach fold,$(shell seq 0 9),\
$(eval $(call make_targets_cv_bmnist_lr3,42,$(repeat),$(fold)))\
))
$(eval $(call make_targets_full_bmnist_lr3,42,0))
.PHONY: mem_mnist_lr3 mem_mnist_cv_lr3 mem_mnist_full_lr3
mem_mnist_lr3: mem_mnist_cv_lr3 mem_mnist_full_lr3
mem_mnist_cv_lr3: $(BMNIST_LR3_CV_TARGETS)
mem_mnist_full_lr3: $(BMNIST_LR3_FULL_TARGETS)
.PRECIOUS: $(BMNIST_LR3_FULL_TARGETS) $(BMNIST_LR3_CV_TARGETS)
$(BMNIST_LR3_CV_TARGETS) &: $(SCRIPT_DIR)/memorization.py $(MEM_FILES)
python $< \
--dataset BinarizedMNIST \
--model BernoulliMLPVAE \
--mode split-cv \
--latent-dim 16 \
--batch-size 64 \
--learning-rate 1e-3 \
--epochs 100 \
--repeats 10 \
--seed 42 \
--compute-px-every 5 \
--result-dir $(RESULT_DIR_BMNIST_LR3) \
--checkpoint-every 100 \
--checkpoint-dir $(CKPT_DIR_BMNIST_LR3)
$(BMNIST_LR3_FULL_TARGETS) &: $(SCRIPT_DIR)/memorization.py $(MEM_FILES)
python $< \
--dataset BinarizedMNIST \
--model BernoulliMLPVAE \
--mode full \
--latent-dim 16 \
--batch-size 64 \
--learning-rate 1e-3 \
--epochs 100 \
--repeats 1 \
--seed 42 \
--compute-px-every 5 \
--result-dir $(RESULT_DIR_BMNIST_LR3) \
--checkpoint-every 100 \
--checkpoint-dir $(CKPT_DIR_BMNIST_LR3)
############################
# BinarizedMNIST lr = 1e-4 #
############################
BMNIST_LR4_CV_TARGETS=
BMNIST_LR4_FULL_TARGETS=
define make_targets_cv_bmnist_lr4
BMNIST_LR4_CV_TARGETS += $(RESULT_DIR_BMNIST_LR4)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed$(1)_cv_repeat$(2)_fold$(3).json.gz
endef
define make_targets_full_bmnist_lr4
BMNIST_LR4_FULL_TARGETS += $(RESULT_DIR_BMNIST_LR4)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed$(1)_full_repeat$(2).json.gz
endef
$(foreach repeat,$(shell seq 0 9),\
$(foreach fold,$(shell seq 0 9),\
$(eval $(call make_targets_cv_bmnist_lr4,42,$(repeat),$(fold)))\
))
$(eval $(call make_targets_full_bmnist_lr4,42,0))
.PHONY: mem_mnist_lr4 mem_mnist_cv_lr4 mem_mnist_full_lr4
mem_mnist_lr4: mem_mnist_cv_lr4 mem_mnist_full_lr4
mem_mnist_cv_lr4: $(BMNIST_LR4_CV_TARGETS)
mem_mnist_full_lr4: $(BMNIST_LR4_FULL_TARGETS)
.PRECIOUS: $(BMNIST_LR4_FULL_TARGETS) $(BMNIST_LR4_CV_TARGETS)
$(BMNIST_LR4_CV_TARGETS) &: $(SCRIPT_DIR)/memorization.py $(MEM_FILES)
python $< \
--dataset BinarizedMNIST \
--model BernoulliMLPVAE \
--mode split-cv \
--latent-dim 16 \
--batch-size 64 \
--learning-rate 1e-4 \
--epochs 100 \
--repeats 10 \
--seed 42 \
--compute-px-every 5 \
--result-dir $(RESULT_DIR_BMNIST_LR4) \
--checkpoint-every 100 \
--checkpoint-dir $(CKPT_DIR_BMNIST_LR4)
$(BMNIST_LR4_FULL_TARGETS) &: $(SCRIPT_DIR)/memorization.py $(MEM_FILES)
python $< \
--dataset BinarizedMNIST \
--model BernoulliMLPVAE \
--mode full \
--latent-dim 16 \
--batch-size 64 \
--learning-rate 1e-4 \
--epochs 100 \
--repeats 1 \
--seed 42 \
--compute-px-every 5 \
--result-dir $(RESULT_DIR_BMNIST_LR4) \
--checkpoint-every 100 \
--checkpoint-dir $(CKPT_DIR_BMNIST_LR4)
############
# CIFAR-10 #
############
CIFAR10_CV_TARGETS=
CIFAR10_FULL_TARGETS=
define make_targets_cv_cifar10
CIFAR10_CV_TARGETS += $(RESULT_DIR_CIFAR10)/CIFAR10_DiagonalGaussianDCVAE_NF32-L64_seed$(1)_cv_repeat$(2)_fold$(3).json.gz
endef
define make_targets_full_cifar10
CIFAR10_FULL_TARGETS += $(RESULT_DIR_CIFAR10)/CIFAR10_DiagonalGaussianDCVAE_NF32-L64_seed$(1)_full_repeat$(2).json.gz
endef
$(foreach repeat,$(shell seq 0 9),\
$(foreach fold,$(shell seq 0 9),\
$(eval $(call make_targets_cv_cifar10,42,$(repeat),$(fold)))\
))
$(eval $(call make_targets_full_cifar10,42,0))
.PHONY: mem_cifar10 mem_cifar10_cv mem_cifar10_full
mem_cifar10: mem_cifar10_cv mem_cifar10_full
mem_cifar10_cv: $(CIFAR10_CV_TARGETS)
mem_cifar10_full: $(CIFAR10_FULL_TARGETS)
.PRECIOUS: $(CIFAR10_FULL_TARGETS) $(CIFAR10_CV_TARGETS)
$(CIFAR10_CV_TARGETS) &: $(SCRIPT_DIR)/memorization.py $(MEM_FILES)
python $< \
--dataset CIFAR10 \
--model DiagonalGaussianDCVAE \
--mode split-cv \
--latent-dim 64 \
--batch-size 64 \
--learning-rate 1e-3 \
--epochs 100 \
--repeats 10 \
--seed 42 \
--compute-px-every 50 \
--result-dir $(RESULT_DIR_CIFAR10) \
--checkpoint-every 50 \
--checkpoint-dir $(CKPT_DIR_CIFAR10)
$(CIFAR10_FULL_TARGETS) &: $(SCRIPT_DIR)/memorization.py $(MEM_FILES)
python $< \
--dataset CIFAR10 \
--model DiagonalGaussianDCVAE \
--mode full \
--latent-dim 64 \
--batch-size 64 \
--learning-rate 1e-3 \
--epochs 100 \
--repeats 1 \
--seed 42 \
--compute-px-every 50 \
--result-dir $(RESULT_DIR_CIFAR10) \
--checkpoint-every 50 \
--checkpoint-dir $(CKPT_DIR_CIFAR10)
##########
# CelebA #
##########
CELEBA_CV_TARGETS=
CELEBA_FULL_TARGETS=
define make_targets_cv_celeba
CELEBA_CV_TARGETS += $(RESULT_DIR_CELEBA)/CelebA_ConstantGaussianDCVAE_NF32-L32_seed$(1)_cv_repeat$(2)_fold$(3).json.gz
endef
define make_targets_full_celeba
CELEBA_FULL_TARGETS += $(RESULT_DIR_CELEBA)/CelebA_ConstantGaussianDCVAE_NF32-L32_seed$(1)_full_repeat$(2).json.gz
endef
$(foreach repeat,$(shell seq 0 9),\
$(foreach fold,$(shell seq 0 9),\
$(eval $(call make_targets_cv_celeba,42,$(repeat),$(fold)))\
))
$(eval $(call make_targets_full_celeba,42,0))
.PHONY: mem_celeba mem_celeba_cv mem_celeba_full
mem_celeba: mem_celeba_cv mem_celeba_full
mem_celeba_cv: $(CELEBA_CV_TARGETS)
mem_celeba_full: $(CELEBA_FULL_TARGETS)
.PRECIOUS: $(CELEBA_FULL_TARGETS) $(CELEBA_CV_TARGETS)
$(CELEBA_CV_TARGETS) &: $(SCRIPT_DIR)/memorization.py $(MEM_FILES)
python $< \
--dataset CelebA \
--model ConstantGaussianDCVAE \
--mode split-cv \
--latent-dim 32 \
--batch-size 64 \
--learning-rate 1e-3 \
--epochs 50 \
--repeats 10 \
--seed 42 \
--compute-px-every 25 \
--result-dir $(RESULT_DIR_CELEBA) \
--checkpoint-every 25 \
--checkpoint-dir $(CKPT_DIR_CELEBA)
$(CELEBA_FULL_TARGETS) &: $(SCRIPT_DIR)/memorization.py $(MEM_FILES)
python $< \
--dataset CelebA \
--model ConstantGaussianDCVAE \
--mode full \
--latent-dim 32 \
--batch-size 64 \
--learning-rate 1e-3 \
--epochs 50 \
--repeats 1 \
--seed 42 \
--compute-px-every 25 \
--result-dir $(RESULT_DIR_CELEBA) \
--checkpoint-every 25 \
--checkpoint-dir $(CKPT_DIR_CELEBA)
#################
# #
# SUMMARIZATION #
# #
#################
.PHONY: summaries summary-dir
summaries: \
$(SUMMARY_DIR)/mem_bmnist_lr3.npz \
$(SUMMARY_DIR)/mem_bmnist_lr4.npz \
$(SUMMARY_DIR)/mem_cifar10.npz \
$(SUMMARY_DIR)/mem_celeba.npz
summary-dir:
mkdir -p $(SUMMARY_DIR)
$(SUMMARY_DIR)/mem_bmnist_lr3.npz: $(SCRIPT_DIR)/summarize.py \
$(BMNIST_LR3_CV_TARGETS) | summary-dir
python $< -o $@ --result-files $(BMNIST_LR3_CV_TARGETS)
$(SUMMARY_DIR)/mem_bmnist_lr4.npz: $(SCRIPT_DIR)/summarize.py \
$(BMNIST_LR4_CV_TARGETS) | summary-dir
python $< -o $@ --result-files $(BMNIST_LR4_CV_TARGETS)
$(SUMMARY_DIR)/mem_cifar10.npz: $(SCRIPT_DIR)/summarize.py \
$(CIFAR10_CV_TARGETS) | summary-dir
python $< -o $@ --result-files $(CIFAR10_CV_TARGETS)
$(SUMMARY_DIR)/mem_celeba.npz: $(SCRIPT_DIR)/summarize.py \
$(CELEBA_CV_TARGETS) | summary-dir
python $< -o $@ --result-files $(CELEBA_CV_TARGETS)
############
# #
# ANALYSIS #
# #
############
.PHONY: analysis
analysis: \
qualitative \
losses \
quantiles \
mnist_densities \
mem_logprob \
nearest_neighbors
#############################
# Qualitative illustrations #
#############################
.PHONY: qualitative \
qualitative_celeba \
qualitative_cifar10 \
qualitative_bmnist_lr3 \
qualitative_bmnist_lr4 \
qualitative-dir
qualitative: \
qualitative_celeba \
qualitative_cifar10 \
qualitative_bmnist_lr3 \
qualitative_bmnist_lr4
qualitative-dir:
mkdir -p $(OUTPUT_DIR)/qualitative
QUALITATIVE_TARGETS=
define make_qualitative
QUALITATIVE_TARGETS_$(1)=\
$(OUTPUT_DIR)/qualitative/$(1)_top.png \
$(OUTPUT_DIR)/qualitative/$(1)_middle.png \
$(OUTPUT_DIR)/qualitative/$(1)_bottom.png
QUALITATIVE_TARGETS += $$(QUALITATIVE_TARGETS_$(1))
qualitative_$(1): $$(QUALITATIVE_TARGETS_$(1))
endef
$(foreach dset,celeba cifar10 bmnist_lr3 bmnist_lr4,\
$(eval $(call make_qualitative,$(dset)))\
)
$(OUTPUT_DIR)/qualitative/%_top.png: \
$(SUMMARY_DIR)/mem_%.npz \
$(SCRIPT_DIR)/analysis_figure_minmaxmedian.py | qualitative-dir
python $(SCRIPT_DIR)/analysis_figure_minmaxmedian.py -i $< -o $@ \
--mode top
$(OUTPUT_DIR)/qualitative/%_middle.png: \
$(SUMMARY_DIR)/mem_%.npz \
$(SCRIPT_DIR)/analysis_figure_minmaxmedian.py | qualitative-dir
python $(SCRIPT_DIR)/analysis_figure_minmaxmedian.py -i $< -o $@ \
--mode middle
$(OUTPUT_DIR)/qualitative/%_bottom.png: \
$(SUMMARY_DIR)/mem_%.npz \
$(SCRIPT_DIR)/analysis_figure_minmaxmedian.py | qualitative-dir
python $(SCRIPT_DIR)/analysis_figure_minmaxmedian.py -i $< -o $@ \
--mode bottom
###############
# Loss Curves #
###############
.PHONY: losses losses-dir
losses: $(OUTPUT_DIR)/losses/MNIST_losses.pdf
losses-dir:
mkdir -p $(OUTPUT_DIR)/losses
$(OUTPUT_DIR)/losses/MNIST_losses.tex: \
$(SCRIPT_DIR)/analysis_figure_losses.py \
$(RESULT_DIR_BMNIST_LR3)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed42_full_repeat0.json.gz \
$(RESULT_DIR_BMNIST_LR4)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed42_full_repeat0.json.gz\
| losses-dir
python $< -o $@ \
--lr3-file $(RESULT_DIR_BMNIST_LR3)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed42_full_repeat0.json.gz \
--lr4-file $(RESULT_DIR_BMNIST_LR4)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed42_full_repeat0.json.gz
$(OUTPUT_DIR)/losses/%.pdf: $(OUTPUT_DIR)/losses/%.tex
cd $(OUTPUT_DIR)/losses && \
latexmk -pdf \
-pdflatex="pdflatex -interaction=nonstopmode --shell-escape" \
MNIST_losses.tex
#############
# Quantiles #
#############
.PHONY: quantiles quantile-dir
quantiles: $(OUTPUT_DIR)/quantiles/MNIST_quantiles.pdf
quantile-dir:
mkdir -p $(OUTPUT_DIR)/quantiles
$(OUTPUT_DIR)/quantiles/MNIST_quantiles.tex: \
$(SCRIPT_DIR)/analysis_figure_mem_quantiles.py \
$(SUMMARY_DIR)/mem_bmnist_lr3.npz \
$(SUMMARY_DIR)/mem_bmnist_lr4.npz | quantile-dir
python $(SCRIPT_DIR)/analysis_figure_mem_quantiles.py -o $@ \
--lr3-file $(SUMMARY_DIR)/mem_bmnist_lr3.npz \
--lr4-file $(SUMMARY_DIR)/mem_bmnist_lr4.npz
$(OUTPUT_DIR)/quantiles/%.pdf: $(OUTPUT_DIR)/quantiles/%.tex
cd $(OUTPUT_DIR)/quantiles && \
latexmk -pdf \
-pdflatex="pdflatex -interaction=nonstopmode --shell-escape" \
MNIST_quantiles.tex
###################
# MNIST Densities #
###################
.PHONY: mnist_densities mnist_density-dir
mnist_densities: $(OUTPUT_DIR)/mnist_densities/MNIST_densities.pdf
mnist_density-dir:
mkdir -p $(OUTPUT_DIR)/mnist_densities
$(OUTPUT_DIR)/mnist_densities/MNIST_densities.tex: \
$(SCRIPT_DIR)/analysis_figure_mem_histograms.py \
$(SUMMARY_DIR)/mem_bmnist_lr3.npz \
$(SUMMARY_DIR)/mem_bmnist_lr4.npz | mnist_density-dir
python $(SCRIPT_DIR)/analysis_figure_mem_histograms.py -o $@ \
--lr3-file $(SUMMARY_DIR)/mem_bmnist_lr3.npz \
--lr4-file $(SUMMARY_DIR)/mem_bmnist_lr4.npz
$(OUTPUT_DIR)/mnist_densities/%.pdf: $(OUTPUT_DIR)/mnist_densities/%.tex
cd $(OUTPUT_DIR)/mnist_densities && lualatex MNIST_densities.tex
#################################
# Memorization in log prob bins #
#################################
.PHONY: mem_logprob \
mem_logprob_celeba \
mem_logprob_bmnist_lr3 \
mem_logprob_bmnist_lr4
mem_logprob: \
mem_logprob_celeba \
mem_logprob_bmnist_lr3 \
mem_logprob_bmnist_lr4
mem_logprob-dir:
mkdir -p $(OUTPUT_DIR)/mem_logprob/
MEM_LOGPROB_TARGETS=
define make_mem_logprob
MEM_LOGPROB_TARGETS_$(1)=\
$(OUTPUT_DIR)/mem_logprob/mem_logpx_binned_$(1).pdf \
$(OUTPUT_DIR)/mem_logprob/mem_logpx_prop_$(1).pdf
MEM_LOGPROB_TARGETS += $$(MEM_LOGPROB_TARGETS_$(1))
mem_logprob_$(1): $$(MEM_LOGPROB_TARGETS_$(1))
endef
$(foreach dset,celeba bmnist_lr3 bmnist_lr4,\
$(eval $(call make_mem_logprob,$(dset)))\
)
$(OUTPUT_DIR)/mem_logprob/mem_logpx_binned_%.tex: \
$(SUMMARY_DIR)/mem_%.npz \
$(SCRIPT_DIR)/analysis_figure_histogram_logpx_bins.py | mem_logprob-dir
python $(SCRIPT_DIR)/analysis_figure_histogram_logpx_bins.py \
-i $< --seed 555 -o $@
$(OUTPUT_DIR)/mem_logprob/mem_logpx_prop_%.tex: \
$(SUMMARY_DIR)/mem_%.npz \
$(SCRIPT_DIR)/analysis_figure_logpx_props.py | mem_logprob-dir
python $(SCRIPT_DIR)/analysis_figure_logpx_props.py -i $< -o $@
$(OUTPUT_DIR)/mem_logprob/%.pdf: $(OUTPUT_DIR)/mem_logprob/%.tex
cd $(OUTPUT_DIR)/mem_logprob && \
latexmk -pdf \
-pdflatex="pdflatex -interaction=nonstopmode --shell-escape" \
$(notdir $<)
#####################
# Nearest Neighbors #
#####################
.PHONY: nearest_neighbors \
nearest_neighbors_celeba \
nearest_neighbors_cifar10 \
nearest_neighbors_bmnist_lr3 \
nearest_neighbors_bmnist_lr4
nearest_neighbors: \
nearest_neighbors_celeba \
nearest_neighbors_cifar10 \
nearest_neighbors_bmnist_lr3 \
nearest_neighbors_bmnist_lr4
nearest_neighbors-dir:
mkdir -p $(OUTPUT_DIR)/nearest_neighbors/
NEAREST_NEIGHBOR_TARGETS=
define make_nearest_neighbors
NEAREST_NEIGHBOR_TARGETS_$(1)=\
$(OUTPUT_DIR)/nearest_neighbors/nn_histogram_$(1).pdf \
$(OUTPUT_DIR)/nearest_neighbors/nn_scatter_$(1).pdf
NEAREST_NEIGHBOR_TARGETS += $$(NEAREST_NEIGHBOR_TARGETS_$(1))
nearest_neighbors_$(1): $$(NEAREST_NEIGHBOR_TARGETS_$(1))
endef
$(foreach dset,celeba bmnist_lr3 bmnist_lr4,\
$(eval $(call make_nearest_neighbors,$(dset)))\
)
$(OUTPUT_DIR)/nearest_neighbors/nn_histogram_%.tex: \
$(OUTPUT_DIR)/nearest_neighbors/nns_%.npz \
$(SUMMARY_DIR)/mem_%.npz \
$(SCRIPT_DIR)/analysis_figure_nn_histograms.py | nearest_neighbors-dir
python $(SCRIPT_DIR)/analysis_figure_nn_histograms.py \
--nns $< --results $(SUMMARY_DIR)/mem_$*.npz -o $@
$(OUTPUT_DIR)/nearest_neighbors/nn_scatter_%.tex: \
$(OUTPUT_DIR)/nearest_neighbors/nns_%.npz \
$(SUMMARY_DIR)/mem_%.npz \
$(SCRIPT_DIR)/analysis_figure_nn_scatter.py | nearest_neighbors-dir
python $(SCRIPT_DIR)/analysis_figure_nn_scatter.py \
--nns $< --results $(SUMMARY_DIR)/mem_$*.npz -o $@
$(OUTPUT_DIR)/nearest_neighbors/nn_scatter_%.pdf: \
$(OUTPUT_DIR)/nearest_neighbors/nn_scatter_%.tex
cd $(OUTPUT_DIR)/nearest_neighbors && \
latexmk -pdf \
-pdflatex="pdflatex -interaction=nonstopmode --shell-escape" \
$(notdir $<)
$(OUTPUT_DIR)/nearest_neighbors/nn_histogram_%.pdf: \
$(OUTPUT_DIR)/nearest_neighbors/nn_histogram_%.tex
cd $(OUTPUT_DIR)/nearest_neighbors && lualatex $(notdir $<)
$(OUTPUT_DIR)/nearest_neighbors/nns_celeba.npz: \
$(CKPT_DIR_CELEBA)/CelebA_ConstantGaussianDCVAE_NF32-L32_seed42_full_repeat0_epoch50.params \
$(SCRIPT_DIR)/analysis_nearest_neighbor_distance.py \
| nearest_neighbors-dir
python $(SCRIPT_DIR)/analysis_nearest_neighbor_distance.py \
--model ConstantGaussianDCVAE \
--dataset CelebA \
--latent-dim 32 \
--seed 123 \
--checkpoint $< \
--output $@
$(OUTPUT_DIR)/nearest_neighbors/nns_bmnist_lr3.npz: \
$(CKPT_DIR_BMNIST_LR3)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed42_full_repeat0_epoch100.params \
$(SCRIPT_DIR)/analysis_nearest_neighbor_distance.py \
| nearest_neighbors-dir
python $(SCRIPT_DIR)/analysis_nearest_neighbor_distance.py \
--model BernoulliMLPVAE \
--dataset BinarizedMNIST \
--latent-dim 16 \
--seed 42 \
--checkpoint $< \
--output $@
$(OUTPUT_DIR)/nearest_neighbors/nns_bmnist_lr4.npz: \
$(CKPT_DIR_BMNIST_LR4)/BinarizedMNIST_BernoulliMLPVAE_512-256-16_seed42_full_repeat0_epoch100.params \
$(SCRIPT_DIR)/analysis_nearest_neighbor_distance.py \
| nearest_neighbors-dir
python $(SCRIPT_DIR)/analysis_nearest_neighbor_distance.py \
--model BernoulliMLPVAE \
--dataset BinarizedMNIST \
--latent-dim 16 \
--seed 42 \
--checkpoint $< \
--output $@
############
# #
# Clean up #
# #
############
.PHONY: clean
clean: clean_output clean_memorization
check_clean:
@echo -n "This will remove all memorization result files. Are you sure? [y/N] " && read ans && [ "$$ans" == "y" ]
clean_output:
rm -rf $(OUTPUT_DIR)
rm -rf $(SUMMARY_DIR)
clean_memorization: check_clean
rm -rf $(RESULT_DIR)