OSCR

A critical initialization for biological neural networks.

Code ↔ Paper

13 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

10 blocks of code here have a permanent identifier (oscr:b:…), listed with the matches below: citable for good, with a page of its own. Select a match and press Cite to copy it. What a block identifier is.

The 13 matches
  1. [1] § Methods › Data acquisition › Neuropixel recordings and processing ↔ fig2/analysis.py, lines 269 to 325 · score 0.85 · hippocampal formation, subcortical areas, firing rate, visual cortex, cortices, striatum · block oscr:b:99E64DC1RMK4Y-H · Report a mismatch
  2. [2] § Intrinsic structure in neural recordings ↔ fig2/fig2.py, lines 10 to 72 · score 0.82 · 2385–10344 regions, 2961–8566 ROIs, 1716–2914, 2385 regions, 2961 ROIs, Neuropixels · block oscr:b:NS9M9FN4SWWG2-Z · Report a mismatch
  3. [3] § Intrinsic structure in neural recordings ↔ fig2/fig2.py, lines 10 to 72 · score 0.82 · 2385–10344 regions, 2961–8566 ROIs, 1716–2914, 2385 regions, 2961 ROIs, Neuropixels · block oscr:b:2WAX6YQGTPV9V-T · Report a mismatch
  4. [4] § Computations with symmetric dynamics ↔ fig5/fig5.ipynb, lines 61 to 163 · score 0.74 · zero shot working, persistent activity, working memory, symmetric dynamics, subspace, training · Report a mismatch
  5. [5] § Computations with symmetric dynamics ↔ fig5/fig5.ipynb, lines 61 to 163 · score 0.69 · zero shot working, working memory, symmetric dynamics, binary, training, models · Report a mismatch
  6. [6] § Methods › Data analysis › Estimating rotational components from data ↔ fig3/other_datasets.py, lines 405 to 474 · score 0.65 · linear track, virtual reality, visual cortex, reward, maze, PSTHs · block oscr:b:8ZG0K75A87K8R-C · Report a mismatch
  7. [7] § Methods › Data analysis › Estimating rotational components from data ↔ fig3/other_datasets.py, lines 405 to 474 · score 0.65 · linear track, virtual reality, visual cortex, reward, maze, PSTHs · block oscr:b:8J65P2RPSXJHM-W · Report a mismatch
  8. [8] § Methods ↔ fig_utils.py, lines 1 to 27 · score 0.62 · Howard Hughes Medical · block oscr:b:CJRNHRW5A1QN0-2 · Report a mismatch
  9. [9] § Methods › Simulations of dynamical systems › Sparse/varied connectivity ↔ fig4/sparse_clustered_local_sims.py, lines 136 to 193 · score 0.58 · exponential decay, locally connected, Bernoulli, distances, global, Sparse · block oscr:b:Q1H1AY3WB3J3H-E · Report a mismatch
  10. [10] § Methods › Simulations of dynamical systems ↔ simulations.py, lines 241 to 319 · score 0.54 · shot noise, relu, SNR, Poisson, decay, simulate · block oscr:b:KHG73G56PJD3N-P · Report a mismatch
  11. [11] § Intrinsic structure in neural recordings ↔ fig2/fig2.py, lines 413 to 470 · score 0.54 · brainwide ephys, power law exponents, duration, SVCA2, CA1, neurons · block oscr:b:79BXW3KTM0KGF-Q · Report a mismatch
  12. [12] § Intrinsic structure in neural recordings ↔ fig2/fig2.py, lines 413 to 470 · score 0.54 · brainwide ephys, power law exponents, duration, SVCA2, CA1, neurons · block oscr:b:H5BAS9EAF629R-U · Report a mismatch
  13. [13] § Methods › Simulations of dynamical systems › Sparse/varied connectivity ↔ fig4/sparse_clustered_local_sims.py, lines 136 to 193 · score 0.53 · global connection, local connection, Bernoulli, clustered, Sparse, symmetric · block oscr:b:Q1H1AY3WB3J3H-E · Report a mismatch

Paper

Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Python · 973 lines · 43 KB · GPL-3.0 · 2 matches

  1. from matplotlib.patches import Ellipse
  2. from fig_utils import *
  3. from scipy.stats import zscore
  4. from powerlaw import fit_powerlaw_exp
  5. from scipy.stats import ttest_rel
  6. from matplotlib import gridspec
  7. from scipy.interpolate import interp1d
  8. def fig2(dat):
  9. areas_all = dat["areas_all"]
  10. evals_all = dat["evals_svca2_all"]
  11. evals_shuff_all = dat["evals_shuff_all"]
  12. evals_run = dat["evals_run_all"]
  13. fig = plt.figure(figsize=(14, 7), dpi=300)
  14. yratio = 14/7
  15. grid = plt.GridSpec(8, 7, wspace=0.4, hspace=0.2, figure=fig,
  16. bottom=0.04, top=0.94, left=0.02, right=1.)
  17. titles = ["cortical 2P imaging", "CA1 2P imaging",
  18. "brainwide Neuropixels"]
  19. sneur = ["2,385 - 10,344 ROIs", "2,961 - 8,566 ROIs", "1,716 - 2,914 units"]
  20. colors = dcolors[:3].copy()
  21. n_dset = len(areas_all)
  22. ids = np.zeros(n_dset, "int")
  23. for d in range(len(areas)):
  24. ids[np.array(areas_all)==areas[d]] = d
  25. ls = ["-", "-", "-", "--", "-."]
  26. print(areas_all, ids)
  27. dy = [0, 2, 1]
  28. alphas = np.zeros(n_dset)
  29. alphas_shuff = np.zeros(n_dset)
  30. ymax = 500
  31. norms = np.zeros(n_dset)
  32. if "imexs" in dat:
  33. # example images/traces (extracted from suite2p folders from example data)
  34. # (if available make example panels)
  35. imexs = dat["imexs"]
  36. masksexs = dat["masksexs"]
  37. for d in range(3):
  38. ax = plt.subplot(grid[:2, d])
  39. pos = ax.get_position().bounds
  40. ax.set_position([pos[0]+0.04*d + 0.01, pos[1], pos[2]*(1.3 +0.4*(d<2)), pos[3]*1.])
  41. if d==2:
  42. im = plt.imread("allenprobes.png")
  43. #print(im.shape, imexs[1].shape)
  44. ax.imshow(im[58:-100])
  45. else:
  46. ax.imshow(imexs[d], vmin=0, vmax=0.9,
  47. cmap="gray", aspect=0.75/0.5 if d==1 else 1)
  48. masks0 = masksexs[d].copy()
  49. yo, xo = np.nonzero(masks0[:,:,-1]>0)
  50. masks0[yo,xo,-1] = 0.25
  51. ax.imshow(masks0, aspect=0.75/0.5 if d==1 else 1)
  52. if d==0:
  53. ax.set_ylim([380, 380+90])
  54. ax.set_xlim(50, 50 + 130)
  55. elif d==1:
  56. #ax.set_ylim([350, 430])
  57. #ax.set_xlim([100, 100 + 80*0.75/0.5])
  58. ax.set_ylim([50, 50+90])
  59. ax.set_xlim([250, 250+130*0.75/0.5])
  60. ax.set_title(titles[d], color=colors[d], fontstyle="italic",
  61. y=1.075, loc="left", x=-0.05)#, fontweight="bold")
  62. ax.text(0.5, 1.025, sneur[d], transform=ax.transAxes,
  63. fontsize="small", ha="center")
  64. ax.axis("off")
  65. il = d
  66. transl = mtransforms.ScaledTranslation(-25 / 72, 12 / 72, fig.dpi_scale_trans)
  67. il = plot_label(ltr, il, ax, transl)
  68. for j in range(2):
  69. Xexs = dat["Xexs"] if j==0 else dat["Xemb_ex"]
  70. Xexs = [Xexs[0], Xexs[1]] if j==0 else Xexs
  71. if j==0:
  72. titles = ['Rastermap of 2p data - V1', 'CA1']
  73. tmins = [5800, 42000//7+200] # 5000
  74. tlen = 22*60*3//7
  75. else:
  76. titles = ['Simulated 2p data - max eigenvalue = 0.998', 'max eigenvalue = 0.975']
  77. tmins = [5960*2, 0]
  78. tlen = 22*60*3//7
  79. for d in range(2):
  80. ax = plt.subplot(grid[2+3*j:5+3*j, 2*d:2*d+2])
  81. pos = ax.get_position().bounds
  82. ax.set_position([pos[0]-d*0.015, pos[1]-j*0.02, pos[2]+0.005, pos[3]*0.9])
  83. #Xe = zscore(Xexs[d][:, tmins[d]:tmins[d]+tlen].copy(), axis=1)
  84. im = ax.imshow(zscore(Xexs[d][:, tmins[d]:tmins[d]+tlen], axis=1),
  85. aspect="auto", cmap="gray_r", vmin=0., vmax=1.5)
  86. ax.plot([0, 22*30/7], -Xexs[d].shape[0]*0.04*np.ones(2), color="k", lw=1.5)
  87. ax.plot(-0.025*tlen*np.ones(2), [0, 50], color="k", lw=1.5)
  88. if d==0:
  89. if j==0:
  90. ax.text((22*30/2)/7, -50, "30 sec.", ha="center", va="center", fontsize="small")
  91. ax.text(-0.05*tlen, 0, "1000 neurons", ha="center", va="bottom", fontsize="small", rotation=90)
  92. cax = ax.inset_axes([0.85, -0.01, 0.15, 0.025])
  93. cb = plt.colorbar(im, cax=cax, orientation="horizontal")
  94. cb.set_ticks([0, 1.0])
  95. cb.set_ticklabels(["0", "1.0"], fontsize="small")
  96. ax.text(0.83, -0.005, "z-scored activity", fontsize="small",
  97. ha="right", va="top", transform=ax.transAxes)
  98. ax.set_ylim([-Xexs[d].shape[0]*0.05, Xexs[d].shape[0]+0.5])
  99. ax.set_xlim([-0.028*tlen, tlen])
  100. ax.axis("off")
  101. ax.set_title(titles[d], fontsize='medium')
  102. if d==0:
  103. il = 3 + 3*j
  104. transl = mtransforms.ScaledTranslation(-10 / 72, 0 / 72, fig.dpi_scale_trans)
  105. il = plot_label(ltr, il, ax, transl)
  106. grid1 = gridspec.GridSpecFromSubplotSpec(3, 1, subplot_spec=grid[:5, 4], wspace=0., hspace=0.3)
  107. for d in range(3):
  108. ax = fig.add_subplot(grid1[d,0])
  109. pos = ax.get_position().bounds
  110. ax.set_position([pos[0]+0.01, pos[1]+(pos[3]-pos[2]*yratio)/2+0.01,
  111. pos[2]*0.8, pos[2]*yratio*0.8])
  112. pose = ax.get_position().bounds
  113. ix = np.nonzero(ids==d)[0]
  114. if d==0:
  115. ix = np.hstack((ix, np.nonzero(ids==4)[0]))
  116. ix = np.hstack((ix, np.nonzero(ids==3)[0]))
  117. lns = []
  118. for i in ix:
  119. ss = evals_all[i][:1000].copy()
  120. alphas[i], yp = fit_powerlaw_exp(evals_all[i],
  121. np.arange(10, ymax))
  122. ss /= yp[0]
  123. norms[i] = yp[0] #yp[10] * 10
  124. ax.loglog(np.arange(1, min(len(evals_all[i])+1, 1001)),
  125. ss, color=colors[d], lw=0.5, alpha=0.75, ls=ls[ids[i]])
  126. alphas_shuff[i] = fit_powerlaw_exp(evals_shuff_all[i],
  127. np.arange(10, ymax))[0]
  128. ln = ax.plot([], [], color=colors[d], lw=1, ls=ls[ids[i]])
  129. lns.append(ln)
  130. if d==0:
  131. ax.legend([lns[0][0], lns[-5][0], lns[-1][0]], ["V1", "sensori-\nmotor", "PPC"],
  132. frameon=False, loc="upper left", bbox_to_anchor=(0.3, 1.3),
  133. handlelength=1.2)
  134. ax.set_ylim(0.003, 3)
  135. ax.set_xlim(1, 1000)
  136. ax.set_xticks([1, 10, 100, 1000])
  137. ax.set_xticklabels(["1", "10", "100", "1,000"])
  138. ax.set_yticks([0.01, 0.1 ,1])
  139. ax.set_yticklabels(["0.01", "0.1", "1"])
  140. aexp = [-0.69, -1.254]
  141. yc = 1
  142. ax.fill_between([1, 1000], [yc, yc * 1000**aexp[0]], [yc, yc * 1000**aexp[1]],
  143. color="k", lw=0, alpha=0.1)
  144. if d==0:
  145. il = 4
  146. transl_e = mtransforms.ScaledTranslation(-50 / 72, 12 / 72, fig.dpi_scale_trans)
  147. il = plot_label(ltr, il, ax, transl_e)
  148. ax.set_ylabel("normalized variance")
  149. axin = ax.inset_axes([1.2, 0.5, 0.7, 0.7])
  150. axin.fill_between([1, 1000], [yc, yc * 1000**aexp[0]], [yc, yc * 1000**aexp[1]],
  151. color="k", lw=0, alpha=0.1)
  152. axin.text(0.27, 0.37, "symmetric", transform=axin.transAxes, fontsize="small",
  153. color=0.*np.ones(3), rotation=-(0.38)*90, fontstyle="italic")
  154. axin.text(0.08, 0.01, "non-symmetric", transform=axin.transAxes, fontsize="small",
  155. color=0.*np.ones(3), rotation=-(0.58)*90, fontstyle="italic")
  156. axin.set_xlim(1, 1000)
  157. axin.set_ylim(0.001, 1)
  158. axin.set_xscale("log")
  159. axin.set_yscale("log")
  160. axin.set_xticks([]); axin.set_yticks([])
  161. axin.minorticks_off()
  162. elif d==2:
  163. ax.set_xlabel("PC index")
  164. ax = plt.subplot(grid[:5, -2:])
  165. pos = ax.get_position().bounds
  166. ax.set_position([pos[0]+0.03, pos[1]+(pos[3]-pos[2]*yratio)/2-0.03,
  167. pos[2]*0.8, pos[2]*yratio*0.8])
  168. yh = [0, 2, 1]
  169. for d in range(3):
  170. ix = np.nonzero(ids==d)[0]
  171. emax = min(1000, np.array([len(evals_all[i]) for i in ix]).min())
  172. ev_all = np.array([evals_all[i][:emax] / norms[i] for i in ix])
  173. ev_mean = ev_all.mean(axis=0)
  174. ev_std = ev_all.std(axis=0) #/ np.sqrt(len(ix)-1)
  175. ax.loglog(np.arange(1, len(ev_mean)+1), ev_mean, color=colors[d], lw=1)
  176. ax.fill_between(np.arange(1, len(ev_mean)+1), ev_mean-ev_std, ev_mean+ev_std,
  177. color=colors[d], alpha=0.5, lw=0)
  178. ax.text(0.05, 0.1 + 0.12*yh[d], r"$\alpha$" + f" = {alphas[ix].mean():.2f}",
  179. transform=ax.transAxes, color=colors[d], fontsize="large")
  180. ax.set_ylim(0.003, 3)
  181. ax.set_xlim(1, 1000)
  182. ax.set_xticks([1, 10, 100, 1000])
  183. ax.set_xticklabels(["1", "10", "100", "1,000"])
  184. ax.set_yticks([0.01, 0.1 ,1])
  185. ax.set_yticklabels(["0.01", "0.1", "1"])
  186. ax.set_xlabel("PC index")
  187. ax.set_ylabel("normalized variance")
  188. ax.set_title("average", y=1, loc='left')
  189. il = 5
  190. transl = mtransforms.ScaledTranslation(-40 / 72, 0 / 72, fig.dpi_scale_trans)
  191. il = plot_label(ltr, il, ax, transl)
  192. ax = ax.inset_axes([0.7, 0.9, 0.3, 0.4])
  193. for d in range(3):
  194. ix = np.nonzero(ids==d)[0]
  195. if d==0:
  196. ix = np.hstack((ix, np.nonzero(ids==4)[0]))
  197. ix = np.hstack((ix, np.nonzero(ids==3)[0]))
  198. ash = np.stack((alphas[ix], alphas_shuff[ix]), axis=0)
  199. p = ttest_rel(ash[0], ash[1]).pvalue
  200. for i in ix:
  201. ax.plot(np.arange(0,2) + dy[d] * 1.5, (alphas[i], alphas_shuff[i]),
  202. color=colors[d], lw=1., alpha=0.75, ls=ls[ids[i]])
  203. star = "***" if p < 0.001 else "**" if p < 0.01 else "*" if p < 0.05 else "n.s."
  204. print(p)
  205. ax.text(dy[d]*1.5 + 0.5 + (dy[d]-1)*0., 0.9, f"{star}", ha="center",
  206. va="center", color=colors[d], fontsize="small" if p>=0.05 else "medium")
  207. ax.set_ylim([0., 1.0])
  208. ax.set_yticks([0., 0.5, 1.0])
  209. ax.set_xticks([0, 1])
  210. ax.set_xticklabels(["original", "shuffled"], rotation=90, ha="center", va="top")
  211. ax.set_ylabel("power-law\nexponent ($\\alpha$)")
  212. #il += 1
  213. #il = plot_label(ltr, il, ax, transl)
  214. evals_all = dat['evals_sub'].copy()
  215. alphas_sim = np.zeros((2, evals_all.shape[1])) * np.nan
  216. ax = plt.subplot(grid[-2:, 4])
  217. pos = ax.get_position().bounds
  218. ypos = pos[1]+(pos[3]-pos[2]*yratio)/2+0.03
  219. ax.set_position([pose[0], ypos, pos[2]*0.9, pos[2]*yratio*0.9])
  220. for d in range(2):
  221. for i in range(len(evals_all[0])):
  222. ss = evals_all[d, i].copy()
  223. alphas_sim[d, i], yp = fit_powerlaw_exp(ss, np.arange(10, ymax))
  224. ss /= yp[0]
  225. ax.loglog(np.arange(1, min(len(ss)+1, 1001)),
  226. ss[:1000], color=colors[d], lw=0.5, alpha=0.75)
  227. ax.text(0.35, 0.65 + 0.15*(1-d), r"$\alpha$" + f" = {alphas_sim[d].mean():.2f}",
  228. transform=ax.transAxes, color=colors[d], fontsize="medium")
  229. # ax.fill_between(np.arange(1, len(ev_mean)+1), ev_mean-ev_std, ev_mean+ev_std,
  230. # color=colors[d], alpha=0.5, lw=0)
  231. print(alphas_sim.mean(axis=-1))
  232. ax.set_title('simulated 2p data', fontsize='medium')
  233. ax.set_ylim(0.003, 3)
  234. ax.set_xlim(1, 1000)
  235. ax.set_xticks([1, 10, 100, 1000])
  236. ax.set_xticklabels(["1", "10", "100", "1,000"])
  237. ax.set_yticks([0.01, 0.1 ,1])
  238. ax.set_yticklabels(["0.01", "0.1", "1"])
  239. ax.set_xlabel("PC index")
  240. ax.set_ylabel("normalized variance")
  241. il += 1
  242. il = plot_label(ltr, il, ax, transl_e)
  243. transl = mtransforms.ScaledTranslation(-50 / 72, 0 / 72, fig.dpi_scale_trans)
  244. evals_enorms = dat['evals_enorms']
  245. enorms = dat['enorms']
  246. nnorm = len(enorms)
  247. n_sim = len(evals_enorms[0])
  248. alphas_enorms = np.zeros((nnorm, n_sim)) * np.nan
  249. ecolor = ['g', [0, 1, 0]]
  250. for d in range(nnorm):
  251. for i in range(len(evals_enorms[0])):
  252. alphas_enorms[d, i], yp = fit_powerlaw_exp(evals_enorms[d, i], np.arange(10, ymax))
  253. ax = plt.subplot(grid[-2:, -2])
  254. pos = ax.get_position().bounds
  255. ax.errorbar(enorms, alphas_enorms.mean(axis=1), alphas_enorms.std(axis=1)/(n_sim-1)**0.5, color=ecolor[0])
  256. ax1 = ax.twinx()
  257. ax1.set_position([pos[0] + pos[2]*0.25, ypos,
  258. pos[2]*0.5, pos[2]*yratio])
  259. ax1.plot(enorms, 0.5/(1-enorms) * 0.02, color=ecolor[1])
  260. ax1.spines['right'].set_visible(True)
  261. ax1.spines['right'].set_color(ecolor[1])
  262. ax1.tick_params(axis='y', colors=ecolor[1])
  263. ax1.set_ylabel('timescale (sec.)', color=ecolor[1], rotation=-90, va='bottom')
  264. ax1.set_yticks([0, 2, 4])
  265. ax.spines['left'].set_color(ecolor[0])
  266. ax.tick_params(axis='y', colors=ecolor[0])
  267. ax.set_xticks([0.975, 0.985, 0.998])
  268. ax.set_xlim([0.975, 0.998])
  269. ax.set_yticks([0.5, 0.6, 0.7])
  270. ax.set_ylabel('power-law exponent ($\\alpha$)', color=ecolor[0])
  271. ax.set_position([pos[0] + pos[2]*0.6, ypos,
  272. pos[2]*1.25, pos[2]*yratio])
  273. il = plot_label(ltr, il, ax, transl)
  274. return fig, alphas
  275. def suppfig_svca2(dat, dat_subsample, dat_janelia, dat_london):
  276. fig = plt.figure(figsize=(14, 10))
  277. yratio = 14 / 10
  278. grid = plt.GridSpec(5, 5, wspace=0.4, hspace=0.6, figure=fig,
  279. bottom=0.05, top=0.92, left=0.05, right=0.95)
  280. ix = 5
  281. il = 0
  282. dy = 0.
  283. shapes = dat['shapes']
  284. titles = ["eigenspectrum - direct", "SVCA", "SVCA2"]
  285. ticks = ["direct", "SVCA", "SVCA2"]
  286. evals_all_list = [dat["evals_all"], dat["evals_svca_all"], dat["evals_svca2_all"]]
  287. areas_all = dat["areas_all"]
  288. n_dset = len(areas_all)
  289. ids = np.zeros(n_dset, "int")
  290. alphas_all = np.zeros((n_dset, 3))
  291. for d in range(5):
  292. ids[np.array(areas_all)==areas[d]] = d
  293. colors = dcolors[:3].copy()
  294. colors = np.vstack((colors, colors[0], colors[0]))
  295. ls = ["-", "-", "-", "--", "-."]
  296. anames = ['2P cortex', '2P CA1', 'brainwide\nephys']
  297. grid1 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=grid[:3, :3], wspace=0.2, hspace=0.4)
  298. for d in range(3):
  299. for k in range(3):
  300. ax = plt.subplot(grid1[d, k])
  301. pos = ax.get_position().bounds
  302. ax.set_position([pos[0] + 0.02*(1-k), pos[1], pos[3]/yratio, pos[3]])
  303. ix = (ids==0) + (ids==3) + (ids==4) if d==0 else ids==d
  304. ix = np.nonzero(ix)[0]
  305. for i in ix:
  306. evals = evals_all_list[k][i].copy()
  307. alphas_all[i, k], yp = fit_powerlaw_exp(evals, np.arange(10, 500))
  308. evals /= yp[0]
  309. ax.loglog(np.arange(1, len(evals)+1), evals, color=colors[ids[i]],
  310. lw=1, alpha=0.25 if d!=3 else 0.75, ls=ls[ids[i]], zorder=-30*(ids[i]==1) + 20*(ids[i]!=1))
  311. ax.minorticks_on()
  312. ax.set_ylim(0.001, 3)
  313. ax.set_xlim(1, 3000)
  314. ax.set_yticks([0.01, 0.1, 1])
  315. ax.set_yticklabels(["0.01", "0.1", "1"], fontsize='small')
  316. ax.set_xticks([1, 10, 100, 1000])
  317. ax.set_xticklabels(['1', '10 ', '100 ', ' 1,000'], fontsize='small')
  318. ax.text(0.3, 0.85, "$\\alpha = $" + f"{alphas_all[ix, k].mean():.2f}",
  319. color=colors[d], transform=ax.transAxes, fontweight="bold")
  320. ax.xaxis.set_minor_locator(matplotlib.ticker.LogLocator(base=10, subs=np.arange(2,10), numticks=10))
  321. if k==0:
  322. ax.text(0.05, 0.05, anames[d], color=colors[d],
  323. transform=ax.transAxes, fontweight='bold', fontstyle='italic')
  324. transl = mtransforms.ScaledTranslation(-40 / 72, 5 / 72, fig.dpi_scale_trans)
  325. il = plot_label(ltr, il, ax, transl)
  326. if d==0:
  327. if k==0:
  328. ax.set_xlabel("PC index")
  329. ax.set_ylabel("normalized variance")
  330. #ax.set_title("neural recordings", loc="left", x=-0.1, fontweight="bold")
  331. ax.set_title(titles[k], y=1.1, fontstyle='italic')
  332. ax = plt.subplot(grid[:3, 3])
  333. pos = ax.get_position().bounds
  334. ax.set_position([pos[0]- 0.03, pos[1]+0.25*pos[3], pos[2], pos[3]*0.8])
  335. xp = np.arange(3)*np.ones((len(evals_all_list[0]),1))
  336. xp += np.random.randn(*xp.shape)*0.05
  337. cols = np.tile(colors[ids][:,np.newaxis], (1,3)).reshape(-1,3)
  338. ax.scatter(xp.flatten(), alphas_all.flatten(), color=cols, s=10)
  339. for d in range(3):
  340. ix = (ids==0) + (ids==4) + (ids==5) if d==0 else ids==d
  341. ax.scatter(np.arange(3), alphas_all[ix].mean(axis=0), color=colors[d],
  342. s=400, marker="_")
  343. ax.set_ylabel("power-law exponent ($\\alpha$)")
  344. ax.set_xticks(np.arange(3))
  345. ax.set_xticklabels(["direct", "SVCA", "SVCA2"], rotation=45, ha='right')
  346. transl = mtransforms.ScaledTranslation(-50 / 72, -5 / 72, fig.dpi_scale_trans)
  347. il = plot_label(ltr, il, ax, transl)
  348. ax.set_ylim([0.2, 1.4])
  349. ax = plt.subplot(grid[:3, 4])
  350. cols = [colors[0], colors[0], [0.8, 0, 0], [0.5, 0, 0.5], [1, 0, 1]]
  351. pos = ax.get_position().bounds
  352. ax.set_position([pos[0]-0.01, pos[1]+0.25*pos[3], pos[2]*1.25, pos[3]*0.8])
  353. ix = (ids==0) + (ids==4) + (ids==5)
  354. for j in range(5):
  355. if j<2:
  356. alphas = alphas_all[ix, (1-j)+1]
  357. elif j==2:
  358. alphas = dat_subsample['alphas_all']
  359. elif j==3:
  360. alphas = dat_janelia['alphas_all']
  361. elif j==4:
  362. alphas = dat_london['alphas_all']
  363. xp = j*np.ones(len(alphas))
  364. xp += np.random.randn(*xp.shape)*(0.05 + 0.05*(j==4))
  365. ax.scatter(xp, alphas, color=cols[j], s=10)
  366. ax.scatter(j, alphas.mean(), color=cols[j], s=500, marker="_")
  367. ax.set_ylabel("power-law exponent ($\\alpha$)")
  368. ax.set_ylim([0.2, 1.4])
  369. ax.set_xticks(np.arange(5))
  370. ax.set_xticklabels(["SVCA2, GCaMP8s 22Hz", "SVCA, GCaMP8s 22Hz",
  371. "SVCA, GCaMP8s 3Hz", "SVCA, GCaMP6s 3Hz\n(Janelia)",
  372. "SVCA, GCaMP6s 3Hz\n(London)"], rotation=45, ha='right')
  373. for idx, lbl in enumerate(ax.get_xticklabels()):
  374. lbl.set_color(cols[idx])
  375. transl = mtransforms.ScaledTranslation(-50 / 72, -5 / 72, fig.dpi_scale_trans)
  376. il = plot_label(ltr, il, ax, transl)
  377. shapes = dat['shapes']
  378. areas_all = dat['areas_all']
  379. n_dset = len(shapes)
  380. ids = np.zeros(n_dset, "int")
  381. for d in range(5):
  382. ids[np.array(areas_all)==areas[d]] = d
  383. anames = ['2P cortex', '2P CA1', 'brainwide ephys']
  384. scolors = ['g', 'y', 'b']
  385. bsize = 4000
  386. ikeeps = np.arange(50, bsize+1, 200)
  387. ikeeps[-1] = 4000
  388. ineurs = np.arange(0.01, 1.05, 0.05)
  389. ineurs[-1] = 1.0
  390. nneurons = ineurs * np.array(shapes)[:,:1]
  391. ntimes = ikeeps / bsize * np.array(shapes)[:,1:] / (22*60)
  392. xticks = [[[0, 2500, 5000], [0, 50, 100]],
  393. [[0, 2500, 5000], [0, 50, 100]],
  394. [[0, 1000, 2000], [0, 15, 30]]]
  395. fstr = ['', 'svca_', 'svca2_']
  396. grid1 = gridspec.GridSpecFromSubplotSpec(1, 6, subplot_spec=grid[-2:, :],
  397. wspace=0.4, hspace=0.4)
  398. axs = [[plt.subplot(grid1[-2:, 2*d]) for d in range(3)],
  399. [plt.subplot(grid1[-2:, 2*d+1]) for d in range(3)]]
  400. for k in range(3):
  401. evals_all = [dat[f'evals_{fstr[k]}all_times'].copy(), dat[f'evals_{fstr[k]}all_neurons'].copy()]
  402. for j in range(2):
  403. nvar = len(evals_all[j][0])
  404. alphas_all = np.zeros((n_dset, nvar))*np.nan
  405. for i in range(len(evals_all[j])):
  406. for n in range(len(evals_all[j][i])):
  407. evals = evals_all[j][i][n].copy()
  408. ymax = min(len(evals)//2, 500) #500 if len(evals) > 500 else min(len(evals), 100)
  409. if ymax > 15:
  410. alphas_all[i,n], yp = fit_powerlaw_exp(evals, np.arange(10, ymax))
  411. for d in range(3):
  412. ax = axs[j][d]
  413. ix = (ids==0) + (ids==4) + (ids==5) if d==0 else ids==d
  414. nn = nneurons[ix].mean(axis=0) if j==1 else ntimes[ix].mean(axis=0)
  415. ax.errorbar(nn, np.nanmean(alphas_all[ix], axis=0),
  416. np.nanstd(alphas_all[ix], axis=0) / ((~np.isnan(alphas_all[ix])).sum(axis=0)-1)**0.5,
  417. color=scolors[k], lw=1)
  418. ax.set_ylim([0.2, 1.5])
  419. ax.tick_params(axis='both', labelsize='small')
  420. ax.set_xticks(xticks[d][1-j])
  421. ax.set_yticks([0.5, 1, 1.5])
  422. ax.set_xlabel('# of neurons' if j==1 else 'duration (min.)')
  423. if k==0 and j==0:
  424. ax.set_ylabel('power-law exponent ($\\alpha$)')
  425. transl = mtransforms.ScaledTranslation(-55 / 72, -5 / 72, fig.dpi_scale_trans)
  426. il = plot_label(ltr, il, ax, transl)
  427. ax.set_title(anames[d], loc='left', color=colors[d],
  428. fontstyle='italic', fontweight='bold')
  429. if k==0:
  430. pos = ax.get_position().bounds
  431. ax.set_position([pos[0]+0.015*(j==0)*(k==0), pos[1], pos[2], pos[3]*0.9])
  432. if j==0 and d==0:
  433. ax.text(1, 0.9-0.1*k, ['direct', 'SVCA', 'SVCA2'][k], color=scolors[k],
  434. ha='right', transform=ax.transAxes)
  435. return fig
  436. def suppfig_ephys(dat, dat_areas, dat_tbins):
  437. fig = plt.figure(figsize=(8, 9))
  438. yratio = 8 / 9
  439. grid = plt.GridSpec(7, 4, wspace=0.45, hspace=0.6, figure=fig,
  440. bottom=0.07, top=0.98, left=0.1, right=0.95)
  441. ix = 5
  442. il = 0
  443. dy = 0.
  444. shapes = dat['shapes']
  445. areas_all = dat["areas_all"]
  446. n_dset = len(areas_all)
  447. ids = np.zeros(n_dset, "int")
  448. alphas_all = np.zeros((n_dset, 3))
  449. for d in range(5):
  450. ids[np.array(areas_all)==areas[d]] = d
  451. ax = plt.subplot(grid[:3, :])
  452. pos = ax.get_position().bounds
  453. ax.set_position([pos[0]-0.05, pos[1]-0.2*pos[3], pos[2]+0.065, pos[3]*1.08])
  454. tmin = 1120#42000//7 - 0
  455. tlen = 22*60*3//7
  456. Xex = zscore(dat['Xexs'][2][:, tmin:tmin+tlen], axis=1)
  457. im = ax.imshow(Xex, aspect="auto", cmap="gray_r", vmin=0., vmax=1.25)
  458. ax.plot([0, 22*30/7], -Xex.shape[0]*0.03*np.ones(2), color="k", lw=1.5)
  459. ax.plot(-0.015*tlen*np.ones(2), [0, 50], color="k", lw=1.5)
  460. ax.text((22*30/2)/7, -0.07*Xex.shape[0], "30 sec.", ha="center", va="center", fontsize="small")
  461. ax.text(-0.03*tlen, 0, "500 neurons", ha="center", va="bottom", fontsize="small", rotation=90)
  462. cax = ax.inset_axes([0.85, -0.01, 0.15, 0.025])
  463. cb = plt.colorbar(im, cax=cax, orientation="horizontal")
  464. cb.set_ticks([0, 1.0])
  465. cb.set_ticklabels(["0", "1.0"], fontsize="small")
  466. ax.text(0.83, -0.005, "z-scored activity", fontsize="small",
  467. ha="right", va="top", transform=ax.transAxes)
  468. ax.set_ylim([-Xex.shape[0]*0.05, Xex.shape[0]+0.5])
  469. ax.set_xlim([-0.028*tlen, tlen])
  470. ax.axis("off")
  471. ax.set_title('Rastermap of brainwide ephys activity')
  472. transl = mtransforms.ScaledTranslation(-20 / 72, 0 / 72, fig.dpi_scale_trans)
  473. il = plot_label(ltr, il, ax, transl)
  474. colors = dcolors[:3].copy()
  475. acolors = ['g', 'm', [0.25, 1, 0.25], 'r', [0.5, 0, 0]]
  476. ineurs = np.arange(0.01, 1.05, 0.05)
  477. ineurs[-1] = 1.0
  478. nneurons = ineurs * np.array(shapes)[:,:1]
  479. evals_all = dat[f'evals_svca2_all_neurons'].copy()
  480. nvar = len(evals_all[0])
  481. alphas_all = np.zeros((n_dset, nvar))*np.nan
  482. for i in range(len(evals_all)):
  483. for n in range(len(evals_all[i])):
  484. evals = evals_all[i][n].copy()
  485. ymax = min(len(evals)//2, 500) #500 if len(evals) > 500 else min(len(evals), 100)
  486. if ymax > 15:
  487. alphas_all[i,n], yp = fit_powerlaw_exp(evals, np.arange(10, ymax))
  488. nh = [4, 2, 3, 1, 0]
  489. area_names = dat_areas['area_groups'].keys()
  490. evals_all = dat_areas['evals_areas'].copy()
  491. nareas = len(area_names)
  492. alphas_areas = np.zeros((nareas, 3)) * np.nan
  493. nn_areas = np.stack([dat_areas['nneurons'][a] for a in area_names], axis=0)
  494. for i in range(3):
  495. ax = plt.subplot(grid[3:5, i+1])
  496. pos = ax.get_position().bounds
  497. ax.set_position([pos[0] + (2-i)*0.03 + 0.01, pos[1]-0.02, pos[2]*0.95, pos[2]*yratio*0.95])
  498. for n, area in enumerate(area_names):
  499. evals = evals_all[area][i].copy()
  500. if len(evals) > 0:
  501. ymax = min(len(evals)//2, 500) #500 if len(evals) > 500 else min(len(evals), 100)
  502. alphas_areas[n, i], yp = fit_powerlaw_exp(evals, np.arange(10, ymax))
  503. evals /= yp[0]
  504. ax.loglog(np.arange(1, len(evals)+1), evals, color=acolors[n], lw=1)
  505. nstr = '# of neurons ' if nh[n]==0 else ''
  506. nhn = nh[n] if i<2 else nh[n] - 1*(nh[n]>1)
  507. ax.text(1, 0.95-0.12*nhn, f'{nstr}= {int(nn_areas[n, i]):,d}', color=acolors[n],
  508. ha='right', transform=ax.transAxes, fontsize='small')
  509. ax.set_ylim(0.003, 3)
  510. ax.set_xlim(1, 1000)
  511. ax.set_yticks([0.01, 0.1, 1])
  512. ax.set_yticklabels(["0.01", "0.1", "1"], fontsize='small')
  513. ax.set_xticks([1, 10, 100, 1000])
  514. ax.set_xticklabels(['1', '10', '100', '1,000'], fontsize='small')
  515. ax.set_title(f'mouse {i+1}', fontsize='medium', y=1.1)
  516. ax.set_xlabel("PC index")
  517. if i==0:
  518. ax.set_ylabel("normalized variance")
  519. transl = mtransforms.ScaledTranslation(-50 / 72, 10 / 72, fig.dpi_scale_trans)
  520. il = 2
  521. il = plot_label(ltr, il, ax, transl)
  522. il -= 2
  523. d = 2
  524. ax = plt.subplot(grid[3:5, 0])
  525. pos = ax.get_position().bounds
  526. ax.set_position([pos[0], pos[1]-0.02, pos[2], pos[2]*yratio*1.1])
  527. ix = ids==d
  528. nn = nneurons[ix].mean(axis=0)
  529. ax.errorbar(nn, np.nanmean(alphas_all[ix], axis=0),
  530. np.nanstd(alphas_all[ix], axis=0) / ((~np.isnan(alphas_all[ix])).sum(axis=0)-1)**0.5,
  531. color=colors[d], lw=1)
  532. for n, area in enumerate(area_names):
  533. ax.scatter(nn_areas[n], alphas_areas[n], color=acolors[n],
  534. s=30, marker='x', zorder=30, alpha=0.9)
  535. ax.text(1.25, 1-0.12*nh[n], area, color=acolors[n], ha='right',
  536. transform=ax.transAxes, fontsize='small', va='bottom')
  537. ax.text(1.25, 0.02, u'\u2014 random\nsubsets', color=dcolors[d], ha='right',
  538. transform=ax.transAxes, fontweight='bold')
  539. ax.set_ylim([0.4, 1.8])
  540. ax.set_xscale('log')
  541. ax.set_xticks([100, 1000])
  542. ax.set_xticklabels(['100', '1,000'])
  543. ax.set_xlabel('# of neurons')
  544. ax.set_ylabel('power-law exponent ($\\alpha$)')
  545. transl = mtransforms.ScaledTranslation(-55 / 72, 0 / 72, fig.dpi_scale_trans)
  546. il = plot_label(ltr, il, ax, transl)
  547. il += 1
  548. tbins = dat_tbins['tbins']
  549. acolors = plt.get_cmap('YlOrBr_r')(np.linspace(0, 0.6, len(tbins)))
  550. evals_all = dat_tbins['evals_tbins']
  551. alphas_tbins = np.zeros((len(tbins), 3)) * np.nan
  552. for i in range(3):
  553. ax = plt.subplot(grid[5:7, i+1])
  554. pos = ax.get_position().bounds
  555. ax.set_position([pos[0] + (2-i)*0.03 + 0.01, pos[1], pos[2]*0.95, pos[2]*yratio*0.95])
  556. for n, tbin in enumerate(tbins):
  557. evals = evals_all[i][n].copy()
  558. if len(evals) > 0:
  559. ymax = min(len(evals)//2, 500) #500 if len(evals) > 500 else min(len(evals), 100)
  560. alphas_tbins[n, i], yp = fit_powerlaw_exp(evals, np.arange(10, ymax))
  561. evals /= yp[0]
  562. ax.loglog(np.arange(1, len(evals)+1), evals, color=acolors[n], lw=1)
  563. ax.set_ylim(0.003, 3)
  564. ax.set_xlim(1, 1000)
  565. ax.set_yticks([0.01, 0.1, 1])
  566. ax.set_yticklabels(["0.01", "0.1", "1"], fontsize='small')
  567. ax.set_xticks([1, 10, 100, 1000])
  568. ax.set_xticklabels(['1', '10', '100', '1,000'], fontsize='small')
  569. ax.set_title(f'mouse {i+1}', fontsize='medium')
  570. ax.set_xlabel("PC index")
  571. if i==0:
  572. ax.set_ylabel("normalized variance")
  573. transl = mtransforms.ScaledTranslation(-50 / 72, 10 / 72, fig.dpi_scale_trans)
  574. il += 1
  575. il = plot_label(ltr, il, ax, transl)
  576. il -= 2
  577. ax = plt.subplot(grid[5:7, 0])
  578. pos = ax.get_position().bounds
  579. ax.set_position([pos[0], pos[1], pos[2], pos[2]*yratio*1.1])
  580. ax.errorbar(tbins*1000, alphas_tbins.mean(axis=-1),
  581. alphas_tbins.std(axis=-1)/(2**0.5), color='k')
  582. for n, tbin in enumerate(tbins):
  583. ax.scatter(tbin*1000, alphas_tbins[n].mean(), s=30,
  584. color=acolors[n], zorder=30)
  585. ax.set_xscale('log')
  586. ax.set_xlabel('time bin (ms)')
  587. ax.set_ylabel('power-law exponent ($\\alpha$)')
  588. ax.set_xticks([10, 100])
  589. ax.set_xticklabels(['10', '100'])
  590. ax.set_ylim([0.65, 0.85])
  591. ax.set_yticks([0.7, 0.8])
  592. transl = mtransforms.ScaledTranslation(-58 / 72, 0 / 72, fig.dpi_scale_trans)
  593. il = plot_label(ltr, il, ax, transl)
  594. return fig
  595. def suppfig_running(dat):
  596. colors = [[0.7, 0, 0], [1, 0.5, 0.5]]
  597. fig = plt.figure(figsize=(14, 3), dpi=150)
  598. yratio = 14 / 3
  599. grid = plt.GridSpec(1, 5, wspace=0.4, hspace=0.2, figure=fig,
  600. bottom=0.18, top=0.9, left=0.05, right=0.95)
  601. transl = mtransforms.ScaledTranslation(-45 / 72, 5 / 72, fig.dpi_scale_trans)
  602. il = 0
  603. evals_run_all = dat['evals_run_all'].copy()
  604. nrun = evals_run_all.shape[1]
  605. alphas_all = np.zeros((2, nrun))
  606. ax = plt.subplot(grid[0, 0])
  607. pos = ax.get_position().bounds
  608. ax.set_position([pos[0], pos[1], pos[2], pos[2]*yratio])
  609. rstr = ['running', 'not running']
  610. for j in range(2):
  611. for i in range(nrun):
  612. alphas_all[j, i], yp = fit_powerlaw_exp(evals_run_all[j, i], np.arange(10, 500))
  613. evals_run_all[j, i] /= yp[0]
  614. evals = np.nanmean(evals_run_all[j], axis=0)
  615. evals_std = np.nanstd(evals_run_all[j], axis=0) / (nrun-1)**0.5
  616. ax.loglog(np.arange(1, len(evals)+1), evals, lw=1, color=colors[j])
  617. ax.fill_between(np.arange(1, len(evals)+1), evals - evals_std, evals + evals_std,
  618. edgecolor='none', facecolor=colors[j], alpha=0.25)
  619. alpha = fit_powerlaw_exp(evals, np.arange(10, 500))[0]
  620. ax.text(1, 1-0.1*j, f'{rstr[j]}, $\\alpha$={alpha:.2f}', ha='right',
  621. transform=ax.transAxes, color=colors[j])
  622. ax.set_yscale('log')
  623. ax.set_xscale('log')
  624. ax.set_ylim(0.003, 0.003*700)
  625. ax.set_xlim(1, 700)
  626. ax.set_yticks([0.01, 0.1, 1])
  627. ax.set_yticklabels(["0.01", "0.1", "1"], fontsize='small')
  628. ax.set_xticks([1, 10, 100])
  629. ax.set_xticklabels(['1', '10', '100'], fontsize='small')
  630. ax.set_xlabel("PC index")
  631. ax.set_ylabel("normalized variance")
  632. il = plot_label(ltr, il, ax, transl)
  633. ax = plt.subplot(grid[0, 1])
  634. pos = ax.get_position().bounds
  635. ax.set_position([pos[0] + pos[2]*0.1, pos[1], pos[2]*0.5, pos[2]*yratio])
  636. areas = dat['areas']
  637. ls = {'V1': '-', 'sensorimotor': '--', 'PPC': '-.'}
  638. for i in range(nrun):
  639. ax.plot(np.arange(0,2), alphas_all[:,i],
  640. color='k', lw=1., alpha=0.75, ls=ls[areas[i]])
  641. p = ttest_rel(alphas_all[0], alphas_all[1]).pvalue
  642. star = "***" if p < 0.001 else "**" if p < 0.01 else "*" if p < 0.05 else "n.s."
  643. print(p)
  644. ax.text(0.5, 1., f"{star}", ha="center",
  645. va="center", color='k', fontsize="small" if p>=0.05 else "medium")
  646. ax.set_ylim([0., 1.0])
  647. ax.set_yticks([0., 0.5, 1.0])
  648. ax.set_xticks([0, 1])
  649. ax.set_xticklabels(["running", "not\nrunning"], rotation=0, ha="center", va="top")
  650. ax.set_ylabel("power-law exponent ($\\alpha$)")
  651. lns = []
  652. area_names = ['V1', 'sensorimotor', 'PPC']
  653. for area in area_names:
  654. ln = ax.plot([], [], color='k', lw=1, ls=ls[area])
  655. lns.append(ln[0])
  656. ax.legend(lns, area_names,
  657. frameon=False, loc="lower left", #bbox_to_anchor=(0.2, 1.1),
  658. handlelength=1.2)
  659. il = plot_label(ltr, il, ax, transl)
  660. iex = 2
  661. for j in range(2):
  662. ax = plt.subplot(grid[0, 2+j])
  663. pos = ax.get_position().bounds
  664. ax.set_position([pos[0], pos[1], pos[2], pos[2]*yratio])
  665. e = dat['dmd_evals_all'][j, iex].copy()
  666. ix = np.abs(e)>.25
  667. iang = np.angle(e[ix]) / (2*np.pi)
  668. iabs = -np.log10(np.abs(e[ix]))
  669. irot = iang/iabs
  670. ixx = e[ix].imag>=0
  671. mu = irot[ixx].mean()
  672. sd = irot[ixx].std()
  673. m = np.percentile(irot[ixx], [5, 25, 75, 95])
  674. med = np.median(irot[ixx])
  675. print(m, med)
  676. ax.scatter(e.real, e.imag, s=10, color=colors[j])
  677. ax.set_ylim([-1, 1])
  678. ax.set_xlim([0.25, 1])
  679. ax.set_xlabel('real part')
  680. ax.set_ylabel('imaginary part')
  681. ax.text(0.5, 0.8, rstr[j], color=colors[j], ha='center', transform=ax.transAxes)
  682. if j==0:
  683. il = plot_label(ltr, il, ax, transl)
  684. ax.set_title('Eigenvalues of DMD matrix (dt=0.23s), example mouse', loc='left', y=1.02, fontsize='medium')
  685. ax = plt.subplot(grid[0, -1])
  686. pos = ax.get_position().bounds
  687. ax.set_position([pos[0], pos[1], pos[2], pos[2]*yratio])
  688. igood = np.nonzero(~np.isnan(dat['dmd_evals_all'][0,:,0]))[0]
  689. for i, iex in enumerate(igood):
  690. for j in range(2):
  691. e = dat['dmd_evals_all'][j, iex].copy()
  692. ix = np.abs(e)>.25
  693. iang = np.angle(e[ix]) / (2*np.pi)
  694. iabs = -np.log10(np.abs(e[ix]))
  695. irot = iang/iabs
  696. ixx = e[ix].imag>=0
  697. mu = irot[ixx].mean()
  698. sd = irot[ixx].std()
  699. m = np.percentile(irot[ixx], [5, 25, 50, 75, 95])
  700. med = np.median(irot[ixx])
  701. dy = 0.3
  702. yy = -(4*i - j)
  703. print(ixx.sum())
  704. ax.plot([m[0], m[-1]], -(4*i - j) * np.ones(2), lw=1, color=np.minimum(1, np.array(colors[j])+0.25))
  705. ax.plot([m[1], m[-2]], -(4*i - j) * np.ones(2), lw=4, color=np.minimum(1, np.array(colors[j])+0.25))
  706. ax.plot([m[2], m[2]], [yy-dy, yy+dy], lw=1, color=colors[j])
  707. if j==0:
  708. ax.text(-0.1, -4*i, f'mouse {len(igood) - i}', rotation=90, ha='center', va='center', fontsize='small')
  709. ax.set_xlim([-0.1, 1])
  710. ax.set_ylim([3, -9])
  711. ax.spines['left'].set_visible(False)
  712. ax.set_yticks([])
  713. ax.set_xlabel('rotations per 10-fold attenuation')
  714. il = plot_label(ltr, il, ax, transl)
  715. return fig
  716. # def suppfig_svca(dat):
  717. # fig = plt.figure(figsize=(14, 14), dpi=150)
  718. # yratio = 14 / 14
  719. # grid = plt.GridSpec(5, 6, wspace=0.4, hspace=0.2, figure=fig,
  720. # bottom=0.05, top=1, left=0.08, right=0.95)
  721. # ix = 5
  722. # transl = mtransforms.ScaledTranslation(-45 / 72, ix / 72, fig.dpi_scale_trans)
  723. # il = 0
  724. # dy = 0.
  725. # titles = ["eigenspectrum - direct", "SVCA", "SVCA2"]
  726. # ticks = ["direct", "SVCA", "SVCA2"]
  727. # evals_all_list = [dat["evals_all"], dat["evals_svca_all"], dat["evals_svca2_all"]]
  728. # areas_all = dat["areas_all"]
  729. # ids = np.zeros(len(areas_all), "int")
  730. # alphas_all = np.zeros((len(evals_all_list[0]), 3))
  731. # for d in range(5):
  732. # ids[np.array(areas_all)==areas[d]] = d
  733. # colors = dcolors[:3].copy()
  734. # colors.append(colors[0])
  735. # colors.append(colors[0])
  736. # ls = ["-", "-", "-", "--", "-."]
  737. # for d in range(5):
  738. # ax = plt.subplot(grid[-1, d])
  739. # pos = ax.get_position().bounds
  740. # ax.set_position([pos[0], pos[1], pos[2], pos[2]*yratio])
  741. # for i in range(len(evals_all_list[d])):
  742. # evals = evals_all_list[d][i].copy()
  743. # alphas_all[i, d], yp = fit_powerlaw_exp(evals, np.arange(10, 500))
  744. # evals /= yp[0]
  745. # ax.loglog(np.arange(1, len(evals)+1), evals, color=dcolors[ids[i]],
  746. # lw=1, alpha=1, ls=ls[d])
  747. # ax.set_ylim(0.001, 3)
  748. # ax.set_xlim(1, 3000)
  749. # ax.set_yticks([0.01, 0.1, 1])
  750. # ax.set_yticklabels(["0.01", "0.1", "1"])
  751. # ax.set_xticks([1, 10, 100, 1000])
  752. # ax.set_xticklabels(["1", "10", "100", "1,000"])
  753. # for k in range(3):
  754. # ax.text(0.05, 0.32 - 0.12*k, "$\\alpha = $" + f"{alphas_all[ids==k, d].mean():.2f}",
  755. # color=dcolors[k], transform=ax.transAxes, fontweight="bold")
  756. # ax.set_xlabel("PC index")
  757. # if d==0:
  758. # ax.set_ylabel("normalized variance")
  759. # il = plot_label(ltr, il, ax, transl)
  760. # ax.set_title("neural recordings", loc="left", x=-0.1, fontweight="bold")
  761. # ax = plt.subplot(grid[-1, 3])
  762. # pos = ax.get_position().bounds
  763. # ax.set_position([pos[0] + 0.025, pos[1]+dy-0.02, pos[2], pos[2]*yratio + 0.04])
  764. # xp = np.arange(3)*np.ones((len(evals_all_list[0]),1))
  765. # xp += np.random.randn(*xp.shape)*0.05
  766. # cols = np.tile(dcolors[ids][:,np.newaxis], (1,3)).reshape(-1,3)
  767. # ax.scatter(xp.flatten(), alphas_all.flatten(), color=cols, s=10)
  768. # for k in range(3):
  769. # ax.scatter(np.arange(3), alphas_all[ids==k].mean(axis=0), color=dcolors[k],
  770. # s=400, marker="_")
  771. # ax.set_ylabel("power-law exponent ($\\alpha$)")
  772. # ax.set_xticks(np.arange(3))
  773. # ax.set_xticklabels(["direct", "SVCA", "SVCA2"], rotation=0)
  774. # il = plot_label(ltr, il, ax, transl)
  775. # return fig
  776. # def suppfig_svca2_sizes(dat_sim, alphas=None):
  777. # evals_svca2_all = dat_sim["evals_svca2_all"]
  778. # nonsyms = dat_sim["nonsyms"]
  779. # nneurons = dat_sim["nneurons"]
  780. # ntimes = dat_sim["ntimes"].astype('float32') / 23 # convert to seconds
  781. # noise_levels = dat_sim["noise_levels"]
  782. # n_sim = len(evals_svca2_all)
  783. # if alphas is None:
  784. # alphas = np.zeros((evals_svca2_all.shape[:-1]))
  785. # for i in range(n_sim):
  786. # for ni, nonsym in enumerate(nonsyms):
  787. # for nl, noise_level in enumerate(noise_levels):
  788. # for ii, nneur in enumerate(nneurons):
  789. # for jj, ntime in enumerate(ntimes):
  790. # evals = evals_svca2_all[i,ni,nl,ii,jj].copy()
  791. # ymax = min((~np.isnan(evals)).sum(), int(nneur*0.4), int(ntime*0.4))
  792. # evals = evals_svca2_all[i,ni,nl,ii,jj].copy()
  793. # yrange = np.arange(10, min(500, (~np.isnan(evals)).sum()-1))
  794. # alpha = fit_powerlaw_exp(evals, yrange)[0]
  795. # alphas[i,ni,nl,ii,jj] = alpha
  796. # fig = plt.figure(figsize=(14, 9), dpi=150)
  797. # yratio = 14 / 9
  798. # grid = plt.GridSpec(4, 7, wspace=0.6, hspace=0.7, figure=fig,
  799. # bottom=0.05, top=0.95, left=0.06, right=0.98)
  800. # grid1 = gridspec.GridSpecFromSubplotSpec(4, 6, subplot_spec=grid[:, 2:], wspace=0.3, hspace=0.7)
  801. # il = 0
  802. # n_sim = len(evals_svca2_all)
  803. # for ni, nonsym in enumerate(nonsyms):
  804. # for j in range(2):
  805. # if j==0:
  806. # lcolors = plt.get_cmap("Oranges")(np.linspace(0.5, 1, len(nneurons)//2))
  807. # else:
  808. # lcolors = plt.get_cmap("Greens")(np.linspace(0.5, 1, len(ntimes)//2))
  809. # ax = plt.subplot(grid[ni, j])
  810. # pos = ax.get_position().bounds
  811. # ax.set_position([pos[0], pos[1], pos[2], pos[2]*yratio])
  812. # if ni==0:
  813. # transl = mtransforms.ScaledTranslation(-40 / 72, -4 / 72, fig.dpi_scale_trans)
  814. # else:
  815. # transl = mtransforms.ScaledTranslation(-40 / 72, -10 / 72, fig.dpi_scale_trans)
  816. # il = plot_label(ltr, il, ax, transl)
  817. # if j==0:
  818. # if ni==0:
  819. # x0, y0 = -0.65, 1.3
  820. # else:
  821. # x0, y0 = -0.65, 1.2
  822. # ax.text(x0, y0, ["symmetric", "1/3 non-symmetric", "2/3 non-symmetric", "non-symmetric"][ni] + " connectivity",
  823. # transform=ax.transAxes, fontsize="medium", fontweight="bold", fontstyle='italic')
  824. # if ni == 0:
  825. # ax.text(0.7, 1.05, '# neurons = ' if j==0 else 'time =',
  826. # color='k', transform=ax.transAxes, ha='right')
  827. # for ii, nn in enumerate(nneurons) if j ==0 else enumerate(ntimes):
  828. # if ii%2==1:
  829. # continue
  830. # evals = evals_svca2_all[0,ni,0,ii,-1].copy() if j==0 else evals_svca2_all[0,ni,0,-1,ii].copy()
  831. # ymax = min((~np.isnan(evals)).sum(), int(nn*0.4))
  832. # evals = evals[:ymax]
  833. # alpha = plot_spectrum(ax, evals, color=lcolors[ii//2], lw=1, plot_fit=False)
  834. # if ii%4==0 and ni==0:
  835. # if j==0:
  836. # ax.text(0.75, 0.65 + 0.1*ii/4, f"{nn:.0f}",
  837. # color=lcolors[ii//2], transform=ax.transAxes, fontsize="small")
  838. # else:
  839. # ax.text(0.75, 1.05 - 0.1*ii/4, f"{nn/60:.1f} min",
  840. # color=lcolors[ii//2], transform=ax.transAxes, fontsize="small")
  841. # if ni==0:
  842. # if j==0:
  843. # ax.set_xlabel("PC index")
  844. # ax.set_ylabel("normalized\nvariance")
  845. # else:
  846. # ax.set_xlabel("PC index")
  847. # for j in range(len(noise_levels)):
  848. # ax = plt.subplot(grid1[ni, j])
  849. # pos = ax.get_position().bounds
  850. # ax.set_position([pos[0]+0.008*(len(noise_levels) - j), pos[1], pos[2], pos[2]*yratio])
  851. # im = ax.imshow(alphas.mean(axis=0)[ni, j].T, vmin=0.5, vmax=2, cmap='viridis',
  852. # aspect='auto')
  853. # #ax.invert_yaxis()
  854. # xticks = np.array(1 * 2**np.arange(0, 9, 2))
  855. # f = interp1d(ntimes, np.arange(len(ntimes)))
  856. # ax.set_xticks(f(xticks * 60))
  857. # yticks = np.array(200 * 2**np.arange(0, 6, 1))
  858. # yticks = np.hstack((yticks, 10000))
  859. # f = interp1d(nneurons, np.arange(len(nneurons)))
  860. # ax.set_yticks(f(yticks))
  861. # ax.tick_params(labelsize='small')
  862. # #ax.axis('square')
  863. # ax.set_title(['low', 'medium', 'high'][j%3], fontsize='small')
  864. # if j==1:
  865. # ax.text(0.5, 1.2, 'Gaussian noise + smoothing', fontsize='medium',
  866. # ha='center', transform=ax.transAxes, fontstyle='italic')
  867. # elif j==4:
  868. # ax.text(0.5, 1.2, 'Poisson noise', fontsize='medium',
  869. # ha='center', transform=ax.transAxes, fontstyle='italic')
  870. # if ni==0:
  871. # if j==1:
  872. # axin = ax.inset_axes([0.05, -0.25, 0.8, 0.1]);
  873. # cb = plt.colorbar(im, cax=axin, orientation='horizontal')
  874. # cb.ax.tick_params(labelsize='small')
  875. # axin.text(1.05, 0.5, 'power-law exponent ($\\alpha$)', fontsize='small',
  876. # ha='left', transform=axin.transAxes, va='center')
  877. # cb.ax.set_xticks([0.5, 1, 1.5, 2])
  878. # #cb.ax.yaxis.label.set_size('medium')
  879. # elif j==0:
  880. # ax.set_ylabel('# of neurons')
  881. # ax.set_xlabel('time (min)')
  882. # if j==0:
  883. # transl = mtransforms.ScaledTranslation(-50 / 72, -5 / 72, fig.dpi_scale_trans)
  884. # il = plot_label(ltr, il, ax, transl)
  885. # ax.set_yticklabels(yticks)
  886. # ax.set_xticklabels(xticks, rotation=30, ha='right', va='top')
  887. # else:
  888. # ax.set_yticklabels([])
  889. # ax.set_xticklabels([])
  890. # return fig

fig2.py at commit 2c15edf, under GPL-3.0 · at the source

Overview

Authors: Marius Pachitariu1, Lin Zhong1, Alexa Gracias1, Amanda Minisi1, Crystall Lopez1, Carsen Stringer1
  1. HHMI Janelia Research Campus,Ashburn, VA USA
Institutions: Janelia Research Campus (United States)
Journal: Nature, volume 655, issue 8124, pages 990-996
Dates: received 29 January 2025; accepted 10 April 2026; published online 20 May 2026; in print 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1038/s41586-026-10528-1 · PMID 42162432 · PMCID PMC13391357 · OpenAlex W4406241453
Open access: hybrid, a free copy (OpenAlex)
Status: code verified (how the code is found and verified)
Categories: computational modeling (no new data) (modality), mouse (organism)
Methods: Statistics, Smoothing, state filtering, decompositions, Machine learning, Preprocessing, Connectivity, fMRI & imaging, Single-unit activity, calcium imaging, Spectral & time-frequency
Keywords: Network models, Cellular neuroscience
MeSH: Models, Neurological*, Nerve Net*, Neurons*, Animals, CA1 Region, Hippocampal, Memory, Short-Term, Mice, Time Factors (* major topic)
Topic: Neural Networks and Applications (Artificial Intelligence, Computer Science), according to OpenAlex
Citations: cited by 5 papers (Europe PMC); 110 references in the paper

Abstract

Intrinsically generated, brainwide neural activity displays macroscopic coordination among large populations of neurons that persists beyond the biophysical timescales of individual neurons1–3. It is not well understood how these macroscopic behaviours arise from microscopic, short-lived interactions between pairs of neurons. Here we show that the eigenvalue spectrum and dynamical properties of large-scale neural recordings in mice are similar to those produced by linear dynamics governed by a random symmetric matrix that is critically normalized. An exception was population activity in hippocampal area CA1, which resembled an efficient, uncorrelated neural code that may be optimized for information storage capacity. High-dimensional, global activity modes emerged in critically normalized artificial networks and persisted under sparse, clustered or spatial connectivity. These dynamics were useful for solving time-dependent tasks such as a zero-shot working memory task.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above, with 13 matches between paragraphs and lines of code.

mouseland/critical_init

License: GPL-3.0
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Commit: 2c15edf4e770165fc3962dcc3920c8bcaf555bed, 4 June 2026
Languages: Python (13), Jupyter (7)
Size: 32 files, 20 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README, license file, environment (requirements.txt), 7 notebooks
Not found: CITATION.cff, tests, continuous integration, documentation
Tools: NumPy (17 files), PyTorch (13 files), Matplotlib (10 files), SciPy (8 files), scikit-learn (2 files), Neurodata Without Borders (PyNWB, MatNWB) (1 file), Suite2p (1 file)
Availability: 1 check, the latest on 28 September 2026: the link answers
  • 28 September 2026: the link answers
22 files

Zenodo 19322086

License: GPL-3.0
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: the references
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (17 files), PyTorch (13 files), Matplotlib (10 files), SciPy (8 files), scikit-learn (2 files), Neurodata Without Borders (PyNWB, MatNWB) (1 file), Suite2p (1 file)
Availability: 1 check, the latest on 28 September 2026: the link answers (HTTP 200)
  • 28 September 2026: the link answers (HTTP 200)
22 files
At the source:

Code availability

Code to reproduce all the analyses and figures is available at GitHub (https://github.com/mouseland/critical_init)110.

Reproduced under the paper's license (CC BY), from the paper cited above.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 40 scripts, each with its path and the digest of its content;
  • 13 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Data availability

The new neural recordings from this study are available at Figshare (10.25378/janelia.27854448)108. Datasets in Fig. 4 are publicly available at Figshare (10.25378/janelia.23712957)75. The eight-probe Neuropixels recordings were published previously109; we have uploaded the Kilosort4 processing of these recordings to Figshare (10.25378/janelia.27854448)108. The datasets in Extended Data Fig. 8 are publicly available88,90,92,95,97,99.

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 2, 28 September 2026

  • Publisher: n/a → Nature Portfolio

Version 1, 28 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 6 authors, 2 keywords, 8 MeSH terms, 84 references.

Cite

This paper

Pachitariu, M., Zhong, L., Gracias, A., Minisi, A., Lopez, C., & Stringer, C. (2026). A critical initialization for biological neural networks. Nature, 655(8124), 990-996. https://doi.org/10.1038/s41586-026-10528-1

BibTeX

@article{pachitariu2026critical,
author = {Pachitariu, Marius and Zhong, Lin and Gracias, Alexa and Minisi, Amanda and Lopez, Crystall and Stringer, Carsen},
title = {{A critical initialization for biological neural networks}},
journal = {Nature},
year = {2026},
month = may,
volume = {655},
number = {8124},
pages = {990--996},
publisher = {Nature Portfolio},
issn = {0028-0836},
doi = {10.1038/s41586-026-10528-1},
url = {https://doi.org/10.1038/s41586-026-10528-1},
pmid = {42162432},
pmcid = {PMC13391357}
}

RIS

TY - JOUR
AU - Pachitariu, Marius
AU - Zhong, Lin
AU - Gracias, Alexa
AU - Minisi, Amanda
AU - Lopez, Crystall
AU - Stringer, Carsen
TI - A critical initialization for biological neural networks
T2 - Nature
J2 - Nature
PY - 2026
DA - 2026/05/20
VL - 655
IS - 8124
SP - 990
EP - 996
SN - 0028-0836
PB - Nature Portfolio
DO - 10.1038/s41586-026-10528-1
UR - https://doi.org/10.1038/s41586-026-10528-1
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41586-026-10528-1",
"type": "article-journal",
"title": "A critical initialization for biological neural networks",
"container-title": "Nature",
"author": [
{
"family": "Pachitariu",
"given": "Marius"
},
{
"family": "Zhong",
"given": "Lin"
},
{
"family": "Gracias",
"given": "Alexa"
},
{
"family": "Minisi",
"given": "Amanda"
},
{
"family": "Lopez",
"given": "Crystall"
},
{
"family": "Stringer",
"given": "Carsen"
}
],
"container-title-short": "Nature",
"volume": "655",
"issue": "8124",
"page": "990-996",
"DOI": "10.1038/s41586-026-10528-1",
"PMID": "42162432",
"PMCID": "PMC13391357",
"ISSN": "0028-0836",
"publisher": "Nature Portfolio",
"URL": "https://doi.org/10.1038/s41586-026-10528-1",
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
20
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41593-024-01783-4 [code]
Rastermap: a discovery method for neural population recordings.
Journal: Nature neuroscience
In common: Suite2p, Neurodata Without Borders (PyNWB, MatNWB), PyTorch, 4 other tools, mouse, 14 references, 3 authors
[2] doi:10.1038/s41593-023-01490-6 [code]
Facemap: a framework for modeling neural activity based on orofacial tracking.
Journal: Nature neuroscience
In common: PyTorch, scikit-learn, SciPy, 2 other tools, mouse, 12 references, 3 authors
[3] doi:10.1038/s41586-025-09180-y [code]
Unsupervised pretraining in biological neural networks.
Journal: Nature
In common: SciPy, Matplotlib, NumPy, mouse, 9 references, 3 authors
[4] doi:10.1038/s41467-025-61171-9 [code]
A simplified minimodel of visual cortical neurons.
Journal: Nature communications
In common: PyTorch, scikit-learn, SciPy, 2 other tools, mouse, 8 references, 2 authors
[5] doi:10.1038/s41586-024-08548-w [code]
Learning produces an orthogonalized state machine in the hippocampus.
Journal: Nature
In common: Suite2p, PyTorch, scikit-learn, 3 other tools, mouse, 5 references, author Carsen Stringer
[6] doi:10.1371/journal.pcbi.1010855 [code]
Relating local connectivity and global dynamics in recurrent excitatory-inhibitory networks.
Journal: PLoS computational biology
In common: SciPy, Matplotlib, NumPy, 10 references
[7] doi:10.1038/s41592-024-02232-7 [code]
Spike sorting with Kilosort4.
Journal: Nature methods
In common: PyTorch, scikit-learn, SciPy, 2 other tools, 3 references, 2 authors
[8] doi:10.1073/pnas.2404039122 [code]
Structure of activity in multiregion recurrent neural networks.
Journal: Proceedings of the National Academy of Sciences of the United States of America
In common: PyTorch, scikit-learn, SciPy, 2 other tools, 9 references
[9] doi:10.1038/s41586-023-06680-7 [code]
Vagal sensory neurons mediate the Bezold-Jarisch reflex and induce syncope.
Journal: Nature
In common: PyTorch, SciPy, Matplotlib, 1 other tool, 6 references, author Carsen Stringer
[10] doi:10.1038/s41593-025-02114-x [code]
Brain-wide analysis reveals movement encoding structured across and within brain areas.
Journal: Nature neuroscience
In common: scikit-learn, SciPy, Matplotlib, 1 other tool, mouse, 9 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Add the badge to the code's README

OSCR: the badge of this paper

If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.

Markdown
<!-- oscr-badge:start -->
[![OSCR](https://openscicode.org/badge/doi/10.1038/s41586-026-10528-1.svg)](https://openscicode.org/badge/doi/10.1038/s41586-026-10528-1)
<!-- oscr-badge:end -->
reStructuredText
.. oscr-badge:start

.. image:: https://openscicode.org/badge/doi/10.1038/s41586-026-10528-1.svg
   :target: https://openscicode.org/badge/doi/10.1038/s41586-026-10528-1
   :alt: OSCR

.. oscr-badge:end
HTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1038/s41586-026-10528-1"><img src="https://openscicode.org/badge/doi/10.1038/s41586-026-10528-1.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->

On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".

If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.

Report a mismatch between the code and the paper · Report a code error (signed in)

Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.

Report a reproduction failure (signed in)

Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.