Wakhloo, Slatton & Chung (2026) on DANDI:000978¶
Paper: A. J. Wakhloo, W. Slatton and S. Chung, "Neural population geometry and optimal coding of tasks with shared latent structure", Nature Neuroscience (2026), doi:10.1038/s41593-025-02183-y. The paper reuses the data of Tang, Shin and Jadhav (2023).
Dataset: DANDI:000978 "Single Day W-Track Learning", version 0.240511.0307 (doi:10.48324/dandi.000978/0.240511.0307). The paper cites this version (ref. 67, and the README of its code), and it is also the most recent published version; the dandiset has three published versions, all made on 2024-05-11 within twenty minutes, with the same nine assets and the same total size, so the choice does not change the data read.
Claims: claims/wakhloo-2026.yaml, written from the version of record (published 4 February 2026),
main text, figure legends and Methods; the Supplementary Information was not in the text read. The
paper's code is github.com/awakhloo/population_geometry_optimal_coding at commit 9674a6c, which the
claims file and the helper wtrack.py cite for each method detail the Methods leave open.
| Claim | Tested here |
|---|---|
| eq1-generalization-error-formula, eq1-sample-dependence, optimal-code-disentangled, eq2-optimal-spectrum-flattens, fig6ce-optimal-early-low-dim-high-corr | Blocked: theory, no recorded data |
| fig3bc-mlp-theory-tracks-error, fig3dg-mlp-geometry-tradeoff | Blocked: simulations, no recorded data |
| fig4bf-pose-network-geometry, fig4g-pose-theory-r2 | Blocked: DeepLabCut data elsewhere, needs a trained network |
| fig5d, fig5e, fig5h (macaque) | Blocked: Brain-Score data elsewhere, not attempted in this run |
| svc-hebbian-correlation | Tested (PFC and CA1 part) |
| fig7d-behavioral-error-learning | Tested |
| fig7e-readout-error-learning | Tested |
| figs12c-behavior-readout-r2 | Tested |
| fig7f-theory-vs-empirical | Tested |
| fig7g-total-dimension-drops-early | Tested |
| fig7h-task-dimension-increases | Tested |
| fig7hk-measures-increase-early | Tested |
| fig7-late-reversal | Tested |
| mixed-quadratic-dim-corr-snf | Tested |
| mixed-quadratic-ssf-not-nonmonotonic | Tested |
| mixed-quadratic-task-dim | Tested |
| mixed-linear-ssf-task-dim | Tested |
| late-trends-match-optimal | Tested |
| glm-cross-validated-d2 | Tested |
import os
for v in ["OMP_NUM_THREADS", "OPENBLAS_NUM_THREADS", "MKL_NUM_THREADS"]:
os.environ[v] = "1" # many small fits; one linear-algebra thread each
import time, resource
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats
from joblib import Parallel, delayed
from statsmodels.stats.multitest import multipletests
import wtrack as w
T0 = time.time()
N_SUBSETS = 500 # Methods: every value is the mean over 500 random subsets
SVC_EVERY = 125 # the SVC is run on every 125th subset (4 per session), see the SVC section
N_PR = 500 # code: participation ratio of the GLM predictions over 500 unit sets
GLM_MAX_UNITS = None # None: every unit is fitted
N_JOBS = 4
print("dandiset", w.DANDISET, "version", w.VERSION)
dandiset 000978 version 0.240511.0307
urls = w.asset_urls()
print(len(urls), "assets")
for p in sorted(urls):
print(" ", p)
t = time.time()
D = {r: w.load_rat(r, urls) for r in w.RATS}
print(f"streamed and binned in {time.time() - t:.0f} s; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB")
9 assets sub-JDS-SingleDay-ER1/sub-JDS-SingleDay-ER1_behavior+ecephys.nwb sub-JDS-SingleDay-JS14/sub-JDS-SingleDay-JS14_behavior+ecephys.nwb sub-JDS-SingleDay-JS15/sub-JDS-SingleDay-JS15_behavior+ecephys.nwb sub-JDS-SingleDay-JS17/sub-JDS-SingleDay-JS17_behavior+ecephys.nwb sub-JDS-SingleDay-JS21/sub-JDS-SingleDay-JS21_behavior+ecephys.nwb sub-JDS-SingleDay-JS34/sub-JDS-SingleDay-JS34_behavior+ecephys.nwb sub-JDS-SingleDay-KL8/sub-JDS-SingleDay-KL8_behavior+ecephys.nwb sub-JDS-SingleDay-ZT2/sub-JDS-SingleDay-ZT2_obj-1dss6zi_behavior+ecephys.nwb sub-JDS-SingleDay-ZT2/sub-JDS-SingleDay-ZT2_obj-u40err_behavior+ecephys.nwb
streamed and binned in 42 s; peak memory 0.59 GB
Data check¶
What was loaded, per rat and session, and each check of the description against the values.
rows = []
for r, d in D.items():
for k, s in enumerate(d["sessions"]):
z = s["z"]
sp = np.linalg.norm(z[:, 3:5], axis=1)
rows.append(dict(rat=r, session=k + 1, file=s["file"], epoch=s["epoch"], trials=s["n_trials"],
minutes=round((s["stop"] - s["start"]) / 60, 1), bins=len(z),
bins_moving=int((sp > w.VMIN).sum()), bins_moving_speedcol=int((z[:, 2] > w.VMIN).sum()),
frac_correct=round(s["frac_correct"], 3),
PFC_units=int((s["loc"] == "PFC").sum()), CA1_units=int((s["loc"] == "CA1").sum()),
PFC_kept=w.process_session(s["counts"], z, s["loc"], "PFC")[0].shape[1],
CA1_kept=w.process_session(s["counts"], z, s["loc"], "CA1")[0].shape[1],
max_gap_s=s["max_gap"]))
S = pd.DataFrame(rows)
pd.set_option("display.width", 250); pd.set_option("display.max_columns", 30); pd.set_option("display.max_rows", 100)
print(S.to_string(index=False))
print("\nrats", S.rat.nunique(), "| sessions per rat", S.groupby("rat").size().unique(), "| session length", S.minutes.min(), "to", S.minutes.max(), "min")
print("fewest units kept in a session: PFC", S.PFC_kept.min(), "CA1", S.CA1_kept.min(), "(Methods use 19 PFC and 24 CA1 units)")
print("fewest moving bins in a session", S.bins_moving.min(), "(the subsets take 500)")
print("largest gap between consecutive trials within a session", S.max_gap_s.max(), "s (the code asserts none)")
print("\nPer file:")
for r, d in D.items():
for raw in d["raw"]:
tr = raw["trials"]
print(f"{raw['path']}: subject {raw['info']['subject_id']}, session_id {raw['info']['session_id']}, units {raw['n_units']} "
f"({', '.join(f'{k} {int((raw['unit_loc'] == k).sum())}' for k in sorted(set(raw['unit_loc'])))}), "
f"epochs {len(raw['epochs'])}, trials {len(tr)} (correct values {sorted(set(tr.correct))}, trajectory types {sorted(set(tr.trajectory_type))}), "
f"spike times sorted {raw['spikes_sorted']}")
print(f" position unit '{raw['info']['pos_unit']}', x {raw['pos_range'][0][0]:.1f} to {raw['pos_range'][1][0]:.1f}, "
f"y {raw['pos_range'][0][1]:.1f} to {raw['pos_range'][1][1]:.1f}, speed column {raw['pos_range'][0][2]:.1f} to {raw['pos_range'][1][2]:.1f}; "
f"frame interval {raw['pos_dt'] * 1000:.2f} ms ({1 / raw['pos_dt']:.1f} fps); position t {raw['pos_t_range'][0]:.0f} to {raw['pos_t_range'][1]:.0f} s, "
f"spikes t {raw['spike_t_range'][0]:.0f} to {raw['spike_t_range'][1]:.0f} s; electrical series {raw['info']['ephys_shape']}")
# recordings deposited more than once: identical spike trains or position traces across files
allh = [(raw["path"], u, h) for d in D.values() for raw in d["raw"] for u, h in enumerate(raw["spike_hashes"])]
byh = {}
for p, u, h in allh:
byh.setdefault(h, []).append((p, u))
dups = [v for v in byh.values() if len(v) > 1 and len({p for p, _ in v}) > 1]
print("\nunit spike trains identical across files:", len(dups))
ph = [raw["pos_hash"] for d in D.values() for raw in d["raw"]]
print("position traces identical across files:", len(ph) - len(set(ph)))
z1, z2 = D["ZT2"]["raw"]
print("ZT2 files: position time ranges", [tuple(np.round(x["pos_t_range"])) for x in (z1, z2)],
"| trial time ranges", [(round(x["trials"].start_time.min()), round(x["trials"].stop_time.max())) for x in (z1, z2)])
# speed: the dataset's speed column against the norm of the smoothed velocity
sp_col = np.concatenate([s["z"][:, 2] for d in D.values() for s in d["sessions"]])
sp_vel = np.concatenate([np.linalg.norm(s["z"][:, 3:5], axis=1) for d in D.values() for s in d["sessions"]])
print(f"\nspeed column against |smoothed velocity| per bin: r = {np.corrcoef(sp_col, sp_vel)[0, 1]:.3f}, "
f"median ratio {np.median(sp_col[sp_vel > 4] / sp_vel[sp_vel > 4]):.2f}; bins above 4 cm/s: {np.mean(sp_col > 4):.3f} (column), {np.mean(sp_vel > 4):.3f} (velocity)")
rat session file epoch trials minutes bins bins_moving bins_moving_speedcol frac_correct PFC_units CA1_units PFC_kept CA1_kept max_gap_s
KL8 1 0 1 15 15.4 1845 1020 1030 0.200 22 69 20 61 0.0
KL8 2 0 3 22 15.7 1888 1022 1037 0.455 22 69 20 62 0.0
KL8 3 0 5 33 16.6 1990 1103 1117 0.636 22 69 20 60 0.0
KL8 4 0 7 42 15.9 1908 1101 1098 0.738 22 69 20 61 0.0
KL8 5 0 9 42 15.4 1852 977 974 0.952 22 69 19 62 0.0
KL8 6 0 11 35 15.3 1831 971 964 0.914 22 69 20 62 0.0
KL8 7 0 13 38 15.4 1846 979 969 0.947 22 69 21 61 0.0
KL8 8 0 15 31 15.3 1832 939 945 0.806 22 69 21 62 0.0
ER1 1 0 1 18 15.8 1894 1016 1027 0.222 40 82 21 54 0.0
ER1 2 0 3 38 16.2 1939 1061 1043 0.711 40 82 23 58 0.0
ER1 3 0 5 50 15.8 1895 1012 1001 0.900 40 82 23 59 0.0
ER1 4 0 7 55 16.1 1936 1107 1089 0.873 40 82 24 61 0.0
ER1 5 0 9 51 16.2 1938 1066 1051 0.922 40 82 24 64 0.0
ER1 6 0 11 49 15.5 1859 1043 1033 0.918 40 82 24 64 0.0
ER1 7 0 13 50 15.7 1887 1047 1036 0.960 40 82 24 62 0.0
ER1 8 0 15 51 15.9 1901 1059 1045 0.882 40 82 23 65 0.0
JS34 1 0 1 48 17.5 2099 1426 1431 0.458 49 53 37 43 0.0
JS34 2 0 3 58 15.5 1856 1132 1124 0.690 49 53 39 43 0.0
JS34 3 0 5 44 16.2 1948 1115 1114 0.773 49 53 38 42 0.0
JS34 4 0 7 40 16.5 1975 903 928 0.725 49 53 39 42 0.0
JS34 5 0 9 24 14.4 1724 935 951 0.542 49 53 38 41 0.0
JS34 6 0 11 20 13.0 1553 687 704 0.600 49 53 38 41 0.0
JS34 7 0 13 29 15.0 1802 748 751 0.724 49 53 39 41 0.0
JS34 8 0 15 34 17.1 2049 904 917 0.853 49 53 39 40 0.0
JS14 1 0 1 25 15.4 1843 955 970 0.440 41 31 31 27 0.0
JS14 2 0 3 30 15.3 1836 823 827 0.800 41 31 32 26 0.0
JS14 3 0 5 41 15.9 1906 899 898 0.976 41 31 33 26 0.0
JS14 4 0 7 45 15.4 1849 916 917 0.911 41 31 33 26 0.0
JS14 5 0 9 43 15.1 1807 902 900 0.884 41 31 32 25 0.0
JS14 6 0 11 38 15.3 1838 903 904 0.947 41 31 31 25 0.0
JS14 7 0 13 38 15.1 1816 917 913 0.921 41 31 32 24 0.0
JS14 8 0 15 38 15.0 1802 984 977 0.868 41 31 31 24 0.0
JS17 1 0 1 26 17.1 2054 1227 1233 0.154 42 36 39 36 0.0
JS17 2 0 3 35 15.8 1899 880 868 0.686 42 36 39 35 0.0
JS17 3 0 5 57 15.4 1846 770 763 0.860 42 36 37 34 0.0
JS17 4 0 7 56 16.1 1930 789 782 0.893 42 36 37 34 0.0
JS17 5 0 9 53 15.6 1874 700 684 0.887 42 36 36 34 0.0
JS17 6 0 11 55 15.8 1890 714 699 0.891 42 36 37 33 0.0
JS17 7 0 13 47 16.3 1951 739 731 0.936 42 36 36 34 0.0
JS17 8 0 15 37 15.4 1851 781 779 0.784 42 36 38 34 0.0
JS21 1 0 1 30 16.4 1971 1042 1046 0.300 46 26 44 26 0.0
JS21 2 0 3 34 18.1 2168 928 942 0.647 46 26 43 25 0.0
JS21 3 0 5 41 17.9 2141 905 898 0.683 46 26 44 26 0.0
JS21 4 0 7 47 16.3 1955 669 662 0.936 46 26 43 25 0.0
JS21 5 0 9 46 15.9 1903 646 641 0.891 46 26 46 25 0.0
JS21 6 0 11 42 15.2 1824 602 597 0.905 46 26 42 25 0.0
JS21 7 0 13 40 15.3 1829 619 614 0.900 46 26 43 26 0.0
JS21 8 0 15 41 15.2 1825 678 671 0.805 46 26 43 25 0.0
JS15 1 0 1 30 16.4 1972 1175 1182 0.433 36 45 31 36 0.0
JS15 2 0 3 40 16.0 1913 937 945 0.775 36 45 33 37 0.0
JS15 3 0 5 42 16.6 1986 900 899 0.810 36 45 32 37 0.0
JS15 4 0 7 37 16.5 1975 809 818 0.811 36 45 30 37 0.0
JS15 5 0 9 34 16.0 1920 749 748 0.912 36 45 29 38 0.0
JS15 6 0 11 35 16.2 1944 703 701 0.971 36 45 29 36 0.0
JS15 7 0 13 32 15.5 1856 713 714 0.969 36 45 30 37 0.0
JS15 8 0 15 25 15.5 1859 684 679 0.840 36 45 30 40 0.0
ZT2 1 0 1 20 15.5 1858 1153 1162 0.450 82 151 62 129 0.0
ZT2 2 0 3 23 16.7 1999 1014 1014 0.565 82 151 65 129 0.0
ZT2 3 0 5 48 17.4 2090 1187 1192 0.729 82 151 70 129 0.0
ZT2 4 0 7 42 20.0 2394 1192 1202 0.857 82 151 69 132 0.0
ZT2 5 1 0 46 16.7 2005 1005 1010 0.891 78 162 66 132 0.0
ZT2 6 1 2 31 16.5 1980 1000 1009 0.806 78 162 66 132 0.0
ZT2 7 1 4 24 17.4 2086 962 973 0.750 78 162 65 134 0.0
ZT2 8 1 6 18 17.6 2115 873 888 0.722 78 162 65 150 0.0
rats 8 | sessions per rat [8] | session length 13.0 to 20.0 min
fewest units kept in a session: PFC 19 CA1 24 (Methods use 19 PFC and 24 CA1 units)
fewest moving bins in a session 602 (the subsets take 500)
largest gap between consecutive trials within a session 0.0 s (the code asserts none)
Per file:
sub-JDS-SingleDay-KL8/sub-JDS-SingleDay-KL8_behavior+ecephys.nwb: subject JDS-SingleDay-KL8, session_id 01, units 91 (CA1 69, PFC 22), epochs 17, trials 258 (correct values [0.0, 1.0], trajectory types [0.0, 1.0]), spike times sorted True
position unit 'centimeters; centimeters/second', x 16.7 to 135.7, y 0.0 to 109.5, speed column 0.0 to 48.8; frame interval 30.23 ms (33.1 fps); position t 270 to 22633 s, spikes t 270 to 22633 s; electrical series (31505271, 64)
sub-JDS-SingleDay-ER1/sub-JDS-SingleDay-ER1_behavior+ecephys.nwb: subject JDS-SingleDay-ER1, session_id 01, units 122 (CA1 82, PFC 40), epochs 17, trials 362 (correct values [0.0, 1.0], trajectory types [0.0, 1.0]), spike times sorted True
position unit 'centimeters; centimeters/second', x 41.4 to 157.7, y 9.8 to 122.9, speed column 0.0 to 93.7; frame interval 37.00 ms (27.0 fps); position t 365 to 21747 s, spikes t 365 to 21747 s; electrical series (30707777, 60)
sub-JDS-SingleDay-JS34/sub-JDS-SingleDay-JS34_behavior+ecephys.nwb: subject JDS-SingleDay-JS34, session_id 01, units 102 (CA1 53, PFC 49), epochs 17, trials 297 (correct values [0.0, 1.0], trajectory types [0.0, 1.0]), spike times sorted True
position unit 'centimeters; centimeters/second', x 19.9 to 145.1, y 1.3 to 115.5, speed column 0.0 to 68.4; frame interval 30.67 ms (32.6 fps); position t 274 to 27007 s, spikes t 274 to 27007 s; electrical series (39308612, 64)
sub-JDS-SingleDay-JS14/sub-JDS-SingleDay-JS14_behavior+ecephys.nwb: subject JDS-SingleDay-JS14, session_id 01, units 72 (CA1 31, PFC 41), epochs 17, trials 298 (correct values [0.0, 1.0], trajectory types [0.0, 1.0]), spike times sorted True
position unit 'centimeters; centimeters/second', x 14.0 to 131.1, y 0.0 to 108.5, speed column 0.0 to 74.2; frame interval 30.70 ms (32.6 fps); position t 168 to 19732 s, spikes t 168 to 19732 s; electrical series (28036066, 62)
sub-JDS-SingleDay-JS17/sub-JDS-SingleDay-JS17_behavior+ecephys.nwb: subject JDS-SingleDay-JS17, session_id 01, units 78 (CA1 36, PFC 42), epochs 17, trials 366 (correct values [0.0, 1.0], trajectory types [0.0, 1.0]), spike times sorted True
position unit 'centimeters; centimeters/second', x 18.8 to 137.9, y 0.8 to 115.3, speed column 0.0 to 129.5; frame interval 30.57 ms (32.7 fps); position t 953 to 24222 s, spikes t 953 to 24222 s; electrical series (34275511, 64)
sub-JDS-SingleDay-JS21/sub-JDS-SingleDay-JS21_behavior+ecephys.nwb: subject JDS-SingleDay-JS21, session_id 01, units 72 (CA1 26, PFC 46), epochs 17, trials 321 (correct values [0.0, 1.0], trajectory types [0.0, 1.0]), spike times sorted True
position unit 'centimeters; centimeters/second', x 18.1 to 138.4, y 0.1 to 115.2, speed column 0.0 to 74.4; frame interval 30.73 ms (32.5 fps); position t 211 to 21348 s, spikes t 211 to 21348 s; electrical series (31188886, 64)
sub-JDS-SingleDay-JS15/sub-JDS-SingleDay-JS15_behavior+ecephys.nwb: subject JDS-SingleDay-JS15, session_id 01, units 81 (CA1 45, PFC 36), epochs 17, trials 275 (correct values [0.0, 1.0], trajectory types [0.0, 1.0]), spike times sorted True
position unit 'centimeters; centimeters/second', x 19.8 to 137.3, y 4.5 to 115.8, speed column 0.0 to 114.4; frame interval 30.97 ms (32.3 fps); position t 3605 to 90718 s, spikes t 3605 to 90718 s; electrical series (33336475, 62)
sub-JDS-SingleDay-ZT2/sub-JDS-SingleDay-ZT2_obj-u40err_behavior+ecephys.nwb: subject JDS-SingleDay-ZT2, session_id 01, units 233 (CA1 151, PFC 82), epochs 9, trials 133 (correct values [0.0, 1.0], trajectory types [0.0, 1.0]), spike times sorted True
position unit 'centimeters; centimeters/second', x 20.3 to 134.5, y 1.1 to 113.3, speed column 0.0 to 60.2; frame interval 30.80 ms (32.5 fps); position t 206 to 14664 s, spikes t 206 to 14664 s; electrical series (20306442, 128)
sub-JDS-SingleDay-ZT2/sub-JDS-SingleDay-ZT2_obj-1dss6zi_behavior+ecephys.nwb: subject JDS-SingleDay-ZT2, session_id 01, units 240 (CA1 162, PFC 78), epochs 8, trials 119 (correct values [0.0, 1.0], trajectory types [0.0, 1.0]), spike times sorted True
position unit 'centimeters; centimeters/second', x 20.6 to 133.9, y 1.5 to 112.9, speed column 0.0 to 67.0; frame interval 30.80 ms (32.5 fps); position t 14760 to 30586 s, spikes t 14760 to 30586 s; electrical series (22792731, 128)
unit spike trains identical across files: 0
position traces identical across files: 0
ZT2 files: position time ranges [(np.float64(206.0), np.float64(14664.0)), (np.float64(14760.0), np.float64(30586.0))] | trial time ranges [(2001, 11862), (14760, 28718)]
speed column against |smoothed velocity| per bin: r = 0.998, median ratio 1.02; bins above 4 cm/s: 0.484 (column), 0.484 (velocity)
Clock check¶
Spikes, position and trials must share one clock. Two contrasts show it: (1) position from trials: at the end of each trial the animal should be at the trial's end well, so the position just before the end time should be nearest to that well, and less often so 15 s earlier; (2) spikes from position: a ridge decoder of x and y position from CA1 counts (500 ms bins, five contiguous folds) should do better with the true alignment than with the counts shifted by 10 s or more. The decoder and its penalty are a standard choice for this check only.
rows = []
for r, d in D.items():
for k, s in enumerate(d["sessions"]):
z = s["z"]
m = np.linalg.norm(z[:, 3:5], axis=1) > w.VMIN
x = s["counts"][m][:, s["loc"] == "CA1"]
x = (x - x.mean(0)) / (x.std(0) + 1e-9)
y = z[m][:, :2]
rows.append(dict(rat=r, session=k + 1, r2_true=w.decode_r2(x, y), r2_shift_10s=w.decode_r2(x, y, 20),
r2_shift_60s=w.decode_r2(x, y, 120)))
C = pd.DataFrame(rows)
print("position decoded from CA1 counts, cross-validated R2 per session (summary over the 64 sessions):")
print(C[["r2_true", "r2_shift_10s", "r2_shift_60s"]].describe().round(3).to_string())
print("sessions where the true alignment beats both shifts:", int(((C.r2_true > C.r2_shift_10s) & (C.r2_true > C.r2_shift_60s)).sum()), "of", len(C))
print(C.groupby("rat")[["r2_true", "r2_shift_10s"]].mean().round(3).to_string())
# trials against position: the position 0.5 s before each trial's end should be at the trial's end well.
# Well positions are the session's median end positions per end well; each trial is assigned to the
# nearest one, with the true end times and with the end times 15 s earlier.
hit = {0: [], 15: []}
dist = {0: [], 15: []}
for r, d in D.items():
for k, s in enumerate(d["sessions"]):
raw = d["raw"][s["file"]]
tr = raw["trials"][raw["trials"].epoch == s["epoch"]]
bt = s["start"] + (np.arange(len(s["z"])) + 0.5) * w.DT
at = lambda t: np.stack([np.interp(t, bt, s["z"][:, 0]), np.interp(t, bt, s["z"][:, 1])], 1)
wells = np.unique(tr.end_well)
cen = np.stack([np.median(at(tr.stop_time.values - 0.5)[tr.end_well.values == wl], 0) for wl in wells])
for sh in hit:
xy = at(tr.stop_time.values - 0.5 - sh)
dd = np.linalg.norm(xy[:, None] - cen[None], axis=2)
hit[sh] += list(wells[dd.argmin(1)] == tr.end_well.values)
dist[sh] += list(dd[np.arange(len(tr)), np.searchsorted(wells, tr.end_well.values)])
print(f"\ntrials whose position 0.5 s before the end is nearest to their end well: true times {np.mean(hit[0]):.3f}, 15 s earlier {np.mean(hit[15]):.3f}; "
f"median distance to the end well {np.median(dist[0]):.1f} cm and {np.median(dist[15]):.1f} cm (n = {len(hit[0])} trials)")
position decoded from CA1 counts, cross-validated R2 per session (summary over the 64 sessions):
r2_true r2_shift_10s r2_shift_60s
count 64.000 64.000 64.000
mean 0.461 0.034 -0.050
std 0.134 0.079 0.043
min 0.151 -0.111 -0.234
25% 0.338 -0.020 -0.066
50% 0.501 0.028 -0.050
75% 0.556 0.073 -0.027
max 0.729 0.275 0.048
sessions where the true alignment beats both shifts: 64 of 64
r2_true r2_shift_10s
rat
ER1 0.551 0.151
JS14 0.346 0.015
JS15 0.502 0.055
JS17 0.453 0.054
JS21 0.277 0.033
JS34 0.372 -0.051
KL8 0.542 0.026
ZT2 0.645 -0.007
trials whose position 0.5 s before the end is nearest to their end well: true times 0.986, 15 s earlier 0.517; median distance to the end well 4.7 cm and 42.8 cm (n = 2429 trials)
Readout analysis (shared pipeline)¶
For each area, rat and session: locomotion bins (speed of the smoothed velocity above 4 cm/s), units
above 0.1 Hz, each unit centred and divided by its standard deviation plus 0.01 counts per bin
(0.02 Hz), latents x, y, vx, vy z-scored (Methods, Readout analysis; code rat_utils.process_dat).
Then 500 random subsets of units (19 PFC, 24 CA1 as the Methods; 19 CA1 as the code, a variant) and
of 500 bins; per subset the theoretical error (Eq. 5, p = 300), the empirical Hebbian error (300
training and 200 test bins, 500 Gaussian tasks with |mean label| < 0.25), dimension, correlation,
SNF and SSF (Eqs. 6 to 9). Each session's value is the mean over subsets. Each (area, rat, session)
has its own random generator, seeded from its indices.
The linear SVC of the code is fitted on the same split, one per task, which costs about 1.4 s per subset (timed on one PFC session while preparing); on all 500 subsets of the 128 PFC and CA1 cases that is about 25 hours on one core. It is run here on every 125th subset (4 per session), a reduction recorded as a deviation.
AREAS = ["PFC", "CA1"]
VARIANTS = {"PFC": ("PFC", 19), "CA1": ("CA1", 24), "CA1_19": ("CA1", 19)}
def run_readout(counts, z, loc, area, nu, seed, n_subsets, svc_every):
import wtrack as w
x, zz = w.process_session(counts, z, loc, area)
return w.readout_subsets(x, zz, nu, np.random.default_rng(seed), n_subsets, svc_every=svc_every)
t = time.time()
jobs = [(v, ri, si) for v in VARIANTS for ri in range(8) for si in range(w.N_SESSIONS)]
def args(v, ri, si):
s = D[w.RATS[ri]]["sessions"][si]
return (s["counts"], s["z"], s["loc"], VARIANTS[v][0], VARIANTS[v][1], [1, list(VARIANTS).index(v), ri, si],
N_SUBSETS, SVC_EVERY if v != "CA1_19" else 0)
out = Parallel(n_jobs=N_JOBS)(delayed(run_readout)(*args(*j)) for j in jobs)
RO = {v: np.zeros((8, w.N_SESSIONS, N_SUBSETS, 7)) for v in VARIANTS}
for (v, ri, si), o in zip(jobs, out):
RO[v][ri, si] = o
print(f"readout: {len(jobs)} cases in {time.time() - t:.0f} s")
COLS = ["theory", "hebbian", "dim", "corr", "snf", "ssf", "svc"]
M = {v: {c: (np.nanmean(RO[v][..., k], axis=2)) for k, c in enumerate(COLS)} for v in VARIANTS} # rat x session
print("non-finite subset values:", {v: int((~np.isfinite(RO[v][..., :6])).sum()) for v in VARIANTS},
"| SVC subsets per session:", int(np.isfinite(RO["PFC"][0, 0, :, 6]).sum()))
BEH = np.array([[1 - s["frac_correct"] for s in D[r]["sessions"][:w.N_SESSIONS]] for r in w.RATS]) # rat x session
for v in VARIANTS:
print(f"\n{v}: mean over rats per session (sessions 1 to 8)")
print(pd.DataFrame({c: M[v][c].mean(0) for c in COLS}, index=pd.Index(range(1, 9), name="session")).round(4).to_string())
readout: 192 cases in 275 s
non-finite subset values: {'PFC': 0, 'CA1': 0, 'CA1_19': 0} | SVC subsets per session: 4
PFC: mean over rats per session (sessions 1 to 8)
theory hebbian dim corr snf ssf svc
session
1 0.3626 0.3467 15.8326 0.0182 0.3426 0.6323 0.3417
2 0.3387 0.3081 15.1580 0.0260 0.5083 0.6321 0.2937
3 0.3232 0.2822 14.8428 0.0301 0.6307 0.6861 0.2665
4 0.3167 0.2735 14.5163 0.0337 0.6985 0.6661 0.2573
5 0.3205 0.2793 14.8434 0.0310 0.6647 0.6966 0.2630
6 0.3228 0.2852 14.8437 0.0310 0.6632 0.6934 0.2700
7 0.3206 0.2842 14.9387 0.0309 0.6519 0.7075 0.2704
8 0.3320 0.3048 15.4522 0.0260 0.5528 0.7133 0.2917
CA1: mean over rats per session (sessions 1 to 8)
theory hebbian dim corr snf ssf svc
session
1 0.3523 0.3366 19.5369 0.0172 0.3986 0.6905 0.3334
2 0.3270 0.2991 18.8822 0.0238 0.5811 0.6860 0.2874
3 0.3212 0.2865 18.2483 0.0269 0.6637 0.6823 0.2696
4 0.3121 0.2738 18.1301 0.0297 0.7549 0.6787 0.2531
5 0.3149 0.2784 18.4602 0.0280 0.7480 0.7107 0.2634
6 0.3142 0.2782 18.3923 0.0280 0.7453 0.7246 0.2656
7 0.3148 0.2817 18.5862 0.0270 0.7071 0.7287 0.2649
8 0.3241 0.2969 18.9144 0.0237 0.5942 0.7318 0.2889
CA1_19: mean over rats per session (sessions 1 to 8)
theory hebbian dim corr snf ssf svc
session
1 0.3642 0.3516 16.0271 0.0172 0.3252 0.6701 NaN
2 0.3401 0.3156 15.6264 0.0237 0.4704 0.6674 NaN
3 0.3340 0.3026 15.1903 0.0269 0.5402 0.6640 NaN
4 0.3250 0.2901 15.1281 0.0296 0.6167 0.6630 NaN
5 0.3280 0.2953 15.3312 0.0281 0.6072 0.6916 NaN
6 0.3278 0.2968 15.2912 0.0279 0.6039 0.7063 NaN
7 0.3290 0.2999 15.4288 0.0270 0.5720 0.7072 NaN
8 0.3377 0.3142 15.6489 0.0237 0.4825 0.7099 NaN
/tmp/ipykernel_3015/2899580634.py:21: RuntimeWarning: Mean of empty slice
M = {v: {c: (np.nanmean(RO[v][..., k], axis=2)) for k, c in enumerate(COLS)} for v in VARIANTS} # rat x session
Comparison with the paper's own results¶
The paper's repository holds the output of its readout script, results/PFC_results_nu_dt_0.5_ns_500_P_300.npy
and results/CA1_results_nu_dt_0.5_ns_500_P_300.npy (500 subsets x 8 rats x 8 sessions; errors as
behaviour fraction correct, empirical, theory, SVC; geometry as dimension, correlation, SNF, SSF,
...), with 19 units in both areas. They are read here from GitHub at commit 9674a6c, in memory, for
comparison only: no outcome is decided from them. The rat order of that file is the order of the
code's glob, not known, so it is compared through the means over rats per session, and the per-rat
behavioural error, which needs no model, is matched to identify the order.
import io, requests
REPO = "https://raw.githubusercontent.com/awakhloo/population_geometry_optimal_coding/9674a6cb0c39926d70746024ce17de35f87df8f9/results/"
PAPER = {}
for a in AREAS:
r = requests.get(REPO + f"{a}_results_nu_dt_0.5_ns_500_P_300.npy", timeout=120)
PAPER[a] = np.load(io.BytesIO(r.content), allow_pickle=True).item()
print(a, "errs", PAPER[a]["errs"].shape, "geoms", PAPER[a]["all_geoms"].shape)
# match the paper's rats to ours by the behavioural error of 8 sessions, which has no random part
pb = 1 - PAPER["PFC"]["errs"].mean(0)[:, :8, 0]
order = [int(np.argmin(np.abs(pb - BEH[i]).sum(1))) for i in range(8)]
print("paper rat index for", dict(zip(w.RATS, order)), "| largest behavioural error difference after matching", float(np.abs(pb[order] - BEH).max()))
for a, v in [("PFC", "PFC"), ("CA1", "CA1_19")]:
pe, pg = PAPER[a]["errs"].mean(0)[order][:, :8], PAPER[a]["all_geoms"].mean(0)[order][:, :8]
comp = {"theory": pe[..., 2], "hebbian": pe[..., 1], "dim": pg[..., 0], "corr": pg[..., 1], "snf": pg[..., 2], "ssf": pg[..., 3]}
print(f"\n{a}, 19 units: per rat and session, this attempt against the paper's file")
for k, g in comp.items():
ours = M[v][k]
print(f" {k:8s} r = {np.corrcoef(ours.ravel(), g.ravel())[0, 1]:.3f}, median |relative difference| = {np.median(np.abs(ours - g) / np.abs(g)):.4f}; "
f"means per session paper {np.round(g.mean(0), 4)} ours {np.round(ours.mean(0), 4)}")
th, em = pe[..., 2].ravel(), pe[..., 1].ravel()
q = em <= np.quantile(em, 0.25)
print(f" paper's file, fig7f measure: r = {np.corrcoef(th, em)[0, 1]:.3f}, mean theory - empirical = {np.mean(th - em):.4f}, "
f"mean |theory - empirical| / mean empirical = {np.mean(np.abs(th - em)) / em.mean():.4f}, lowest-quarter theory - empirical = {np.mean(th[q] - em[q]):.4f}")
print(f" paper's file, behavioural error against theory r2 = {np.corrcoef(1 - pe[..., 0].ravel(), th)[0, 1] ** 2:.3f}")
PFC errs (500, 8, 8, 4) geoms (500, 8, 8, 8)
CA1 errs (500, 8, 8, 4) geoms (500, 8, 8, 8)
paper rat index for {'KL8': 6, 'ER1': 2, 'JS34': 1, 'JS14': 4, 'JS17': 5, 'JS21': 3, 'JS15': 7, 'ZT2': 0} | largest behavioural error difference after matching 1.1657341758564144e-14
PFC, 19 units: per rat and session, this attempt against the paper's file
theory r = 1.000, median |relative difference| = 0.0014; means per session paper [0.3625 0.3386 0.3234 0.3164 0.32 0.323 0.3207 0.332 ] ours [0.3626 0.3387 0.3232 0.3167 0.3205 0.3228 0.3206 0.332 ]
hebbian r = 1.000, median |relative difference| = 0.0026; means per session paper [0.3465 0.3077 0.2825 0.2729 0.2792 0.2855 0.2845 0.3048] ours [0.3467 0.3081 0.2822 0.2735 0.2793 0.2852 0.2842 0.3048]
dim r = 0.997, median |relative difference| = 0.0019; means per session paper [15.8374 15.1543 14.866 14.5632 14.8593 14.8761 14.9723 15.4578] ours [15.8326 15.158 14.8428 14.5163 14.8434 14.8437 14.9387 15.4522]
corr r = 1.000, median |relative difference| = 0.0050; means per session paper [0.0183 0.026 0.0301 0.0336 0.0312 0.0309 0.0308 0.026 ] ours [0.0182 0.026 0.0301 0.0337 0.031 0.031 0.0309 0.026 ]
snf r = 1.000, median |relative difference| = 0.0064; means per session paper [0.3433 0.5102 0.63 0.6994 0.6702 0.6637 0.6472 0.5514] ours [0.3426 0.5083 0.6307 0.6985 0.6647 0.6632 0.6519 0.5528]
ssf r = 0.998, median |relative difference| = 0.0040; means per session paper [0.6323 0.6302 0.6849 0.6699 0.6965 0.6928 0.7091 0.7146] ours [0.6323 0.6321 0.6861 0.6661 0.6966 0.6934 0.7075 0.7133]
paper's file, fig7f measure: r = 0.982, mean theory - empirical = 0.0341, mean |theory - empirical| / mean empirical = 0.1155, lowest-quarter theory - empirical = 0.0489
paper's file, behavioural error against theory r2 = 0.510
CA1, 19 units: per rat and session, this attempt against the paper's file
theory r = 0.999, median |relative difference| = 0.0012; means per session paper [0.3644 0.3397 0.334 0.3251 0.3284 0.3279 0.3288 0.3378] ours [0.3642 0.3401 0.334 0.325 0.328 0.3278 0.329 0.3377]
hebbian r = 0.999, median |relative difference| = 0.0028; means per session paper [0.3518 0.3147 0.3022 0.2898 0.2956 0.2957 0.2994 0.3141] ours [0.3516 0.3156 0.3026 0.2901 0.2953 0.2968 0.2999 0.3142]
dim r = 0.999, median |relative difference| = 0.0015; means per session paper [16.0147 15.6185 15.1895 15.1182 15.3408 15.2874 15.4171 15.6469] ours [16.0271 15.6264 15.1903 15.1281 15.3312 15.2912 15.4288 15.6489]
corr r = 1.000, median |relative difference| = 0.0065; means per session paper [0.0172 0.0238 0.0269 0.0297 0.028 0.0279 0.027 0.0236] ours [0.0172 0.0237 0.0269 0.0296 0.0281 0.0279 0.027 0.0237]
snf r = 0.999, median |relative difference| = 0.0067; means per session paper [0.3239 0.4734 0.5423 0.6158 0.6043 0.6003 0.5719 0.4825] ours [0.3252 0.4704 0.5402 0.6167 0.6072 0.6039 0.572 0.4825]
ssf r = 0.995, median |relative difference| = 0.0056; means per session paper [0.6699 0.6673 0.6639 0.6613 0.6909 0.7048 0.7065 0.7101] ours [0.6701 0.6674 0.664 0.663 0.6916 0.7063 0.7072 0.7099]
paper's file, fig7f measure: r = 0.960, mean theory - empirical = 0.0278, mean |theory - empirical| / mean empirical = 0.0904, lowest-quarter theory - empirical = 0.0391
paper's file, behavioural error against theory r2 = 0.477
GLM fits (shared pipeline)¶
Per-unit Poisson GLMs (Methods, Generalized linear model analysis; code fit-GLMs-rat.py with the
basis the code chose: position bins of 10 cm, velocity bins of 3 cm/s, variances 100 and 40, centres
from bins holding more than 20 time bins over all of a rat's sessions). Bins are those with the
dataset's speed column above 4 cm/s, as the GLM code (rat_utils.get_all_lat) does. The l2 penalty is
chosen per unit by 10-fold cross-validation over 10 values; the folds are scikit-learn's unshuffled
KFold, which GridSearchCV uses for a regressor, so they involve no random choice. The basis grid
search itself was not repeated: the code's chosen basis is used. Each unit's best score is taken
with np.argmax over the penalties, as rat_utils.format_glm_results does.
CENTRES = {}
for ri, r in enumerate(w.RATS):
flat = np.concatenate([w.glm_session_data(s["counts"], s["z"], s["loc"], "PFC")[1] for s in D[r]["sessions"][:w.N_SESSIONS]])
CENTRES[r] = w.basis_centres(flat)
print(r, "basis centres: position", len(CENTRES[r][0]), "vx", len(CENTRES[r][1]), "vy", len(CENTRES[r][2]))
def run_glm(counts, z, loc, area, centres):
import wtrack as w
return w.glm_session(counts, z, loc, area, centres)
def gargs(a, ri, si):
s = D[w.RATS[ri]]["sessions"][si]
loc = s["loc"]
if GLM_MAX_UNITS: # development only; None in the deposited notebook
idx = np.where(loc == a)[0][:GLM_MAX_UNITS]
loc = np.where(np.isin(np.arange(len(loc)), idx), loc, "none")
return s["counts"], s["z"], loc, a, CENTRES[w.RATS[ri]]
t = time.time()
gjobs = [(a, ri, si) for a in AREAS for ri in range(8) for si in range(w.N_SESSIONS)]
gout = Parallel(n_jobs=N_JOBS)(delayed(run_glm)(*gargs(*j)) for j in gjobs)
GLM = {j: o for j, o in zip(gjobs, gout)}
print(f"GLM: {sum(o['x'].shape[1] for o in gout)} unit fits in {time.time() - t:.0f} s")
print("covariates per session:", sorted({o['n_covariates'] for o in gout})[:3], "...", "constant covariates (dropped by nothing; nan if any):", sum(o['n_constant_covariates'] for o in gout))
GS = {}
for (a, ri, si), o in GLM.items():
for nu in (19, 24):
if a == "PFC" and nu == 24:
continue
rng = np.random.default_rng([2, AREAS.index(a), ri, si, nu])
GS[(a, nu, ri, si)] = w.glm_summary(o, nu, rng, N_PR)
TD = {(a, nu): np.array([[GS[(a, nu, ri, si)]["task_dim"] for si in range(8)] for ri in range(8)]) for a, nu in [("PFC", 19), ("CA1", 19), ("CA1", 24)]}
for a in AREAS:
G = pd.DataFrame([dict(rat=w.RATS[ri], session=si + 1, **GS[(a, 19, ri, si)]) for ri in range(8) for si in range(8)])
print(f"\n{a}: units fitted {G.n_units.sum()}, replaced by the null model {G.n_null.sum()} ({G.n_null.sum() / G.n_units.sum():.1%})")
print(G.pivot(index="rat", columns="session", values="task_dim").round(2).to_string())
KL8 basis centres: position 97 vx 16 vy 26 ER1 basis centres: position 80 vx 16 vy 25 JS34 basis centres: position 108 vx 18 vy 29 JS14 basis centres: position 94 vx 15 vy 27 JS17 basis centres: position 82 vx 16 vy 30 JS21 basis centres: position 88 vx 17 vy 29 JS15 basis centres: position 86 vx 16 vy 25 ZT2 basis centres: position 98 vx 16 vy 25
GLM: 5684 unit fits in 1565 s covariates per session: [201, 210, 213] ... constant covariates (dropped by nothing; nan if any): 0
PFC: units fitted 2327, replaced by the null model 334 (14.4%) session 1 2 3 4 5 6 7 8 rat ER1 4.45 7.03 9.23 9.95 9.40 9.21 9.48 9.90 JS14 8.08 9.63 10.22 10.16 11.38 11.78 10.90 12.20 JS15 7.22 9.37 9.31 9.27 8.40 9.04 9.18 9.24 JS17 6.04 7.96 8.57 8.44 8.56 8.50 9.31 8.94 JS21 6.89 8.11 8.53 9.15 9.13 8.61 9.36 9.43 JS34 7.64 8.08 7.99 6.83 7.55 6.58 7.44 7.93 KL8 6.45 8.11 7.32 7.96 6.86 8.96 7.13 7.89 ZT2 10.30 10.63 11.01 10.58 11.49 11.90 11.10 10.81 CA1: units fitted 3357, replaced by the null model 685 (20.4%) session 1 2 3 4 5 6 7 8 rat ER1 6.18 8.67 9.41 10.03 10.25 11.02 10.48 9.84 JS14 7.65 10.84 10.53 9.58 10.60 9.49 10.09 10.40 JS15 8.17 10.59 10.85 11.23 12.14 11.74 12.00 10.71 JS17 5.00 5.09 6.35 6.62 6.45 6.84 6.79 6.31 JS21 3.25 6.33 6.14 6.35 6.60 6.55 6.37 4.92 JS34 9.46 11.19 10.50 9.53 10.16 9.05 10.07 10.36 KL8 7.41 7.92 9.23 10.40 8.58 10.60 11.12 10.53 ZT2 8.03 8.44 9.15 9.33 10.41 9.45 9.06 8.99
def s4_s1(g): # rat x session -> mean over rats at sessions 1, 4, 8
m = g.mean(0)
return m[0], m[3], m[7]
def per_rat(g, name):
return pd.DataFrame(g, index=pd.Index(w.RATS, name="rat"), columns=range(1, 9)).round(4).to_string()
def sem(g):
return g.std(0, ddof=1) / np.sqrt(g.shape[0])
fig7d-behavioral-error-learning¶
Behavioural error decreases quickly over the first sessions and largely plateaus after session four.
Behavioral error on the continuous alternation task and neural readout error quickly decrease over the first few sessions ... After session four, both behavioral and readout error largely plateau
print("behavioural error (1 - fraction of trials correct) per rat and session:")
print(per_rat(BEH, "beh"))
m = BEH.mean(0)
print("\nmean over rats per session:", np.round(m, 3), "\ns.e.m.:", np.round(sem(BEH), 3))
e1, e4, e8 = s4_s1(BEH)
print(f"session 1 {e1:.3f}, session 4 {e4:.3f}, session 8 {e8:.3f}; drop 1 to 4 = {e1 - e4:.3f}; |change 4 to 8| = {abs(e8 - e4):.3f}")
print("criterion: session 4 below session 1:", e4 < e1, "| |change 4 to 8| smaller than the drop 1 to 4:", abs(e8 - e4) < (e1 - e4))
print("rats with session 4 below session 1:", int((BEH[:, 3] < BEH[:, 0]).sum()), "of 8")
g, _, p, _ = w.fit_mixed(BEH, quad=False, sessions=slice(0, 4))
print(f"linear mixed model over sessions 1 to 4: slope {g:.4f} per session, P = {p:.2g}")
behavioural error (1 - fraction of trials correct) per rat and session:
1 2 3 4 5 6 7 8
rat
KL8 0.8000 0.5455 0.3636 0.2619 0.0476 0.0857 0.0526 0.1935
ER1 0.7778 0.2895 0.1000 0.1273 0.0784 0.0816 0.0400 0.1176
JS34 0.5417 0.3103 0.2273 0.2750 0.4583 0.4000 0.2759 0.1471
JS14 0.5600 0.2000 0.0244 0.0889 0.1163 0.0526 0.0789 0.1316
JS17 0.8462 0.3143 0.1404 0.1071 0.1132 0.1091 0.0638 0.2162
JS21 0.7000 0.3529 0.3171 0.0638 0.1087 0.0952 0.1000 0.1951
JS15 0.5667 0.2250 0.1905 0.1892 0.0882 0.0286 0.0312 0.1600
ZT2 0.5500 0.4348 0.2708 0.1429 0.1087 0.1935 0.2500 0.2778
mean over rats per session: [0.668 0.334 0.204 0.157 0.14 0.131 0.112 0.18 ]
s.e.m.: [0.045 0.04 0.04 0.028 0.046 0.042 0.034 0.018]
session 1 0.668, session 4 0.157, session 8 0.180; drop 1 to 4 = 0.511; |change 4 to 8| = 0.023
criterion: session 4 below session 1: True | |change 4 to 8| smaller than the drop 1 to 4: True
rats with session 4 below session 1: 8 of 8
linear mixed model over sessions 1 to 4: slope -0.1662 per session, P = 5.8e-18
Result: reproduced. The mean behavioural error over the 8 rats falls from 0.668 at session 1 to 0.157 at session 4 (a drop of 0.511, lower in 8 of 8 rats) and is 0.180 at session 8, a change of 0.023 after session 4. The linear mixed model over sessions 1 to 4 has a slope of -0.166 per session (P = 5.8e-18).
fig7e-readout-error-learning¶
The task-averaged readout error for position and velocity decreases over learning in PFC and CA1, then plateaus after session four.
These readout errors decrease over learning (Fig. 7e,f )
def plateau_check(g):
e1, e4, e8 = s4_s1(g)
return dict(s1=round(e1, 4), s4=round(e4, 4), s8=round(e8, 4), drop_1_4=round(e1 - e4, 4), change_4_8=round(e8 - e4, 4),
holds=bool(e4 < e1 and e8 < e1 and abs(e8 - e4) < (e1 - e4)))
rows = []
for v in VARIANTS:
for c in ["theory", "hebbian"]:
rows.append(dict(units=v, reading=c, **plateau_check(M[v][c])))
print(pd.DataFrame(rows).to_string(index=False))
for v in ["PFC", "CA1"]:
print(f"\n{v} theoretical error per rat and session:")
print(per_rat(M[v]["theory"], v))
print("mean", np.round(M[v]["theory"].mean(0), 4), "s.e.m.", np.round(sem(M[v]["theory"]), 4))
units reading s1 s4 s8 drop_1_4 change_4_8 holds
PFC theory 0.3626 0.3167 0.3320 0.0459 0.0153 True
PFC hebbian 0.3467 0.2735 0.3048 0.0733 0.0313 True
CA1 theory 0.3523 0.3121 0.3241 0.0401 0.0119 True
CA1 hebbian 0.3366 0.2738 0.2969 0.0628 0.0231 True
CA1_19 theory 0.3642 0.3250 0.3377 0.0392 0.0127 True
CA1_19 hebbian 0.3516 0.2901 0.3142 0.0615 0.0241 True
PFC theoretical error per rat and session:
1 2 3 4 5 6 7 8
rat
KL8 0.3787 0.3697 0.3477 0.3221 0.3450 0.3343 0.3256 0.3402
ER1 0.3546 0.3388 0.3127 0.3076 0.3187 0.3097 0.3029 0.3065
JS34 0.3681 0.3480 0.3566 0.3424 0.3656 0.3701 0.3466 0.3645
JS14 0.3540 0.3203 0.3088 0.3147 0.2971 0.3157 0.3191 0.3248
JS17 0.3751 0.3455 0.3062 0.3096 0.3048 0.3109 0.3182 0.3433
JS21 0.3431 0.3087 0.3010 0.2782 0.2903 0.2846 0.2865 0.2915
JS15 0.3758 0.3280 0.3156 0.3201 0.3181 0.3130 0.3103 0.3248
ZT2 0.3513 0.3507 0.3373 0.3391 0.3243 0.3443 0.3555 0.3602
mean [0.3626 0.3387 0.3232 0.3167 0.3205 0.3228 0.3206 0.332 ] s.e.m. [0.0048 0.0068 0.0074 0.0071 0.0088 0.0092 0.0079 0.0089]
CA1 theoretical error per rat and session:
1 2 3 4 5 6 7 8
rat
KL8 0.3542 0.3428 0.3344 0.3301 0.3330 0.3306 0.3234 0.3302
ER1 0.3405 0.3385 0.3233 0.3147 0.3237 0.3175 0.3214 0.3245
JS34 0.3384 0.3149 0.3359 0.3164 0.3545 0.3378 0.3242 0.3418
JS14 0.3493 0.3201 0.3181 0.3170 0.3128 0.3199 0.3268 0.3206
JS17 0.3777 0.3314 0.2857 0.2832 0.2776 0.2767 0.2814 0.3044
JS21 0.3601 0.3135 0.3399 0.3034 0.2996 0.2992 0.2931 0.3051
JS15 0.3393 0.3128 0.3148 0.3102 0.3062 0.2934 0.2963 0.3135
ZT2 0.3589 0.3420 0.3178 0.3222 0.3114 0.3382 0.3517 0.3524
mean [0.3523 0.327 0.3212 0.3121 0.3149 0.3142 0.3148 0.3241] s.e.m. [0.0048 0.0046 0.0061 0.005 0.0081 0.0079 0.0081 0.006 ]
Result: reproduced. Under the main reading (theoretical error) the mean over rats falls from session 1 to 4 by 0.0459 in PFC (0.3626 to 0.3167) and by 0.0401 in CA1 (0.3523 to 0.3121), and changes by 0.0153 and 0.0119 from session 4 to 8; session 8 is below session 1 in both. The criterion holds in both areas under both readings and with the 19-unit CA1 variant. In both areas the error rises again at session 8 (PFC 0.3320, CA1 0.3241).
figs12c-behavior-readout-r2¶
Single-session readout errors correlate with behavioural error, R2 = 0.48 in CA1 and 0.51 in PFC.
are correlated with single-session behavioral task performance ( R 2 = 0.48 (CA1) and R 2 = 0.51 (PFC); Supplementary Fig. 12c )
rows = []
for v in VARIANTS:
for c in ["theory", "hebbian"]:
r, p = stats.pearsonr(BEH.ravel(), M[v][c].ravel())
rows.append(dict(units=v, reading=c, r=round(r, 3), r2=round(r * r, 3), p=p, n=BEH.size))
R = pd.DataFrame(rows)
print(R.to_string(index=False))
print("expected: CA1 0.48 +- 0.048 (0.432 to 0.528), PFC 0.51 +- 0.051 (0.459 to 0.561)")
for c in ["theory", "hebbian"]:
ca1 = R[(R.units == "CA1") & (R.reading == c)].r2.item(); pfc = R[(R.units == "PFC") & (R.reading == c)].r2.item()
print(f"{c}: CA1 within {abs(ca1 - 0.48) <= 0.048}, PFC within {abs(pfc - 0.51) <= 0.051}")
print("\nper rat (8 sessions each), r2 of behavioural error against theoretical error:")
print(pd.DataFrame({v: [stats.pearsonr(BEH[i], M[v]['theory'][i])[0] ** 2 for i in range(8)] for v in ["PFC", "CA1"]}, index=w.RATS).round(3).to_string())
fig, ax = plt.subplots(1, 2, figsize=(8, 3.5))
for a, v in zip(ax, ["CA1", "PFC"]):
a.scatter(BEH.ravel(), M[v]["theory"].ravel(), s=12)
a.set_xlabel("behavioural error"); a.set_ylabel("theoretical readout error"); a.set_title(v)
plt.tight_layout(); plt.show()
print("plotted ranges: behavioural error", BEH.min().round(3), "to", BEH.max().round(3), "; theory PFC", M["PFC"]["theory"].min().round(3), "to", M["PFC"]["theory"].max().round(3),
"CA1", M["CA1"]["theory"].min().round(3), "to", M["CA1"]["theory"].max().round(3), "; no points outside the axes")
units reading r r2 p n
PFC theory 0.713 0.508 4.024173e-11 64
PFC hebbian 0.732 0.536 6.345768e-12 64
CA1 theory 0.702 0.493 1.004379e-10 64
CA1 hebbian 0.761 0.579 3.051450e-13 64
CA1_19 theory 0.689 0.475 3.123363e-10 64
CA1_19 hebbian 0.741 0.548 2.652655e-12 64
expected: CA1 0.48 +- 0.048 (0.432 to 0.528), PFC 0.51 +- 0.051 (0.459 to 0.561)
theory: CA1 within True, PFC within True
hebbian: CA1 within False, PFC within True
per rat (8 sessions each), r2 of behavioural error against theoretical error:
PFC CA1
KL8 0.718 0.859
ER1 0.836 0.646
JS34 0.220 0.111
JS14 0.740 0.787
JS17 0.805 0.935
JS21 0.979 0.847
JS15 0.921 0.942
ZT2 0.316 0.477
plotted ranges: behavioural error 0.024 to 0.846 ; theory PFC 0.278 to 0.379 CA1 0.277 to 0.378 ; no points outside the axes
Result: reproduced. Over the 64 rat and session points the squared correlation of behavioural error with the theoretical error is 0.493 in CA1 and 0.508 in PFC, both within tolerance (0.48 +- 0.048, 0.51 +- 0.051). With the empirical Hebbian error (second reading) CA1 is 0.579, outside, and PFC 0.536, inside; with 19 CA1 units the theoretical reading gives 0.475.
fig7f-theory-vs-empirical¶
The theoretical error agrees well overall with the empirical Hebbian error, with a small bias at low error values.
Empirical generalization error versus our estimate from equation ( 1 ). Although there is a small bias for low error values, we find a good agreement overall
Criterion, as the claims file now has it after the question this attempt asked (questions/wakhloo-2026.yaml): per area, over the 64 rat and session pairs of means over the 500 subsets, the Pearson correlation is positive with p < 0.05 and r is at least 0.9. The earlier criterion also asked for a mean absolute difference below 10% of the mean empirical error; the reader found that this bound fails on the paper's own figure, which the legend calls good, and dropped it. The signed and absolute differences and the difference in the lowest-error quarter are printed and not judged, as the legend allows a bias.
rows = []
for v in VARIANTS:
th, em = M[v]["theory"].ravel(), M[v]["hebbian"].ravel()
r, p = stats.pearsonr(th, em)
q = em <= np.quantile(em, 0.25)
rows.append(dict(units=v, r=round(r, 3), p=p, mean_abs_diff=round(np.mean(np.abs(th - em)), 4), mean_emp=round(em.mean(), 4),
ratio=round(np.mean(np.abs(th - em)) / em.mean(), 4), mean_diff_theory_minus_emp=round(np.mean(th - em), 4),
diff_lowest_quarter=round(np.mean(th[q] - em[q]), 4), diff_top_quarter=round(np.mean(th[em >= np.quantile(em, 0.75)] - em[em >= np.quantile(em, 0.75)]), 4),
holds=bool(r > 0 and p < 0.05 and r >= 0.9)))
# criterion (claims file, as amended after the question of this attempt): per area, r > 0 with p < 0.05 and r >= 0.9;
# the signed and absolute differences and the lowest-quarter difference are reported, not judged (the legend allows a bias)
print(pd.DataFrame(rows).to_string(index=False))
for a, (v1, v2) in {"PFC": ("PFC", "PFC"), "CA1": ("CA1", "CA1_19")}.items():
print(a, "holds (main units):", [x["holds"] for x in rows if x["units"] == v1][0], "| holds (19 units):", [x["holds"] for x in rows if x["units"] == v2][0])
print("subset-level: per subset, mean |theory - Hebbian| =", {v: round(float(np.mean(np.abs(RO[v][..., 0] - RO[v][..., 1]))), 4) for v in VARIANTS})
units r p mean_abs_diff mean_emp ratio mean_diff_theory_minus_emp diff_lowest_quarter diff_top_quarter holds
PFC 0.983 2.522613e-47 0.0341 0.2955 0.1155 0.0341 0.0484 0.0145 True
CA1 0.948 1.936522e-32 0.0311 0.2914 0.1069 0.0311 0.0437 0.0159 True
CA1_19 0.960 5.943669e-36 0.0275 0.3082 0.0891 0.0275 0.0388 0.0136 True
PFC holds (main units): True | holds (19 units): True
CA1 holds (main units): True | holds (19 units): True
subset-level: per subset, mean |theory - Hebbian| = {'PFC': 0.0346, 'CA1': 0.0315, 'CA1_19': 0.0281}
Result: reproduced. The theoretical and empirical errors are strongly correlated in both areas, r = 0.983 in PFC and 0.948 in CA1 (24 units), P below 1e-31, both above the criterion's 0.9, and the 19-unit CA1 variant (the code's) holds as well. The theory lies above the empirical error on average (by 0.034 in PFC and 0.031 in CA1), more so in the lowest-error quarter (0.048, 0.044) than in the highest (0.015, 0.016), which is the bias at low error that the legend describes; the mean absolute difference is 11.55% (PFC) and 10.69% (CA1, 24 units) of the mean empirical error. Like for like with the paper's own results file (comparison cell), it is 11.55% against 11.55% in PFC and, with the code's 19 CA1 units, 8.91% against 9.04% in CA1. The train and test bins of the empirical error are drawn at random from 500 ms bins that are correlated in time, as in the paper's code (utils.emp_error), so the empirical errors here and in the paper are likely optimistic; this bears on the size of the gap between theory and empirical error, not on the correlation the criterion judges. Under the claims file before the reader's answer, which also asked for a difference below 10%, the outcome was not reproduced.
fig7g-total-dimension-drops-early¶
The total neural dimension in PFC and CA1 drops over the first four sessions.
Interestingly, we find that although the total neural dimension drops over these initial sessions (Fig. 7g )
for v in VARIANTS:
g = M[v]["dim"]
d1, d4, d8 = s4_s1(g)
sl, _, p, _ = w.fit_mixed(g, quad=False, sessions=slice(0, 4))
print(f"{v}: session 1 {d1:.3f}, session 4 {d4:.3f}, session 8 {d8:.3f}; session 4 below 1: {d4 < d1}; rats lower at 4: {int((g[:, 3] < g[:, 0]).sum())} of 8; "
f"mixed slope 1 to 4 {sl:.3f} (P = {p:.2g})")
print(" mean per session", np.round(g.mean(0), 3), "s.e.m.", np.round(sem(g), 3))
PFC: session 1 15.833, session 4 14.516, session 8 15.452; session 4 below 1: True; rats lower at 4: 8 of 8; mixed slope 1 to 4 -0.426 (P = 1.3e-14) mean per session [15.833 15.158 14.843 14.516 14.843 14.844 14.939 15.452] s.e.m. [0.188 0.261 0.236 0.2 0.178 0.191 0.182 0.193] CA1: session 1 19.537, session 4 18.130, session 8 18.914; session 4 below 1: True; rats lower at 4: 8 of 8; mixed slope 1 to 4 -0.485 (P = 3.5e-08) mean per session [19.537 18.882 18.248 18.13 18.46 18.392 18.586 18.914] s.e.m. [0.169 0.216 0.366 0.417 0.441 0.516 0.437 0.285] CA1_19: session 1 16.027, session 4 15.128, session 8 15.649; session 4 below 1: True; rats lower at 4: 8 of 8; mixed slope 1 to 4 -0.313 (P = 1.2e-07) mean per session [16.027 15.626 15.19 15.128 15.331 15.291 15.429 15.649] s.e.m. [0.123 0.146 0.252 0.284 0.311 0.35 0.301 0.195]
Result: reproduced. The mean total dimension falls from session 1 to 4 in PFC (15.833 to 14.516) and CA1 (19.537 to 18.130), in 8 of 8 rats in each area; the mixed-model slopes over sessions 1 to 4 are -0.426 (P = 1.3e-14) and -0.485 (P = 3.5e-08). The 19-unit CA1 variant also falls (16.027 to 15.128).
fig7h-task-dimension-increases¶
The task-relevant dimension from Poisson GLMs increases over learning, including over the first four sessions.
the dimension of the subspace containing task-relevant information (that is, the dimension of the ‘signal subspace’) increases monotonically over learning, even during those initial four sessions (Fig. 7h )
for key in [("PFC", 19), ("CA1", 19), ("CA1", 24)]:
g = TD[key]
t1, t4, t8 = s4_s1(g)
mono = bool(np.all(np.diff(g.mean(0)) >= 0))
print(f"{key[0]} ({key[1]} units): session 1 {t1:.3f}, 4 {t4:.3f}, 8 {t8:.3f}; (a) rises 1 to 4 and 1 to 8: {t4 > t1 and t8 > t1}; "
f"(b) no fall between consecutive sessions: {mono}; rats higher at 4 than 1: {int((g[:, 3] > g[:, 0]).sum())} of 8")
print(" mean per session", np.round(g.mean(0), 3), "s.e.m.", np.round(sem(g), 3))
for a in AREAS:
print(f"\n{a} task-relevant dimension per rat and session (19 units):")
print(per_rat(TD[(a, 19)], a))
PFC (19 units): session 1 7.131, 4 9.040, 8 9.543; (a) rises 1 to 4 and 1 to 8: True; (b) no fall between consecutive sessions: False; rats higher at 4 than 1: 7 of 8
mean per session [7.131 8.616 9.024 9.04 9.096 9.322 9.238 9.543] s.e.m. [0.599 0.41 0.421 0.441 0.585 0.621 0.499 0.511]
CA1 (19 units): session 1 6.892, 4 9.134, 8 9.008; (a) rises 1 to 4 and 1 to 8: True; (b) no fall between consecutive sessions: False; rats higher at 4 than 1: 8 of 8
mean per session [6.892 8.634 9.021 9.134 9.399 9.342 9.497 9.008] s.e.m. [0.703 0.775 0.647 0.617 0.713 0.659 0.705 0.775]
CA1 (24 units): session 1 7.926, 4 10.286, 8 10.260; (a) rises 1 to 4 and 1 to 8: True; (b) no fall between consecutive sessions: False; rats higher at 4 than 1: 8 of 8
mean per session [ 7.926 9.839 10.157 10.286 10.605 10.551 10.786 10.26 ] s.e.m. [0.79 0.877 0.771 0.762 0.861 0.82 0.851 0.925]
PFC task-relevant dimension per rat and session (19 units):
1 2 3 4 5 6 7 8
rat
KL8 6.4451 8.1107 7.3229 7.9563 6.8634 8.9562 7.1329 7.8917
ER1 4.4478 7.0288 9.2322 9.9475 9.3982 9.2137 9.4803 9.8950
JS34 7.6364 8.0808 7.9865 6.8300 7.5524 6.5780 7.4435 7.9315
JS14 8.0840 9.6331 10.2198 10.1586 11.3784 11.7767 10.9005 12.2003
JS17 6.0371 7.9622 8.5729 8.4436 8.5586 8.5040 9.3121 8.9379
JS21 6.8862 8.1116 8.5316 9.1451 9.1306 8.6107 9.3560 9.4343
JS15 7.2157 9.3727 9.3114 9.2653 8.4027 9.0351 9.1790 9.2380
ZT2 10.2951 10.6286 11.0128 10.5773 11.4861 11.9046 11.1006 10.8138
CA1 task-relevant dimension per rat and session (19 units):
1 2 3 4 5 6 7 8
rat
KL8 7.4125 7.9212 9.2290 10.4018 8.5761 10.5990 11.1211 10.5284
ER1 6.1767 8.6668 9.4143 10.0345 10.2547 11.0195 10.4785 9.8390
JS34 9.4556 11.1861 10.4995 9.5323 10.1589 9.0468 10.0719 10.3617
JS14 7.6489 10.8409 10.5292 9.5795 10.5963 9.4947 10.0853 10.3985
JS17 4.9990 5.0853 6.3517 6.6154 6.4462 6.8435 6.7927 6.3088
JS21 3.2500 6.3319 6.1444 6.3451 6.6045 6.5450 6.3692 4.9249
JS15 8.1674 10.5931 10.8490 11.2343 12.1402 11.7352 11.9972 10.7134
ZT2 8.0273 8.4432 9.1484 9.3285 10.4132 9.4540 9.0605 8.9916
Result: reproduced under reading (a). The mean task-relevant dimension rises from session 1 to 4 and to 8 in PFC (7.131, 9.040, 9.543) and CA1 (6.892, 9.134, 9.008); it is higher at session 4 than 1 in 7 of 8 PFC and 8 of 8 CA1 rats. Under reading (b) it is not monotonic in either area: the PFC mean falls from session 6 to 7 and the CA1 mean from 5 to 6 and from 7 to 8. With 24 CA1 units it rises from 7.926 to 10.286 and 10.260.
fig7hk-measures-increase-early¶
Over the first four sessions nearly every geometric measure (task dimension, SSF, correlation, SNF) increases.
Over the first four sessions, both behavioral and neural readout error rapidly improve (Fig. 7d,e ). During this time, nearly every geometric measure increases (Fig. 7h–k )
for v, td in [("PFC", ("PFC", 19)), ("CA1", ("CA1", 19)), ("CA1", ("CA1", 24)), ("CA1_19", ("CA1", 19))]:
meas = {"task_dim": TD[td], "ssf": M[v]["ssf"], "corr": M[v]["corr"], "snf": M[v]["snf"]}
up = {k: bool(g.mean(0)[3] > g.mean(0)[0]) for k, g in meas.items()}
print(f"{v} (task dim {td[1]} units): increases 1 to 4 {up}; {sum(up.values())} of 4; holds (at least 3): {sum(up.values()) >= 3}")
print(" session 1 / 4:", {k: (round(float(g.mean(0)[0]), 4), round(float(g.mean(0)[3]), 4)) for k, g in meas.items()})
PFC (task dim 19 units): increases 1 to 4 {'task_dim': True, 'ssf': True, 'corr': True, 'snf': True}; 4 of 4; holds (at least 3): True
session 1 / 4: {'task_dim': (7.1309, 9.0404), 'ssf': (0.6323, 0.6661), 'corr': (0.0182, 0.0337), 'snf': (0.3426, 0.6985)}
CA1 (task dim 19 units): increases 1 to 4 {'task_dim': True, 'ssf': False, 'corr': True, 'snf': True}; 3 of 4; holds (at least 3): True
session 1 / 4: {'task_dim': (6.8922, 9.1339), 'ssf': (0.6905, 0.6787), 'corr': (0.0172, 0.0297), 'snf': (0.3986, 0.7549)}
CA1 (task dim 24 units): increases 1 to 4 {'task_dim': True, 'ssf': False, 'corr': True, 'snf': True}; 3 of 4; holds (at least 3): True
session 1 / 4: {'task_dim': (7.9261, 10.2856), 'ssf': (0.6905, 0.6787), 'corr': (0.0172, 0.0297), 'snf': (0.3986, 0.7549)}
CA1_19 (task dim 19 units): increases 1 to 4 {'task_dim': True, 'ssf': False, 'corr': True, 'snf': True}; 3 of 4; holds (at least 3): True
session 1 / 4: {'task_dim': (6.8922, 9.1339), 'ssf': (0.6701, 0.663), 'corr': (0.0172, 0.0296), 'snf': (0.3252, 0.6167)}
Result: reproduced. From session 1 to 4 all four measures increase in PFC (task dimension 7.131 to 9.040, SSF 0.6323 to 0.6661, correlation 0.0182 to 0.0337, SNF 0.3426 to 0.6985) and three of four in CA1, where SSF falls slightly (0.6905 to 0.6787). The 19-unit CA1 variant gives the same three of four, and so does CA1 with the task dimension taken on 24-unit subsets (7.926 to 10.286).
fig7-late-reversal¶
After session four the total dimension begins to increase while the correlation drops.
At this point, several of these initial trends reverse; in particular, the total dimension begins to increase, whereas the correlation drops
for v in VARIANTS:
d, c = M[v]["dim"], M[v]["corr"]
a_dim, a_corr = d.mean(0)[7] - d.mean(0)[3], c.mean(0)[7] - c.mean(0)[3]
sd, _, pd_, _ = w.fit_mixed(d, quad=False, sessions=slice(3, 8))
sc, _, pc, _ = w.fit_mixed(c, quad=False, sessions=slice(3, 8))
print(f"{v}: (a) session 8 - 4: dim {a_dim:+.3f}, corr {a_corr:+.5f} -> holds {a_dim > 0 and a_corr < 0}; "
f"(b) mixed slope 4 to 8: dim {sd:+.3f} (P = {pd_:.2g}), corr {sc:+.5f} (P = {pc:.2g}) -> holds {sd > 0 and sc < 0}")
PFC: (a) session 8 - 4: dim +0.936, corr -0.00764 -> holds True; (b) mixed slope 4 to 8: dim +0.197 (P = 7.5e-07), corr -0.00154 (P = 7e-05) -> holds True
CA1: (a) session 8 - 4: dim +0.784, corr -0.00603 -> holds True; (b) mixed slope 4 to 8: dim +0.169 (P = 0.0022), corr -0.00130 (P = 0.0022) -> holds True
CA1_19: (a) session 8 - 4: dim +0.521, corr -0.00596 -> holds True; (b) mixed slope 4 to 8: dim +0.114 (P = 0.0026), corr -0.00130 (P = 0.0023) -> holds True
Result: reproduced. From session 4 to 8 the total dimension rises and the correlation falls in both areas under both readings: (a) PFC +0.936 and -0.00764, CA1 +0.784 and -0.00603; (b) mixed slopes over sessions 4 to 8 of +0.197 (P = 7.5e-07) and -0.00154 (P = 7e-05) in PFC, +0.169 (P = 0.0022) and -0.00130 (P = 0.0022) in CA1.
# Mixed models of the figure notebook: per area, quadratic models of dim, corr, snf, ssf and task dim,
# linear models of ssf and task dim; Benjamini-Hochberg over the 24 P values (14 linear, 10 quadratic).
def mixed_table(units_ro, units_td, t0=0):
rows = []
for a in AREAS:
v = units_ro[a]; td = TD[units_td[a]]
for meas in ["dim", "corr", "snf", "ssf"]:
g, e, pg, pe = w.fit_mixed(M[v][meas], quad=True, t0=t0)
rows.append(dict(area=a, model="quad", meas=meas, gamma=g, p_gamma=pg, eta=e, p_eta=pe))
g, e, pg, pe = w.fit_mixed(M[v]["ssf"], quad=False, t0=t0)
rows.append(dict(area=a, model="lin", meas="ssf", gamma=g, p_gamma=pg, eta=e, p_eta=pe))
g, e, pg, pe = w.fit_mixed(td, quad=True, t0=t0)
rows.append(dict(area=a, model="quad", meas="task_dim", gamma=g, p_gamma=pg, eta=e, p_eta=pe))
g, e, pg, pe = w.fit_mixed(td, quad=False, t0=t0)
rows.append(dict(area=a, model="lin", meas="task_dim", gamma=g, p_gamma=pg, eta=e, p_eta=pe))
T = pd.DataFrame(rows)
pv = np.concatenate([T.p_gamma.values, T.p_eta.dropna().values])
adj = multipletests(pv, method="fdr_bh")[1]
T["p_gamma_adj"] = adj[:len(T)]
T["p_eta_adj"] = np.nan
T.loc[T.p_eta.notna(), "p_eta_adj"] = adj[len(T):]
return T
MIX = {
"main (t = 0..7, CA1 24 units, task dim 19)": mixed_table({"PFC": "PFC", "CA1": "CA1"}, {"PFC": ("PFC", 19), "CA1": ("CA1", 19)}),
"t = 1..8": mixed_table({"PFC": "PFC", "CA1": "CA1"}, {"PFC": ("PFC", 19), "CA1": ("CA1", 19)}, t0=1),
"CA1 19 units (code)": mixed_table({"PFC": "PFC", "CA1": "CA1_19"}, {"PFC": ("PFC", 19), "CA1": ("CA1", 19)}),
"CA1 24 units, task dim 24": mixed_table({"PFC": "PFC", "CA1": "CA1"}, {"PFC": ("PFC", 19), "CA1": ("CA1", 24)}),
}
fmt = {c: "{:.3g}".format for c in ["gamma", "p_gamma", "eta", "p_eta", "p_gamma_adj", "p_eta_adj"]}
for k, T in MIX.items():
print("=== ", k)
print(T.to_string(index=False, formatters=fmt))
=== main (t = 0..7, CA1 24 units, task dim 19) area model meas gamma p_gamma eta p_eta p_gamma_adj p_eta_adj PFC quad dim -0.592 1.43e-14 0.0788 9.32e-14 1.69e-13 4.47e-13 PFC quad corr 0.00677 1.44e-17 -0.000833 2.11e-14 3.45e-16 1.69e-13 PFC quad snf 0.163 6.38e-14 -0.0195 7.19e-11 3.83e-13 2.46e-10 PFC quad ssf 0.0199 0.0315 -0.00115 0.366 0.036 0.382 PFC lin ssf 0.0119 2.99e-06 NaN NaN 4.22e-06 NaN PFC quad task_dim 0.714 7.88e-06 -0.0664 0.00249 1.05e-05 0.00299 PFC lin task_dim 0.249 1.15e-07 NaN NaN 2.51e-07 NaN CA1 quad dim -0.634 3.34e-08 0.0819 2.04e-07 8.46e-08 4.08e-07 CA1 quad corr 0.00559 3.52e-08 -0.000692 6.84e-07 8.46e-08 1.16e-06 CA1 quad snf 0.173 1.77e-08 -0.0209 7.22e-07 5.3e-08 1.16e-06 CA1 quad ssf -0.000613 0.944 0.00121 0.313 0.944 0.342 CA1 lin ssf 0.00787 0.00106 NaN NaN 0.00134 NaN CA1 quad task_dim 1.01 5.46e-11 -0.109 2.26e-07 2.19e-10 4.18e-07 CA1 lin task_dim 0.242 2.07e-06 NaN NaN 3.1e-06 NaN === t = 1..8 area model meas gamma p_gamma eta p_eta p_gamma_adj p_eta_adj PFC quad dim -0.75 1.45e-14 0.0788 9.32e-14 1.69e-13 5.59e-13 PFC quad corr 0.00844 4.64e-17 -0.000833 2.11e-14 1.11e-15 1.69e-13 PFC quad snf 0.202 2.2e-13 -0.0195 7.19e-11 1.06e-12 2.87e-10 PFC quad ssf 0.0222 0.0582 -0.00115 0.366 0.0665 0.382 PFC lin ssf 0.0119 2.99e-06 NaN NaN 4.22e-06 NaN PFC quad task_dim 0.847 2.86e-05 -0.0664 0.00249 3.81e-05 0.00299 PFC lin task_dim 0.249 1.15e-07 NaN NaN 2.51e-07 NaN CA1 quad dim -0.797 4.06e-08 0.0819 2.04e-07 1.08e-07 4.08e-07 CA1 quad corr 0.00698 5.61e-08 -0.000692 6.84e-07 1.35e-07 1.16e-06 CA1 quad snf 0.214 3.33e-08 -0.0209 7.22e-07 9.98e-08 1.16e-06 CA1 quad ssf -0.00304 0.784 0.00121 0.313 0.784 0.342 CA1 lin ssf 0.00787 0.00106 NaN NaN 0.00134 NaN CA1 quad task_dim 1.22 2.95e-10 -0.109 2.26e-07 1.01e-09 4.18e-07 CA1 lin task_dim 0.242 2.07e-06 NaN NaN 3.1e-06 NaN === CA1 19 units (code) area model meas gamma p_gamma eta p_eta p_gamma_adj p_eta_adj PFC quad dim -0.592 1.43e-14 0.0788 9.32e-14 1.69e-13 4.47e-13 PFC quad corr 0.00677 1.44e-17 -0.000833 2.11e-14 3.45e-16 1.69e-13 PFC quad snf 0.163 6.38e-14 -0.0195 7.19e-11 3.83e-13 2.46e-10 PFC quad ssf 0.0199 0.0315 -0.00115 0.366 0.036 0.399 PFC lin ssf 0.0119 2.99e-06 NaN NaN 4.22e-06 NaN PFC quad task_dim 0.714 7.88e-06 -0.0664 0.00249 1.05e-05 0.00299 PFC lin task_dim 0.249 1.15e-07 NaN NaN 2.76e-07 NaN CA1 quad dim -0.414 1.35e-07 0.0538 6.03e-07 2.94e-07 1.11e-06 CA1 quad corr 0.00558 3.7e-08 -0.00069 7.18e-07 9.87e-08 1.23e-06 CA1 quad snf 0.14 2.61e-08 -0.017 9.15e-07 7.83e-08 1.46e-06 CA1 quad ssf 0.00127 0.875 0.000896 0.419 0.875 0.437 CA1 lin ssf 0.00754 0.000646 NaN NaN 0.000816 NaN CA1 quad task_dim 1.01 5.46e-11 -0.109 2.26e-07 2.19e-10 4.52e-07 CA1 lin task_dim 0.242 2.07e-06 NaN NaN 3.1e-06 NaN === CA1 24 units, task dim 24 area model meas gamma p_gamma eta p_eta p_gamma_adj p_eta_adj PFC quad dim -0.592 1.43e-14 0.0788 9.32e-14 1.69e-13 4.47e-13 PFC quad corr 0.00677 1.44e-17 -0.000833 2.11e-14 3.45e-16 1.69e-13 PFC quad snf 0.163 6.38e-14 -0.0195 7.19e-11 3.83e-13 2.87e-10 PFC quad ssf 0.0199 0.0315 -0.00115 0.366 0.036 0.382 PFC lin ssf 0.0119 2.99e-06 NaN NaN 4.49e-06 NaN PFC quad task_dim 0.714 7.88e-06 -0.0664 0.00249 1.05e-05 0.00299 PFC lin task_dim 0.249 1.15e-07 NaN NaN 2.51e-07 NaN CA1 quad dim -0.634 3.34e-08 0.0819 2.04e-07 8.46e-08 4.08e-07 CA1 quad corr 0.00559 3.52e-08 -0.000692 6.84e-07 8.46e-08 1.24e-06 CA1 quad snf 0.173 1.77e-08 -0.0209 7.22e-07 5.3e-08 1.24e-06 CA1 quad ssf -0.000613 0.944 0.00121 0.313 0.944 0.342 CA1 lin ssf 0.00787 0.00106 NaN NaN 0.00134 NaN CA1 quad task_dim 1.05 4.4e-09 -0.111 5.76e-06 1.51e-08 8.13e-06 CA1 lin task_dim 0.269 2.43e-06 NaN NaN 3.89e-06 NaN
# The paper's own mixed-model table (results/rat_stats.csv in its repository at commit 9674a6c),
# shown next to this notebook's main reading and its 19-unit CA1 variant (the code's choice), for
# comparison only.
RS = pd.read_csv(io.StringIO(requests.get("https://raw.githubusercontent.com/awakhloo/population_geometry_optimal_coding/9674a6cb0c39926d70746024ce17de35f87df8f9/results/rat_stats.csv", timeout=60).text))
RS.columns = ["area", "model", "meas", "gamma", "p_gamma", "p_gamma_adj", "eta", "p_eta", "p_eta_adj"]
RS["model"] = RS.model.map({"Quad.": "quad", "Linear": "lin"})
RS["meas"] = RS.meas.map({"task dim.": "task_dim", "dim.": "dim", "corr.": "corr", "snf": "snf", "ssf": "ssf"})
key = ["area", "model", "meas"]
cmp = RS.merge(MIX["main (t = 0..7, CA1 24 units, task dim 19)"], on=key, suffixes=("_paper", "")).merge(
MIX["CA1 19 units (code)"], on=key, suffixes=("", "_19"))
cols = key + [f"{c}{s}" for c in ["gamma", "p_gamma", "eta", "p_eta"] for s in ("_paper", "", "_19")]
print("columns: _paper = results/rat_stats.csv; no suffix = main reading; _19 = CA1 with 19 units (PFC rows equal the main reading)")
print(cmp[cols].to_string(index=False, formatters={c: "{:.3g}".format for c in cols[3:]}))
same = np.sign(cmp.gamma_paper) == np.sign(cmp.gamma_19)
print(f"gamma signs equal to the paper's in {int(same.sum())} of {len(cmp)} models (19-unit variant)")
columns: _paper = results/rat_stats.csv; no suffix = main reading; _19 = CA1 with 19 units (PFC rows equal the main reading) area model meas gamma_paper gamma gamma_19 p_gamma_paper p_gamma p_gamma_19 eta_paper eta eta_19 p_eta_paper p_eta p_eta_19 PFC quad task_dim 0.716 0.714 0.714 7e-06 7.88e-06 7.88e-06 -0.0662 -0.0664 -0.0664 0.00247 0.00249 0.00249 PFC quad snf 0.164 0.163 0.163 2.8e-14 6.38e-14 6.38e-14 -0.0197 -0.0195 -0.0195 3.1e-11 7.19e-11 7.19e-11 PFC quad ssf 0.0204 0.0199 0.0199 0.0267 0.0315 0.0315 -0.00117 -0.00115 -0.00115 0.352 0.366 0.366 PFC quad corr 0.00677 0.00677 0.00677 1.3e-17 1.44e-17 1.44e-17 -0.00083 -0.000833 -0.000833 1.8e-14 2.11e-14 2.11e-14 PFC quad dim -0.574 -0.592 -0.592 6.9e-14 1.43e-14 1.43e-14 0.0765 0.0788 0.0788 3.7e-13 9.32e-14 9.32e-14 PFC lin ssf 0.0122 0.0119 0.0119 1.4e-06 2.99e-06 2.99e-06 NaN NaN NaN NaN NaN NaN PFC lin task_dim 0.252 0.249 0.249 7.6e-08 1.15e-07 1.15e-07 NaN NaN NaN NaN NaN NaN CA1 quad task_dim 0.997 1.01 1.01 8.8e-11 5.46e-11 5.46e-11 -0.108 -0.109 -0.109 2.8e-07 2.26e-07 2.26e-07 CA1 quad snf 0.139 0.173 0.14 2.4e-08 1.77e-08 2.61e-08 -0.0169 -0.0209 -0.017 8.4e-07 7.22e-07 9.15e-07 CA1 quad corr 0.00557 0.00559 0.00558 2.9e-08 3.52e-08 3.7e-08 -0.00069 -0.000692 -0.00069 5.7e-07 6.84e-07 7.18e-07 CA1 quad ssf 0.00053 -0.000613 0.00127 0.947 0.944 0.875 0.001 0.00121 0.000896 0.36 0.313 0.419 CA1 quad dim -0.409 -0.634 -0.414 1.8e-07 3.34e-08 1.35e-07 0.0532 0.0819 0.0538 7.9e-07 2.04e-07 6.03e-07 CA1 lin ssf 0.0075 0.00787 0.00754 0.00055 0.00106 0.000646 NaN NaN NaN NaN NaN NaN CA1 lin task_dim 0.238 0.242 0.242 3.1e-06 2.07e-06 2.07e-06 NaN NaN NaN NaN NaN NaN gamma signs equal to the paper's in 14 of 14 models (19-unit variant)
mixed-quadratic-dim-corr-snf¶
Quadratic mixed models of total dimension, correlation and SNF have linear and quadratic terms with P < 10^-5 in both areas, of opposite sign.
We found strong, significant effects for both the linear and quadratic terms in PFC and CA1 for the total dimension, correlation and SNF ( P < 10 −5 ; Supplementary Table 2 ). In each case, the sign of the quadratic term was the opposite of the linear term
for k, T in MIX.items():
q = T[(T.model == "quad") & T.meas.isin(["dim", "corr", "snf"])]
opp = bool(np.all(np.sign(q.gamma) != np.sign(q.eta)))
for adj in ["raw", "adjusted"]:
P = np.concatenate([q.p_gamma, q.p_eta]) if adj == "raw" else np.concatenate([q.p_gamma_adj, q.p_eta_adj])
print(f"{k} | {adj}: P below 1e-5 {int((P < 1e-5).sum())} of 12, below 0.05 {int((P < 0.05).sum())} of 12, largest P {P.max():.2g}; opposite signs in all six: {opp}")
main (t = 0..7, CA1 24 units, task dim 19) | raw: P below 1e-5 12 of 12, below 0.05 12 of 12, largest P 7.2e-07; opposite signs in all six: True main (t = 0..7, CA1 24 units, task dim 19) | adjusted: P below 1e-5 12 of 12, below 0.05 12 of 12, largest P 1.2e-06; opposite signs in all six: True t = 1..8 | raw: P below 1e-5 12 of 12, below 0.05 12 of 12, largest P 7.2e-07; opposite signs in all six: True t = 1..8 | adjusted: P below 1e-5 12 of 12, below 0.05 12 of 12, largest P 1.2e-06; opposite signs in all six: True CA1 19 units (code) | raw: P below 1e-5 12 of 12, below 0.05 12 of 12, largest P 9.1e-07; opposite signs in all six: True CA1 19 units (code) | adjusted: P below 1e-5 12 of 12, below 0.05 12 of 12, largest P 1.5e-06; opposite signs in all six: True CA1 24 units, task dim 24 | raw: P below 1e-5 12 of 12, below 0.05 12 of 12, largest P 7.2e-07; opposite signs in all six: True CA1 24 units, task dim 24 | adjusted: P below 1e-5 12 of 12, below 0.05 12 of 12, largest P 1.2e-06; opposite signs in all six: True
Result: reproduced. In the main reading all 12 P values (two areas, three measures, linear and quadratic terms) are below 1e-5, the largest 7.2e-07 raw and 1.2e-06 adjusted, and the quadratic term is opposite in sign to the linear term in all six models. The same holds with sessions coded 1 to 8 and with 19 CA1 units.
mixed-quadratic-ssf-not-nonmonotonic¶
The quadratic mixed model gives no evidence of a non-monotonic SSF trend in either area (P > 0.05).
We did not find evidence for a non-monotonic trend in the SSF in either region ( P > 0.05)
for k, T in MIX.items():
q = T[(T.model == "quad") & (T.meas == "ssf")]
print(k, "|", "; ".join(f"{r.area}: eta {r.eta:.3g}, P {r.p_eta:.3g} (adj. {r.p_eta_adj:.3g})" for r in q.itertuples()),
"| raw P > 0.05 in both:", bool(np.all(q.p_eta > 0.05)))
main (t = 0..7, CA1 24 units, task dim 19) | PFC: eta -0.00115, P 0.366 (adj. 0.382); CA1: eta 0.00121, P 0.313 (adj. 0.342) | raw P > 0.05 in both: True t = 1..8 | PFC: eta -0.00115, P 0.366 (adj. 0.382); CA1: eta 0.00121, P 0.313 (adj. 0.342) | raw P > 0.05 in both: True CA1 19 units (code) | PFC: eta -0.00115, P 0.366 (adj. 0.399); CA1: eta 0.000896, P 0.419 (adj. 0.437) | raw P > 0.05 in both: True CA1 24 units, task dim 24 | PFC: eta -0.00115, P 0.366 (adj. 0.382); CA1: eta 0.00121, P 0.313 (adj. 0.342) | raw P > 0.05 in both: True
Result: reproduced. The quadratic term of the SSF model is not significant in either area: PFC eta = -0.00115 (P = 0.366, adjusted 0.382), CA1 eta = 0.00121 (P = 0.313, adjusted 0.342). The 19-unit CA1 variant gives P = 0.419.
mixed-quadratic-task-dim¶
The quadratic mixed model has weaker but significant effects for the task-relevant dimension (P < 0.01).
Although we did find weaker significant effects of the quadratic model for the task-relevant dimension ( P < 0.01), the model was a comparatively poorer fit to this quantity in PFC
for k, T in MIX.items():
q = T[(T.model == "quad") & (T.meas == "task_dim")]
print(k, "|", "; ".join(f"{r.area}: gamma {r.gamma:.3g} (P {r.p_gamma:.2g}, adj. {r.p_gamma_adj:.2g}), eta {r.eta:.3g} (P {r.p_eta:.2g}, adj. {r.p_eta_adj:.2g})" for r in q.itertuples()))
print(" raw: both terms P < 0.01 in both areas:", bool(np.all(q.p_gamma < 0.01) and np.all(q.p_eta < 0.01)),
"| adjusted:", bool(np.all(q.p_gamma_adj < 0.01) and np.all(q.p_eta_adj < 0.01)))
main (t = 0..7, CA1 24 units, task dim 19) | PFC: gamma 0.714 (P 7.9e-06, adj. 1.1e-05), eta -0.0664 (P 0.0025, adj. 0.003); CA1: gamma 1.01 (P 5.5e-11, adj. 2.2e-10), eta -0.109 (P 2.3e-07, adj. 4.2e-07)
raw: both terms P < 0.01 in both areas: True | adjusted: True
t = 1..8 | PFC: gamma 0.847 (P 2.9e-05, adj. 3.8e-05), eta -0.0664 (P 0.0025, adj. 0.003); CA1: gamma 1.22 (P 3e-10, adj. 1e-09), eta -0.109 (P 2.3e-07, adj. 4.2e-07)
raw: both terms P < 0.01 in both areas: True | adjusted: True
CA1 19 units (code) | PFC: gamma 0.714 (P 7.9e-06, adj. 1.1e-05), eta -0.0664 (P 0.0025, adj. 0.003); CA1: gamma 1.01 (P 5.5e-11, adj. 2.2e-10), eta -0.109 (P 2.3e-07, adj. 4.5e-07)
raw: both terms P < 0.01 in both areas: True | adjusted: True
CA1 24 units, task dim 24 | PFC: gamma 0.714 (P 7.9e-06, adj. 1.1e-05), eta -0.0664 (P 0.0025, adj. 0.003); CA1: gamma 1.05 (P 4.4e-09, adj. 1.5e-08), eta -0.111 (P 5.8e-06, adj. 8.1e-06)
raw: both terms P < 0.01 in both areas: True | adjusted: True
Result: reproduced. Both terms of the quadratic model of the task-relevant dimension have P < 0.01 in both areas, raw and adjusted: PFC gamma = 0.714 (P = 7.9e-06), eta = -0.0664 (P = 0.0025); CA1 gamma = 1.01 (P = 5.5e-11), eta = -0.109 (P = 2.3e-07).
mixed-linear-ssf-task-dim¶
Linear mixed models show monotonic effects on SSF (P < 10^-3) and task-relevant dimension (P < 10^-5) in both areas.
which demonstrated significant, monotonic effects of learning on the SSF and task-relevant dimension across both regions ( P < 10 −3 SSF and P < 10 −5 task dimension; Supplementary Table 2 )
for k, T in MIX.items():
l = T[T.model == "lin"]
print(k, "|", "; ".join(f"{r.area} {r.meas}: gamma {r.gamma:.3g}, P {r.p_gamma:.2g} (adj. {r.p_gamma_adj:.2g})" for r in l.itertuples()))
for adj in ["p_gamma", "p_gamma_adj"]:
ssf = l[l.meas == "ssf"]; td = l[l.meas == "task_dim"]
ok = bool(np.all(ssf.gamma > 0) and np.all(ssf[adj] < 1e-3) and np.all(td.gamma > 0) and np.all(td[adj] < 1e-5))
part = bool(np.all(l.gamma > 0) and np.all(l[adj] < 0.05))
print(f" {adj}: full criterion {ok}; signs positive with P < 0.05 {part}")
main (t = 0..7, CA1 24 units, task dim 19) | PFC ssf: gamma 0.0119, P 3e-06 (adj. 4.2e-06); PFC task_dim: gamma 0.249, P 1.2e-07 (adj. 2.5e-07); CA1 ssf: gamma 0.00787, P 0.0011 (adj. 0.0013); CA1 task_dim: gamma 0.242, P 2.1e-06 (adj. 3.1e-06)
p_gamma: full criterion False; signs positive with P < 0.05 True
p_gamma_adj: full criterion False; signs positive with P < 0.05 True
t = 1..8 | PFC ssf: gamma 0.0119, P 3e-06 (adj. 4.2e-06); PFC task_dim: gamma 0.249, P 1.2e-07 (adj. 2.5e-07); CA1 ssf: gamma 0.00787, P 0.0011 (adj. 0.0013); CA1 task_dim: gamma 0.242, P 2.1e-06 (adj. 3.1e-06)
p_gamma: full criterion False; signs positive with P < 0.05 True
p_gamma_adj: full criterion False; signs positive with P < 0.05 True
CA1 19 units (code) | PFC ssf: gamma 0.0119, P 3e-06 (adj. 4.2e-06); PFC task_dim: gamma 0.249, P 1.2e-07 (adj. 2.8e-07); CA1 ssf: gamma 0.00754, P 0.00065 (adj. 0.00082); CA1 task_dim: gamma 0.242, P 2.1e-06 (adj. 3.1e-06)
p_gamma: full criterion True; signs positive with P < 0.05 True
p_gamma_adj: full criterion True; signs positive with P < 0.05 True
CA1 24 units, task dim 24 | PFC ssf: gamma 0.0119, P 3e-06 (adj. 4.5e-06); PFC task_dim: gamma 0.249, P 1.2e-07 (adj. 2.5e-07); CA1 ssf: gamma 0.00787, P 0.0011 (adj. 0.0013); CA1 task_dim: gamma 0.269, P 2.4e-06 (adj. 3.9e-06)
p_gamma: full criterion False; signs positive with P < 0.05 True
p_gamma_adj: full criterion False; signs positive with P < 0.05 True
Result: partially reproduced. All four slopes are positive with P < 0.05. PFC SSF (0.0119, P = 3.0e-06), PFC task dimension (0.249, P = 1.2e-07) and CA1 task dimension (0.242, P = 2.1e-06) meet their bounds; CA1 SSF (0.00787) has P = 0.00106 raw and 0.00134 adjusted, just above the 1e-3 bound. With the code's 19 CA1 units it is P = 0.00065 (the paper's results/rat_stats.csv, printed with the mixed models, gives 0.00055) and the full criterion holds, so the shortfall rests on the unit count and on random subsets near the bound.
late-trends-match-optimal¶
From session 4 to 8 the dimension measures and SSF increase while the correlation decreases.
Once the readout and behavioral errors begin to plateau at session four, we find that the ensuing trends are consistent with our predictions for optimal representations ... the dimensionality measures and SSF increase over learning, whereas the neural–latent correlation decreases
for v, td in [("PFC", ("PFC", 19)), ("CA1", ("CA1", 19)), ("CA1", ("CA1", 24)), ("CA1_19", ("CA1", 19))]:
meas = {"dim": M[v]["dim"], "task_dim": TD[td], "ssf": M[v]["ssf"], "corr": M[v]["corr"]}
a = {k: g.mean(0)[7] - g.mean(0)[3] for k, g in meas.items()}
b = {k: w.fit_mixed(g, quad=False, sessions=slice(3, 8))[::2] for k, g in meas.items()}
ha = a["dim"] > 0 and a["task_dim"] > 0 and a["ssf"] > 0 and a["corr"] < 0
hb = b["dim"][0] > 0 and b["task_dim"][0] > 0 and b["ssf"][0] > 0 and b["corr"][0] < 0
print(f"{v} (task dim {td[1]} units): (a) session 8 - 4 {dict((k, round(float(x), 5)) for k, x in a.items())} -> {ha}")
print(f" (b) mixed slope 4 to 8 (slope, P) {dict((k, (round(float(x[0]), 5), float('%.2g' % x[1]))) for k, x in b.items())} -> {hb}")
PFC (task dim 19 units): (a) session 8 - 4 {'dim': 0.93585, 'task_dim': 0.50236, 'ssf': 0.0472, 'corr': -0.00764} -> True
(b) mixed slope 4 to 8 (slope, P) {'dim': (0.19669, 7.5e-07), 'task_dim': (0.11465, 0.048), 'ssf': (0.01054, 0.004), 'corr': (-0.00154, 7e-05)} -> True
CA1 (task dim 19 units): (a) session 8 - 4 {'dim': 0.78423, 'task_dim': -0.12564, 'ssf': 0.05307, 'corr': -0.00603} -> False
(b) mixed slope 4 to 8 (slope, P) {'dim': (0.16945, 0.0022), 'task_dim': (-0.0153, 0.82), 'ssf': (0.01242, 0.00098), 'corr': (-0.0013, 0.0022)} -> False
CA1 (task dim 24 units): (a) session 8 - 4 {'dim': 0.78423, 'task_dim': -0.02591, 'ssf': 0.05307, 'corr': -0.00603} -> False
(b) mixed slope 4 to 8 (slope, P) {'dim': (0.16945, 0.0022), 'task_dim': (0.01296, 0.86), 'ssf': (0.01242, 0.00098), 'corr': (-0.0013, 0.0022)} -> True
CA1_19 (task dim 19 units): (a) session 8 - 4 {'dim': 0.52081, 'task_dim': -0.12564, 'ssf': 0.04693, 'corr': -0.00596} -> False
(b) mixed slope 4 to 8 (slope, P) {'dim': (0.11391, 0.0026), 'task_dim': (-0.0153, 0.82), 'ssf': (0.01095, 0.0013), 'corr': (-0.0013, 0.0023)} -> False
Result: partially reproduced. In PFC, from session 4 to 8, both dimension measures and SSF rise and the correlation falls under both readings (total dimension +0.936, task dimension +0.502, SSF +0.0472, correlation -0.00764; mixed slopes all of the same signs). In CA1 the total dimension (+0.784), SSF (+0.0531) and correlation (-0.00603) follow the prediction, but the task-relevant dimension falls (-0.126; slope -0.015, P = 0.82), so the criterion fails there under both readings, with the task dimension on 19-unit subsets as the claims file's pipeline takes it. With the task dimension on 24-unit CA1 subsets it falls under reading (a) (-0.0259) and has a slope of +0.0130 (P = 0.86) under reading (b), which meets reading (b) in sign only; the outcome is judged on the claims file's 19 units.
glm-cross-validated-d2¶
Average cross-validated population D2 of 0.29 (PFC) and 0.25 (CA1); s.d. across rats of session-averaged D2 0.022 (PFC) and 0.1 (CA1).
The average cross-validated population D 2 across all sessions and rats was 0.29 in PFC and 0.25 in CA1, and the standard deviation of the session-averaged population D 2 across rats was 0.022 in PFC and 0.1 in CA1
exp = {"PFC": (0.29, 0.022), "CA1": (0.25, 0.1)}
# readings: (i) each unit's own best score, session value the mean over units as the code (nan if a unit
# has no valid score), then nan-mean over sessions as rat_utils.find_best_params; (ii) the same with a
# nan-mean over units; (iii) units replaced by the null model counted as 0
for a in AREAS:
for key in ["d2", "d2_unit_nanmean", "d2_null0"]:
g = np.array([[GS[(a, 19, ri, si)][key] for si in range(8)] for ri in range(8)])
rm = np.nanmean(g, 1)
m = np.nanmean(g)
ok = [abs(m - exp[a][0]) <= exp[a][0] / 10, abs(rm.std(ddof=0) - exp[a][1]) <= exp[a][1] / 10, abs(rm.std(ddof=1) - exp[a][1]) <= exp[a][1] / 10]
print(f"{a} {key}: mean over sessions = {m:.4f} (expected {exp[a][0]} +- {exp[a][0] / 10:.3f}, within {ok[0]}); nan sessions {int(np.isnan(g).sum())}; "
f"s.d. over rats of rat means ddof 0 = {rm.std(ddof=0):.4f} (within {ok[1]}), ddof 1 = {rm.std(ddof=1):.4f} (within {ok[2]}) (expected {exp[a][1]} +- {exp[a][1] / 10:.4f})")
print(f" s.e.m. over rats of rat means (not a reading of the criterion, shown as asked by the verifier) = {rm.std(ddof=1) / np.sqrt(8):.4f}")
print(" per rat", {r: round(float(x), 3) for r, x in zip(w.RATS, rm)})
allbest = np.concatenate([GLM[(a, ri, si)]["scores"].max(1) for ri in range(8) for si in range(8)])
print(f" {a}: unit best scores, median {np.nanmedian(allbest):.3f}, 10th to 90th percentile {np.nanpercentile(allbest, 10):.3f} to {np.nanpercentile(allbest, 90):.3f}, "
f"nan {int(np.isnan(allbest).sum())}; best alpha at the grid's edges: "
f"{sum(int((np.nanargmax(np.where(np.isfinite(GLM[(a, ri, si)]['scores']), GLM[(a, ri, si)]['scores'], -np.inf), 1) == k).sum()) for ri in range(8) for si in range(8) for k in (0, 9))} units")
nanunits = sum(int(np.isnan(GLM[(a, ri, si)]["scores"]).any(1).sum()) for ri in range(8) for si in range(8))
print(f" {a}: units with a nan mean score at some alpha (best score nan under the code's np.argmax): {nanunits}")
PFC d2: mean over sessions = 0.2786 (expected 0.29 +- 0.029, within True); nan sessions 1; s.d. over rats of rat means ddof 0 = 0.0599 (within False), ddof 1 = 0.0640 (within False) (expected 0.022 +- 0.0022)
s.e.m. over rats of rat means (not a reading of the criterion, shown as asked by the verifier) = 0.0226
per rat {'KL8': 0.161, 'ER1': 0.328, 'JS34': 0.215, 'JS14': 0.322, 'JS17': 0.248, 'JS21': 0.32, 'JS15': 0.304, 'ZT2': 0.336}
PFC d2_unit_nanmean: mean over sessions = 0.2811 (expected 0.29 +- 0.029, within True); nan sessions 0; s.d. over rats of rat means ddof 0 = 0.0613 (within False), ddof 1 = 0.0656 (within False) (expected 0.022 +- 0.0022)
s.e.m. over rats of rat means (not a reading of the criterion, shown as asked by the verifier) = 0.0232
per rat {'KL8': 0.161, 'ER1': 0.328, 'JS34': 0.215, 'JS14': 0.322, 'JS17': 0.248, 'JS21': 0.335, 'JS15': 0.304, 'ZT2': 0.336}
PFC d2_null0: mean over sessions = 0.3012 (expected 0.29 +- 0.029, within True); nan sessions 0; s.d. over rats of rat means ddof 0 = 0.0569 (within False), ddof 1 = 0.0608 (within False) (expected 0.022 +- 0.0022)
s.e.m. over rats of rat means (not a reading of the criterion, shown as asked by the verifier) = 0.0215
per rat {'KL8': 0.196, 'ER1': 0.338, 'JS34': 0.231, 'JS14': 0.338, 'JS17': 0.269, 'JS21': 0.355, 'JS15': 0.335, 'ZT2': 0.348}
PFC: unit best scores, median 0.307, 10th to 90th percentile -0.031 to 0.641, nan 1; best alpha at the grid's edges: 1202 units
PFC: units with a nan mean score at some alpha (best score nan under the code's np.argmax): 1
CA1 d2: mean over sessions = 0.2452 (expected 0.25 +- 0.025, within True); nan sessions 0; s.d. over rats of rat means ddof 0 = 0.1005 (within True), ddof 1 = 0.1075 (within True) (expected 0.1 +- 0.0100)
s.e.m. over rats of rat means (not a reading of the criterion, shown as asked by the verifier) = 0.0380
per rat {'KL8': 0.263, 'ER1': 0.294, 'JS34': 0.263, 'JS14': 0.316, 'JS17': 0.199, 'JS21': 0.037, 'JS15': 0.4, 'ZT2': 0.189}
CA1 d2_unit_nanmean: mean over sessions = 0.2452 (expected 0.25 +- 0.025, within True); nan sessions 0; s.d. over rats of rat means ddof 0 = 0.1005 (within True), ddof 1 = 0.1075 (within True) (expected 0.1 +- 0.0100)
s.e.m. over rats of rat means (not a reading of the criterion, shown as asked by the verifier) = 0.0380
per rat {'KL8': 0.263, 'ER1': 0.294, 'JS34': 0.263, 'JS14': 0.316, 'JS17': 0.199, 'JS21': 0.037, 'JS15': 0.4, 'ZT2': 0.189}
CA1 d2_null0: mean over sessions = 0.2771 (expected 0.25 +- 0.025, within False); nan sessions 0; s.d. over rats of rat means ddof 0 = 0.0797 (within False), ddof 1 = 0.0852 (within False) (expected 0.1 +- 0.0100)
s.e.m. over rats of rat means (not a reading of the criterion, shown as asked by the verifier) = 0.0301
per rat {'KL8': 0.286, 'ER1': 0.326, 'JS34': 0.28, 'JS14': 0.331, 'JS17': 0.251, 'JS21': 0.121, 'JS15': 0.406, 'ZT2': 0.214}
CA1: unit best scores, median 0.251, 10th to 90th percentile -0.079 to 0.603, nan 0; best alpha at the grid's edges: 1750 units
CA1: units with a nan mean score at some alpha (best score nan under the code's np.argmax): 0
# The paper's own GLM fits (results/glm_results in its repository at commit 9674a6c, stored with
# Git LFS), read in memory for comparison only: per rat and session, the population D2 of
# rat_utils.format_glm_results, the unit count, and the task-relevant dimension from the code's
# predictions with the null-model rule and this notebook's participation ratio. No outcome is
# decided from them. fit-GLMs-rat.py takes the rats in the order of a glob over its processed
# files, which it does not record, so the paper's rats are matched to this notebook's by their
# unit counts per area and session.
LFS = "https://media.githubusercontent.com/media/awakhloo/population_geometry_optimal_coding/9674a6cb0c39926d70746024ce17de35f87df8f9/results/glm_results"
PAPER_GLM = {}
for a in AREAS:
R = np.load(io.BytesIO(requests.get(f"{LFS}/glm_res_{a}_bin_size_10_bin_size_vel_3_sp_100_sv_40.npy", timeout=600).content),
allow_pickle=True).item()["results"]
rows = []
for ri in range(8):
for si in range(8):
r = R[ri][si]
sc = r["test_scores"]
bi = np.argmax(sc, axis=1)
best = sc[np.arange(len(sc)), bi]
nv = r["num_valid"][np.arange(len(sc)), bi]
zero = (best <= 0) | (nv < 0.9 * r["glm_params"][-1]) | np.isnan(best)
xh = r["xhat"].copy()
xh[:, zero] = 0.0
row = dict(paper_rat=ri, session=si + 1, d2=float(best.mean()), n_units=len(best), n_null=int(zero.sum()))
for nu in ((19,) if a == "PFC" else (19, 24)):
rng = np.random.default_rng([3, AREAS.index(a), ri, si, nu])
row[f"task_dim_{nu}"] = float(np.mean([w.participation_ratio(xh[:, rng.choice(xh.shape[1], size=nu, replace=False)]) for _ in range(N_PR)]))
rows.append(row)
del R
PAPER_GLM[a] = pd.DataFrame(rows)
from scipy.optimize import linear_sum_assignment
nu_ours = {a: np.array([[GS[(a, 19, ri, si)]["n_units"] for si in range(8)] for ri in range(8)]) for a in AREAS}
nu_paper = {a: PAPER_GLM[a].pivot(index="paper_rat", columns="session", values="n_units").values for a in AREAS}
cost = sum(np.abs(nu_paper[a][:, None, :] - nu_ours[a][None, :, :]).sum(2) for a in AREAS)
pi, oi = linear_sum_assignment(cost)
MATCH = dict(zip(pi, oi))
print("paper's GLM rat index -> this notebook's rat:", {int(k): w.RATS[v] for k, v in MATCH.items()},
f"; total |unit-count difference| over both areas and 64 sessions for the match {int(cost[pi, oi].sum())}, "
f"next best assignment for each paper rat differs by at least {int(np.min(np.sort(cost, 1)[:, 1] - np.sort(cost, 1)[:, 0]))}")
for a in AREAS:
PAPER_GLM[a]["rat"] = PAPER_GLM[a].paper_rat.map(lambda k: w.RATS[MATCH[k]])
PAPER_GLM[a]["ri"] = PAPER_GLM[a].paper_rat.map(MATCH)
PAPER_GLM[a] = PAPER_GLM[a].sort_values(["ri", "session"]).reset_index(drop=True)
for a in AREAS:
P = PAPER_GLM[a]
ours = pd.DataFrame([dict(rat=w.RATS[ri], session=si + 1, d2=GS[(a, 19, ri, si)]["d2"], n_units=GS[(a, 19, ri, si)]["n_units"],
n_null=GS[(a, 19, ri, si)]["n_null"], task_dim_19=GS[(a, 19, ri, si)]["task_dim"],
**({"task_dim_24": GS[(a, 24, ri, si)]["task_dim"]} if a == "CA1" else {})) for ri in range(8) for si in range(8)])
print(f"=== {a}: this attempt against the paper's GLM fits, 64 rat and session values")
print(f" units per session equal in {int((ours.n_units == P.n_units).sum())} of 64 (this attempt {ours.n_units.sum()}, paper {P.n_units.sum()}); "
f"null-model units {ours.n_null.sum()} and {P.n_null.sum()}")
ok = ours.d2.notna() & P.d2.notna()
print(f" population D2: nan sessions {int(ours.d2.isna().sum())} and {int(P.d2.isna().sum())}; on the {int(ok.sum())} with both, "
f"Pearson r = {stats.pearsonr(ours.d2[ok], P.d2[ok])[0]:.4f}, largest |difference| {np.abs(ours.d2[ok] - P.d2[ok]).max():.1e}")
for k in [c for c in P.columns if c.startswith("task_dim")]:
print(f" {k}: Pearson r = {stats.pearsonr(ours[k], P[k])[0]:.4f}, largest |difference| {np.abs(ours[k] - P[k]).max():.3f}, "
f"mean at sessions 1, 4, 8: this attempt {[round(float(ours[k][ours.session == s].mean()), 3) for s in (1, 4, 8)]}, paper {[round(float(P[k][P.session == s].mean()), 3) for s in (1, 4, 8)]}")
for name, T in [("this attempt", ours), ("paper's fits", P)]:
g = T.pivot(index="rat", columns="session", values="d2").loc[w.RATS].values
rm = np.nanmean(g, 1)
print(f" {name}: mean D2 {np.nanmean(g):.4f}; s.d. over rats of rat means ddof 0 {rm.std(ddof=0):.4f}, ddof 1 {rm.std(ddof=1):.4f}; s.e.m. {rm.std(ddof=1) / np.sqrt(8):.4f}; "
f"per rat {dict((r, round(float(x), 3)) for r, x in zip(w.RATS, rm))}")
paper's GLM rat index -> this notebook's rat: {0: 'ZT2', 1: 'JS34', 2: 'ER1', 3: 'JS21', 4: 'JS14', 5: 'JS17', 6: 'KL8', 7: 'JS15'} ; total |unit-count difference| over both areas and 64 sessions for the match 0, next best assignment for each paper rat differs by at least 47
=== PFC: this attempt against the paper's GLM fits, 64 rat and session values
units per session equal in 64 of 64 (this attempt 2327, paper 2327); null-model units 334 and 334
population D2: nan sessions 1 and 1; on the 63 with both, Pearson r = 1.0000, largest |difference| 2.7e-10
task_dim_19: Pearson r = 0.9996, largest |difference| 0.116, mean at sessions 1, 4, 8: this attempt [7.131, 9.04, 9.543], paper [7.125, 9.023, 9.551]
this attempt: mean D2 0.2786; s.d. over rats of rat means ddof 0 0.0599, ddof 1 0.0640; s.e.m. 0.0226; per rat {'KL8': 0.161, 'ER1': 0.328, 'JS34': 0.215, 'JS14': 0.322, 'JS17': 0.248, 'JS21': 0.32, 'JS15': 0.304, 'ZT2': 0.336}
paper's fits: mean D2 0.2786; s.d. over rats of rat means ddof 0 0.0599, ddof 1 0.0640; s.e.m. 0.0226; per rat {'KL8': 0.161, 'ER1': 0.328, 'JS34': 0.215, 'JS14': 0.322, 'JS17': 0.248, 'JS21': 0.32, 'JS15': 0.304, 'ZT2': 0.336}
=== CA1: this attempt against the paper's GLM fits, 64 rat and session values
units per session equal in 64 of 64 (this attempt 3357, paper 3357); null-model units 685 and 685
population D2: nan sessions 0 and 0; on the 64 with both, Pearson r = 1.0000, largest |difference| 1.8e-09
task_dim_19: Pearson r = 0.9997, largest |difference| 0.102, mean at sessions 1, 4, 8: this attempt [6.892, 9.134, 9.008], paper [6.894, 9.156, 9.002]
task_dim_24: Pearson r = 0.9998, largest |difference| 0.127, mean at sessions 1, 4, 8: this attempt [7.926, 10.286, 10.26], paper [7.918, 10.289, 10.289]
this attempt: mean D2 0.2452; s.d. over rats of rat means ddof 0 0.1005, ddof 1 0.1075; s.e.m. 0.0380; per rat {'KL8': 0.263, 'ER1': 0.294, 'JS34': 0.263, 'JS14': 0.316, 'JS17': 0.199, 'JS21': 0.037, 'JS15': 0.4, 'ZT2': 0.189}
paper's fits: mean D2 0.2452; s.d. over rats of rat means ddof 0 0.1005, ddof 1 0.1075; s.e.m. 0.0380; per rat {'KL8': 0.263, 'ER1': 0.294, 'JS34': 0.263, 'JS14': 0.316, 'JS17': 0.199, 'JS21': 0.037, 'JS15': 0.4, 'ZT2': 0.189}
Result: partially reproduced. Three of the four values match under the first reading (each unit's own best score, the code's mean): the mean population D2 is 0.279 in PFC (0.29 +- 0.029) and 0.245 in CA1 (0.25 +- 0.025), and the standard deviation over rats of the session-averaged D2 is 0.1005 in CA1 (ddof 0; 0.1075 with ddof 1; 0.1 +- 0.01). In PFC it is 0.0599 (ddof 0) or 0.0640 (ddof 1), nearly three times the reported 0.022, and no reading brings it within tolerance (0.057 to 0.066); the per-rat PFC means run from 0.161 (KL8) to 0.336 (ZT2). Counting null-model units as 0 moves CA1 out of tolerance (0.277). One PFC unit (JS21) has no valid score; the nan-mean over units gives 0.281. For 1202 of 2327 PFC and 1750 of 3357 CA1 units the chosen penalty is at an end of the code's grid.
The paper's own GLM fits (results/glm_results, matched to this notebook's rats by their unit counts, which agree in all 64 sessions of both areas) give the same session D2 as this notebook (Pearson r = 1.0000, largest difference printed above) and the same spread over rats: 0.0599 (ddof 0) and 0.0640 (ddof 1) in PFC, 0.1005 and 0.1075 in CA1. So the PFC gap to 0.022 is not a difference of fitting. The s.e.m. over rats is 0.0226 in PFC, close to 0.022, but 0.0380 in CA1 against 0.1, so no single reading gives all four reported values. The task-relevant dimension from the paper's predictions agrees with this notebook's too (r = 0.9996 PFC, 0.9997 CA1).
svc-hebbian-correlation¶
The Hebbian error is strongly correlated with the error of a linear SVC on the same tasks (tested here in PFC and CA1).
Across every analysis reported in this paper, we found a strong correlation between SVC and Hebbian errors, particularly in the brain data
for v in ["PFC", "CA1"]:
svc = M[v]["svc"].ravel()
# the theoretical and Hebbian errors on the same 4 subsets as the SVC, and on all 500 subsets
sel = np.isfinite(RO[v][0, 0, :, 6])
th4 = RO[v][:, :, sel, 0].mean(2).ravel(); he4 = RO[v][:, :, sel, 1].mean(2).ravel()
for name, x in [("theory, all subsets", M[v]["theory"].ravel()), ("theory, SVC subsets", th4),
("Hebbian, all subsets", M[v]["hebbian"].ravel()), ("Hebbian, SVC subsets", he4)]:
r, p = stats.pearsonr(x, svc)
print(f"{v} {name}: r = {r:.3f}, r2 = {r * r:.3f}, P = {p:.2g}; (a) r > 0 and P < 0.05: {r > 0 and p < 0.05}; (b) r2 >= 0.5: {r * r >= 0.5}")
print(f" {v}: SVC error {svc.min():.3f} to {svc.max():.3f}, mean {svc.mean():.3f}; Hebbian mean {M[v]['hebbian'].mean():.3f}; SVC subsets per session {int(sel.sum())}")
PFC theory, all subsets: r = 0.962, r2 = 0.926, P = 1.1e-36; (a) r > 0 and P < 0.05: True; (b) r2 >= 0.5: True
PFC theory, SVC subsets: r = 0.965, r2 = 0.931, P = 9e-38; (a) r > 0 and P < 0.05: True; (b) r2 >= 0.5: True
PFC Hebbian, all subsets: r = 0.971, r2 = 0.943, P = 3.1e-40; (a) r > 0 and P < 0.05: True; (b) r2 >= 0.5: True
PFC Hebbian, SVC subsets: r = 0.989, r2 = 0.978, P = 6.8e-53; (a) r > 0 and P < 0.05: True; (b) r2 >= 0.5: True
PFC: SVC error 0.197 to 0.362, mean 0.282; Hebbian mean 0.296; SVC subsets per session 4
CA1 theory, all subsets: r = 0.912, r2 = 0.832, P = 1.1e-25; (a) r > 0 and P < 0.05: True; (b) r2 >= 0.5: True
CA1 theory, SVC subsets: r = 0.911, r2 = 0.829, P = 1.7e-25; (a) r > 0 and P < 0.05: True; (b) r2 >= 0.5: True
CA1 Hebbian, all subsets: r = 0.973, r2 = 0.946, P = 5.2e-41; (a) r > 0 and P < 0.05: True; (b) r2 >= 0.5: True
CA1 Hebbian, SVC subsets: r = 0.981, r2 = 0.963, P = 4.7e-46; (a) r > 0 and P < 0.05: True; (b) r2 >= 0.5: True
CA1: SVC error 0.200 to 0.360, mean 0.278; Hebbian mean 0.291; SVC subsets per session 4
Result: reproduced. Over the 64 rat and session values the squared correlation between the theoretical Hebbian error and the SVC error is 0.926 in PFC and 0.832 in CA1 (P below 1e-24), so both readings hold in both areas; with the empirical Hebbian error it is 0.943 and 0.946. The SVC was run on 4 of the 500 subsets per session; on those same subsets the theoretical error gives 0.931 and 0.829.
Summary¶
| Claim | Outcome |
|---|---|
| fig7d-behavioral-error-learning | reproduced |
| fig7e-readout-error-learning | reproduced |
| figs12c-behavior-readout-r2 | reproduced (0.493 CA1, 0.508 PFC) |
| fig7f-theory-vs-empirical | reproduced (r 0.98 and 0.95; criterion amended after a question, earlier not reproduced) |
| fig7g-total-dimension-drops-early | reproduced |
| fig7h-task-dimension-increases | reproduced (reading a) |
| fig7hk-measures-increase-early | reproduced |
| fig7-late-reversal | reproduced |
| mixed-quadratic-dim-corr-snf | reproduced |
| mixed-quadratic-ssf-not-nonmonotonic | reproduced |
| mixed-quadratic-task-dim | reproduced |
| mixed-linear-ssf-task-dim | partially reproduced (CA1 SSF P = 0.00106 against 1e-3) |
| late-trends-match-optimal | partially reproduced (PFC only) |
| glm-cross-validated-d2 | partially reproduced (PFC s.d. across rats 0.060 against 0.022) |
| svc-hebbian-correlation | reproduced (PFC and CA1 part) |
| theory, simulations, pose network and macaque claims (12) | blocked |
A failure to reproduce here may be a failure of this attempt, not of the paper: see the reasoning and the differences from the paper's method.
How the analysis differs from the paper's: the pipeline is the paper's code, re-implemented on the streamed files (h5py in place of pynwb; Nadaraya-Watson smoothing truncated at ten bandwidths); the random subsets use their own seeds; CA1 uses 24 units as the Methods say, with the code's 19 as a variant; the linear SVC is run on 4 of the 500 subsets per session; the GLM basis is the code's chosen one, without repeating its grid search. The per-rat behavioural errors equal those of the paper's results file, and the readout measures agree with it closely (comparison cell). The GLM D2 per session equals that of the paper's own GLM fits, and the mixed-model table is printed next to the paper's results/rat_stats.csv, with the same signs of gamma in all 14 models in the 19-unit CA1 variant.
What was found about the dataset: the eight rats and the 8 sessions each that the paper uses are all
there, with the units, areas, trials (correct, trajectory type) and position the analysis needs, and
the fewest units per session (19 PFC, 24 CA1) are the numbers the Methods use. Both ZT2 files carry
session_id "01"; nothing in the files says that they are two parts of one rat's day or in which
order, which the code supplies. Position is sampled at 27 to 33 frames per second (the Methods say
30). JS15's timestamps run from 3605 to 90718 s, a span of about 24 hours for a single-day dataset.
Sessions last 13 to 20 minutes. Trials within a session are contiguous, with no gaps.
print(f"total run time {(time.time() - T0) / 60:.1f} min; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB")
total run time 32.3 min; peak memory 0.85 GB