deepof_experiments.smk 5.19 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
24
25
next_sequence_pred_weights = [0.0, 0.15]
phenotype_pred_weights = [0.0]
rule_based_pred_weights = [0.0, 0.15]
26
27
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
        #
35
        # Hyperparameter tuning
36
37
38
39
40
41
42
43
44
        # 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,
        # ),
45
        #
46
        # Train a variety of models
lucas_miranda's avatar
lucas_miranda committed
47
        expand(
48
            outpath + "train_models/trained_weights/"
49
50
            "GMVAE_input_type={input_type}_"
            "NextSeqPred={nspredweight}_"
51
52
53
54
55
56
            "PhenoPred={phenpredweight}_"
            "RuleBasedPred={rulesweight}_"
            "loss={loss}_"
            "encoding={encs}_"
            "k={k}_"
            "latreg={latreg}_"
57
            "entknn={entknn}_"
58
59
            "run={run}_"
            "final_weights.h5",
60
            input_type=input_types,
lucas_miranda's avatar
lucas_miranda committed
61
62
63
64
65
            loss=losses,
            encs=encodings,
            k=cluster_numbers,
            latreg=latent_reg,
            entknn=entropy_knn,
66
67
68
69
            nspredweight=next_sequence_pred_weights,
            phenpredweight=phenotype_pred_weights,
            rulesweight=rule_based_pred_weights,
            run=run,
lucas_miranda's avatar
lucas_miranda committed
70
        ),
71

72

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


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


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