Skip to content

Commit

Permalink
updating figs
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed May 14, 2024
1 parent b0a50ab commit 7ee6eac
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 123 deletions.
85 changes: 68 additions & 17 deletions paper/fig1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"from scipy.stats import zscore\n",
"from rastermap.utils import bin1d\n",
"\n",
"\n",
"sys.path.insert(0, '/github/rastermap/paper/')\n",
"import metrics, simulations, fig1\n",
"\n",
Expand All @@ -37,16 +36,14 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"n_per_module = 1000\n",
"for random_state in range(0, 10):\n",
" out = simulations.make_full_simulation(n_per_module=n_per_module, random_state=random_state)\n",
" spks, xi_all, stim_times_all, psth, psth_spont, iperm = out\n",
" np.savez(os.path.join(root, \"simulations/\", f\"sim_{random_state}.npz\"), \n",
" spks=spks, xi_all=xi_all, \n",
" stim_times_all=np.array(stim_times_all, dtype=object), \n",
" psth=psth, psth_spont=psth_spont, iperm=iperm)\n",
"\n"
" psth=psth, psth_spont=psth_spont, iperm=iperm)"
]
},
{
Expand All @@ -62,8 +59,6 @@
"metadata": {},
"outputs": [],
"source": [
"import imp\n",
"imp.reload(simulations)\n",
"simulations.embedding_performance(root, save=True)"
]
},
Expand All @@ -82,7 +77,6 @@
"source": [
"# root path has folder \"simulations\" with saved results\n",
"# will save figures to \"figures\" folder\n",
"imp.reload(fig1)\n",
"os.makedirs(os.path.join(root, \"figures/\"), exist_ok=True)\n",
"fig1.fig1(root, save_figure=True) "
]
Expand Down Expand Up @@ -162,7 +156,6 @@
" M = metrics.run_UMAP(model.Usv, n_neighbors=nneigh)\n",
" embs_all[random_state, j] = M\n",
" j += 1\n",
" print(j)\n",
" contamination_scores, triplet_scores = metrics.benchmarks(dat[\"xi_all\"], embs_all[random_state])\n",
" mnn, rho = metrics.embedding_quality_gt(dat[\"xi_all\"], embs_all[random_state], knn=knn.copy())\n",
" mnn_all[random_state], rho_all[random_state] = mnn, rho\n",
Expand Down Expand Up @@ -209,15 +202,14 @@
"metadata": {},
"outputs": [],
"source": [
"imp.reload(fig1)\n",
"fig1.suppfig_scores(root, save_figure=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### supp reproducible"
"### supp power-law only simulation"
]
},
{
Expand All @@ -226,15 +218,15 @@
"metadata": {},
"outputs": [],
"source": [
"simulations.repro_algs(root)\n",
"fig1.suppfig_repro(root, save_fig=False)"
"# create sims and benchmark\n",
"simulations.spont_simulations(root)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### supp power-law only simulation"
"### supp reproducible"
]
},
{
Expand All @@ -243,10 +235,8 @@
"metadata": {},
"outputs": [],
"source": [
"# create sims and benchmark\n",
"simulations.spont_simulations(root)\n",
"# make figure\n",
"fig1.suppfig_spont(root)"
"simulations.repro_algs(root)\n",
"fig1.suppfig_repro(root, save_fig=True)"
]
},
{
Expand All @@ -267,6 +257,67 @@
"# make figure\n",
"fig1.suppfig_params(root)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### supp no power-law noise added"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"n_per_module = 1000\n",
"for random_state in range(1, 10):\n",
" out = simulations.make_full_simulation(n_per_module=n_per_module, \n",
" random_state=random_state, add_spont=False)\n",
" spks, xi_all, stim_times_all, psth, psth_spont, iperm = out\n",
" np.savez(os.path.join(root, \"simulations/\", f\"sim_no_add_spont_{random_state}.npz\"), \n",
" spks=spks, xi_all=xi_all, \n",
" stim_times_all=np.array(stim_times_all, dtype=object), \n",
" psth=psth, psth_spont=psth_spont, iperm=iperm)\n",
"\n",
"# 6000 neurons in simulation with 5 modules\n",
"from tqdm import trange\n",
"embs_all = np.zeros((10, 7, 6000, 1))\n",
"scores_all = np.zeros((10, 2, 8, 5))\n",
"algos = [\"rastermap\", \"tSNE\", \"UMAP\", \"isomap\", \"laplacian\\neigenmaps\", \"hierarchical\\nclustering\", \"PCA\"]\n",
"\n",
"for random_state in trange(10):\n",
" path = os.path.join(root, \"simulations\", f\"sim_no_add_spont_{random_state}.npz\")\n",
" dat = np.load(path, allow_pickle=True)\n",
" spks = dat[\"spks\"]\n",
" embs, model = simulations.run_algos(spks, time_lag_window=10, locality=0.8)\n",
"\n",
" # benchmarks\n",
" contamination_scores, triplet_scores = metrics.benchmarks(dat[\"xi_all\"], \n",
" embs.copy())\n",
" embs_all[random_state] = embs\n",
" scores_all[random_state] = np.stack((contamination_scores, triplet_scores), \n",
" axis=0)\n",
" if random_state==0:\n",
" xi_all = dat[\"xi_all\"]\n",
"\n",
"np.savez(os.path.join(root, \"simulations\", \"sim_no_add_spont_performance.npz\"), \n",
" scores_all=scores_all, \n",
" embs_all=embs_all,\n",
" xi_all=xi_all)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# make figure\n",
"fig1.suppfig_spont(root)"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 7ee6eac

Please sign in to comment.