-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.py
352 lines (323 loc) · 15.1 KB
/
run.py
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
#!/usr/bin/python3
import os
# if os.environ.get('inside_singularity_container', "NO") == "YES":
# # If this code is running in a singularity container, update the mei package
# import subprocess
# import sys
# print("Reinstalling MEI package...")
# subprocess.check_call([sys.executable,
# "-m",
# "pip",
# "install",
# "git+https://github.com/kklurz/mei@inception_loop",
# '--force-reinstall'])
import time
import datajoint as dj
import pandas as pd
import numpy as np
dj.config["database.host"] = os.environ["DJ_HOST"]
dj.config["database.user"] = os.environ["DJ_USERNAME"]
dj.config["database.password"] = os.environ["DJ_PASSWORD"]
dj.config["enable_python_native_blobs"] = True
name = "vei2"
os.environ["DJ_SCHEMA_NAME"] = f"metrics_{name}"
dj.config["nnfabrik.schema_name"] = os.environ["DJ_SCHEMA_NAME"]
# from nnfabrik.utility.hypersearch import Bayesian
from nnfabrik.main import *
from mei.main import MEISeed, MEIMethod
from nnvision.tables.main import Recording
from nnsysident.tables.mei import (
MEISelector,
TrainedEnsembleModel,
MEI,
MEIMonkey,
MEIExperimentsMouse,
Gradients
)
from nnsysident.tables.experiments import *
from nnsysident.tables.scoring import (
OracleScore,
R2erScore,
FeveScore,
TestCorr,
)
from nnsysident.utility.data_helpers import extract_data_key
TrainedModelMeanVarScale.populate("dataset_hash = '2859e8af6428fd49e6a306006e81a1ba'",
"model_hash = '49503eacc668e8950bcc3414e1d623d7'",
reserve_jobs=True)
# MEI.populate("ensemble_hash = '2c2e63c647c6c032c126dfe804d5bc06'", reserve_jobs=True)
# restr = {'model_fn': 'nnsysident.models.models.stacked2d_zig',
# 'model_hash': '49503eacc668e8950bcc3414e1d623d7',
# 'dataset_fn': 'nnsysident.datasets.mouse_loaders.static_loaders',
# 'dataset_hash': '9a0e27627452efcb94aed97825771e23',
# 'trainer_fn': 'nnsysident.training.trainers.standard_trainer',
# 'trainer_hash': '69601593d387758e9ff6a5bf26dd6739'}
# TrainedModel.populate(restr, reserve_jobs=True)
#
# keys = (TrainedModel() & "dataset_hash = 'd4869853a4fd946b12adf99b70f9f1cf'" & "model_fn like '%zig%'").proj().fetch(as_dict=True)
# for key in keys:
# key["dataset_hash"] = "9a0e27627452efcb94aed97825771e23"
# key["model_hash"] = "49503eacc668e8950bcc3414e1d623d7"
# TrainedModel.populate(keys, reserve_jobs=True)
# Plain MEIs
# unit_ids = np.sort((((Dataset & "dataset_hash = '2859e8af6428fd49e6a306006e81a1ba'")) * MEISelector).fetch("unit_id"))[:700]
# MEI.populate("method_hash = 'f0dbefc00da768eeda4bd8dce49a016f'",
# "dataset_hash = '2859e8af6428fd49e6a306006e81a1ba'",
# "unit_id in {}".format(tuple(unit_ids)),
# "ensemble_hash = '004f742851122a3cb7b5fb131b44a7d6'", reserve_jobs=True)
#
# key = dict(dataset_fn = "nnsysident.datasets.mouse_loaders.static_loaders",
# dataset_hash = "9a0e27627452efcb94aed97825771e23",
# ensemble_hash = '694b7602e4c885daccccc10991dddded',)
# Gradients().populate(key, reserve_jobs=True)
# Experiment
# experiment_names = ["Orthogonal VEIs from MEIs, Lurz dataset"]
# for experiment_name in experiment_names:
# restr = MEIExperimentsMouse.Restrictions & f'experiment_name="{experiment_name}"'
# uis = np.unique(restr.fetch("unit_id"))
# for ui in uis:
# MEI.populate(restr & f"unit_id = {ui}", reserve_jobs=True)
########### Mouse MEI
# for experiment_name in ["Zhiwei0, alternative ensemble, OneValue init"]:
# for mei_type in ["MEI", "CEI", "VEI+", "VEI-"]:
# restr = (
# MEIExperimentsMouse.Restrictions &
# (MEIMethod
# & f"method_comment like '%{mei_type}%'")
# & 'experiment_name="{}"'.format(experiment_name)
# )
# MEI().populate(
# restr,
# display_progress=True,
# reserve_jobs=True,
# )
# progress = MEI().progress(restr, display=False)
# while progress[0] != 0:
# time.sleep(3 * 60)
# progress = MEI().progress(restr, display=False)
########### Monkey MEI
# ensemble_hash = (TrainedEnsembleModel() &
# "ensemble_comment = 'Monkey V1 Gamma Model, PointPooled'").fetch1("ensemble_hash")
# monkey_data_key = "3631807112901"
# monkey_unit_ids = (Recording.Units() & f"data_key = '{monkey_data_key}'").fetch("unit_id")[:10]
#
# for mei_type in ["MEI", "CEI", "VEI+, 0.8", "VEI-, 0.8"]:
# method_hash = (MEIMethod() & f"method_comment like '%{mei_type}%'").fetch1("method_hash")
# restr = ["unit_id in {}".format(tuple(monkey_unit_ids)),
# f"data_key = '{monkey_data_key}'",
# "method_hash = '{}'".format(method_hash),
# "ensemble_hash = '{}'".format(ensemble_hash),]
# MEIMonkey().populate(*restr,
# display_progress=True,
# reserve_jobs=True,
# )
# progress = MEIMonkey().progress(*restr, display=False)
# while progress[0] != 0:
# time.sleep(3*60)
# progress = MEIMonkey().progress(*restr, display=False)
### Experiment
# for experiment_name in ['Direct training on transfer dataset']:
#
# TrainedModel.progress(Experiments.Restrictions & 'seed in (1,2,3,4,5)' & 'experiment_name="{}"'.format(experiment_name))
#
# TrainedModel.populate(Experiments.Restrictions & 'seed in (1,2,3,4,5)' & 'experiment_name="{}"'.format(experiment_name),
# reserve_jobs=True,
# order="random",)
### Transfer Experiment
# for experiment_name in ['Transfer between areas (indiv. hyperparams)']:
#
# TrainedModelTransfer.progress(ExperimentsTransfer.Restrictions & 'seed = 1' & 'experiment_name="{}"'.format(experiment_name))
#
# TrainedModelTransfer.populate(ExperimentsTransfer.Restrictions & 'seed = 1' & 'experiment_name="{}"'.format(experiment_name),
# reserve_jobs=True,
# order="random",)
# ###################### Bayesian Search ###################################
# paths = ["/project/notebooks/data/static20457-5-9-preproc0.zip"]
# img_data_key = extract_data_key(paths[0])
# dataset_fn = "nnsysident.datasets.mouse_loaders.static_loaders"
# dataset_config = {'paths': ['/project/notebooks/data/static20457-5-9-preproc0'],
# 'batch_size': 64,
# 'seed': 42,
# 'loader_outputs': ['images', 'responses'],
# 'normalize': True,
# 'exclude': None}
# dataset_config_auto = dict()
# print(dataset_config)
#
# model_fn = "nnsysident.models.models.stacked2d_zig"
# loc = np.exp(-10)
# model_config = {
# 'zero_thresholds': {img_data_key: loc},
# "init_sigma": 0.4,
# 'init_mu_range': 0.55,
# 'gamma_input': 1.0,
# 'grid_mean_predictor': {'type': 'cortex',
# 'input_dimensions': 2,
# 'hidden_layers': 0,
# 'hidden_features': 0,
# 'final_tanh': False},
# "readout_type": "MultipleGeneralizedFullGaussian2d",
# }
#
# print(model_fn)
# print(model_config)
# model_config_auto = dict(
# feature_reg_weight={"type": "range", "bounds": [1e-2, 1e2], "log_scale": True},
# hidden_channels={"type": "choice", "values": [32, 64, 128, 256]},
# layers={"type": "choice", "values": [3, 4, 5, 6]},
# hidden_kern={"type": "choice", "values": [9, 11, 13, 15, 17]},
# input_kern={"type": "choice", "values": [9, 11, 13, 15, 17]},
# )
#
#
# trainer_fn = "nnsysident.training.trainers.standard_trainer"
# trainer_config = {'detach_core': False,
# 'stop_function': 'get_loss',
# 'maximize': False}
# trainer_config_auto = dict()
#
# autobayes = Bayesian(
# dataset_fn,
# dataset_config,
# dataset_config_auto,
# model_fn,
# model_config,
# model_config_auto,
# trainer_fn,
# trainer_config,
# trainer_config_auto,
# architect="kklurz",
# trained_model_table="nnsysident.tables.bayesian.TrainedModelBayesian",
# total_trials=200,
# )
#
# best_parameters, _, _, _ = autobayes.run()
#
# model_config.update(best_parameters["model"])
# Model().add_entry(
# model_fn=model_fn,
# model_config=model_config,
# model_fabrikant="kklurz",
# model_comment=f"ZIG, {trainer_config['stop_function']}",
# )
###########################################################################
# OracleScore.populate(reserve_jobs=True)
# OracleScoreTransfer.populate(reserve_jobs=True)
#
# TestCorr.populate(reserve_jobs=True)
# TestCorrTransfer.populate(reserve_jobs=True)
# ################ MONKEY #################################
#
# ###################### Bayesian Search ###################################
# dataset_fn = "nnvision.datasets.monkey_loaders.monkey_static_loader"
# dataset_config = {'dataset': 'CSRF19_V1',
# 'neuronal_data_files': [
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3631896544452.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3632669014376.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3632932714885.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3633364677437.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3634055946316.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3634142311627.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3634658447291.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3634744023164.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3635178040531.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3635949043110.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3636034866307.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3636552742293.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3637161140869.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3637248451650.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3637333931598.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3637760318484.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3637851724731.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3638367026975.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3638456653849.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3638885582960.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3638373332053.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3638541006102.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3638802601378.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3638973674012.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3639060843972.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3639406161189.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3640011636703.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3639664527524.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3639492658943.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3639749909659.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3640095265572.pickle',
# '/project/notebooks/data/monkey/CSRF19_V1/neuronal_data/CSRF19_V1_3631807112901.pickle'],
# 'image_cache_path': '/project/notebooks/data/monkey/CSRF19_V1/images/individual',
# 'crop': 70,
# 'subsample': 1,
# 'seed': 1000,
# 'time_bins_sum': 12,
# 'batch_size': 128}
# dataset_config_auto = dict()
#
# # model_fn = "nnsysident.models.models.stacked2d_gamma"
# # model_config = {
# # "init_sigma": 0.4,
# # 'init_mu_range': 0.55,
# # 'gamma_input': 1.0,
# # 'grid_mean_predictor': None,
# # "readout_type": "MultipleGeneralizedFullGaussian2d",
# # }
# #
# # print(model_fn)
# # print(model_config)
# # model_config_auto = dict(
# # feature_reg_weight={"type": "range", "bounds": [1e-2, 1e2], "log_scale": True},
# # hidden_channels={"type": "choice", "values": [32, 64, 128, 256]},
# # layers={"type": "choice", "values": [3, 4, 5, 6]},
# # hidden_kern={"type": "choice", "values": [9, 11, 13, 15, 17]},
# # input_kern={"type": "choice", "values": [9, 11, 13, 15, 17]},
# # gamma_input={"type": "range", "bounds": [0.1, 10.]}
# # )
#
#
# model_fn = "nnsysident.models.models.stacked2d_gamma"
# model_config = {
# "readout_type": "MultipleGeneralizedPointPooled2d",
# 'hidden_dilation': 2,
# }
#
# print(model_fn)
# print(model_config)
# model_config_auto = dict(
# gamma_readout={"type": "range", "bounds": [1e-2, 1e2], "log_scale": True},
# hidden_channels={"type": "choice", "values": [20, 32, 64, 128]},
# layers={"type": "choice", "values": [3, 4, 5, 6]},
# hidden_kern={"type": "choice", "values": [7, 9, 11, 13, 15]},
# input_kern={"type": "choice", "values": [9, 15, 20, 24, 30]},
# gamma_input={"type": "range", "bounds": [0.1, 100.], "log_scale": True}
# )
#
#
# trainer_fn = "nnsysident.training.trainers.standard_trainer"
# trainer_config = {'detach_core': False,
# 'stop_function': 'get_correlations',
# 'maximize': True}
# trainer_config_auto = dict()
#
# autobayes = Bayesian(
# dataset_fn,
# dataset_config,
# dataset_config_auto,
# model_fn,
# model_config,
# model_config_auto,
# trainer_fn,
# trainer_config,
# trainer_config_auto,
# architect="kklurz",
# trained_model_table="nnsysident.tables.bayesian.TrainedModelBayesian",
# total_trials=200,
# )
#
# best_parameters, _, _, _ = autobayes.run()
#
# model_config.update(best_parameters["model"])
# Model().add_entry(
# model_fn=model_fn,
# model_config=model_config,
# model_fabrikant="kklurz",
# model_comment=f"Gamma, monkey, {trainer_config['stop_function']}",
# )