deepof_experiments.smk 5.36 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
losses = ["ELBO"]  # , "MMD", "ELBO+MMD"]
19
encodings = [6]  # [2, 4, 6, 8, 10, 12, 14, 16]
20
cluster_numbers = [15]  # [1, 5, 10, 15, 20, 25]
21
latent_reg = ["variance"]  # ["none", "categorical", "variance", "categorical+variance"]
22
entropy_knn = [100]
23
next_sequence_pred_weights = [0.15, 0.15]
24
phenotype_pred_weights = [0.0]
25
rule_based_pred_weights = [0.15, 0.15]
26
window_lengths = range(11,56,11)
27
28
input_types = ["coords"]
run = list(range(1, 11))
29

30

31
32
rule deepof_experiments:
    input:
33
        # Elliptical arena detection
lucas_miranda's avatar
lucas_miranda committed
34
        # "/psycl/g/mpsstatgen/lucas/DLC/DLC_autoencoders/DeepOF/deepof/supplementary_notebooks/recognise_elliptical_arena.ipynb",
35
        #
36
        # Hyperparameter tuning
37
38
39
40
41
42
43
44
45
        # 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,
        # ),
46
        #
47
        # Train a variety of models
lucas_miranda's avatar
lucas_miranda committed
48
        expand(
49
            outpath + "train_models/trained_weights/"
50
            "GMVAE_input_type={input_type}_"
51
            "window_size={window_size}_"
52
            "NextSeqPred={nspredweight}_"
53
54
55
56
57
58
            "PhenoPred={phenpredweight}_"
            "RuleBasedPred={rulesweight}_"
            "loss={loss}_"
            "encoding={encs}_"
            "k={k}_"
            "latreg={latreg}_"
59
            "entknn={entknn}_"
60
61
            "run={run}_"
            "final_weights.h5",
62
            input_type=input_types,
63
            window_size=window_lengths,
lucas_miranda's avatar
lucas_miranda committed
64
65
66
67
68
            loss=losses,
            encs=encodings,
            k=cluster_numbers,
            latreg=latent_reg,
            entknn=entropy_knn,
69
70
71
72
            nspredweight=next_sequence_pred_weights,
            phenpredweight=phenotype_pred_weights,
            rulesweight=rule_based_pred_weights,
            run=run,
lucas_miranda's avatar
lucas_miranda committed
73
        ),
74

75

76
77
rule elliptical_arena_detector:
    input:
78
        to_exec="/psycl/g/mpsstatgen/lucas/DLC/DLC_autoencoders/DeepOF/deepof/supplementary_notebooks/recognise_elliptical_arena_blank.ipynb",
79
    output:
80
        exec="/psycl/g/mpsstatgen/lucas/DLC/DLC_autoencoders/DeepOF/deepof/supplementary_notebooks/recognise_elliptical_arena.ipynb",
81
    shell:
82
        "papermill {input.to_exec} "
83
        "-p vid_path './supplementary_notebooks/' "
84
        "-p log_path './logs/' "
85
        "-p out_path './deepof/trained_models/' "
86
87
88
        "{output.exec}"


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


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