|
16 | 16 | "from scipy.stats import zscore\n", |
17 | 17 | "from rastermap.utils import bin1d\n", |
18 | 18 | "\n", |
19 | | - "\n", |
20 | 19 | "sys.path.insert(0, '/github/rastermap/paper/')\n", |
21 | 20 | "import metrics, simulations, fig1\n", |
22 | 21 | "\n", |
|
37 | 36 | "metadata": {}, |
38 | 37 | "outputs": [], |
39 | 38 | "source": [ |
40 | | - "\n", |
41 | 39 | "n_per_module = 1000\n", |
42 | 40 | "for random_state in range(0, 10):\n", |
43 | 41 | " out = simulations.make_full_simulation(n_per_module=n_per_module, random_state=random_state)\n", |
44 | 42 | " spks, xi_all, stim_times_all, psth, psth_spont, iperm = out\n", |
45 | 43 | " np.savez(os.path.join(root, \"simulations/\", f\"sim_{random_state}.npz\"), \n", |
46 | 44 | " spks=spks, xi_all=xi_all, \n", |
47 | 45 | " 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)" |
50 | 47 | ] |
51 | 48 | }, |
52 | 49 | { |
|
62 | 59 | "metadata": {}, |
63 | 60 | "outputs": [], |
64 | 61 | "source": [ |
65 | | - "import imp\n", |
66 | | - "imp.reload(simulations)\n", |
67 | 62 | "simulations.embedding_performance(root, save=True)" |
68 | 63 | ] |
69 | 64 | }, |
|
82 | 77 | "source": [ |
83 | 78 | "# root path has folder \"simulations\" with saved results\n", |
84 | 79 | "# will save figures to \"figures\" folder\n", |
85 | | - "imp.reload(fig1)\n", |
86 | 80 | "os.makedirs(os.path.join(root, \"figures/\"), exist_ok=True)\n", |
87 | 81 | "fig1.fig1(root, save_figure=True) " |
88 | 82 | ] |
|
162 | 156 | " M = metrics.run_UMAP(model.Usv, n_neighbors=nneigh)\n", |
163 | 157 | " embs_all[random_state, j] = M\n", |
164 | 158 | " j += 1\n", |
165 | | - " print(j)\n", |
166 | 159 | " contamination_scores, triplet_scores = metrics.benchmarks(dat[\"xi_all\"], embs_all[random_state])\n", |
167 | 160 | " mnn, rho = metrics.embedding_quality_gt(dat[\"xi_all\"], embs_all[random_state], knn=knn.copy())\n", |
168 | 161 | " mnn_all[random_state], rho_all[random_state] = mnn, rho\n", |
|
209 | 202 | "metadata": {}, |
210 | 203 | "outputs": [], |
211 | 204 | "source": [ |
212 | | - "imp.reload(fig1)\n", |
213 | 205 | "fig1.suppfig_scores(root, save_figure=True)" |
214 | 206 | ] |
215 | 207 | }, |
216 | 208 | { |
217 | 209 | "cell_type": "markdown", |
218 | 210 | "metadata": {}, |
219 | 211 | "source": [ |
220 | | - "### supp reproducible" |
| 212 | + "### supp power-law only simulation" |
221 | 213 | ] |
222 | 214 | }, |
223 | 215 | { |
|
226 | 218 | "metadata": {}, |
227 | 219 | "outputs": [], |
228 | 220 | "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)" |
231 | 223 | ] |
232 | 224 | }, |
233 | 225 | { |
234 | 226 | "cell_type": "markdown", |
235 | 227 | "metadata": {}, |
236 | 228 | "source": [ |
237 | | - "### supp power-law only simulation" |
| 229 | + "### supp reproducible" |
238 | 230 | ] |
239 | 231 | }, |
240 | 232 | { |
|
243 | 235 | "metadata": {}, |
244 | 236 | "outputs": [], |
245 | 237 | "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)" |
250 | 240 | ] |
251 | 241 | }, |
252 | 242 | { |
|
267 | 257 | "# make figure\n", |
268 | 258 | "fig1.suppfig_params(root)" |
269 | 259 | ] |
| 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 | + ] |
270 | 321 | } |
271 | 322 | ], |
272 | 323 | "metadata": { |
|
0 commit comments