Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ines Filipa Fernandes Ramos
inception_loop_asari_lab
Commits
eafb2dcb
Commit
eafb2dcb
authored
Mar 19, 2021
by
Ines Filipa Fernandes Ramos
Browse files
notebook example_plot(ax, fontsize=24)
parent
b987a0c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
example_notebook_RGC_sim.ipynb
View file @
eafb2dcb
...
...
@@ -63,7 +63,6 @@
{
"cell_type": "code",
"execution_count": 34,
f38591a3e541db669b81e10e304f4f091346ce53
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -77,11 +76,12 @@ f38591a3e541db669b81e10e304f4f091346ce53
" 'batch_size': 64, \n",
" 'seed': 1, \n",
" 'cuda': True,\n",
" 'normalize':
Fals
e, \n",
" 'normalize':
Tru
e, \n",
" 'exclude': \"images\"}\n",
"\n",
"dataloaders_RGCs = static_loaders(**dataset_config)\n",
"dat = FileTreeDataset('D://inception_loop/RGC_sim_data/data/static15032021_oval_RF', \"images\", \"responses\")" ]
"dat = FileTreeDataset('D://inception_loop/RGC_sim_data/data/static15032021_oval_RF', \"images\", \"responses\")"
]
},
{
"cell_type": "code",
...
...
@@ -3176,7 +3176,7 @@ f38591a3e541db669b81e10e304f4f091346ce53
},
{
"cell_type": "code",
"execution_count":
172
,
"execution_count":
null
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -3187,9 +3187,9 @@ f38591a3e541db669b81e10e304f4f091346ce53
"from bayes_opt.logger import JSONLogger\n",
"from bayes_opt.event import Events\n",
"\n",
"neurons = [
556,771
]\n",
"neurons = [
0,10
]\n",
"\n",
"responses_training_set = responses
[:,neurons]
\n",
"responses_training_set = responses\n",
"images_training_set = images\n",
"\n",
"tier = 'validation'\n",
...
...
@@ -3200,11 +3200,11 @@ f38591a3e541db669b81e10e304f4f091346ce53
" responses_validation_set.append(y.squeeze().cpu().data.numpy())\n",
" \n",
"images_validation_set = np.vstack(images_validation_set)\n",
"responses_validation_set = np.vstack(responses_validation_set)
[:,neurons]
\n",
"responses_validation_set = np.vstack(responses_validation_set)\n",
"\n",
"#Estimation of rcond\n",
"\n",
"def STA_estim(responses_training_set, images_training_set, rcond):\n",
"def STA_estim(
neurons,
responses_training_set, images_training_set, rcond):\n",
" \n",
" S = []\n",
" for i in range(len(images_training_set)):\n",
...
...
@@ -3216,7 +3216,7 @@ f38591a3e541db669b81e10e304f4f091346ce53
" \n",
" sta_neurons = []\n",
" sta_neurons_decorr = []\n",
" for neuron in
range(responses_training_set.shape[1])
:\n",
" for neuron in
neurons
:\n",
" pseudo_inv = linalg.pinv2(S, rcond)\n",
" sta = np.dot(pseudo_inv, responses_training_set[:,neuron])\n",
" sta_neurons_decorr.append((sta/sum(responses_training_set[:,neuron])).reshape(images_training_set.shape[1],images_training_set.shape[2]))\n",
...
...
@@ -3236,17 +3236,19 @@ f38591a3e541db669b81e10e304f4f091346ce53
"def pred_RGC_response(rfs, images):\n",
" spikes = []\n",
" for image in images:\n",
" Img_barHat = image * rf
s
\n",
" Img_barHat = image * rf\n",
" g = ELU(np.sum(np.sum(Img_barHat,axis=1), axis=1))\n",
" spikes.append(np.random.poisson(lam=g, size=None))\n",
" \n",
" return
np.array(
spikes
)
\n",
" return spikes\n",
"\n",
"def grid_response_prediction(rcond):\n",
" y_true = responses_validation_set\n",
" rfs, rfs_decorr = STA_estim(responses_training_set, images_training_set, rcond)\n",
" y_true = responses_validation_set[:,neurons]\n",
" rfs, rfs_decorr = STA_estim(neurons, responses_training_set, images_training_set, rcond)\n",
" y_pred = pred_RGC_response(rfs_decorr, images_validation_set)\n",
" mse = mean_squared_error(y_true, y_pred)\n",
" \n",
" return
corr
"
" return
1/mse
"
]
},
{
...
...
@@ -3290,7 +3292,44 @@ f38591a3e541db669b81e10e304f4f091346ce53
},
{
"cell_type": "code",
"execution_count": 171,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, figsize=(7,7))\n",
"plt.imshow(sta_neurons[20:56,20:84])\n",
"plt.title('STA of target unit '+str(neuron)+' with natural stimuli')\n",
"plt.savefig(\"D://inception_loop/RGC_sim_data/results/STA_natur_target_unit_\"+str(neuron)+\".png\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time \n",
"%%memit\n",
"#Bounded region of parameter space\n",
"pbounds={'rcond' : (1, 100)}\n",
"\n",
"optimizer_rcond_ = BayesianOptimization(\n",
" f=grid_response_prediction,\n",
" pbounds=pbounds,\n",
" random_state=1,\n",
" verbose = 1,\n",
")\n",
"\n",
"#Run optimization to maximize the target \n",
"#init_points: number of random exploration points\n",
"#n_iter: number of exploitation points\n",
"\n",
"optimizer_rcond_.maximize(init_points=5, n_iter=5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -3312,13 +3351,20 @@ f38591a3e541db669b81e10e304f4f091346ce53
"metadata": {},
"outputs": [],
"source": [
"TargetUnit = 5
56
\n",
"TargetUnit = 5
70
\n",
"#rf = np.load('D://inception_loop/RGC_sim/data/static27012021/RFs/'+str(TargetUnit)+'.npy')\n",
"rf =np.load('C://Users/Asus/Desktop/Intership EMBL/Python docs/Inception_loop/
RGC_sim_data/data
/static27012021/RFs/'+str(TargetUnit)+'.npy')\n",
"rf =np.load('C://Users/Asus/Desktop/Intership EMBL/Python docs/Inception_loop/
Lurz_2020_code/notebooks/data/RGC_sim
/static27012021/RFs/'+str(TargetUnit)+'.npy')\n",
"fig, axs = plt.subplots(figsize=(20,4))\n",
"axs.imshow(rf, vmin=-1, vmax=1, cmap=\"gray\")\n",
"axs.set_title(\"RGC RF\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"-----------------------------"
]
}
],
"metadata": {
...
...
@@ -3337,7 +3383,7 @@ f38591a3e541db669b81e10e304f4f091346ce53
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.
7.9
"
"version": "3.
8.5
"
}
},
"nbformat": 4,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment