deepof_experiments.smk 5.24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
# @authors lucasmiranda42
# encoding: utf-8
# deepof_experiments

"""

Snakefile for data and imputation.
Execution: sbatch snakemake
Plot DAG: snakemake --snakefile deepof_experiments.smk --forceall --dag | dot -Tpdf > deepof_experiments_DAG.pdf
Plot rule graph: snakemake --snakefile deepof_experiments.smk --forceall --rulegraph | dot -Tpdf > deepof_experiments_RULEGRAPH.pdf

"""

14
import os
15

lucas_miranda's avatar
lucas_miranda committed
16
outpath = "/psycl/g/mpsstatgen/lucas/DLC/DLC_autoencoders/DeepOF/deepof/logs/"
17

18
19
20
21
losses = ["ELBO", "MMD", "ELBO+MMD"]
encodings = [6]  # [2, 4, 6, 8, 10, 12, 14, 16]
cluster_numbers = [25]  # [1, 5, 10, 15, 20, 25]
latent_reg = ["none"]  # ["none", "categorical", "variance", "categorical+variance"]
22
23
24
25
26
27
entropy_knn = [100]
next_sequence_pred_weights = [0.0, 0.15, 0.30]
phenotype_pred_weights = [0.0, 0.15]
rule_based_pred_weights = [0.0, 0.15, 0.30]
input_types = ["coords"]
run = list(range(1, 11))
28

29

30
31
rule deepof_experiments:
    input:
32
        # Elliptical arena detection
lucas_miranda's avatar
lucas_miranda committed
33
        # "/psycl/g/mpsstatgen/lucas/DLC/DLC_autoencoders/DeepOF/deepof/supplementary_notebooks/recognise_elliptical_arena.ipynb",
34
        # Hyperparameter tuning
35
36
37
38
39
40
41
42
43
        # expand(
        #     os.path.join(
        #         outpath,
        #         "coarse_hyperparameter_tuning/trained_weights/GMVAE_loss={loss}_k={k}_encoding={enc}_final_weights.h5",
        #     ),
        #     loss=losses,
        #     k=cluster_numbers,
        #     enc=encodings,
        # ),
44
        # Train a variety of models
lucas_miranda's avatar
lucas_miranda committed
45
        expand(
46
            "/psycl/g/mpsstatgen/lucas/DLC/DLC_autoencoders/DeepOF/deepof/logs/train_models/trained_weights/"
47
48
49
50
51
52
53
54
55
56
            "GMVAE_NextSeqPred={nspredweight}_"
            "PhenoPred={phenpredweight}_"
            "RuleBasedPred={rulesweight}_"
            "loss={loss}_"
            "encoding={encs}_"
            "k={k}_"
            "latreg={latreg}_"
            "entropyknn={entknn}_"
            "run={run}_"
            "final_weights.h5",
57
            input_type=input_types,
lucas_miranda's avatar
lucas_miranda committed
58
59
60
61
62
            loss=losses,
            encs=encodings,
            k=cluster_numbers,
            latreg=latent_reg,
            entknn=entropy_knn,
63
64
65
66
            nspredweight=next_sequence_pred_weights,
            phenpredweight=phenotype_pred_weights,
            rulesweight=rule_based_pred_weights,
            run=run,
lucas_miranda's avatar
lucas_miranda committed
67
        ),
68

69

70
71
rule elliptical_arena_detector:
    input:
72
        to_exec="/psycl/g/mpsstatgen/lucas/DLC/DLC_autoencoders/DeepOF/deepof/supplementary_notebooks/recognise_elliptical_arena_blank.ipynb",
73
    output:
74
        exec="/psycl/g/mpsstatgen/lucas/DLC/DLC_autoencoders/DeepOF/deepof/supplementary_notebooks/recognise_elliptical_arena.ipynb",
75
    shell:
76
        "papermill {input.to_exec} "
77
        "-p vid_path './supplementary_notebooks/' "
78
        "-p log_path './logs/' "
79
        "-p out_path './deepof/trained_models/' "
80
81
82
        "{output.exec}"


83
rule coarse_hyperparameter_tuning:
84
    input:
85
        data_path="/psycl/g/mpsstatgen/lucas/DLC/DLC_models/deepof_single_topview/",
86
87
88
    output:
        trained_models=os.path.join(
            outpath,
89
            "coarse_hyperparameter_tuning/trained_weights/GMVAE_loss={loss}_k={k}_encoding={enc}_final_weights.h5",
90
91
92
93
        ),
    shell:
        "pipenv run python -m deepof.train_model "
        "--train-path {input.data_path} "
94
        "--val-num 25 "
95
        "--components {wildcards.k} "
96
        "--input-type coords "
97
98
99
        "--next-sequence-prediction {wildcards.nspredweight} "
        "--phenotype-prediction {wildcards.phenpredweight} "
        "--rule-based-prediction {wildcards.rulesweight} "
100
101
        "--variational True "
        "--loss {wildcards.loss} "
102
103
        "--kl-warmup 5 "
        "--mmd-warmup 5 "
104
        "--encoding-size {wildcards.enc} "
105
106
        "--batch-size 256 "
        "--window-size 24 "
107
        "--window-step 12 "
108
109
        "--output-path {outpath}coarse_hyperparameter_tuning "
        "--hyperparameter-tuning hyperband "
110
        "--hpt-trials 1"
111
112


113
rule train_models:
114
    input:
115
116
117
        data_path=ancient(
            "/psycl/g/mpsstatgen/lucas/DLC/DLC_models/deepof_single_topview/"
        ),
118
119
120
    output:
        trained_models=os.path.join(
            outpath,
121
122
123
124
125
126
127
128
129
130
131
            "/trained_weights/"
            "GMVAE_NextSeqPred={nspredweight}_"
            "PhenoPred={phenpredweight}_"
            "RuleBasedPred={rulesweight}_"
            "loss={loss}_"
            "encoding={encs}_"
            "k={k}_"
            "latreg={latreg}_"
            "entropyknn={entknn}_"
            "run={run}_"
            "final_weights.h5",
132
133
134
135
        ),
    shell:
        "pipenv run python -m deepof.train_model "
        "--train-path {input.data_path} "
136
        "--val-num 15 "
137
        "--components {wildcards.k} "
138
139
140
141
        "--input-type {wildcards.input_type} "
        "--next-sequence-prediction {wildcards.nspredweight} "
        "--phenotype-prediction {wildcards.phenpredweight} "
        "--rule-based-prediction {wildcards.rulesweight} "
142
143
144
        "--variational True "
        "--latent-reg {wildcards.latreg} "
        "--loss {wildcards.loss} "
145
146
        "--kl-warmup 5 "
        "--mmd-warmup 5 "
147
148
        "--montecarlo-kl 10 "
        "--encoding-size {wildcards.encs} "
149
        "--entropy-knn {wildcards.entknn} "
150
151
152
        "--batch-size 256 "
        "--window-size 24 "
        "--window-step 12 "
153
        "--run {wildcards.run}"
154
        "--output-path {outpath}train_models"