Skip to content

Commit 7ee6eac

Browse files
updating figs
1 parent b0a50ab commit 7ee6eac

11 files changed

Lines changed: 445 additions & 123 deletions

File tree

paper/fig1.ipynb

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"from scipy.stats import zscore\n",
1717
"from rastermap.utils import bin1d\n",
1818
"\n",
19-
"\n",
2019
"sys.path.insert(0, '/github/rastermap/paper/')\n",
2120
"import metrics, simulations, fig1\n",
2221
"\n",
@@ -37,16 +36,14 @@
3736
"metadata": {},
3837
"outputs": [],
3938
"source": [
40-
"\n",
4139
"n_per_module = 1000\n",
4240
"for random_state in range(0, 10):\n",
4341
" out = simulations.make_full_simulation(n_per_module=n_per_module, random_state=random_state)\n",
4442
" spks, xi_all, stim_times_all, psth, psth_spont, iperm = out\n",
4543
" np.savez(os.path.join(root, \"simulations/\", f\"sim_{random_state}.npz\"), \n",
4644
" spks=spks, xi_all=xi_all, \n",
4745
" stim_times_all=np.array(stim_times_all, dtype=object), \n",
48-
" psth=psth, psth_spont=psth_spont, iperm=iperm)\n",
49-
"\n"
46+
" psth=psth, psth_spont=psth_spont, iperm=iperm)"
5047
]
5148
},
5249
{
@@ -62,8 +59,6 @@
6259
"metadata": {},
6360
"outputs": [],
6461
"source": [
65-
"import imp\n",
66-
"imp.reload(simulations)\n",
6762
"simulations.embedding_performance(root, save=True)"
6863
]
6964
},
@@ -82,7 +77,6 @@
8277
"source": [
8378
"# root path has folder \"simulations\" with saved results\n",
8479
"# will save figures to \"figures\" folder\n",
85-
"imp.reload(fig1)\n",
8680
"os.makedirs(os.path.join(root, \"figures/\"), exist_ok=True)\n",
8781
"fig1.fig1(root, save_figure=True) "
8882
]
@@ -162,7 +156,6 @@
162156
" M = metrics.run_UMAP(model.Usv, n_neighbors=nneigh)\n",
163157
" embs_all[random_state, j] = M\n",
164158
" j += 1\n",
165-
" print(j)\n",
166159
" contamination_scores, triplet_scores = metrics.benchmarks(dat[\"xi_all\"], embs_all[random_state])\n",
167160
" mnn, rho = metrics.embedding_quality_gt(dat[\"xi_all\"], embs_all[random_state], knn=knn.copy())\n",
168161
" mnn_all[random_state], rho_all[random_state] = mnn, rho\n",
@@ -209,15 +202,14 @@
209202
"metadata": {},
210203
"outputs": [],
211204
"source": [
212-
"imp.reload(fig1)\n",
213205
"fig1.suppfig_scores(root, save_figure=True)"
214206
]
215207
},
216208
{
217209
"cell_type": "markdown",
218210
"metadata": {},
219211
"source": [
220-
"### supp reproducible"
212+
"### supp power-law only simulation"
221213
]
222214
},
223215
{
@@ -226,15 +218,15 @@
226218
"metadata": {},
227219
"outputs": [],
228220
"source": [
229-
"simulations.repro_algs(root)\n",
230-
"fig1.suppfig_repro(root, save_fig=False)"
221+
"# create sims and benchmark\n",
222+
"simulations.spont_simulations(root)"
231223
]
232224
},
233225
{
234226
"cell_type": "markdown",
235227
"metadata": {},
236228
"source": [
237-
"### supp power-law only simulation"
229+
"### supp reproducible"
238230
]
239231
},
240232
{
@@ -243,10 +235,8 @@
243235
"metadata": {},
244236
"outputs": [],
245237
"source": [
246-
"# create sims and benchmark\n",
247-
"simulations.spont_simulations(root)\n",
248-
"# make figure\n",
249-
"fig1.suppfig_spont(root)"
238+
"simulations.repro_algs(root)\n",
239+
"fig1.suppfig_repro(root, save_fig=True)"
250240
]
251241
},
252242
{
@@ -267,6 +257,67 @@
267257
"# make figure\n",
268258
"fig1.suppfig_params(root)"
269259
]
260+
},
261+
{
262+
"cell_type": "markdown",
263+
"metadata": {},
264+
"source": [
265+
"### supp no power-law noise added"
266+
]
267+
},
268+
{
269+
"cell_type": "code",
270+
"execution_count": null,
271+
"metadata": {},
272+
"outputs": [],
273+
"source": [
274+
"\n",
275+
"n_per_module = 1000\n",
276+
"for random_state in range(1, 10):\n",
277+
" out = simulations.make_full_simulation(n_per_module=n_per_module, \n",
278+
" random_state=random_state, add_spont=False)\n",
279+
" spks, xi_all, stim_times_all, psth, psth_spont, iperm = out\n",
280+
" np.savez(os.path.join(root, \"simulations/\", f\"sim_no_add_spont_{random_state}.npz\"), \n",
281+
" spks=spks, xi_all=xi_all, \n",
282+
" stim_times_all=np.array(stim_times_all, dtype=object), \n",
283+
" psth=psth, psth_spont=psth_spont, iperm=iperm)\n",
284+
"\n",
285+
"# 6000 neurons in simulation with 5 modules\n",
286+
"from tqdm import trange\n",
287+
"embs_all = np.zeros((10, 7, 6000, 1))\n",
288+
"scores_all = np.zeros((10, 2, 8, 5))\n",
289+
"algos = [\"rastermap\", \"tSNE\", \"UMAP\", \"isomap\", \"laplacian\\neigenmaps\", \"hierarchical\\nclustering\", \"PCA\"]\n",
290+
"\n",
291+
"for random_state in trange(10):\n",
292+
" path = os.path.join(root, \"simulations\", f\"sim_no_add_spont_{random_state}.npz\")\n",
293+
" dat = np.load(path, allow_pickle=True)\n",
294+
" spks = dat[\"spks\"]\n",
295+
" embs, model = simulations.run_algos(spks, time_lag_window=10, locality=0.8)\n",
296+
"\n",
297+
" # benchmarks\n",
298+
" contamination_scores, triplet_scores = metrics.benchmarks(dat[\"xi_all\"], \n",
299+
" embs.copy())\n",
300+
" embs_all[random_state] = embs\n",
301+
" scores_all[random_state] = np.stack((contamination_scores, triplet_scores), \n",
302+
" axis=0)\n",
303+
" if random_state==0:\n",
304+
" xi_all = dat[\"xi_all\"]\n",
305+
"\n",
306+
"np.savez(os.path.join(root, \"simulations\", \"sim_no_add_spont_performance.npz\"), \n",
307+
" scores_all=scores_all, \n",
308+
" embs_all=embs_all,\n",
309+
" xi_all=xi_all)"
310+
]
311+
},
312+
{
313+
"cell_type": "code",
314+
"execution_count": null,
315+
"metadata": {},
316+
"outputs": [],
317+
"source": [
318+
"# make figure\n",
319+
"fig1.suppfig_spont(root)"
320+
]
270321
}
271322
],
272323
"metadata": {

0 commit comments

Comments
 (0)