deepof_experiments.smk 5.17 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
20
21
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
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
        # 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
            outpath + "train_models/trained_weights/"
47
48
            "GMVAE_input_type={input_type}_"
            "NextSeqPred={nspredweight}_"
49
50
51
52
53
54
55
56
57
            "PhenoPred={phenpredweight}_"
            "RuleBasedPred={rulesweight}_"
            "loss={loss}_"
            "encoding={encs}_"
            "k={k}_"
            "latreg={latreg}_"
            "entropyknn={entknn}_"
            "run={run}_"
            "final_weights.h5",
58
            input_type=input_types,
lucas_miranda's avatar
lucas_miranda committed
59
60
61
62
63
            loss=losses,
            encs=encodings,
            k=cluster_numbers,
            latreg=latent_reg,
            entknn=entropy_knn,
64
65
66
67
            nspredweight=next_sequence_pred_weights,
            phenpredweight=phenotype_pred_weights,
            rulesweight=rule_based_pred_weights,
            run=run,
lucas_miranda's avatar
lucas_miranda committed
68
        ),
69

70

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


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


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