Reproducing Prince et al. (2025) from dandiset 001371¶
Paper. Prince, Cushing, Yassine, Katragadda, Roberts & Singer (2025), "New information triggers prospective codes to adapt for flexible navigation", Nat. Commun. 16, 4822, doi:10.1038/s41467-025-60122-8.
Dataset. DANDI:001371, version 0.260831.0201 (doi:10.48324/dandi.001371/0.260831.0201), streamed from the archive. The paper cites the dandiset without a version; this is the only published version (the draft has the same 66 assets), so it is pinned.
Claims. claims/001371/10.1038-s41467-025-60122-8.yaml, written from the version of record (Europe PMC, PMC12102184) with its Supplementary Information, and the paper's code (github.com/stephprince/update-project at d8557f0). The shared method S1 to S11 of that file is cited below as "S1" and so on.
| Claim | Tested here |
|---|---|
| recordings, trial-mix, task-timing, fig1b-above-chance, fig1b-window-performance, fig1d-heading-switch, fig5a-stay-performance | tested (behaviour and counts) |
| tuning-tiles-track, decoding-validation | tested (position decoding) |
| fig2e-hpc-goal-increase, fig2e-hpc-arms-equal, sfig2e-goal-bias, sfig3c-goals-over-retrospective, sfig3c-retrospective-unchanged, sfig3ab-original-vs-update-cue, sfig2f-all-trials-encoder | tested (CA1 position decoding) |
| sfig5f-pfc-wider-spread, sfig5g-ca1-more-goal-coding, fig2g-pfc-no-goal-increase, sfig5e-pfc-windows | tested (PFC and CA1 position decoding) |
| fig3c-theta-phase-segregation, fig3b-theta-pre-post, sfig6-theta-switch-over-delay, fig3d-new-arm-theta-modulated | tested (CA1 decoding in 25 ms bins with theta phase) |
| fig5d-stay-hpc-like-delay, fig5d-stay-hpc-below-switch, sfig10-stay-transient-new-arm | tested |
| fig6b-hpc-new-lower-incorrect, fig6b-hpc-initial-no-difference, fig6-hpc-pre-cue-initial-higher-incorrect, sfig12-delay-hpc-no-outcome-difference | tested (residual GLM) |
| fig7c-hpc-commitment-new-arm, fig7c-hpc-commitment-initial-arm | tested |
| fig4a-lstm-choice-estimate and every claim on choice decoding (fig4f, fig4d, sfig7d, sfig7e, fig4h, fig4g, fig5f, fig6d, sfig12-delay-pfc, fig6e, fig7e) | blocked, too_large: the per-session LSTM is timed on one session below and the whole does not fit |
The notebook takes about 25 minutes, most of it streaming the 66 files (only units, trials, behaviour and one LFP channel are read).
import os, time, warnings
os.environ.setdefault("OMP_NUM_THREADS", "1")
warnings.filterwarnings("ignore")
import numpy as np, pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import concurrent.futures as cf
import prince2025 as P
pd.set_option("display.width", 200); pd.set_option("display.max_columns", 30)
print("dandiset", P.DANDISET, "version", P.VERSION)
dandiset 001371 version 0.260831.0201
# Stream every session and reduce it to what the analyses use (prince2025.process_session).
ASSETS = P.list_assets()
t0 = time.time()
def _job(i):
a = ASSETS.iloc[i]
return P.process_session(a.asset_id, a.subject, a.session, seed=i) # each session its own seed
with cf.ProcessPoolExecutor(8) as ex:
R = list(ex.map(_job, range(len(ASSETS))))
print(f"{len(R)} sessions processed in {time.time() - t0:.0f} s")
66 sessions processed in 1313 s
# ---- Data check -------------------------------------------------------------------------
print("assets:", len(ASSETS), "subjects:", ASSETS.subject.nunique(), ASSETS.groupby("subject").size().to_dict())
print("asset sizes (GB): %.0f to %.0f" % (ASSETS.size_gb.min(), ASSETS.size_gb.max()))
S = pd.DataFrame([dict(subject=r["subject"], session=r["session"], CA1=r["n_units"]["CA1"], PFC=r["n_units"]["PFC"],
no_region=r["n_units"].get("unknown", 0), trials_all=len(r["trials_all"]),
final=len(r["trials"]), warmup=int((r["trials_all"].maze_id == 3).sum()),
other_maze=int((~r["trials_all"].maze_id.isin([3, 4])).sum()),
delay=int((r["trials"].update_type == 1).sum()), switch=int((r["trials"].update_type == 2).sum()),
stay=int((r["trials"].update_type == 3).sum()), n_train=r["n_train"],
quality=str(r["quality"])) for r in R])
print(S.to_string())
print("\ntotals:", S[["CA1", "PFC", "no_region", "trials_all", "final", "warmup", "delay", "switch", "stay"]].sum().to_dict())
print("unit quality labels over all sessions:", set(S.quality))
ct = pd.concat([r["cell_types"] for r in R]).groupby(level=0).sum()
print("\ncell types by region:\n", ct)
nore = S[S.no_region > 0]
print("\nsessions whose units table has no region or cell type columns:", list(nore.session), "units:", int(nore.no_region.sum()))
# can the region of these units be recovered? what their units table holds, and whether the phy channel separates the probes
for r in R:
if r["n_units"]["unknown"]:
print(f" {r['session']}: units columns {r['unit_cols']}; electrodes {r['electrode_locations']}; phy channel 'ch' range {r['ch_range']['unknown']}")
lab = [r for r in R if not r["n_units"]["unknown"]]
print(" labelled sessions, phy channel 'ch' range by region (over sessions): CA1 %.0f to %.0f, PFC %.0f to %.0f" % (
min(r["ch_range"]["CA1"][0] for r in lab if "CA1" in r["ch_range"]), max(r["ch_range"]["CA1"][1] for r in lab if "CA1" in r["ch_range"]),
min(r["ch_range"]["PFC"][0] for r in lab if "PFC" in r["ch_range"]), max(r["ch_range"]["PFC"][1] for r in lab if "PFC" in r["ch_range"])))
print(" units tables with an 'electrodes' or 'electrode_group' column:", sum(("electrodes" in r["unit_cols"]) or ("electrode_group" in r["unit_cols"]) for r in R),
"of", len(R), "; of the unlabelled sessions:", sum(("electrodes" in r["unit_cols"]) or ("electrode_group" in r["unit_cols"]) for r in R if r["n_units"]["unknown"]))
assets: 66 subjects: 7 {'S17': 8, 'S20': 12, 'S25': 10, 'S28': 11, 'S29': 12, 'S33': 6, 'S34': 7}
asset sizes (GB): 83 to 427
subject session CA1 PFC no_region trials_all final warmup other_maze delay switch stay n_train quality
0 S17 S17-210407 41 75 0 92 92 0 0 72 14 6 57 {'good': 116}
1 S17 S17-210408 59 29 0 51 51 0 0 35 11 5 28 {'good': 88}
2 S17 S17-210409 26 41 0 91 91 0 0 55 28 8 44 {'good': 67}
3 S17 S17-210410 41 36 0 61 61 0 0 37 19 5 29 {'good': 77}
4 S17 S17-210412 68 34 0 14 14 0 0 10 4 0 8 {'good': 102}
5 S17 S17-210413 69 2 0 86 86 0 0 69 10 7 55 {'good': 71}
6 S17 S17-210414 39 12 0 97 97 0 0 63 19 15 50 {'good': 51}
7 S17 S17-210415 56 18 0 99 87 12 0 76 9 2 60 {'good': 74}
8 S20 S20-210509 59 0 0 151 143 8 0 91 37 15 72 {'good': 59}
9 S20 S20-210510 49 7 0 113 105 8 0 79 20 6 63 {'good': 56}
10 S20 S20-210511 33 0 0 298 284 14 0 200 60 24 160 {'good': 33}
11 S20 S20-210512 52 0 0 133 119 14 0 87 26 6 69 {'good': 52}
12 S20 S20-210513 42 0 0 154 143 11 0 110 28 5 88 {'good': 42}
13 S20 S20-210514 46 1 0 46 39 7 0 36 3 0 28 {'good': 47}
14 S20 S20-210516 38 78 0 168 154 14 0 103 32 19 82 {'good': 116}
15 S20 S20-210517 0 0 138 137 125 12 0 94 24 7 75 {'good': 138}
16 S20 S20-210518 76 33 0 132 122 10 0 104 11 7 83 {'good': 109}
17 S20 S20-210519 72 30 0 136 130 6 0 85 33 12 68 {'good': 102}
18 S20 S20-210520 79 37 0 143 127 16 0 98 17 12 78 {'good': 116}
19 S20 S20-210521 78 29 0 78 65 13 0 49 12 4 39 {'good': 107}
20 S25 S25-210906 113 39 0 148 137 11 0 119 11 7 95 {'good': 152}
21 S25 S25-210907 91 20 0 262 253 9 0 190 38 25 152 {'good': 111}
22 S25 S25-210908 69 32 0 230 222 8 0 147 50 25 117 {'good': 101}
23 S25 S25-210909 38 19 0 200 186 14 0 145 30 11 116 {'good': 57}
24 S25 S25-210910 75 29 0 368 354 14 0 238 78 38 190 {'good': 104}
25 S25 S25-210912 42 41 0 275 267 8 0 183 60 24 146 {'good': 83}
26 S25 S25-210913 55 44 0 226 215 11 0 145 51 19 116 {'good': 99}
27 S25 S25-210914 50 32 0 239 221 18 0 156 50 15 124 {'good': 82}
28 S25 S25-210915 31 0 0 135 106 29 0 77 19 10 61 {'good': 31}
29 S25 S25-210916 56 30 0 161 155 6 0 106 34 15 84 {'good': 86}
30 S28 S28-211112 17 29 0 70 57 13 0 51 6 0 40 {'good': 46}
31 S28 S28-211113 74 33 0 170 136 34 0 123 10 3 98 {'good': 107}
32 S28 S28-211114 0 0 142 180 155 25 0 119 29 7 95 {'good': 142}
33 S28 S28-211115 70 49 0 145 132 13 0 95 25 12 76 {'good': 119}
34 S28 S28-211116 93 51 0 267 238 29 0 180 44 14 144 {'good': 144}
35 S28 S28-211117 85 69 0 258 238 20 0 168 62 8 134 {'good': 154}
36 S28 S28-211118 64 47 0 188 177 11 0 125 42 10 100 {'good': 111}
37 S28 S28-211119 0 67 0 179 156 23 0 112 29 15 89 {'good': 67}
38 S28 S28-211120 48 52 0 288 271 17 0 208 45 18 166 {'good': 100}
39 S28 S28-211122 42 50 0 198 184 14 0 139 32 13 111 {'good': 92}
40 S28 S28-211123 24 49 0 194 184 10 0 156 20 8 124 {'good': 73}
41 S29 S29-211104 0 0 116 150 140 10 0 117 18 5 93 {'good': 116}
42 S29 S29-211105 0 0 126 259 237 22 0 173 44 20 138 {'good': 126}
43 S29 S29-211106 46 71 0 223 202 21 0 162 30 10 129 {'good': 117}
44 S29 S29-211107 55 66 0 153 131 22 0 100 21 10 80 {'good': 121}
45 S29 S29-211108 111 45 0 83 59 24 0 51 5 3 40 {'good': 156}
46 S29 S29-211111 88 86 0 218 185 33 0 134 39 12 107 {'good': 174}
47 S29 S29-211114 64 67 0 195 180 15 0 123 37 20 98 {'good': 131}
48 S29 S29-211116 51 65 0 262 255 7 0 159 71 25 127 {'good': 116}
49 S29 S29-211118 90 52 0 298 291 7 0 194 77 20 155 {'good': 142}
50 S29 S29-211119 82 57 0 187 178 9 0 140 26 12 112 {'good': 139}
51 S29 S29-211122 86 49 0 176 169 7 0 118 37 14 94 {'good': 135}
52 S29 S29-211123 41 16 0 104 96 8 0 69 17 10 55 {'good': 57}
53 S33 S33-220420 103 73 0 104 87 17 0 62 17 8 49 {'good': 176}
54 S33 S33-220421 74 32 0 189 175 14 0 130 30 15 104 {'good': 106}
55 S33 S33-220422 60 31 0 113 97 16 0 74 17 6 59 {'good': 91}
56 S33 S33-220425 70 28 0 129 104 25 0 85 13 6 68 {'good': 98}
57 S33 S33-220426 60 14 0 73 54 19 0 50 4 0 40 {'good': 74}
58 S33 S33-220428 72 0 0 88 76 12 0 53 16 7 42 {'good': 72}
59 S34 S34-220614 10 42 0 113 95 18 0 60 21 14 48 {'good': 52}
60 S34 S34-220615 63 34 0 120 99 21 0 87 10 2 69 {'good': 97}
61 S34 S34-220616 76 49 0 115 96 19 0 81 15 0 64 {'good': 125}
62 S34 S34-220617 0 0 111 168 144 24 0 111 21 12 88 {'good': 111}
63 S34 S34-220620 0 34 0 73 62 11 0 55 5 2 44 {'good': 34}
64 S34 S34-220621 29 66 0 150 97 53 0 75 16 6 60 {'good': 95}
65 S34 S34-220623 54 50 0 257 241 16 0 174 51 16 139 {'good': 104}
totals: {'CA1': 3545, 'PFC': 2271, 'no_region': 633, 'trials_all': 10661, 'final': 9729, 'warmup': 932, 'delay': 7172, 'switch': 1840, 'stay': 717}
unit quality labels over all sessions: {"{'good': 99}", "{'good': 67}", "{'good': 111}", "{'good': 83}", "{'good': 121}", "{'good': 82}", "{'good': 142}", "{'good': 102}", "{'good': 107}", "{'good': 86}", "{'good': 174}", "{'good': 73}", "{'good': 126}", "{'good': 138}", "{'good': 152}", "{'good': 72}", "{'good': 52}", "{'good': 91}", "{'good': 104}", "{'good': 119}", "{'good': 92}", "{'good': 59}", "{'good': 33}", "{'good': 131}", "{'good': 57}", "{'good': 176}", "{'good': 95}", "{'good': 116}", "{'good': 144}", "{'good': 77}", "{'good': 106}", "{'good': 156}", "{'good': 74}", "{'good': 51}", "{'good': 154}", "{'good': 135}", "{'good': 88}", "{'good': 46}", "{'good': 31}", "{'good': 139}", "{'good': 97}", "{'good': 34}", "{'good': 42}", "{'good': 47}", "{'good': 109}", "{'good': 101}", "{'good': 117}", "{'good': 71}", "{'good': 125}", "{'good': 98}", "{'good': 100}", "{'good': 56}"}
cell types by region:
col_0 Narrow Interneuron Pyramidal Cell Wide Interneuron unknown
row_0
CA1 431.0 3039.0 75.0 0.0
PFC 199.0 1591.0 481.0 0.0
unknown 0.0 0.0 0.0 633.0
sessions whose units table has no region or cell type columns: ['S20-210517', 'S28-211114', 'S29-211104', 'S29-211105', 'S34-220617'] units: 633
S20-210517: units columns ['Amplitude', 'ContamPct', 'KSLabel', 'amp', 'ch', 'depth', 'fr', 'id', 'n_spikes', 'original_cluster_id', 'quality', 'spike_times', 'spike_times_index', 'unit_name']; electrodes {'PFC': 64, 'CA1': 64}; phy channel 'ch' range (1.0, 63.0)
S28-211114: units columns ['Amplitude', 'ContamPct', 'KSLabel', 'amp', 'ch', 'depth', 'fr', 'id', 'n_spikes', 'original_cluster_id', 'quality', 'spike_times', 'spike_times_index', 'unit_name']; electrodes {'PFC': 64, 'CA1': 64}; phy channel 'ch' range (0.0, 63.0)
S29-211104: units columns ['Amplitude', 'ContamPct', 'KSLabel', 'amp', 'ch', 'depth', 'fr', 'id', 'n_spikes', 'original_cluster_id', 'quality', 'spike_times', 'spike_times_index', 'unit_name']; electrodes {'CA1': 64, 'PFC': 64}; phy channel 'ch' range (2.0, 63.0)
S29-211105: units columns ['Amplitude', 'ContamPct', 'KSLabel', 'amp', 'ch', 'depth', 'fr', 'id', 'n_spikes', 'original_cluster_id', 'quality', 'spike_times', 'spike_times_index', 'unit_name']; electrodes {'CA1': 64, 'PFC': 64}; phy channel 'ch' range (0.0, 62.0)
S34-220617: units columns ['Amplitude', 'ContamPct', 'KSLabel', 'amp', 'ch', 'depth', 'fr', 'id', 'n_spikes', 'original_cluster_id', 'quality', 'spike_times', 'spike_times_index', 'unit_name']; electrodes {'CA1': 64, 'PFC': 64}; phy channel 'ch' range (1.0, 63.0)
labelled sessions, phy channel 'ch' range by region (over sessions): CA1 0 to 63, PFC 0 to 63
units tables with an 'electrodes' or 'electrode_group' column: 61 of 66 ; of the unlabelled sessions: 0
# Units and ranges of every variable used, and the metadata stated in the files.
ua = R[0]["units_attrs"]
print("metadata as stated:", ua, "(identical in all sessions:", all(r["units_attrs"] == ua for r in R), ")")
pos_lo = np.min([r["pos_range"][0] for r in R], 0); pos_hi = np.max([r["pos_range"][1] for r in R], 0)
print("position x range %.1f to %.1f, y range %.1f to %.1f (stated unit 'meters')" % (pos_lo[0], pos_hi[0], pos_lo[1], pos_hi[1]))
va = np.array([r["va_range"] for r in R]); print("view angle range %.3f to %.3f (stated unit 'degrees')" % (va[:, 0].min(), va[:, 1].max()))
lin = np.array([r["lin_range"] for r in R]); print("linearized position range %.1f to %.1f" % (lin[:, 0].min(), lin[:, 1].max()))
print("moving fraction of behaviour samples (|rot|+|trans| > 1000): %.3f to %.3f" % (min(r["moving_frac"] for r in R), max(r["moving_frac"] for r in R)))
h = np.sum([r["acq_speed_hist"] for r in R], 0); e = np.linspace(0, 5, 51)
print("log10(|rot|+|trans|+1) histogram of the acquisition series, all sessions (bin start: count):")
print({round(float(a), 1): int(c) for a, c in zip(e[:-1], h)})
# clocks: spikes, behaviour and trials within the same span
bad = [r["session"] for r in R if not (r["spike_range"][0] < r["trials"].start_time.min() and r["spike_range"][1] > r["trials"].stop_time.max() * 0.9)]
print("sessions whose spikes do not span the trials:", bad)
metadata as stated: {'pos_unit': 'meters', 'va_unit': 'degrees', 'turn_type_desc': "{'right': 1, 'left': 2}", 'update_type_desc': "{'nan': 1, 'switch': 2, 'stay': 3}"} (identical in all sessions: True )
position x range -177.0 to 177.0, y range -117.2 to 286.1 (stated unit 'meters')
view angle range -1.047 to 1.047 (stated unit 'degrees')
linearized position range 0.0 to 379.9
moving fraction of behaviour samples (|rot|+|trans| > 1000): 0.728 to 0.997
log10(|rot|+|trans|+1) histogram of the acquisition series, all sessions (bin start: count):
{0.0: 18519, 0.1: 0, 0.2: 0, 0.3: 26001, 0.4: 9168, 0.5: 0, 0.6: 0, 0.7: 0, 0.8: 0, 0.9: 51936, 1.0: 77118, 1.1: 0, 1.2: 231243, 1.3: 183004, 1.4: 172971, 1.5: 481083, 1.6: 1097050, 1.7: 618863, 1.8: 1127096, 1.9: 1638739, 2.0: 1656902, 2.1: 2354555, 2.2: 3050983, 2.3: 3879726, 2.4: 3399178, 2.5: 3227821, 2.6: 3367432, 2.7: 3644355, 2.8: 4311445, 2.9: 4991225, 3.0: 6854131, 3.1: 8849812, 3.2: 12509037, 3.3: 16817401, 3.4: 23543306, 3.5: 32539852, 3.6: 44205565, 3.7: 55017035, 3.8: 69215230, 3.9: 95125789, 4.0: 125701009, 4.1: 138867434, 4.2: 72160216, 4.3: 14049415, 4.4: 152262, 4.5: 343, 4.6: 0, 4.7: 0, 4.8: 0, 4.9: 0}
sessions whose spikes do not span the trials: []
# Trial-table checks: the meaning of turn_type, of the cue times, and of view angle sign.
rows = []
for r in R:
tr = r["trials"]
for _, t in tr.iterrows():
rows.append(dict(session=r["session"], update_type=t.update_type, correct=t.correct, turn_type=t.turn_type,
choice=t.choice))
TT = pd.DataFrame(rows)
print("correct trials: final choice by turn_type and trial type")
print(pd.crosstab([TT[TT.correct == 1].update_type, TT[TT.correct == 1].turn_type], TT[TT.correct == 1].choice))
g = R[0]["geo"]
print("\nlinearized segments: arm bins left", np.where(g["left"])[0], "right", np.where(g["right"])[0])
correct trials: final choice by turn_type and trial type
choice 0.0 1.0 2.0
update_type turn_type
1.0 1.0 1 2520 0
2.0 1 0 2304
2.0 1.0 0 0 792
2.0 0 601 0
3.0 1.0 1 324 0
2.0 0 0 268
linearized segments: arm bins left [35 36 37 38 39 40 41] right [43 44 45 46 47 48 49]
# Checks of the trial table against the behaviour (continued).
ALLT = pd.concat([r["trials"].assign(animal=r["subject"], session=r["session"]) for r in R], ignore_index=True)
c = ALLT[ALLT.correct == 1]
print("correct trials, sign of x at choice made by turn_type and trial type:")
print(pd.crosstab([c.update_type, c.turn_type], np.sign(c.x_at_choice)))
print("\ny position at t_update on switch and stay trials: median %.2f, 1st to 99th percentile %.2f to %.2f (update cue start 145.125 in the code)"
% tuple(np.nanpercentile(ALLT[ALLT.update_type > 1].y_at_update, [50, 1, 99])))
print("y position at t_delay: median %.2f, 1st to 99th percentile %.2f to %.2f (delay cue start 120.325 in the code)"
% tuple(np.nanpercentile(ALLT.y_at_delay, [50, 1, 99])))
print("y at the stored update_location minus y at t_update: median %.3f" % np.nanmedian(ALLT.update_location - ALLT.y_at_update))
r_va = np.array([r["va_dx_r"] for r in R])
print("\nSpearman r between view angle and sideways movement dx in the central arm, per session: median %.2f, range %.2f to %.2f"
% (np.median(r_va), r_va.min(), r_va.max()))
correct trials, sign of x at choice made by turn_type and trial type:
x_at_choice -1.0 1.0
update_type turn_type
1 1 2521 0
2 0 2305
2 1 0 792
2 601 0
3 1 325 0
2 0 268
y position at t_update on switch and stay trials: median 145.34, 1st to 99th percentile 145.10 to 145.63 (update cue start 145.125 in the code)
y position at t_delay: median 120.43, 1st to 99th percentile 120.13 to 215.43 (delay cue start 120.325 in the code)
y at the stored update_location minus y at t_update: median 0.000
Spearman r between view angle and sideways movement dx in the central arm, per session: median -0.12, range -0.36 to 0.20
# Clock of spikes against behaviour: position decoding error on held-out delay only trials with the
# position at the same time, and with the position 2 s earlier or later (per region, included sessions).
for reg, rule in (("CA1", "final"), ("PFC", "final"), ("CA1", "train"), ("PFC", "train")):
rows = [dict(session=r["session"], same=np.median(r["dec"][reg]["val_err"]), minus2=r["dec"][reg].get("val_err_shift", {}).get(-2.0, np.nan),
plus2=r["dec"][reg].get("val_err_shift", {}).get(2.0, np.nan)) for r in R if P.included(r, reg, rule)]
d = pd.DataFrame(rows)
print(f"{reg} rule={rule}: {len(d)} sessions; median error (linearized units) same time {d.same.median():.1f}, "
f"-2 s {d.minus2.median():.1f}, +2 s {d.plus2.median():.1f}; sessions where same time is lowest: "
f"{int(((d.same < d.minus2) & (d.same < d.plus2)).sum())} of {len(d)}")
CA1 rule=final: 55 sessions; median error (linearized units) same time 67.6, -2 s 79.1, +2 s 87.5; sessions where same time is lowest: 52 of 55 PFC rule=final: 46 sessions; median error (linearized units) same time 55.3, -2 s 63.6, +2 s 63.4; sessions where same time is lowest: 43 of 46 CA1 rule=train: 47 sessions; median error (linearized units) same time 66.7, -2 s 76.5, +2 s 88.8; sessions where same time is lowest: 45 of 47 PFC rule=train: 37 sessions; median error (linearized units) same time 49.4, -2 s 63.6, +2 s 63.6; sessions where same time is lowest: 36 of 37
recordings¶
Seven mice were recorded over 66 sessions, yielding 3892 hippocampal CA1 units and 2557 medial prefrontal units after curation and cell type classification.
n_animals = ASSETS.subject.nunique(); n_sessions = len(ASSETS)
nCA1, nPFC, nNo = S.CA1.sum(), S.PFC.sum(), S.no_region.sum()
print("animals", n_animals, "(expected 7); sessions", n_sessions, "(expected 66)")
print("CA1 units", nCA1, "(expected 3892 +/- 389.2); PFC units", nPFC, "(expected 2557 +/- 255.7)")
print("units without region:", nNo, "; all units", nCA1 + nPFC + nNo, "against the paper's total", 3892 + 2557)
print("\nper animal (Supplementary Table 1 gives per-animal counts beside the totals):")
print(S.groupby("subject")[["CA1", "PFC", "no_region"]].sum().assign(sessions=S.groupby("subject").size()))
print("\nwithin tolerance: CA1", abs(nCA1 - 3892) <= 389.2, "PFC", abs(nPFC - 2557) <= 255.7)
animals 7 (expected 7); sessions 66 (expected 66)
CA1 units 3545 (expected 3892 +/- 389.2); PFC units 2271 (expected 2557 +/- 255.7)
units without region: 633 ; all units 6449 against the paper's total 6449
per animal (Supplementary Table 1 gives per-animal counts beside the totals):
CA1 PFC no_region sessions
subject
S17 399 247 0 8
S20 624 215 138 12
S25 620 286 0 10
S28 517 496 142 11
S29 714 574 242 12
S33 439 178 0 6
S34 232 275 111 7
within tolerance: CA1 True PFC False
Result: partially reproduced. 7 animals and 66 sessions match, with 8, 12, 10, 11, 12, 6 and 7 sessions per animal. The CA1 count (3545) is within tolerance and the PFC count (2271) is not. The units of five sessions carry no region or cell type; with them the three counts sum exactly to the paper's 6449 units (3545 + 2271 + 633), which is consistent with the shortfall being those unlabelled units; how the 633 units divide between the two regions is not known. Their region cannot be recovered from the files: their units tables have no electrodes or electrode_group column (0 of the 5; 61 of 66 tables over all sessions have one), and the phy channel ch runs from 0 to 63 on both probes in the labelled sessions (CA1 0 to 63, PFC 0 to 63), so it does not say which probe a unit is on (data check).
trial-mix¶
In the final task 65% of trials are delay only, 25% switch and 10% stay trials.
F = ALLT # final-task trials (maze_id 4)
pooled = F.update_type.value_counts(normalize=True).sort_index()
per = F.groupby("session").update_type.value_counts(normalize=True).unstack().fillna(0).mean()
exp = {1: (0.65, 0.065), 2: (0.25, 0.025), 3: (0.10, 0.01)}
for name, fr in (("(a) pooled", pooled), ("(b) mean of sessions", per)):
ok = all(abs(fr[k] - v) <= tol for k, (v, tol) in exp.items())
print(name, {P.TRIAL_TYPES[k]: round(float(fr[k]), 4) for k in exp}, "all within tolerance:", ok)
print("counts:", F.update_type.map(P.TRIAL_TYPES).value_counts().to_dict(), "of", len(F))
(a) pooled {'delay only': 0.7372, 'switch': 0.1891, 'stay': 0.0737} all within tolerance: False
(b) mean of sessions {'delay only': 0.7501, 'switch': 0.1809, 'stay': 0.069} all within tolerance: False
counts: {'delay only': 7172, 'switch': 1840, 'stay': 717} of 9729
Result: not reproduced. The realized fractions are 0.737, 0.189 and 0.074 (delay only, switch, stay) pooled over the 9729 final-task trials and 0.750, 0.181 and 0.069 averaged over sessions, outside the tolerances under both readings, as the claims file foresaw from the paper's own counts (Supplementary Table 1). The 65/25/10% read as programmed probabilities, which the realized trials do not show. The 932 warm-up trials (maze_id 3) and the 7172 final-task delay only trials make 8104, the delay count of Supplementary Table 1 (data check).
task-timing¶
The delay on delay only trials lasted 10.56 s on average, the shortened delay before the update cue on switch trials 1.40 s, and the delay after the update cue 6.02 s; trials lasted about 21 s from start to choice.
def msem(x):
x = np.asarray(x, float); x = x[np.isfinite(x)]
return x.mean(), x.std(ddof=1) / np.sqrt(len(x)), len(x)
rows = []
for tset, sub in (("(c) all", F), ("(d) correct", F[F.correct == 1])):
d1 = sub[sub.update_type == 1]; sw = sub[sub.update_type == 2]; ss = sub[sub.update_type.isin([2, 3])]
vals = {"delay, delay only (t_choice_made - t_delay)": (d1.t_choice_made - d1.t_delay, 10.56, 0.14),
"first delay, switch (t_update - t_delay)": (sw.t_update - sw.t_delay, 1.40, 0.06),
"second delay (a) t_choice_made - t_delay2, (e) switch": (sw.t_choice_made - sw.t_delay2, 6.02, 0.16),
"second delay (b) t_choice_made - t_update, (e) switch": (sw.t_choice_made - sw.t_update, 6.02, 0.16),
"second delay (a), (f) switch and stay": (ss.t_choice_made - ss.t_delay2, 6.02, 0.16),
"second delay (b), (f) switch and stay": (ss.t_choice_made - ss.t_update, 6.02, 0.16),
"trial start to choice, delay only": (d1.t_choice_made - d1.start_time, 20.93, 0.18),
"trial start to choice, switch": (sw.t_choice_made - sw.start_time, 20.79, 0.45)}
for k, (x, e, tol) in vals.items():
m, se, n = msem(x)
rows.append(dict(trials=tset, quantity=k, mean=round(m, 3), sem=round(se, 3), n=n, expected=e, within=abs(m - e) <= tol))
TIM = pd.DataFrame(rows); print(TIM.to_string())
trials quantity mean sem n expected within 0 (c) all delay, delay only (t_choice_made - t_delay) 10.559 0.067 7172 10.56 True 1 (c) all first delay, switch (t_update - t_delay) 1.403 0.029 1840 1.40 True 2 (c) all second delay (a) t_choice_made - t_delay2, (e) switch 6.020 0.084 1840 6.02 True 3 (c) all second delay (b) t_choice_made - t_update, (e) switch 9.928 0.137 1840 6.02 False 4 (c) all second delay (a), (f) switch and stay 6.060 0.069 2556 6.02 True 5 (c) all second delay (b), (f) switch and stay 9.919 0.106 2557 6.02 False 6 (c) all trial start to choice, delay only 21.004 0.090 7172 20.93 True 7 (c) all trial start to choice, switch 20.882 0.231 1840 20.79 True 8 (d) correct delay, delay only (t_choice_made - t_delay) 10.414 0.068 4826 10.56 False 9 (d) correct first delay, switch (t_update - t_delay) 1.328 0.018 1393 1.40 False 10 (d) correct second delay (a) t_choice_made - t_delay2, (e) switch 5.968 0.102 1393 6.02 True 11 (d) correct second delay (b) t_choice_made - t_update, (e) switch 9.873 0.172 1393 6.02 False 12 (d) correct second delay (a), (f) switch and stay 5.976 0.080 1985 6.02 True 13 (d) correct second delay (b), (f) switch and stay 9.814 0.128 1986 6.02 False 14 (d) correct trial start to choice, delay only 20.773 0.097 4826 20.93 True 15 (d) correct trial start to choice, switch 20.623 0.242 1393 20.79 True
Result: reproduced. Over all final-task trials, the delay on delay only trials is 10.559 +/- 0.067 s (n = 7172), the first delay on switch trials 1.403 +/- 0.029 s (n = 1840), the second delay from its onset (t_delay2) to choice made 6.020 +/- 0.084 s on switch trials, and trial start to choice 21.00 s (delay only) and 20.88 s (switch), all within tolerance (readings a, c, e; the trial counts equal the paper's). Reading (b), update cue onset to choice, gives 9.93 s and does not match. On correct trials only, the delay only delay (10.41 s) and first delay (1.33 s) fall outside.
fig1b-above-chance¶
Animals performed above 50% correct on delay only trials (65 +/- 2%) and on switch trials (74 +/- 2%).
def windows(F, types, w):
"""Rolling proportion correct over w consecutive trials of one type within a session
(pandas rolling, min_periods = w) [claims fig1b-window-performance; code behavior_analyzer]."""
out = []
for (an, se, ut), g in F[F.update_type.isin(types)].sort_values("start_time").groupby(["animal", "session", "update_type"]):
v = g.correct.astype(float).rolling(w, min_periods=w).mean().dropna()
out.append(pd.DataFrame(dict(animal=an, session=se, update_type=ut, prop=v.to_numpy())))
return pd.concat(out, ignore_index=True)
sess_pc = F.groupby(["animal", "session", "update_type"]).correct.mean().reset_index()
for ut, e in ((1, 0.65), (2, 0.74)):
x = sess_pc[sess_pc.update_type == ut]
w = stats.wilcoxon(x.correct - 0.5)
m_s, se_s = x.correct.mean(), x.correct.std(ddof=1) / np.sqrt(len(x))
an = x.groupby("animal").correct.mean()
print(f"{P.TRIAL_TYPES[ut]}: (a) sessions n={len(x)}, Wilcoxon W={w.statistic:.1f}, p={w.pvalue:.3g}; "
f"(c) mean over sessions {m_s:.3f} +/- {se_s:.3f} SEM; (d) mean over animals {an.mean():.3f} +/- {an.std(ddof=1)/np.sqrt(len(an)):.3f} "
f"(expected {e} +/- 0.039)")
W40 = windows(F, [ut], 40)
w2 = stats.wilcoxon(W40.prop - 0.5)
print(f" (b) 40-trial windows n={len(W40)}, W={w2.statistic:.1f}, p={w2.pvalue:.3g}, mean {W40.prop.mean():.3f}")
print("\nper animal proportion correct (mean of sessions):")
print(sess_pc.groupby(["animal", "update_type"]).correct.mean().unstack().round(3))
delay only: (a) sessions n=66, Wilcoxon W=125.5, p=6.07e-10; (c) mean over sessions 0.649 +/- 0.017 SEM; (d) mean over animals 0.641 +/- 0.031 (expected 0.65 +/- 0.039) (b) 40-trial windows n=4636, W=349151.0, p=0, mean 0.683 switch: (a) sessions n=66, Wilcoxon W=48.5, p=3.33e-11; (c) mean over sessions 0.745 +/- 0.020 SEM; (d) mean over animals 0.745 +/- 0.034 (expected 0.74 +/- 0.039)
(b) 40-trial windows n=239, W=0.0, p=4.73e-41, mean 0.810 per animal proportion correct (mean of sessions): update_type 1 2 3 animal S17 0.516 0.689 0.556 S20 0.702 0.787 0.816 S25 0.756 0.632 0.861 S28 0.598 0.697 0.733 S29 0.680 0.838 0.844 S33 0.657 0.881 0.745 S34 0.577 0.693 0.641
Result: reproduced. One proportion per session and trial type (reading a): delay only mean 0.649 +/- 0.017 over 66 sessions, Wilcoxon W = 125.5, p = 6.1e-10 (the paper prints W = 125.5, p = 6.197e-10); switch 0.745 +/- 0.020, W = 48.5, p = 3.3e-11 (paper W = 48.5). The means over animals (0.641 and 0.745) are also within tolerance. The 40-trial windows (reading b) also give p far below 0.05.
fig1b-window-performance¶
Over rolling windows of trials, proportion correct averaged 0.68 on delay only and 0.78 on switch trials.
exp = {1: dict(mean=(0.68, 0.068), median=(0.67, 0.067)), 2: dict(mean=(0.78, 0.0196), median=(0.80, 0.08))}
for w in (40, 15):
for ut in (1, 2):
Wd = windows(F, [ut], w)
mn, md_ = Wd.prop.mean(), Wd.prop.median()
ok = abs(mn - exp[ut]["mean"][0]) <= exp[ut]["mean"][1] and abs(md_ - exp[ut]["median"][0]) <= exp[ut]["median"][1]
print(f"window {w}: {P.TRIAL_TYPES[ut]} n windows={len(Wd)} mean {mn:.3f} median {md_:.3f} "
f"(expected mean {exp[ut]['mean'][0]}, median {exp[ut]['median'][0]}); within tolerance: {ok}; "
f"by animal mean {Wd.groupby('animal').prop.mean().round(2).to_dict()}")
window 40: delay only n windows=4636 mean 0.683 median 0.675 (expected mean 0.68, median 0.67); within tolerance: True; by animal mean {'S17': 0.5, 'S20': 0.71, 'S25': 0.79, 'S28': 0.58, 'S29': 0.7, 'S33': 0.7, 'S34': 0.61}
window 40: switch n windows=239 mean 0.810 median 0.825 (expected mean 0.78, median 0.8); within tolerance: False; by animal mean {'S20': 0.89, 'S25': 0.73, 'S28': 0.8, 'S29': 0.9, 'S34': 0.78}
window 15: delay only n windows=6252 mean 0.678 median 0.667 (expected mean 0.68, median 0.67); within tolerance: True; by animal mean {'S17': 0.52, 'S20': 0.72, 'S25': 0.79, 'S28': 0.58, 'S29': 0.7, 'S33': 0.68, 'S34': 0.6}
window 15: switch n windows=1002 mean 0.775 median 0.800 (expected mean 0.78, median 0.8); within tolerance: True; by animal mean {'S17': 0.63, 'S20': 0.85, 'S25': 0.67, 'S28': 0.77, 'S29': 0.84, 'S33': 0.92, 'S34': 0.77}
Result: reproduced. With 15-trial windows (reading b) the window counts equal the paper's (6252 delay only, 1002 switch), and the means and medians are 0.678 and 0.667 (delay only) and 0.775 and 0.800 (switch), all within tolerance. With 40-trial windows (reading a) there are 4636 and 239 windows and the switch mean, 0.810, is outside tolerance.
fig5a-stay-performance¶
Animals performed very well on stay trials (proportion correct 0.92 over windows).
for w in (40, 15):
Wd = windows(F, [3], w)
if len(Wd):
print(f"window {w}: stay n windows={len(Wd)} mean {Wd.prop.mean():.3f} median {Wd.prop.median():.3f} "
f"(expected mean 0.92 +/- 0.0196, median 0.93); within: {abs(Wd.prop.mean() - 0.92) <= 0.0196}")
else:
print(f"window {w}: no session has {w} stay trials")
x = sess_pc[sess_pc.update_type == 3]
print("per-session stay proportion correct: mean %.3f, median %.3f, n sessions %d; pooled over trials %.3f"
% (x.correct.mean(), x.correct.median(), len(x), F[F.update_type == 3].correct.mean()))
print("stay trials per session: max", F[F.update_type == 3].groupby("session").size().max())
window 40: no session has 40 stay trials
window 15: stay n windows=117 mean 0.921 median 0.933 (expected mean 0.92 +/- 0.0196, median 0.93); within: True
per-session stay proportion correct: mean 0.763, median 0.833, n sessions 61; pooled over trials 0.827 stay trials per session: max 38
Result: reproduced. With 15-trial windows there are 117 stay windows, the paper's count, with mean 0.921 and median 0.933. No session has 40 stay trials, so the 40-trial reading gives no window.
fig1d-heading-switch¶
On switch trials the animals' heading (view angle) shifts from the initial toward the new side after the update cue, while on delay only trials it stays toward the initial side.
View angle is in radians (see the data check). Positive view angle goes with movement toward negative x (the left arm, turn_type 1), as the sign of the correlation above shows, and as the paper's code assumes when it negates view angle on right trials. "Toward the initial side" is therefore a positive angle on turn_type 1 trials and a negative one on turn_type 2 trials.
edges = R[0]["va_edges"]; centers = (edges[:-1] + edges[1:]) / 2
traj = []
for r in R:
tr = r["trials"]
for j, idx in enumerate(r["va_traj_trials"]):
traj.append((r["subject"], tr.loc[idx, "update_type"], tr.loc[idx, "turn_type"], r["va_traj"][j]))
TR = pd.DataFrame(traj, columns=["animal", "update_type", "turn_type", "traj"])
b_update = int(np.digitize(145.125, edges) - 1) # bin of the update cue onset position
b_last = len(centers) - 1 # last central-arm bin before the choice point (y < 255)
res = {}
for tt, sgn in ((1, 1), (2, -1)):
for ut in (1, 2):
A_ = np.stack(TR[(TR.turn_type == tt) & (TR.update_type == ut)].traj.to_numpy())
m = np.nanmean(A_, 0) * sgn # positive = toward the initial side
res[(tt, ut)] = m
print(f"turn_type {tt} {P.TRIAL_TYPES[ut]:10s} n={len(A_)}: toward-initial view angle at update cue bin (y {centers[b_update]:.0f}) "
f"{m[b_update]:+.3f} rad, in last central bin (y {centers[b_last]:.0f}) {m[b_last]:+.3f} rad; range of the trajectory {m.min():+.3f} to {m.max():+.3f}")
ok = all(res[(tt, 2)][b_update] > 0 and res[(tt, 2)][b_last] < 0 and res[(tt, 1)][b_last] > 0 for tt in (1, 2))
print("criterion holds for both sides:", ok)
print("\nper animal, switch trials, toward-initial angle in the last central bin:")
for an, g in TR[TR.update_type == 2].groupby("animal"):
v = [np.nanmean(np.stack(g[g.turn_type == tt].traj.to_numpy()), 0)[b_last] * s for tt, s in ((1, 1), (2, -1)) if (g.turn_type == tt).any()]
print(an, np.round(v, 3))
fig, ax = plt.subplots(1, 2, figsize=(9, 3), sharey=True)
for k, tt in enumerate((1, 2)):
for ut, col in ((1, "k"), (2, "m")):
ax[k].plot(centers, res[(tt, ut)], col, label=P.TRIAL_TYPES[ut])
ax[k].axvline(145.125, ls=":"); ax[k].axhline(0, c="grey", lw=0.5); ax[k].set_title(f"turn_type {tt}"); ax[k].set_xlabel("y position")
ax[0].set_ylabel("view angle toward initial side (rad)"); ax[0].legend(); plt.show()
turn_type 1 delay only n=3618: toward-initial view angle at update cue bin (y 148) +0.200 rad, in last central bin (y 252) +0.197 rad; range of the trajectory +0.000 to +0.201 turn_type 1 switch n=1003: toward-initial view angle at update cue bin (y 148) +0.198 rad, in last central bin (y 252) -0.318 rad; range of the trajectory -0.318 to +0.199 turn_type 2 delay only n=3554: toward-initial view angle at update cue bin (y 148) +0.159 rad, in last central bin (y 252) +0.217 rad; range of the trajectory -0.045 to +0.217 turn_type 2 switch n=837: toward-initial view angle at update cue bin (y 148) +0.183 rad, in last central bin (y 252) -0.154 rad; range of the trajectory -0.154 to +0.188 criterion holds for both sides: True per animal, switch trials, toward-initial angle in the last central bin: S17 [ 0.201 -0.507] S20 [-0.289 -0.188] S25 [-0.318 0.1 ] S28 [-0.237 -0.121] S29 [-0.541 -0.151] S33 [-0.554 -0.167] S34 [-0.028 -0.504]
Result: reproduced. On switch trials the mean view angle points toward the initial side at the update cue position (+0.198 and +0.183 rad for the two sides) and toward the new side in the last central-arm bin (-0.318 and -0.154 rad), while on delay only trials it points toward the initial side there (+0.197 and +0.217 rad). Per animal, 12 of the 14 animal-side means in the last bin point to the new side on switch trials.
Position decoding: shared definitions¶
Encoder from 80% of the final-task delay only trials (S3), decoding of the held-out delay only trials and of all switch and stay trials in 200 ms bins aligned to the update cue (pseudo update on delay only trials; S4, S5). The bins are those of the code's aligned grid (_align_by_times, samples at -2.5, -2.3, ..., -0.1, 0.1, ..., 2.5 s): 26 bins of 0.2 s from -2.6 to 2.6 s whose edges fall on the cue, so no bin straddles it. Windows take bins by centre as the code does (calc_trial_by_trial_quant_data): (lo, hi] after the cue, [lo, hi) before it, so 0 to 1.5 s is the 8 bins centred 0.1 to 1.5 s and -1.5 to 0 s the 8 bins centred -1.5 to -0.1 s (printed below). In round 1 one bin was centred on the cue and counted after it; that grid is kept as a variant (section "Variant: the round-1 time grid"). Sessions are included per region with at least 20 units and at least 50 final-task trials of the session, warm-up trials left out (S1, as a reader amended it on 2026-11-02 in answer to this attempt's question; Methods, Decoding analyses: "less than 50 trials for the behavioral session"). This rule decides (rule="final"). The code's count of the encoder training trials (_meets_exclusion_criteria), which S1 keeps as a named variant, is shown beside every test (rule="train"). The trial counts under each rule are printed against the paper's.
Statistics (S9): a linear mixed model with random intercepts for animal and session within animal, with one predictor combining the grouping factors. The ANOVA is a Wald test of that predictor; statsmodels has no Kenward-Roger degrees of freedom. Pairwise contrasts of the predictor's levels are Tukey-adjusted with the studentized range over all levels, as emmeans pairs() does.
W = dict(init=("init", 0, 1.5), new=("new", 0, 1.5), init_pre=("init", -1.5, 0), new_pre=("new", -1.5, 0),
retro=("retro", 0, 1.5), init05=("init", 0, 0.5), new05=("new", 0, 0.5), init1=("init", 0, 1), new1=("new", 0, 1),
init051=("init", 0.5, 1), new051=("new", 0.5, 1),
init_front=("init_front", 0, 1.5), init_back=("init_back", 0, 1.5), new_front=("new_front", 0, 1.5), new_back=("new_back", 0, 1.5),
init_front_occ=("init_front_occ", 0, 1.5), init_back_occ=("init_back_occ", 0, 1.5), new_front_occ=("new_front_occ", 0, 1.5), new_back_occ=("new_back_occ", 0, 1.5))
TAB = {(reg, rule): P.trial_table(R, reg, W, rule) for reg in ("CA1", "PFC") for rule in ("final", "train")}
for (reg, rule), T in TAB.items():
c = T[T.correct == 1]
print(f"{reg} rule={rule}: {T.session.nunique()} sessions, {T.animal.nunique()} animals; correct trials "
f"{c.type.value_counts().to_dict()}; incorrect {T[T.correct == 0].type.value_counts().to_dict()}")
# the bins each window averages (bin centres, s), and the feature bins of each zone
tms = R[0]["dec"]["CA1"]["times"]
print("bin centres of the update-aligned grid:", tms.tolist())
for name, (zone, lo, hi) in W.items():
if zone in ("init", "retro") or name == "init_front":
print(f" window {lo} to {hi} s: bin centres {tms[P.window_mask(tms, lo, hi)].tolist()}")
zb = pd.DataFrame([{k: str(np.where(r["geo"][k])[0].tolist()) for k in ("left", "right", "left_front", "left_back", "right_front", "right_back",
"left_front_occ", "left_back_occ", "right_front_occ", "right_back_occ", "central", "home_window", "retro", "gap")}
for r in R if "left_front" in r["geo"]])
for k in zb.columns:
print(f" zone {k}: feature bins {zb[k].value_counts().to_dict()} (sessions per configuration)")
print("paper: CA1 1295 switch, 926 delay only, 551 stay correct, 407 incorrect switch, 56 sessions; "
"PFC 1109 switch, 798 delay only, 483 stay correct, 359 incorrect switch, 47 sessions")
def arm_model(T, types, cols=("init", "new"), outcome=(1,), factor="type", name="arm"):
d = T[T.update_type.isin(types) & T.correct.isin(outcome)]
L = P.long_format(d, list(cols), name=name)
L["pred"] = L[factor].astype(str) + "|" + L[name]
return P.lme(L, "value", "pred"), L
def report(res, pairs, label=""):
print(f" {label} ANOVA F({res['df1']}) = {res['F']:.2f}, p = {res['p_anova']:.3g}; n per level {res['n'].to_dict()}")
print(" model means:", res["emm"].round(4).to_dict())
out = {}
for a, b in pairs:
c = P.contrast(res, a, b)
out[(a, b)] = c
ps = f"{c['p_tukey']:.3g}" if c["p_tukey"] > 0 else "< 1e-15 (below the precision of the studentized range)"
print(f" {a} - {b}: estimate {c['estimate']:+.4f}, z = {c['z']:+.2f}, Tukey p = {ps} "
f"(on {c['df_lo']} df: {c['p_tukey_lowdf']:.3g})")
return out
CA1 rule=final: 55 sessions, 7 animals; correct trials {'switch': 1241, 'delay only': 871, 'stay': 530}; incorrect {'switch': 395, 'delay only': 393, 'stay': 105}
CA1 rule=train: 47 sessions, 7 animals; correct trials {'switch': 1158, 'delay only': 825, 'stay': 504}; incorrect {'switch': 366, 'delay only': 358, 'stay': 91}
PFC rule=final: 46 sessions, 7 animals; correct trials {'switch': 1055, 'delay only': 755, 'stay': 461}; incorrect {'switch': 347, 'delay only': 328, 'stay': 87}
PFC rule=train: 37 sessions, 7 animals; correct trials {'switch': 968, 'delay only': 698, 'stay': 425}; incorrect {'switch': 310, 'delay only': 291, 'stay': 74}
bin centres of the update-aligned grid: [-2.5, -2.3, -2.1, -1.9, -1.7, -1.5, -1.3, -1.1, -0.9, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3, 1.5, 1.7, 1.9, 2.1, 2.3, 2.5]
window 0 to 1.5 s: bin centres [0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3, 1.5]
window -1.5 to 0 s: bin centres [-1.5, -1.3, -1.1, -0.9, -0.7, -0.5, -0.3, -0.1]
window 0 to 1.5 s: bin centres [0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3, 1.5]
window 0 to 0.5 s: bin centres [0.1, 0.3, 0.5]
window 0 to 1 s: bin centres [0.1, 0.3, 0.5, 0.7, 0.9]
window 0.5 to 1 s: bin centres [0.7, 0.9]
window 0 to 1.5 s: bin centres [0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3, 1.5]
zone left: feature bins {'[35, 36, 37, 38, 39, 40, 41]': 61} (sessions per configuration)
zone right: feature bins {'[43, 44, 45, 46, 47, 48, 49]': 61} (sessions per configuration)
zone left_front: feature bins {'[35, 36, 37]': 61} (sessions per configuration)
zone left_back: feature bins {'[38, 39, 40, 41]': 61} (sessions per configuration)
zone right_front: feature bins {'[43, 44, 45]': 61} (sessions per configuration)
zone right_back: feature bins {'[46, 47, 48, 49]': 61} (sessions per configuration)
zone left_front_occ: feature bins {'[36, 37, 38]': 61} (sessions per configuration)
zone left_back_occ: feature bins {'[39, 40, 41]': 61} (sessions per configuration)
zone right_front_occ: feature bins {'[44, 45, 46]': 61} (sessions per configuration)
zone right_back_occ: feature bins {'[47, 48, 49]': 61} (sessions per configuration)
zone central: feature bins {'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]': 61} (sessions per configuration)
zone home_window: feature bins {'[15, 16, 17, 18, 19, 20, 21]': 61} (sessions per configuration)
zone retro: feature bins {'[0, 1, 2, 3, 4, 5]': 61} (sessions per configuration)
zone gap: feature bins {'[34, 35, 42, 43]': 61} (sessions per configuration)
paper: CA1 1295 switch, 926 delay only, 551 stay correct, 407 incorrect switch, 56 sessions; PFC 1109 switch, 798 delay only, 483 stay correct, 359 incorrect switch, 47 sessions
tuning-tiles-track¶
Spatial tuning curves of hippocampal and prefrontal neurons tile the virtual track.
for reg, rule in (("CA1", "final"), ("PFC", "final"), ("CA1", "train"), ("PFC", "train")):
peaks = []
for r in R:
if not P.included(r, reg, rule):
continue
d = r["dec"][reg]
peaks += list(d["tc_peak"][d["tc_active"]])
gaps = np.where(r["geo"]["gap"])[0].tolist()
cnt = np.bincount(peaks, minlength=P.N_BINS)
track = [b for b in range(P.N_BINS) if b not in gaps]
empty_track = [b for b in track if cnt[b] == 0]
# longest run of empty bins among the track bins (gap bins between segments excluded)
run, best = 0, 0
for b in range(P.N_BINS):
if b in gaps:
run = 0; continue
run = run + 1 if cnt[b] == 0 else 0; best = max(best, run)
print(f"{reg} rule={rule}: {len(peaks)} units with spikes in the encoder; bins wholly inside the gaps between track segments: {gaps}")
print(f" units peaking per bin: {cnt.tolist()}")
print(f" (a) bins that are no unit's peak: all 50 bins -> {[b for b in range(P.N_BINS) if cnt[b] == 0]}; track bins only -> {empty_track}")
print(f" (b) longest run of empty track bins: {best}; peaks in central arm {int(cnt[:34].sum())}, goal arms {int(cnt[34:].sum())}")
CA1 rule=final: 3404 units with spikes in the encoder; bins wholly inside the gaps between track segments: [34, 35, 42, 43] units peaking per bin: [56, 140, 62, 64, 51, 71, 44, 39, 44, 34, 38, 33, 38, 28, 27, 55, 141, 46, 39, 54, 31, 26, 44, 24, 25, 23, 25, 20, 26, 23, 25, 74, 81, 179, 0, 0, 194, 141, 159, 113, 115, 83, 0, 0, 258, 136, 145, 122, 124, 84] (a) bins that are no unit's peak: all 50 bins -> [34, 35, 42, 43]; track bins only -> [] (b) longest run of empty track bins: 0; peaks in central arm 1730, goal arms 1674 PFC rule=final: 2148 units with spikes in the encoder; bins wholly inside the gaps between track segments: [34, 35, 42, 43] units peaking per bin: [90, 103, 73, 48, 46, 39, 32, 33, 38, 35, 27, 30, 31, 17, 26, 25, 47, 28, 15, 29, 19, 14, 11, 10, 9, 12, 15, 15, 15, 17, 24, 18, 22, 62, 0, 0, 67, 52, 61, 51, 94, 158, 0, 0, 115, 54, 64, 94, 118, 145] (a) bins that are no unit's peak: all 50 bins -> [34, 35, 42, 43]; track bins only -> [] (b) longest run of empty track bins: 0; peaks in central arm 1075, goal arms 1073 CA1 rule=train: 2854 units with spikes in the encoder; bins wholly inside the gaps between track segments: [34, 35, 42, 43] units peaking per bin: [45, 125, 53, 57, 40, 57, 34, 31, 34, 30, 29, 27, 30, 24, 21, 39, 116, 41, 33, 46, 27, 19, 35, 19, 19, 21, 24, 16, 20, 21, 22, 62, 67, 138, 0, 0, 170, 131, 140, 96, 98, 68, 0, 0, 211, 110, 126, 101, 106, 75] (a) bins that are no unit's peak: all 50 bins -> [34, 35, 42, 43]; track bins only -> [] (b) longest run of empty track bins: 0; peaks in central arm 1422, goal arms 1432 PFC rule=train: 1790 units with spikes in the encoder; bins wholly inside the gaps between track segments: [34, 35, 42, 43] units peaking per bin: [80, 81, 62, 36, 40, 34, 30, 26, 28, 32, 22, 23, 27, 12, 21, 21, 35, 21, 13, 25, 16, 11, 10, 8, 7, 9, 12, 13, 12, 14, 21, 16, 17, 46, 0, 0, 55, 43, 44, 40, 81, 140, 0, 0, 96, 48, 51, 81, 100, 130] (a) bins that are no unit's peak: all 50 bins -> [34, 35, 42, 43]; track bins only -> [] (b) longest run of empty track bins: 0; peaks in central arm 881, goal arms 909
Result: reproduced. In both regions every track bin is the peak of at least one unit (CA1 3404 units, PFC 2148 units), and the only bins that are no unit's peak are the four bins lying wholly in the gaps between track segments (34, 35, 42, 43), which hold no position. Peaks fall about equally on the central arm and the goal arms (CA1 1730 and 1674, PFC 1075 and 1073). The code's count of trials gives the same (CA1 2854, PFC 1790 units, no empty track bin).
decoding-validation¶
Hippocampal and prefrontal population activity decodes the animal's current position across the track.
rng = np.random.default_rng(101)
for reg, rule in (("CA1", "final"), ("PFC", "final"), ("CA1", "train"), ("PFC", "train")):
rows, confs = [], []
for r in R:
if not P.included(r, reg, rule):
continue
d = r["dec"][reg]
tb = d["val_occ_bins"]; track = np.unique(tb)
null = np.abs(rng.choice(track, size=len(tb)) - tb)
rows.append(dict(session=r["session"], animal=r["subject"], err_bins=np.median(d["val_err_bins"]), null_bins=np.median(null),
err_units=np.median(d["val_err"]), err_moving=np.median(d["val_err_bins"][d["val_moving"]]),
moving_share=d["val_moving"].mean()))
cf_ = d["val_conf"]; col = cf_.sum(0)
with np.errstate(invalid="ignore"):
confs.append(cf_ / col)
V = pd.DataFrame(rows)
a_ok = (V.err_bins < V.null_bins).mean()
C = np.nanmean(np.stack(confs), 0)
gaps = np.where(R[0]["geo"]["gap"])[0]
occ = np.array([b for b in np.where(np.nansum(C, 0) > 0)[0] if b not in gaps])
near = [abs(int(np.nanargmax(C[:, b])) - b) <= 2 for b in occ]
print(f"{reg} rule={rule}: {len(V)} sessions; median error {V.err_bins.median():.1f} bins ({V.err_units.median():.1f} linearized units), "
f"uniform null {V.null_bins.median():.1f} bins; (a) sessions with error below null: {int((V.err_bins < V.null_bins).sum())} of {len(V)} ({a_ok:.2f})")
print(f" (b) occupied track bins (gap bins excluded) whose session-averaged confusion column peaks within 2 bins: {sum(near)} of {len(occ)} ({np.mean(near):.2f})")
print(f" variant, moving bins only (as the encoder): median error {V.err_moving.median():.1f} bins; sessions below the null: "
f"{int((V.err_moving < V.null_bins).sum())} of {len(V)}; share of bins moving: median {V.moving_share.median():.2f}")
print(" per animal median error (bins):", V.groupby("animal").err_bins.median().to_dict())
CA1 rule=final: 55 sessions; median error 9.0 bins (67.6 linearized units), uniform null 16.0 bins; (a) sessions with error below null: 52 of 55 (0.95)
(b) occupied track bins (gap bins excluded) whose session-averaged confusion column peaks within 2 bins: 37 of 46 (0.80)
variant, moving bins only (as the encoder): median error 9.0 bins; sessions below the null: 52 of 55; share of bins moving: median 0.97
per animal median error (bins): {'S17': 9.0, 'S20': 7.0, 'S25': 10.0, 'S28': 10.0, 'S29': 9.0, 'S33': 8.5, 'S34': 12.0}
PFC rule=final: 46 sessions; median error 7.0 bins (55.3 linearized units), uniform null 16.0 bins; (a) sessions with error below null: 46 of 46 (1.00)
(b) occupied track bins (gap bins excluded) whose session-averaged confusion column peaks within 2 bins: 35 of 46 (0.76)
variant, moving bins only (as the encoder): median error 7.0 bins; sessions below the null: 46 of 46; share of bins moving: median 0.97
per animal median error (bins): {'S17': 6.0, 'S20': 5.0, 'S25': 8.0, 'S28': 6.0, 'S29': 6.0, 'S33': 8.0, 'S34': 9.25}
CA1 rule=train: 47 sessions; median error 9.0 bins (66.7 linearized units), uniform null 16.0 bins; (a) sessions with error below null: 44 of 47 (0.94)
(b) occupied track bins (gap bins excluded) whose session-averaged confusion column peaks within 2 bins: 36 of 46 (0.78)
variant, moving bins only (as the encoder): median error 9.0 bins; sessions below the null: 44 of 47; share of bins moving: median 0.97
per animal median error (bins): {'S17': 8.5, 'S20': 7.0, 'S25': 10.0, 'S28': 10.0, 'S29': 9.0, 'S33': 8.0, 'S34': 12.0}
PFC rule=train: 37 sessions; median error 7.0 bins (49.4 linearized units), uniform null 16.0 bins; (a) sessions with error below null: 37 of 37 (1.00)
(b) occupied track bins (gap bins excluded) whose session-averaged confusion column peaks within 2 bins: 41 of 46 (0.89)
variant, moving bins only (as the encoder): median error 7.0 bins; sessions below the null: 37 of 37; share of bins moving: median 0.97
per animal median error (bins): {'S17': 4.0, 'S20': 4.5, 'S25': 8.0, 'S28': 6.0, 'S29': 5.5, 'S33': 8.0, 'S34': 9.25}
Result: reproduced. On held-out delay only trials, the median error is below the uniform null in 52 of 55 CA1 sessions and 46 of 46 PFC sessions (median 9 and 7 bins against 16), and the session-averaged confusion matrix peaks within 2 bins of the true bin in 37 of 46 track bins for CA1 and 35 of 46 for PFC. Both readings hold for both regions, and under the code's count of trials too (44 of 47 and 37 of 37 sessions; 36 and 41 of 46 bins). Scoring only the bins where the animal moves, as the encoder uses, changes nothing (median 9 and 7 bins; 52 of 55 and 46 of 46 sessions); 97% of bins are moving bins (median over sessions). The error is lowest with the position at the same time, not 2 s earlier or later, in 52 of 55 CA1 and 43 of 46 PFC sessions (data check).
fig2e-hpc-goal-increase¶
After the update cue, hippocampal decoding of both the initial and the new goal arm is higher on switch than on delay only trials.
pairs = [("switch|init", "delay only|init"), ("switch|new", "delay only|new")]
for rule in ("final", "train"):
T = TAB[("CA1", rule)]
for lab, types in (("(a) switch and delay only", [1, 2]), ("(b) with stay", [1, 2, 3])):
print(f"rule={rule} {lab}")
res, L = arm_model(T, types)
report(res, pairs)
c = TAB[("CA1", "final")]; c = c[c.correct == 1]
print("\ntrial means (rule=final):", c.groupby("type")[["init", "new"]].mean().round(4).to_dict())
print("per animal, switch minus delay only (init, new):")
g = c.groupby(["animal", "type"])[["init", "new"]].mean().unstack()
print((g.xs("switch", axis=1, level=1) - g.xs("delay only", axis=1, level=1)).round(3))
rule=final (a) switch and delay only
ANOVA F(3) = 33.64, p = 9.88e-22; n per level {'delay only|init': 871, 'delay only|new': 871, 'switch|init': 1241, 'switch|new': 1241}
model means: {'delay only|init': 0.0893, 'delay only|new': 0.0964, 'switch|init': 0.1286, 'switch|new': 0.1318}
switch|init - delay only|init: estimate +0.0393, z = +7.47, Tukey p = 2.35e-12 (on 51 df: 5.87e-09)
switch|new - delay only|new: estimate +0.0354, z = +6.74, Tukey p = 1.05e-10 (on 51 df: 8.47e-08)
rule=final (b) with stay
ANOVA F(5) = 23.34, p = 1.56e-23; n per level {'delay only|init': 871, 'delay only|new': 871, 'stay|init': 530, 'stay|new': 530, 'switch|init': 1241, 'switch|new': 1241}
model means: {'delay only|init': 0.0891, 'delay only|new': 0.0962, 'stay|init': 0.0973, 'stay|new': 0.1113, 'switch|init': 0.1285, 'switch|new': 0.1317}
switch|init - delay only|init: estimate +0.0394, z = +7.65, Tukey p = 6.73e-13 (on 49 df: 9.6e-09)
switch|new - delay only|new: estimate +0.0356, z = +6.90, Tukey p = 8.1e-11 (on 49 df: 1.38e-07)
rule=train (a) switch and delay only
ANOVA F(3) = 34.87, p = 1.59e-22; n per level {'delay only|init': 825, 'delay only|new': 825, 'switch|init': 1158, 'switch|new': 1158}
model means: {'delay only|init': 0.0883, 'delay only|new': 0.0967, 'switch|init': 0.1305, 'switch|new': 0.1331}
switch|init - delay only|init: estimate +0.0423, z = +7.76, Tukey p = 1.88e-12 (on 43 df: 6.19e-09)
switch|new - delay only|new: estimate +0.0364, z = +6.69, Tukey p = 1.45e-10 (on 43 df: 2.16e-07)
rule=train (b) with stay
ANOVA F(5) = 24.88, p = 3.64e-25; n per level {'delay only|init': 825, 'delay only|new': 825, 'stay|init': 504, 'stay|new': 504, 'switch|init': 1158, 'switch|new': 1158}
model means: {'delay only|init': 0.0874, 'delay only|new': 0.0958, 'stay|init': 0.0944, 'stay|new': 0.1127, 'switch|init': 0.1298, 'switch|new': 0.1324}
switch|init - delay only|init: estimate +0.0425, z = +7.98, Tukey p = 3.78e-13 (on 41 df: 1.05e-08)
switch|new - delay only|new: estimate +0.0366, z = +6.88, Tukey p = 9.42e-11 (on 41 df: 3.52e-07)
trial means (rule=final): {'init': {'delay only': 0.0934, 'stay': 0.1011, 'switch': 0.1318}, 'new': {'delay only': 0.1004, 'stay': 0.1151, 'switch': 0.135}}
per animal, switch minus delay only (init, new):
init new
animal
S17 -0.012 -0.008
S20 0.036 0.050
S25 0.065 0.015
S28 0.121 0.063
S29 -0.004 0.035
S33 -0.015 -0.012
S34 0.016 0.080
Result: reproduced. Under both readings of the model and both inclusion rules, the ANOVA and both switch against delay only contrasts give p < 2e-10 with switch higher (Methods' count of trials, reading a: ANOVA p = 9.9e-22; initial +0.039, z = 7.47, Tukey p = 2.4e-12; new +0.035, z = 6.74, p = 1.1e-10). The trial means (switch initial 0.132 and new 0.135, delay only 0.093 and 0.100) are all within tolerance of 0.13, 0.14, 0.10 and 0.11. There are 1241 switch and 871 delay only correct trials in 55 sessions, against the paper's 1295 and 926 in 56. The increase holds in 4 of 7 animals for the initial arm and 5 of 7 for the new arm. On the round-1 grid (variant below) the contrasts give p = 2.7e-12 and 1.8e-7.
fig2e-hpc-arms-equal¶
Within trials, hippocampal decoding of the initial and the new arm after the update cue does not differ: the initial minus new difference is not different from zero and does not differ between switch and delay only trials.
def diff_tests(T, types=(1, 2), cols=("init", "new"), outcome=(1,)):
d = T[T.update_type.isin(types) & T.correct.isin(outcome)].copy()
d["diff"] = d[cols[0]] - d[cols[1]]
res = P.lme(d, "diff", "type")
print(f" LME diff ~ trial type: F({res['df1']}) = {res['F']:.2f}, p = {res['p_anova']:.3g}; means {res['emm'].round(4).to_dict()}")
out = dict(p_lme=res["p_anova"])
for ut in types:
s = d[d.update_type == ut].groupby("session")["diff"].mean()
w = stats.wilcoxon(s)
print(f" {P.TRIAL_TYPES[ut]}: trial mean diff {d[d.update_type == ut]['diff'].mean():+.4f} (n={int((d.update_type == ut).sum())}); "
f"per-session Wilcoxon W = {w.statistic:.0f}, p = {w.pvalue:.3g}, n = {len(s)} sessions")
out[ut] = (d[d.update_type == ut]["diff"].mean(), w.pvalue)
return out
for rule in ("final", "train"):
print("rule =", rule); diff_tests(TAB[("CA1", rule)])
rule = final
LME diff ~ trial type: F(1) = 0.30, p = 0.586; means {'delay only': -0.0083, 'switch': -0.0042}
delay only: trial mean diff -0.0071 (n=871); per-session Wilcoxon W = 658, p = 0.348, n = 55 sessions
switch: trial mean diff -0.0032 (n=1241); per-session Wilcoxon W = 667, p = 0.388, n = 55 sessions
rule = train
LME diff ~ trial type: F(1) = 0.64, p = 0.424; means {'delay only': -0.0111, 'switch': -0.005}
delay only: trial mean diff -0.0084 (n=825); per-session Wilcoxon W = 414, p = 0.114, n = 47 sessions
switch: trial mean diff -0.0025 (n=1158); per-session Wilcoxon W = 476, p = 0.358, n = 47 sessions
Result: reproduced. The LME on the initial minus new difference gives p = 0.59 (p = 0.42 with the code's count of trials), and the per-session Wilcoxon tests over 55 sessions give p = 0.35 (delay only, mean -0.0071) and p = 0.39 (switch, mean -0.0032); none is below 0.05. Both means are within tolerance of -0.01. The round-1 grid gives p = 0.17, 0.27 and 0.44.
sfig2e-goal-bias¶
Within single 200 ms bins hippocampal goal decoding is strongly biased to one arm (43% of bins highly biased), yet within a trial both arms are represented (70% of trials have a mean goal bias index between -0.5 and 0.5).
for rule, lo, hi, lab in (("final", 0, 1.5, "(a) 0 to 1.5 s"), ("final", 0, 2.5, "(b) 0 to 2.5 s"), ("train", 0, 1.5, "(a) 0 to 1.5 s"), ("train", 0, 2.5, "(b) 0 to 2.5 s")):
bins_all, trial_means, n_tr = [], [], 0
for r in R:
if not P.included(r, "CA1", rule):
continue
d = r["dec"]["CA1"]; m = (d["update_type"] == 2) & (d["correct"] == 1)
tm = P.window_mask(d["times"], lo, hi)
I, N = d["zones"]["init"][m][:, tm], d["zones"]["new"][m][:, tm]
with np.errstate(invalid="ignore", divide="ignore"):
g = (N - I) / (N + I)
bins_all.append(g.ravel()); trial_means.append(np.nanmean(g, 1)); n_tr += m.sum()
b = np.concatenate(bins_all); b = b[np.isfinite(b)]; tmn = np.concatenate(trial_means); tmn = tmn[np.isfinite(tmn)]
f1 = np.mean(np.abs(b) > 0.93); f2 = np.mean(np.abs(tmn) <= 0.5)
print(f"rule={rule} {lab}: {n_tr} correct switch trials, {int(P.window_mask(d['times'], lo, hi).sum())} bins per trial, {len(b)} bins; fraction of bins |index| > 0.93: {f1:.3f} (expected 0.43 +/- 0.043); "
f"fraction of trials with mean index in [-0.5, 0.5]: {f2:.3f} (expected 0.70 +/- 0.07); both within: {abs(f1-0.43)<=0.043 and abs(f2-0.7)<=0.07}")
rule=final (a) 0 to 1.5 s: 1241 correct switch trials, 8 bins per trial, 9928 bins; fraction of bins |index| > 0.93: 0.465 (expected 0.43 +/- 0.043); fraction of trials with mean index in [-0.5, 0.5]: 0.648 (expected 0.70 +/- 0.07); both within: True rule=final (b) 0 to 2.5 s: 1241 correct switch trials, 13 bins per trial, 16133 bins; fraction of bins |index| > 0.93: 0.461 (expected 0.43 +/- 0.043); fraction of trials with mean index in [-0.5, 0.5]: 0.704 (expected 0.70 +/- 0.07); both within: True rule=train (a) 0 to 1.5 s: 1158 correct switch trials, 8 bins per trial, 9264 bins; fraction of bins |index| > 0.93: 0.459 (expected 0.43 +/- 0.043); fraction of trials with mean index in [-0.5, 0.5]: 0.649 (expected 0.70 +/- 0.07); both within: True rule=train (b) 0 to 2.5 s: 1158 correct switch trials, 13 bins per trial, 15054 bins; fraction of bins |index| > 0.93: 0.459 (expected 0.43 +/- 0.043); fraction of trials with mean index in [-0.5, 0.5]: 0.708 (expected 0.70 +/- 0.07); both within: True
Result: reproduced. Over 0 to 1.5 s (reading a, 8 bins per trial), 46.5% of bins of 1241 correct switch trials have an index beyond +/-0.93 and 64.8% of trials have a mean index between -0.5 and 0.5; over 0 to 2.5 s (13 bins), 46.1% and 70.4%. Both readings are within tolerance, as they are under the code's count of trials (45.9% and 64.9%; 45.9% and 70.8%).
sfig3c-goals-over-retrospective¶
On switch trials after the update cue, both goal arms are decoded more than retrospective non-local positions at the start of the track.
for rule in ("final", "train"):
T = TAB[("CA1", rule)]
res, L = arm_model(T, [2], cols=("retro", "init", "new"))
print("rule =", rule)
report(res, [("switch|init", "switch|retro"), ("switch|new", "switch|retro")])
c = TAB[("CA1", "final")]; c = c[(c.correct == 1) & (c.update_type == 2)]
print("trial means (rule=final):", c[["retro", "init", "new"]].mean().round(4).to_dict(), "expected 0.12, 0.13, 0.14")
rule = final
ANOVA F(2) = 0.77, p = 0.461; n per level {'switch|init': 1241, 'switch|new': 1241, 'switch|retro': 1241}
model means: {'switch|init': 0.1263, 'switch|new': 0.1295, 'switch|retro': 0.1236}
switch|init - switch|retro: estimate +0.0027, z = +0.56, Tukey p = 0.839 (on 52 df: 0.839)
switch|new - switch|retro: estimate +0.0059, z = +1.24, Tukey p = 0.428 (on 52 df: 0.434)
rule = train
ANOVA F(2) = 1.54, p = 0.214; n per level {'switch|init': 1158, 'switch|new': 1158, 'switch|retro': 1158}
model means: {'switch|init': 0.1257, 'switch|new': 0.1282, 'switch|retro': 0.1198}
switch|init - switch|retro: estimate +0.0059, z = +1.19, Tukey p = 0.458 (on 44 df: 0.464)
switch|new - switch|retro: estimate +0.0084, z = +1.71, Tukey p = 0.201 (on 44 df: 0.212)
trial means (rule=final): {'retro': 0.1291, 'init': 0.1318, 'new': 0.135} expected 0.12, 0.13, 0.14
Result: not reproduced. On correct switch trials the goal arms exceed the retrospective zone only slightly and not significantly: initial minus retrospective +0.003 (Tukey p = 0.84), new minus retrospective +0.006 (p = 0.43); the ANOVA gives p = 0.46. With the code's count of trials p = 0.46 and 0.20, and on the round-1 grid p = 0.37 and 0.36. The trial means (retrospective 0.129, initial 0.132, new 0.135) are each within tolerance of the paper's 0.12, 0.13 and 0.14.
sfig3c-retrospective-unchanged¶
Retrospective non-local decoding after the update cue does not differ between switch and delay only trials.
for rule in ("final", "train"):
T = TAB[("CA1", rule)]
res, L = arm_model(T, [1, 2], cols=("retro", "init", "new"))
print("rule =", rule)
report(res, [("switch|retro", "delay only|retro")])
rule = final
ANOVA F(5) = 24.19, p = 2e-24; n per level {'delay only|init': 871, 'delay only|new': 871, 'delay only|retro': 871, 'switch|init': 1241, 'switch|new': 1241, 'switch|retro': 1241}
model means: {'delay only|init': 0.0899, 'delay only|new': 0.097, 'delay only|retro': 0.1116, 'switch|init': 0.1292, 'switch|new': 0.1324, 'switch|retro': 0.1265}
switch|retro - delay only|retro: estimate +0.0149, z = +2.96, Tukey p = 0.0359 (on 49 df: 0.0501)
rule = train
ANOVA F(5) = 24.68, p = 6.03e-25; n per level {'delay only|init': 825, 'delay only|new': 825, 'delay only|retro': 825, 'switch|init': 1158, 'switch|new': 1158, 'switch|retro': 1158}
model means: {'delay only|init': 0.0878, 'delay only|new': 0.0962, 'delay only|retro': 0.1116, 'switch|init': 0.1303, 'switch|new': 0.1328, 'switch|retro': 0.1244}
switch|retro - delay only|retro: estimate +0.0128, z = +2.46, Tukey p = 0.136 (on 41 df: 0.16)
Result: not reproduced. The retrospective zone is decoded more on switch than on delay only trials (+0.015, Tukey p = 0.036), below 0.05, so the paper's test finds a difference. The outcome depends on the time grid and on the inclusion rule: the code's count of trials gives +0.013, p = 0.14, and the round-1 grid, with one bin centred on the cue, gave +0.013, p = 0.12 (variant below). The degrees of freedom matter here too: on 49 degrees of freedom (sessions less levels, a deliberately small value in place of Kenward-Roger) the same contrast gives p = 0.050.
sfig3ab-original-vs-update-cue¶
Goal arm decoding also rises during the original cue, but then favours the back half of the goal arms, while after the update cue it favours the front half.
The original cue is aligned at trial start, 0 to 1.5 s after it (code start_time with no time before it). Each goal arm's bins are split as the code splits them (quantify_aligned_data): of an arm's n bins, front ends round(n / 2) bins before the arm's end and rearhalf starts n // 2 bins after its start, the front toward the choice point (lower linearized positions). The code's arm bins include a gap bin next to each arm, where the posterior is NaN; the same split over the bins with a posterior is shown as a variant. The bins of each zone are printed in the shared definitions.
for rule, suf in (("final", ""), ("train", ""), ("final", "_occ")):
Ts = P.trial_table(R, "CA1", W, rule, source="start"); Tu = TAB[("CA1", rule)]
cols = [z + suf for z in ("init_front", "init_back", "new_front", "new_back")]
Ts = Ts[(Ts.update_type == 2) & (Ts.correct == 1)].assign(cue="original"); Tu = Tu[(Tu.update_type == 2) & (Tu.correct == 1)].assign(cue="update")
Lc = P.long_format(pd.concat([Ts, Tu], ignore_index=True)[["animal", "session", "trial", "cue"] + cols], cols, name="zone")
Lc["pred"] = Lc.cue + "|" + Lc.zone
res = P.lme(Lc, "value", "pred")
print(f"rule = {rule}, halves {'of the occupied arm bins (variant)' if suf else 'as the code'}: original cue trials {len(Ts)}, update cue trials {len(Tu)} (paper 1264 and 1295)")
report(res, [(f"original|{z}", f"update|{z}") for z in cols[1::2] + cols[0::2]])
if rule == "final":
means = pd.concat([Ts[cols].mean().rename("original"), Tu[cols].mean().rename("update")], axis=1).round(4)
print(means)
rule = final, halves as the code: original cue trials 1241, update cue trials 1241 (paper 1264 and 1295)
ANOVA F(7) = 184.61, p = 7.88e-275; n per level {'original|init_back': 1241, 'original|init_front': 1241, 'original|new_back': 1241, 'original|new_front': 1241, 'update|init_back': 1241, 'update|init_front': 1241, 'update|new_back': 1241, 'update|new_front': 1241}
model means: {'original|init_back': 0.1206, 'original|init_front': 0.0344, 'original|new_back': 0.1233, 'original|new_front': 0.0387, 'update|init_back': 0.0879, 'update|init_front': 0.0446, 'update|new_back': 0.0855, 'update|new_front': 0.0503}
original|init_back - update|init_back: estimate +0.0326, z = +8.67, Tukey p = < 1e-15 (below the precision of the studentized range) (on 47 df: 7.15e-10)
original|new_back - update|new_back: estimate +0.0378, z = +10.04, Tukey p = < 1e-15 (below the precision of the studentized range) (on 47 df: 7.73e-12)
original|init_front - update|init_front: estimate -0.0102, z = -2.71, Tukey p = 0.118 (on 47 df: 0.144)
original|new_front - update|new_front: estimate -0.0116, z = -3.08, Tukey p = 0.0439 (on 47 df: 0.0633)
original update
init_front 0.0340 0.0442
init_back 0.1202 0.0876
new_front 0.0383 0.0499
new_back 0.1229 0.0851
rule = train, halves as the code: original cue trials 1158, update cue trials 1158 (paper 1264 and 1295)
ANOVA F(7) = 162.54, p = 1.98e-241; n per level {'original|init_back': 1158, 'original|init_front': 1158, 'original|new_back': 1158, 'original|new_front': 1158, 'update|init_back': 1158, 'update|init_front': 1158, 'update|new_back': 1158, 'update|new_front': 1158}
model means: {'original|init_back': 0.1133, 'original|init_front': 0.0324, 'original|new_back': 0.118, 'original|new_front': 0.0366, 'update|init_back': 0.0881, 'update|init_front': 0.0417, 'update|new_back': 0.0849, 'update|new_front': 0.0475}
original|init_back - update|init_back: estimate +0.0252, z = +6.50, Tukey p = 2.33e-09 (on 39 df: 2.76e-06)
original|new_back - update|new_back: estimate +0.0331, z = +8.54, Tukey p = < 1e-15 (below the precision of the studentized range) (on 39 df: 5.03e-09)
original|init_front - update|init_front: estimate -0.0093, z = -2.39, Tukey p = 0.244 (on 39 df: 0.273)
original|new_front - update|new_front: estimate -0.0109, z = -2.82, Tukey p = 0.0911 (on 39 df: 0.12)
rule = final, halves of the occupied arm bins (variant): original cue trials 1241, update cue trials 1241 (paper 1264 and 1295)
ANOVA F(7) = 59.36, p = 1.1e-85; n per level {'original|init_back_occ': 1241, 'original|init_front_occ': 1241, 'original|new_back_occ': 1241, 'original|new_front_occ': 1241, 'update|init_back_occ': 1241, 'update|init_front_occ': 1241, 'update|new_back_occ': 1241, 'update|new_front_occ': 1241}
model means: {'original|init_back_occ': 0.103, 'original|init_front_occ': 0.0519, 'original|new_back_occ': 0.1065, 'original|new_front_occ': 0.0555, 'update|init_back_occ': 0.0702, 'update|init_front_occ': 0.0624, 'update|new_back_occ': 0.0653, 'update|new_front_occ': 0.0705}
original|init_back_occ - update|init_back_occ: estimate +0.0329, z = +8.70, Tukey p = < 1e-15 (below the precision of the studentized range) (on 47 df: 6.38e-10)
original|new_back_occ - update|new_back_occ: estimate +0.0412, z = +10.92, Tukey p = < 1e-15 (below the precision of the studentized range) (on 47 df: 4.79e-13)
original|init_front_occ - update|init_front_occ: estimate -0.0104, z = -2.76, Tukey p = 0.105 (on 47 df: 0.13)
original|new_front_occ - update|new_front_occ: estimate -0.0150, z = -3.97, Tukey p = 0.00186 (on 47 df: 0.00555)
original update
init_front_occ 0.0516 0.0620
init_back_occ 0.1027 0.0698
new_front_occ 0.0551 0.0701
new_back_occ 0.1061 0.0649
Result: partially reproduced. With the arm halves split as the code splits them (feature bins 35 to 37 and 43 to 45 front, 38 to 41 and 46 to 49 back), the back halves of both arms are decoded more during the original cue than after the update cue (initial +0.033, z = 8.67; new +0.038, z = 10.04; Tukey p below the method's precision). The front halves are higher after the update cue, significantly for the new arm (-0.012, p = 0.044) but not for the initial arm (-0.010, p = 0.12), so three of the four contrasts hold. The code's count of trials gives front half p = 0.24 and 0.091. The code's front halves hold a gap bin (35, 43) with no posterior; split over the arm bins that have one (36 to 38 and 44 to 46 front, 39 to 41 and 47 to 49 back), the variant gives the same three of four (front: initial p = 0.10, new p = 0.0019), and its eight values (front 0.052, 0.062, 0.055, 0.070; back 0.103, 0.070, 0.106, 0.065) are all within tolerance, where those of the code's split are not (front 0.034 to 0.050 against 0.05 to 0.07; back 0.120 and 0.123 during the original cue against 0.10 and 0.11, 0.088 and 0.085 after the update cue against 0.07). There are 1241 trials per cue (paper 1264 and 1295). The new arm front contrast also depends on the degrees of freedom: on 47 (sessions less levels, a deliberately small value) it gives p = 0.063, and the variant split's p = 0.0019 gives 0.0056.
sfig2f-all-trials-encoder¶
With all trial types in the encoding model, the increase of hippocampal goal arm decoding after the update cue on switch trials remains similar.
for rule in ("final", "train"):
for k, lab in (("a", "(a) encoder from all trials, all decoded"), ("b", "(b) encoder from 80% of all types, held-out 20% decoded")):
rows = []
for r in R:
if not P.included(r, "CA1", rule) or "allenc" not in r:
continue
d = r["allenc"][k]
rows.append(pd.DataFrame(dict(animal=r["subject"], session=r["session"], update_type=d["update_type"], correct=d["correct"],
init=P.window_mean(d["init"], d["times"], 0, 1.5), new=P.window_mean(d["new"], d["times"], 0, 1.5))))
T2 = pd.concat(rows, ignore_index=True); T2["type"] = T2.update_type.map(P.TRIAL_TYPES)
for outc, olab in (((1,), "(c) correct"), ((0, 1), "(d) all outcomes")):
n = T2[T2.correct.isin(outc)].type.value_counts().to_dict()
print(f"rule={rule} {lab} {olab}: trials {n} (paper 1322 switch, 4538 delay only)")
res, L = arm_model(T2, [1, 2], outcome=outc)
report(res, [("switch|init", "delay only|init"), ("switch|new", "delay only|new")])
rule=final (a) encoder from all trials, all decoded (c) correct: trials {'delay only': 4225, 'switch': 1241, 'stay': 530} (paper 1322 switch, 4538 delay only)
ANOVA F(3) = 24.67, p = 5.92e-16; n per level {'delay only|init': 4225, 'delay only|new': 4225, 'switch|init': 1241, 'switch|new': 1241}
model means: {'delay only|init': 0.1015, 'delay only|new': 0.1009, 'switch|init': 0.1143, 'switch|new': 0.1269}
switch|init - delay only|init: estimate +0.0128, z = +3.78, Tukey p = 0.000903 (on 51 df: 0.00226)
switch|new - delay only|new: estimate +0.0260, z = +7.68, Tukey p = 1.93e-12 (on 51 df: 2.78e-09)
rule=final (a) encoder from all trials, all decoded (d) all outcomes: trials {'delay only': 6234, 'switch': 1636, 'stay': 635} (paper 1322 switch, 4538 delay only)
ANOVA F(3) = 17.90, p = 1.29e-11; n per level {'delay only|init': 6234, 'delay only|new': 6234, 'switch|init': 1636, 'switch|new': 1636}
model means: {'delay only|init': 0.1038, 'delay only|new': 0.1072, 'switch|init': 0.1177, 'switch|new': 0.1226}
switch|init - delay only|init: estimate +0.0139, z = +4.70, Tukey p = 1.6e-05 (on 51 df: 0.000118)
switch|new - delay only|new: estimate +0.0154, z = +5.23, Tukey p = 1.04e-06 (on 51 df: 1.88e-05)
rule=final (b) encoder from 80% of all types, held-out 20% decoded (c) correct: trials {'delay only': 848, 'switch': 269, 'stay': 114} (paper 1322 switch, 4538 delay only)
ANOVA F(3) = 8.92, p = 6.65e-06; n per level {'delay only|init': 848, 'delay only|new': 848, 'switch|init': 269, 'switch|new': 269}
model means: {'delay only|init': 0.1076, 'delay only|new': 0.1022, 'switch|init': 0.1191, 'switch|new': 0.1405}
switch|init - delay only|init: estimate +0.0116, z = +1.50, Tukey p = 0.435 (on 51 df: 0.443)
switch|new - delay only|new: estimate +0.0383, z = +4.98, Tukey p = 3.8e-06 (on 51 df: 4.4e-05)
rule=final (b) encoder from 80% of all types, held-out 20% decoded (d) all outcomes: trials {'delay only': 1253, 'switch': 339, 'stay': 134} (paper 1322 switch, 4538 delay only)
ANOVA F(3) = 8.33, p = 1.54e-05; n per level {'delay only|init': 1253, 'delay only|new': 1253, 'switch|init': 339, 'switch|new': 339}
model means: {'delay only|init': 0.1096, 'delay only|new': 0.1069, 'switch|init': 0.1231, 'switch|new': 0.1385}
switch|init - delay only|init: estimate +0.0135, z = +1.98, Tukey p = 0.194 (on 51 df: 0.207)
switch|new - delay only|new: estimate +0.0316, z = +4.63, Tukey p = 2.22e-05 (on 51 df: 0.000148)
rule=train (a) encoder from all trials, all decoded (c) correct: trials {'delay only': 3979, 'switch': 1158, 'stay': 504} (paper 1322 switch, 4538 delay only)
ANOVA F(3) = 26.58, p = 3.47e-17; n per level {'delay only|init': 3979, 'delay only|new': 3979, 'switch|init': 1158, 'switch|new': 1158}
model means: {'delay only|init': 0.1009, 'delay only|new': 0.1017, 'switch|init': 0.116, 'switch|new': 0.1285}
switch|init - delay only|init: estimate +0.0151, z = +4.32, Tukey p = 9.13e-05 (on 43 df: 0.000503)
switch|new - delay only|new: estimate +0.0268, z = +7.69, Tukey p = 1.92e-12 (on 43 df: 7.8e-09)
rule=train (a) encoder from all trials, all decoded (d) all outcomes: trials {'delay only': 5842, 'switch': 1524, 'stay': 595} (paper 1322 switch, 4538 delay only)
ANOVA F(3) = 21.58, p = 5.71e-14; n per level {'delay only|init': 5842, 'delay only|new': 5842, 'switch|init': 1524, 'switch|new': 1524}
model means: {'delay only|init': 0.1019, 'delay only|new': 0.106, 'switch|init': 0.1181, 'switch|new': 0.1228}
switch|init - delay only|init: estimate +0.0162, z = +5.33, Tukey p = 5.95e-07 (on 43 df: 1.97e-05)
switch|new - delay only|new: estimate +0.0169, z = +5.56, Tukey p = 1.67e-07 (on 43 df: 9.32e-06)
rule=train (b) encoder from 80% of all types, held-out 20% decoded (c) correct: trials {'delay only': 797, 'switch': 255, 'stay': 107} (paper 1322 switch, 4538 delay only)
ANOVA F(3) = 8.31, p = 1.6e-05; n per level {'delay only|init': 797, 'delay only|new': 797, 'switch|init': 255, 'switch|new': 255}
model means: {'delay only|init': 0.1068, 'delay only|new': 0.1041, 'switch|init': 0.1202, 'switch|new': 0.1413}
switch|init - delay only|init: estimate +0.0134, z = +1.69, Tukey p = 0.328 (on 43 df: 0.34)
switch|new - delay only|new: estimate +0.0372, z = +4.69, Tukey p = 1.62e-05 (on 43 df: 0.000157)
rule=train (b) encoder from 80% of all types, held-out 20% decoded (d) all outcomes: trials {'delay only': 1168, 'switch': 319, 'stay': 126} (paper 1322 switch, 4538 delay only)
ANOVA F(3) = 8.61, p = 1.03e-05; n per level {'delay only|init': 1168, 'delay only|new': 1168, 'switch|init': 319, 'switch|new': 319}
model means: {'delay only|init': 0.1072, 'delay only|new': 0.1075, 'switch|init': 0.1245, 'switch|new': 0.1386}
switch|init - delay only|init: estimate +0.0173, z = +2.46, Tukey p = 0.0658 (on 43 df: 0.0803)
switch|new - delay only|new: estimate +0.0310, z = +4.43, Tukey p = 5.74e-05 (on 43 df: 0.000365)
Result: partially reproduced. With the encoder built from all trials and every trial decoded (reading a), both arms are higher on switch than on delay only trials for correct trials (initial +0.013, Tukey p = 9.0e-4; new +0.026, p = 1.9e-12) and for all outcomes (p = 1.6e-5 and 1.0e-6). With an 80/20 split of all trial types (reading b), only the new arm differs (p = 3.8e-6; all outcomes p = 2.2e-5); the initial arm does not (p = 0.44; all outcomes p = 0.19). The criterion asks for every reading, so the claim holds in part. The code's count of trials gives the same pattern (reading b, initial arm p = 0.33 and 0.066). Reading (a) has 1241 switch and 4225 delay only correct trials, closer to the paper's 1322 and 4538 than reading (b) (269 and 848).
sfig5f-pfc-wider-spread¶
Decoded position distributions are spatially wider in prefrontal cortex than in CA1.
Sessions with at least 20 units in each region; the region with more units is subsampled at random to the other's count (seeded per session), and both are decoded with the same encoder trials. Spread per bin follows the paper's code (plot_region_error_distribution, checked at the pinned commit: the outermost bins at or above the peak minus one standard deviation, before and after the peak); bins where the animal is at or past 120.35, delay only test trials of both outcomes. The verifier read the Methods' "how far in front and behind of the peak value the decoding results dropped below this threshold" as the first crossing on each side; that reading is shown as a variant.
def equal_table(rule):
rows = []
for r in R:
if "equal" not in r or (r["n_train"] if rule == "train" else len(r["trials"])) < P.MIN_TRIALS:
continue
for reg in ("CA1", "PFC"):
d = r["equal"][reg]
sp = np.where(d["pos"] >= 120.35, d["spread"], np.nan)
with np.errstate(all="ignore"):
rows.append(pd.DataFrame(dict(animal=r["subject"], session=r["session"], region=reg, update_type=d["update_type"],
correct=d["correct"], spread=np.nanmean(sp, 1),
spread_first=np.nanmean(np.where(d["pos"] >= 120.35, d["spread_first"], np.nan), 1),
init_pre=P.window_mean(d["init"], d["times"], -2, 0),
new_pre=P.window_mean(d["new"], d["times"], -2, 0), n_units=d["n_units"])))
return pd.concat(rows, ignore_index=True)
binw = np.diff(R[0]["geo"]["edges"])[0]
for rule in ("final", "train"):
E = equal_table(rule)
d = E[E.update_type == 1].dropna(subset=["spread"])
res = P.lme(d, "spread", "region")
m = d.groupby("region").spread.mean()
print(f"rule={rule}: {d.session.nunique()} sessions, units per region per session {E.groupby('session').n_units.first().min()} to {E.groupby('session').n_units.first().max()}, "
f"trials per region {d.groupby('region').size().to_dict()} (paper 829 trials)")
print(f" (a) feature bins: CA1 {m['CA1']:.3f}, PFC {m['PFC']:.3f} (expected 2.4 +/- 0.25, 3.13 +/- 0.27); LME region p = {res['p_anova']:.3g}, PFC - CA1 = {res['emm']['PFC'] - res['emm']['CA1']:+.3f}")
print(f" (b) linearized units (bin width {binw:.2f}): CA1 {m['CA1'] * binw:.2f}, PFC {m['PFC'] * binw:.2f}")
rf = P.lme(d.dropna(subset=["spread_first"]), "spread_first", "region"); mf = d.groupby("region").spread_first.mean()
print(f" variant, first crossing on each side of the peak (Methods wording): CA1 {mf['CA1']:.3f}, PFC {mf['PFC']:.3f} bins; "
f"LME region p = {rf['p_anova']:.3g}, PFC - CA1 = {rf['emm']['PFC'] - rf['emm']['CA1']:+.3f}")
if rule == "final":
print(" per animal (CA1, PFC):", d.groupby(["animal", "region"]).spread.mean().unstack().round(2).to_dict("index"))
rule=final: 42 sessions, units per region per session 20 to 86, trials per region {'CA1': 1026, 'PFC': 1026} (paper 829 trials)
(a) feature bins: CA1 4.073, PFC 4.367 (expected 2.4 +/- 0.25, 3.13 +/- 0.27); LME region p = 0.00313, PFC - CA1 = +0.294
(b) linearized units (bin width 7.50): CA1 30.55, PFC 32.76
variant, first crossing on each side of the peak (Methods wording): CA1 0.142, PFC 0.365 bins; LME region p = 1.75e-122, PFC - CA1 = +0.222
per animal (CA1, PFC): {'S17': {'CA1': 2.41, 'PFC': 2.69}, 'S20': {'CA1': 4.07, 'PFC': 3.85}, 'S25': {'CA1': 5.3, 'PFC': 5.89}, 'S28': {'CA1': 3.31, 'PFC': 3.45}, 'S29': {'CA1': 3.38, 'PFC': 2.55}, 'S33': {'CA1': 5.65, 'PFC': 6.67}, 'S34': {'CA1': 3.89, 'PFC': 6.85}}
rule=train: 36 sessions, units per region per session 20 to 86, trials per region {'CA1': 966, 'PFC': 966} (paper 829 trials)
(a) feature bins: CA1 4.048, PFC 4.441 (expected 2.4 +/- 0.25, 3.13 +/- 0.27); LME region p = 0.000132, PFC - CA1 = +0.393
(b) linearized units (bin width 7.50): CA1 30.36, PFC 33.31
variant, first crossing on each side of the peak (Methods wording): CA1 0.147, PFC 0.378 bins; LME region p = 2.62e-119, PFC - CA1 = +0.231
Result: partially reproduced. With equal cell numbers in 42 sessions (1026 delay only trials per region), PFC spread exceeds CA1 under the code's rule (4.37 against 4.07 feature bins, LME p = 0.0031), but both values are outside the tolerances of the paper's 3.13 and 2.4 bins. PFC exceeds CA1 in 5 of 7 animals. The code's count of trials (36 sessions) gives 4.44 against 4.05, p = 1.3e-4. The first-crossing reading of the Methods' wording also gives PFC wider (0.37 against 0.14 bins, p = 1.8e-122), with values much further from the paper's: at that threshold the run of bins around the peak is mostly the peak alone. Both readings give the same outcome.
sfig5g-ca1-more-goal-coding¶
Before the update cue, goal arms are decoded more strongly from CA1 than from prefrontal cortex.
for rule in ("final", "train"):
E = equal_table(rule)
d = E[(E.update_type == 1) & (E.correct == 1)]
L = P.long_format(d[["animal", "session", "region", "init_pre", "new_pre"]], ["init_pre", "new_pre"], name="arm")
L["pred"] = L.region + "|" + L.arm
res = P.lme(L, "value", "pred")
print(f"rule={rule}: correct delay only trials per region {d.groupby('region').size().to_dict()} (paper 364)")
report(res, [("CA1|init_pre", "PFC|init_pre"), ("CA1|new_pre", "PFC|new_pre")])
print(" trial means:", d.groupby("region")[["init_pre", "new_pre"]].mean().round(4).to_dict("index"),
"(expected PFC init 0.06, CA1 new 0.11, PFC new 0.05)")
rule=final: correct delay only trials per region {'CA1': 717, 'PFC': 717} (paper 364)
ANOVA F(3) = 129.36, p = 8.4e-84; n per level {'CA1|init_pre': 717, 'CA1|new_pre': 717, 'PFC|init_pre': 717, 'PFC|new_pre': 717}
model means: {'CA1|init_pre': 0.1069, 'CA1|new_pre': 0.1089, 'PFC|init_pre': 0.0503, 'PFC|new_pre': 0.048}
CA1|init_pre - PFC|init_pre: estimate +0.0566, z = +13.40, Tukey p = 1.83e-12 (on 38 df: 0)
CA1|new_pre - PFC|new_pre: estimate +0.0610, z = +14.44, Tukey p = 1.83e-12 (on 38 df: 0)
trial means: {'CA1': {'init_pre': 0.1076, 'new_pre': 0.1096}, 'PFC': {'init_pre': 0.051, 'new_pre': 0.0487}} (expected PFC init 0.06, CA1 new 0.11, PFC new 0.05)
rule=train: correct delay only trials per region {'CA1': 682, 'PFC': 682} (paper 364)
ANOVA F(3) = 120.54, p = 4.57e-78; n per level {'CA1|init_pre': 682, 'CA1|new_pre': 682, 'PFC|init_pre': 682, 'PFC|new_pre': 682}
model means: {'CA1|init_pre': 0.1072, 'CA1|new_pre': 0.1089, 'PFC|init_pre': 0.0514, 'PFC|new_pre': 0.0477}
CA1|init_pre - PFC|init_pre: estimate +0.0558, z = +12.81, Tukey p = 1.83e-12 (on 32 df: 2.29e-13)
CA1|new_pre - PFC|new_pre: estimate +0.0612, z = +14.05, Tukey p = 1.83e-12 (on 32 df: 1.95e-14)
trial means: {'CA1': {'init_pre': 0.108, 'new_pre': 0.1096}, 'PFC': {'init_pre': 0.0522, 'new_pre': 0.0485}} (expected PFC init 0.06, CA1 new 0.11, PFC new 0.05)
Result: reproduced. Before the pseudo update time (-2 to 0 s), CA1 decodes both arms more than PFC with equal cell numbers (initial +0.057, z = 13.4; new +0.061, z = 14.4; Tukey p at the method's precision floor; 717 trials per region, paper 364). The PFC initial (0.051), CA1 new (0.110) and PFC new (0.049) means are within tolerance. The code's count of trials gives the same (z = 12.8 and 14.1).
fig2g-pfc-no-goal-increase¶
Prefrontal position decoding of the goal arms after the update cue does not differ between switch and delay only trials, and the two arms are represented equally.
pairs = [("switch|init", "delay only|init"), ("switch|new", "delay only|new")]
for rule in ("final", "train"):
T = TAB[("PFC", rule)]
for lab, types in (("(a) switch and delay only", [1, 2]), ("(b) with stay", [1, 2, 3])):
print(f"rule={rule} {lab}")
res, L = arm_model(T, types)
report(res, pairs)
print(f"rule={rule} within-trial difference")
diff_tests(T)
c = TAB[("PFC", "final")]; c = c[c.correct == 1]
print("\ntrial means (rule=final):", c.groupby("type")[["init", "new"]].mean().round(4).to_dict(), "expected switch 0.07/0.07, delay only 0.06/0.06")
rule=final (a) switch and delay only
ANOVA F(3) = 3.41, p = 0.0168; n per level {'delay only|init': 755, 'delay only|new': 755, 'switch|init': 1055, 'switch|new': 1055}
model means: {'delay only|init': 0.0646, 'delay only|new': 0.0608, 'switch|init': 0.07, 'switch|new': 0.0739}
switch|init - delay only|init: estimate +0.0054, z = +1.22, Tukey p = 0.611 (on 42 df: 0.615)
switch|new - delay only|new: estimate +0.0131, z = +2.97, Tukey p = 0.0157 (on 42 df: 0.0242)
rule=final (b) with stay
ANOVA F(5) = 2.56, p = 0.0253; n per level {'delay only|init': 755, 'delay only|new': 755, 'stay|init': 461, 'stay|new': 461, 'switch|init': 1055, 'switch|new': 1055}
model means: {'delay only|init': 0.0649, 'delay only|new': 0.0611, 'stay|init': 0.0633, 'stay|new': 0.0635, 'switch|init': 0.0702, 'switch|new': 0.0742}
switch|init - delay only|init: estimate +0.0054, z = +1.24, Tukey p = 0.817 (on 40 df: 0.815)
switch|new - delay only|new: estimate +0.0131, z = +3.02, Tukey p = 0.0301 (on 40 df: 0.0464)
rule=final within-trial difference
LME diff ~ trial type: F(1) = 2.37, p = 0.123; means {'delay only': 0.0004, 'switch': -0.0083}
delay only: trial mean diff +0.0037 (n=755); per-session Wilcoxon W = 451, p = 0.334, n = 46 sessions
switch: trial mean diff -0.0040 (n=1055); per-session Wilcoxon W = 365, p = 0.0553, n = 46 sessions
rule=train (a) switch and delay only
ANOVA F(3) = 3.37, p = 0.0178; n per level {'delay only|init': 698, 'delay only|new': 698, 'switch|init': 968, 'switch|new': 968}
model means: {'delay only|init': 0.0648, 'delay only|new': 0.0612, 'switch|init': 0.0714, 'switch|new': 0.0747}
switch|init - delay only|init: estimate +0.0066, z = +1.42, Tukey p = 0.49 (on 33 df: 0.499)
switch|new - delay only|new: estimate +0.0134, z = +2.87, Tukey p = 0.0213 (on 33 df: 0.034)
rule=train (b) with stay
ANOVA F(5) = 2.52, p = 0.0277; n per level {'delay only|init': 698, 'delay only|new': 698, 'stay|init': 425, 'stay|new': 425, 'switch|init': 968, 'switch|new': 968}
model means: {'delay only|init': 0.0652, 'delay only|new': 0.0617, 'stay|init': 0.0636, 'stay|new': 0.0647, 'switch|init': 0.0718, 'switch|new': 0.075}
switch|init - delay only|init: estimate +0.0066, z = +1.44, Tukey p = 0.703 (on 31 df: 0.704)
switch|new - delay only|new: estimate +0.0134, z = +2.93, Tukey p = 0.0401 (on 31 df: 0.0637)
rule=train within-trial difference
LME diff ~ trial type: F(1) = 1.92, p = 0.165; means {'delay only': 0.0031, 'switch': -0.0052}
delay only: trial mean diff +0.0035 (n=698); per-session Wilcoxon W = 316, p = 0.602, n = 37 sessions
switch: trial mean diff -0.0033 (n=968); per-session Wilcoxon W = 218, p = 0.0439, n = 37 sessions
trial means (rule=final): {'init': {'delay only': 0.0657, 'stay': 0.0659, 'switch': 0.0691}, 'new': {'delay only': 0.062, 'stay': 0.0662, 'switch': 0.073}} expected switch 0.07/0.07, delay only 0.06/0.06
Result: not reproduced. In reading (a), switch and delay only trials in the model, the new arm is higher on switch than on delay only trials (+0.013, Tukey p = 0.016) and the ANOVA gives p = 0.017. In reading (b), with stay trials, the new arm contrast (p = 0.030) and the ANOVA (p = 0.025) are also below 0.05, so the outcome no longer depends on the reading. The initial arm contrasts (p = 0.61 and 0.82), the LME on the within-trial difference (p = 0.12) and the per-session Wilcoxon tests over 46 sessions (switch p = 0.055, delay only p = 0.33) are not significant. The effect is small, and the trial means (switch 0.069 and 0.073, delay only 0.066 and 0.062) are all within tolerance of the paper's. With the code's count of trials (37 sessions), reading (a) gives new arm p = 0.021 and ANOVA p = 0.018, and the switch Wilcoxon p = 0.044. On the round-1 grid reading (a) gave p = 0.035 and 0.038 and reading (b) none below 0.05 (new arm p = 0.066).
sfig5e-pfc-windows¶
Prefrontal goal arm decoding on switch and delay only trials does not differ in shorter windows after the update cue either.
for rule in ("final", "train"):
T = TAB[("PFC", rule)]
for a, b, lab in (("init05", "new05", "0 to 0.5 s"), ("init1", "new1", "0 to 1 s"), ("init", "new", "0 to 1.5 s"), ("init051", "new051", "0.5 to 1 s")):
res, L = arm_model(T, [1, 2], cols=(a, b))
print(f"rule={rule} window {lab}")
report(res, [(f"switch|{a}", f"delay only|{a}"), (f"switch|{b}", f"delay only|{b}")])
rule=final window 0 to 0.5 s
ANOVA F(3) = 1.28, p = 0.28; n per level {'delay only|init05': 755, 'delay only|new05': 755, 'switch|init05': 1055, 'switch|new05': 1055}
model means: {'delay only|init05': 0.064, 'delay only|new05': 0.0569, 'switch|init05': 0.0645, 'switch|new05': 0.0669}
switch|init05 - delay only|init05: estimate +0.0005, z = +0.09, Tukey p = 1 (on 42 df: 1)
switch|new05 - delay only|new05: estimate +0.0099, z = +1.91, Tukey p = 0.225 (on 42 df: 0.241)
rule=final window 0 to 1 s
ANOVA F(3) = 2.49, p = 0.0586; n per level {'delay only|init1': 755, 'delay only|new1': 755, 'switch|init1': 1055, 'switch|new1': 1055}
model means: {'delay only|init1': 0.0657, 'delay only|new1': 0.0586, 'switch|init1': 0.0671, 'switch|new1': 0.0717}
switch|init1 - delay only|init1: estimate +0.0014, z = +0.30, Tukey p = 0.991 (on 42 df: 0.99)
switch|new1 - delay only|new1: estimate +0.0131, z = +2.72, Tukey p = 0.0331 (on 42 df: 0.0449)
rule=final window 0 to 1.5 s
ANOVA F(3) = 3.41, p = 0.0168; n per level {'delay only|init': 755, 'delay only|new': 755, 'switch|init': 1055, 'switch|new': 1055}
model means: {'delay only|init': 0.0646, 'delay only|new': 0.0608, 'switch|init': 0.07, 'switch|new': 0.0739}
switch|init - delay only|init: estimate +0.0054, z = +1.22, Tukey p = 0.611 (on 42 df: 0.615)
switch|new - delay only|new: estimate +0.0131, z = +2.97, Tukey p = 0.0157 (on 42 df: 0.0242)
rule=final window 0.5 to 1 s
ANOVA F(3) = 2.65, p = 0.0473; n per level {'delay only|init051': 755, 'delay only|new051': 755, 'switch|init051': 1055, 'switch|new051': 1055}
model means: {'delay only|init051': 0.0681, 'delay only|new051': 0.061, 'switch|init051': 0.071, 'switch|new051': 0.079}
switch|init051 - delay only|init051: estimate +0.0029, z = +0.45, Tukey p = 0.97 (on 42 df: 0.969)
switch|new051 - delay only|new051: estimate +0.0180, z = +2.76, Tukey p = 0.0292 (on 42 df: 0.0405)
rule=train window 0 to 0.5 s
ANOVA F(3) = 0.96, p = 0.411; n per level {'delay only|init05': 698, 'delay only|new05': 698, 'switch|init05': 968, 'switch|new05': 968}
model means: {'delay only|init05': 0.0624, 'delay only|new05': 0.0555, 'switch|init05': 0.0615, 'switch|new05': 0.0645}
switch|init05 - delay only|init05: estimate -0.0010, z = -0.18, Tukey p = 0.998 (on 33 df: 0.998)
switch|new05 - delay only|new05: estimate +0.0090, z = +1.66, Tukey p = 0.347 (on 33 df: 0.362)
rule=train window 0 to 1 s
ANOVA F(3) = 2.37, p = 0.0684; n per level {'delay only|init1': 698, 'delay only|new1': 698, 'switch|init1': 968, 'switch|new1': 968}
model means: {'delay only|init1': 0.0651, 'delay only|new1': 0.058, 'switch|init1': 0.0668, 'switch|new1': 0.0715}
switch|init1 - delay only|init1: estimate +0.0016, z = +0.32, Tukey p = 0.988 (on 33 df: 0.988)
switch|new1 - delay only|new1: estimate +0.0135, z = +2.65, Tukey p = 0.04 (on 33 df: 0.0563)
rule=train window 0 to 1.5 s
ANOVA F(3) = 3.37, p = 0.0178; n per level {'delay only|init': 698, 'delay only|new': 698, 'switch|init': 968, 'switch|new': 968}
model means: {'delay only|init': 0.0648, 'delay only|new': 0.0612, 'switch|init': 0.0714, 'switch|new': 0.0747}
switch|init - delay only|init: estimate +0.0066, z = +1.42, Tukey p = 0.49 (on 33 df: 0.499)
switch|new - delay only|new: estimate +0.0134, z = +2.87, Tukey p = 0.0213 (on 33 df: 0.034)
rule=train window 0.5 to 1 s
ANOVA F(3) = 3.11, p = 0.0253; n per level {'delay only|init051': 698, 'delay only|new051': 698, 'switch|init051': 968, 'switch|new051': 968}
model means: {'delay only|init051': 0.0693, 'delay only|new051': 0.0616, 'switch|init051': 0.0749, 'switch|new051': 0.082}
switch|init051 - delay only|init051: estimate +0.0056, z = +0.81, Tukey p = 0.849 (on 33 df: 0.848)
switch|new051 - delay only|new051: estimate +0.0204, z = +2.95, Tukey p = 0.0167 (on 33 df: 0.0281)
Result: not reproduced. The new arm is higher on switch than on delay only trials over 0 to 1 s (+0.013, Tukey p = 0.033), 0.5 to 1 s (+0.018, p = 0.029) and 0 to 1.5 s (+0.013, p = 0.016); only 0 to 0.5 s gives no difference (new arm p = 0.23, initial arm p = 1.0). The code's count of trials gives the same pattern (p = 0.040, 0.017 and 0.021; 0 to 0.5 s p = 0.35), and so does the round-1 grid (p = 0.019, 0.024 and 0.035). No initial arm contrast is significant.
fig5d-stay-hpc-like-delay¶
Hippocampal goal arm decoding after the second cue on stay trials does not differ from delay only trials.
STAY = {}
for rule in ("final", "train"):
T = TAB[("CA1", rule)]
res, L = arm_model(T, [1, 2, 3])
print(f"rule={rule}")
STAY[rule] = report(res, [("stay|init", "delay only|init"), ("stay|new", "delay only|new"), ("stay|init", "switch|init"), ("stay|new", "switch|new")])
c = TAB[("CA1", "final")]; c = c[(c.correct == 1) & (c.update_type == 3)]
print("stay trial means (rule=final): init %.4f, new %.4f (expected 0.10, 0.12)" % (c.init.mean(), c.new.mean()))
rule=final
ANOVA F(5) = 23.34, p = 1.56e-23; n per level {'delay only|init': 871, 'delay only|new': 871, 'stay|init': 530, 'stay|new': 530, 'switch|init': 1241, 'switch|new': 1241}
model means: {'delay only|init': 0.0891, 'delay only|new': 0.0962, 'stay|init': 0.0973, 'stay|new': 0.1113, 'switch|init': 0.1285, 'switch|new': 0.1317}
stay|init - delay only|init: estimate +0.0082, z = +1.28, Tukey p = 0.794 (on 49 df: 0.792)
stay|new - delay only|new: estimate +0.0152, z = +2.37, Tukey p = 0.168 (on 49 df: 0.188)
stay|init - switch|init: estimate -0.0312, z = -5.18, Tukey p = 3.45e-06 (on 49 df: 5.98e-05)
stay|new - switch|new: estimate -0.0204, z = -3.38, Tukey p = 0.00935 (on 49 df: 0.0167)
rule=train
ANOVA F(5) = 24.88, p = 3.64e-25; n per level {'delay only|init': 825, 'delay only|new': 825, 'stay|init': 504, 'stay|new': 504, 'switch|init': 1158, 'switch|new': 1158}
model means: {'delay only|init': 0.0874, 'delay only|new': 0.0958, 'stay|init': 0.0944, 'stay|new': 0.1127, 'switch|init': 0.1298, 'switch|new': 0.1324}
stay|init - delay only|init: estimate +0.0070, z = +1.07, Tukey p = 0.895 (on 41 df: 0.892)
stay|new - delay only|new: estimate +0.0170, z = +2.58, Tukey p = 0.103 (on 41 df: 0.127)
stay|init - switch|init: estimate -0.0354, z = -5.70, Tukey p = 1.81e-07 (on 41 df: 1.63e-05)
stay|new - switch|new: estimate -0.0197, z = -3.16, Tukey p = 0.0194 (on 41 df: 0.0324)
stay trial means (rule=final): init 0.1011, new 0.1151 (expected 0.10, 0.12)
Result: reproduced. Neither arm on stay trials differs from delay only trials: initial +0.008 (Tukey p = 0.79), new +0.015 (p = 0.17). The stay means (0.101 and 0.115) are within tolerance of 0.10 and 0.12; there are 530 correct stay trials (paper 551). The code's count of trials gives p = 0.90 and 0.10, and the round-1 grid gave p = 0.85 and 0.063.
fig5d-stay-hpc-below-switch¶
Hippocampal goal arm decoding after the second cue is lower on stay trials than on switch trials.
The model is the one fitted for fig5d-stay-hpc-like-delay; its stay against switch contrasts are printed there and repeated here.
for rule in ("final", "train"):
for k in [("stay|init", "switch|init"), ("stay|new", "switch|new")]:
c = STAY[rule][k]
print(f"rule={rule} {k[0]} - {k[1]}: estimate {c['estimate']:+.4f}, z = {c['z']:+.2f}, Tukey p = {c['p_tukey']:.3g}")
rule=final stay|init - switch|init: estimate -0.0312, z = -5.18, Tukey p = 3.45e-06 rule=final stay|new - switch|new: estimate -0.0204, z = -3.38, Tukey p = 0.00935 rule=train stay|init - switch|init: estimate -0.0354, z = -5.70, Tukey p = 1.81e-07 rule=train stay|new - switch|new: estimate -0.0197, z = -3.16, Tukey p = 0.0194
Result: reproduced. Both arms are lower on stay than on switch trials: initial -0.031 (Tukey p = 3.5e-6), new -0.020 (p = 0.0094); with the code's count of trials p = 1.8e-7 and 0.019. On the round-1 grid the new arm contrast was not significant (-0.012, p = 0.38), so the new arm part depends on the grid.
sfig10-stay-transient-new-arm¶
In the first 0.5 s after the stay cue, hippocampal decoding of the new arm is transiently higher on stay than on delay only trials, with no difference for the initial arm.
for rule in ("final", "train"):
T = TAB[("CA1", rule)]
res, L = arm_model(T, [1, 2, 3], cols=("init05", "new05"))
print(f"rule={rule}")
report(res, [("stay|new05", "delay only|new05"), ("stay|init05", "delay only|init05")])
c = TAB[("CA1", "final")]; c = c[c.correct == 1]
print("trial means 0 to 0.5 s (rule=final):", c.groupby("type")[["init05", "new05"]].mean().round(4).to_dict(),
"(expected stay new 0.13, delay only new 0.11, stay init 0.09)")
rule=final
ANOVA F(5) = 13.53, p = 3.18e-13; n per level {'delay only|init05': 871, 'delay only|new05': 871, 'stay|init05': 530, 'stay|new05': 530, 'switch|init05': 1241, 'switch|new05': 1241}
model means: {'delay only|init05': 0.0849, 'delay only|new05': 0.0885, 'stay|init05': 0.093, 'stay|new05': 0.1186, 'switch|init05': 0.1268, 'switch|new05': 0.1214}
stay|new05 - delay only|new05: estimate +0.0301, z = +3.55, Tukey p = 0.00524 (on 49 df: 0.0106)
stay|init05 - delay only|init05: estimate +0.0081, z = +0.96, Tukey p = 0.931 (on 49 df: 0.928)
rule=train
ANOVA F(5) = 14.67, p = 2.07e-14; n per level {'delay only|init05': 825, 'delay only|new05': 825, 'stay|init05': 504, 'stay|new05': 504, 'switch|init05': 1158, 'switch|new05': 1158}
model means: {'delay only|init05': 0.0838, 'delay only|new05': 0.0882, 'stay|init05': 0.0892, 'stay|new05': 0.1205, 'switch|init05': 0.1279, 'switch|new05': 0.1231}
stay|new05 - delay only|new05: estimate +0.0324, z = +3.70, Tukey p = 0.00297 (on 41 df: 0.0078)
stay|init05 - delay only|init05: estimate +0.0053, z = +0.61, Tukey p = 0.99 (on 41 df: 0.99)
trial means 0 to 0.5 s (rule=final): {'init05': {'delay only': 0.0903, 'stay': 0.0983, 'switch': 0.1308}, 'new05': {'delay only': 0.094, 'stay': 0.124, 'switch': 0.1254}} (expected stay new 0.13, delay only new 0.11, stay init 0.09)
Result: reproduced. Over 0 to 0.5 s (bins centred 0.1, 0.3 and 0.5 s) the new arm is higher on stay than on delay only trials (+0.030, Tukey p = 0.0052; p = 0.0030 with the code's count of trials) and the initial arm does not differ (p = 0.93). The stay new arm (0.124) and stay initial arm (0.098) means are within tolerance; the delay only new arm mean (0.094) is below the tolerance of 0.11 +/- 0.011. The round-1 grid gave +0.024, p = 0.037.
Residual goal codes (GLM)¶
Methods, "Generalized linear model (GLM) analysis": one GLM per goal representation (initial, new) with rotational and translational velocity as predictors and the integrated goal probability as response, fitted on the 200 ms bins over 2.5 s before and after the update cue "across all trial types and animals"; the Pearson residuals are the residual goal codes. The family is Poisson, as in the paper's code (get_residuals, statsmodels GLM). Rotational velocity is mirrored with the decoding (S5), so that its sign is relative to the initial side. The code's variant fits the GLM per session on the switch trials of the comparison; it is shown and does not decide.
import statsmodels.api as sm
def bin_table(reg, rule="final", RR=None):
rows = []
for r in (R if RR is None else RR):
if not P.included(r, reg, rule):
continue
d = r["dec"][reg]; n, k = d["zones"]["init"].shape
sgn = np.where(d["turn_type"] == 1, 1.0, -1.0)[:, None]
rows.append(pd.DataFrame(dict(animal=r["subject"], session=r["session"], trial=np.repeat(d["trial"], k),
update_type=np.repeat(d["update_type"], k), correct=np.repeat(d["correct"], k),
t=np.tile(d["times"], n), init=d["zones"]["init"].ravel(), new=d["zones"]["new"].ravel(),
rot=(d["rot"] * sgn).ravel(), trans=d["trans"].ravel())))
return pd.concat(rows, ignore_index=True)
def residuals(B, by_session=False, types=(1, 2, 3)):
B = B[B.update_type.isin(types)].dropna(subset=["init", "new", "rot", "trans"]).copy()
for arm in ("init", "new"):
B[arm + "_res"] = np.nan
groups = B.groupby("session") if by_session else [("all", B)]
for _, g in groups:
X = sm.add_constant(g[["rot", "trans"]].to_numpy())
with warnings.catch_warnings():
warnings.simplefilter("ignore")
f = sm.GLM(g[arm].to_numpy(), X, family=sm.families.Poisson()).fit()
B.loc[g.index, arm + "_res"] = f.resid_pearson
return B
def resid_trials(B, lo, hi):
w = B[P.window_mask(B.t.to_numpy(), lo, hi)]
T = w.groupby(["animal", "session", "trial", "update_type", "correct"])[["init_res", "new_res"]].mean().reset_index()
T["outcome"] = np.where(T.correct == 1, "correct", "incorrect")
return T
def outcome_model(T, ut, label):
d = T[T.update_type == ut]
L = P.long_format(d, ["init_res", "new_res"], name="arm"); L["pred"] = L.outcome + "|" + L.arm
res = P.lme(L, "value", "pred")
print(f" {label}: trials {d.outcome.value_counts().to_dict()}")
out = report(res, [("correct|new_res", "incorrect|new_res"), ("correct|init_res", "incorrect|init_res")])
d = d.assign(diff=d.init_res - d.new_res)
rd = P.lme(d, "diff", "outcome")
print(f" initial minus new by outcome: F = {rd['F']:.2f}, p = {rd['p_anova']:.3g}; means {rd['emm'].round(4).to_dict()}")
print(" trial means:", d.groupby("outcome")[["init_res", "new_res"]].mean().round(4).to_dict("index"))
out["diff_p"] = rd["p_anova"]
return out
BC = bin_table("CA1")
BCt = bin_table("CA1", "train")
GLM = {"methods": residuals(BC), "code": residuals(BC, by_session=True, types=(2,)), "methods, rule=train": residuals(BCt)}
GLMd = {"code": residuals(BC, by_session=True, types=(1,))}
print("CA1 bins:", len(BC), "; trials:", BC.groupby(["session", "trial"]).ngroups, "; sessions:", BC.session.nunique())
print("rule=train variant: CA1 bins:", len(BCt), "; trials:", BCt.groupby(["session", "trial"]).ngroups, "; sessions:", BCt.session.nunique())
CA1 bins: 91910 ; trials: 3535 ; sessions: 55 rule=train variant: CA1 bins: 85852 ; trials: 3302 ; sessions: 47
fig6b-hpc-new-lower-incorrect¶
On incorrect switch trials, hippocampal new goal arm decoding after the update cue is less elevated than on correct trials, after accounting for speed and rotation.
G6 = {}
for k, B in GLM.items():
print(f"GLM {k} ({'decides' if k == 'methods' else 'variant'}), 0 to 1.5 s")
G6[(k, "post")] = outcome_model(resid_trials(B, 0, 1.5), 2, "switch trials")
GLM methods (decides), 0 to 1.5 s
switch trials: trials {'correct': 1241, 'incorrect': 395}
ANOVA F(3) = 7.12, p = 8.88e-05; n per level {'correct|init_res': 1241, 'correct|new_res': 1241, 'incorrect|init_res': 395, 'incorrect|new_res': 395}
model means: {'correct|init_res': 0.0567, 'correct|new_res': 0.0485, 'incorrect|init_res': 0.0159, 'incorrect|new_res': -0.0354}
correct|new_res - incorrect|new_res: estimate +0.0838, z = +4.00, Tukey p = 0.000372 (on 51 df: 0.00115)
correct|init_res - incorrect|init_res: estimate +0.0409, z = +1.95, Tukey p = 0.208 (on 51 df: 0.221)
initial minus new by outcome: F = 0.26, p = 0.607; means {'correct': 0.0072, 'incorrect': 0.0226}
trial means: {'correct': {'init_res': 0.0815, 'new_res': 0.0733}, 'incorrect': {'init_res': 0.0631, 'new_res': 0.0118}}
GLM code (variant), 0 to 1.5 s
switch trials: trials {'correct': 1241, 'incorrect': 395}
ANOVA F(3) = 5.74, p = 0.000636; n per level {'correct|init_res': 1241, 'correct|new_res': 1241, 'incorrect|init_res': 395, 'incorrect|new_res': 395}
model means: {'correct|init_res': 0.0507, 'correct|new_res': 0.0577, 'incorrect|init_res': 0.0153, 'incorrect|new_res': -0.0143}
correct|new_res - incorrect|new_res: estimate +0.0720, z = +3.77, Tukey p = 0.000945 (on 51 df: 0.00234)
correct|init_res - incorrect|init_res: estimate +0.0353, z = +1.85, Tukey p = 0.25 (on 51 df: 0.263)
initial minus new by outcome: F = 0.77, p = 0.38; means {'correct': -0.0107, 'incorrect': 0.0137}
trial means: {'correct': {'init_res': 0.0573, 'new_res': 0.0644}, 'incorrect': {'init_res': 0.0286, 'new_res': -0.001}}
GLM methods, rule=train (variant), 0 to 1.5 s
switch trials: trials {'correct': 1158, 'incorrect': 366}
ANOVA F(3) = 7.27, p = 7.18e-05; n per level {'correct|init_res': 1158, 'correct|new_res': 1158, 'incorrect|init_res': 366, 'incorrect|new_res': 366}
model means: {'correct|init_res': 0.0589, 'correct|new_res': 0.0423, 'incorrect|init_res': 0.0138, 'incorrect|new_res': -0.0399}
correct|new_res - incorrect|new_res: estimate +0.0822, z = +3.78, Tukey p = 0.000913 (on 43 df: 0.00262)
correct|init_res - incorrect|init_res: estimate +0.0451, z = +2.07, Tukey p = 0.162 (on 43 df: 0.178)
initial minus new by outcome: F = 0.04, p = 0.839; means {'correct': 0.0119, 'incorrect': 0.0183}
trial means: {'correct': {'init_res': 0.0891, 'new_res': 0.0725}, 'incorrect': {'init_res': 0.066, 'new_res': 0.0124}}
Result: reproduced. With the Methods' GLM, the new arm residual is higher on correct than incorrect switch trials (+0.084, Tukey p = 3.7e-4; ANOVA p = 8.9e-5; 1241 correct and 395 incorrect trials), and the trial means (correct 0.073, incorrect 0.012) are within tolerance of 0.06 and 0.0. The code's per-session GLM gives the same (p = 9.5e-4), and so does the code's count of trials (p = 9.1e-4).
fig6b-hpc-initial-no-difference¶
Hippocampal initial goal arm decoding after the update cue does not differ between correct and incorrect switch trials.
The test is the initial arm contrast of the model above.
for k in GLM:
c = G6[(k, "post")][("correct|init_res", "incorrect|init_res")]
print(f"GLM {k}: correct - incorrect, initial arm residual: {c['estimate']:+.4f}, z = {c['z']:+.2f}, Tukey p = {c['p_tukey']:.3g}")
GLM methods: correct - incorrect, initial arm residual: +0.0409, z = +1.95, Tukey p = 0.208 GLM code: correct - incorrect, initial arm residual: +0.0353, z = +1.85, Tukey p = 0.25 GLM methods, rule=train: correct - incorrect, initial arm residual: +0.0451, z = +2.07, Tukey p = 0.162
Result: reproduced. With the Methods' GLM the initial arm residual does not differ between correct and incorrect switch trials (+0.041, Tukey p = 0.21). The code's per-session GLM, a variant, gives p = 0.25, and the code's count of trials p = 0.16.
fig6-hpc-pre-cue-initial-higher-incorrect¶
Before the update cue, hippocampal initial goal arm decoding is higher on incorrect than on correct switch trials, beyond motor differences.
for k, B in GLM.items():
print(f"GLM {k}, -1.5 to 0 s")
G6[(k, "pre")] = outcome_model(resid_trials(B, -1.5, 0), 2, "switch trials")
GLM methods, -1.5 to 0 s
switch trials: trials {'correct': 1241, 'incorrect': 395}
ANOVA F(3) = 6.29, p = 0.000292; n per level {'correct|init_res': 1241, 'correct|new_res': 1241, 'incorrect|init_res': 395, 'incorrect|new_res': 395}
model means: {'correct|init_res': -0.0468, 'correct|new_res': -0.0427, 'incorrect|init_res': 0.0199, 'incorrect|new_res': -0.055}
correct|new_res - incorrect|new_res: estimate +0.0123, z = +0.73, Tukey p = 0.884 (on 51 df: 0.884)
correct|init_res - incorrect|init_res: estimate -0.0668, z = -3.97, Tukey p = 0.000429 (on 51 df: 0.00127)
initial minus new by outcome: F = 12.67, p = 0.000371; means {'correct': -0.0041, 'incorrect': 0.0827}
trial means: {'correct': {'init_res': -0.0478, 'new_res': -0.0436}, 'incorrect': {'init_res': 0.0277, 'new_res': -0.0473}}
GLM code, -1.5 to 0 s
switch trials: trials {'correct': 1241, 'incorrect': 395}
ANOVA F(3) = 2.77, p = 0.0399; n per level {'correct|init_res': 1241, 'correct|new_res': 1241, 'incorrect|init_res': 395, 'incorrect|new_res': 395}
model means: {'correct|init_res': -0.0429, 'correct|new_res': -0.0334, 'incorrect|init_res': -0.0079, 'incorrect|new_res': -0.0609}
correct|new_res - incorrect|new_res: estimate +0.0276, z = +1.75, Tukey p = 0.299 (on 51 df: 0.31)
correct|init_res - incorrect|init_res: estimate -0.0350, z = -2.22, Tukey p = 0.117 (on 51 df: 0.131)
initial minus new by outcome: F = 8.75, p = 0.00309; means {'correct': -0.0083, 'incorrect': 0.059}
trial means: {'correct': {'init_res': -0.0453, 'new_res': -0.0358}, 'incorrect': {'init_res': -0.0108, 'new_res': -0.0638}}
GLM methods, rule=train, -1.5 to 0 s
switch trials: trials {'correct': 1158, 'incorrect': 366}
ANOVA F(3) = 6.41, p = 0.000245; n per level {'correct|init_res': 1158, 'correct|new_res': 1158, 'incorrect|init_res': 366, 'incorrect|new_res': 366}
model means: {'correct|init_res': -0.0468, 'correct|new_res': -0.0436, 'incorrect|init_res': 0.0237, 'incorrect|new_res': -0.0521}
correct|new_res - incorrect|new_res: estimate +0.0086, z = +0.49, Tukey p = 0.961 (on 43 df: 0.96)
correct|init_res - incorrect|init_res: estimate -0.0705, z = -4.05, Tukey p = 0.000307 (on 43 df: 0.00118)
initial minus new by outcome: F = 12.04, p = 0.000522; means {'correct': -0.0025, 'incorrect': 0.0847}
trial means: {'correct': {'init_res': -0.049, 'new_res': -0.0458}, 'incorrect': {'init_res': 0.0283, 'new_res': -0.0476}}
Result: reproduced. Over -1.5 to 0 s the initial arm residual is higher on incorrect than correct switch trials (+0.067, Tukey p = 4.3e-4), while the new arm does not differ (p = 0.88). The code's count of trials gives the same (p = 3.1e-4); the code's per-session GLM gives the same direction, not significant (+0.035, p = 0.12).
sfig12-delay-hpc-no-outcome-difference¶
On delay only trials, hippocampal goal arm decoding in the update period does not differ between correct and incorrect trials.
Held-out delay only trials of both outcomes, aligned at the pseudo update time, 0 to 1.5 s.
for k, B in (("methods", GLM["methods"]), ("code", GLMd["code"]), ("methods, rule=train", GLM["methods, rule=train"])):
print(f"GLM {k}")
outcome_model(resid_trials(B, 0, 1.5), 1, "delay only trials")
GLM methods
delay only trials: trials {'correct': 871, 'incorrect': 393}
ANOVA F(3) = 2.88, p = 0.0346; n per level {'correct|init_res': 871, 'correct|new_res': 871, 'incorrect|init_res': 393, 'incorrect|new_res': 393}
model means: {'correct|init_res': -0.0289, 'correct|new_res': -0.007, 'incorrect|init_res': 0.0256, 'incorrect|new_res': 0.0155}
correct|new_res - incorrect|new_res: estimate -0.0225, z = -1.09, Tukey p = 0.698 (on 51 df: 0.699)
correct|init_res - incorrect|init_res: estimate -0.0545, z = -2.63, Tukey p = 0.0426 (on 51 df: 0.0533)
initial minus new by outcome: F = 1.77, p = 0.183; means {'correct': -0.0238, 'incorrect': 0.0156}
trial means: {'correct': {'init_res': -0.0378, 'new_res': -0.016}, 'incorrect': {'init_res': 0.0318, 'new_res': 0.0216}}
GLM code
delay only trials: trials {'correct': 871, 'incorrect': 393}
ANOVA F(3) = 1.14, p = 0.33; n per level {'correct|init_res': 871, 'correct|new_res': 871, 'incorrect|init_res': 393, 'incorrect|new_res': 393}
model means: {'correct|init_res': -0.016, 'correct|new_res': -0.0027, 'incorrect|init_res': 0.0168, 'incorrect|new_res': 0.0092}
correct|new_res - incorrect|new_res: estimate -0.0119, z = -0.61, Tukey p = 0.929 (on 51 df: 0.929)
correct|init_res - incorrect|init_res: estimate -0.0329, z = -1.68, Tukey p = 0.333 (on 51 df: 0.344)
initial minus new by outcome: F = 0.69, p = 0.407; means {'correct': -0.0141, 'incorrect': 0.009}
trial means: {'correct': {'init_res': -0.0183, 'new_res': -0.0049}, 'incorrect': {'init_res': 0.0138, 'new_res': 0.0062}}
GLM methods, rule=train
delay only trials: trials {'correct': 825, 'incorrect': 358}
ANOVA F(3) = 2.09, p = 0.0998; n per level {'correct|init_res': 825, 'correct|new_res': 825, 'incorrect|init_res': 358, 'incorrect|new_res': 358}
model means: {'correct|init_res': -0.0309, 'correct|new_res': -0.0077, 'incorrect|init_res': 0.0188, 'incorrect|new_res': 0.0041}
correct|new_res - incorrect|new_res: estimate -0.0118, z = -0.55, Tukey p = 0.947 (on 43 df: 0.946)
correct|init_res - incorrect|init_res: estimate -0.0497, z = -2.31, Tukey p = 0.0962 (on 43 df: 0.112)
initial minus new by outcome: F = 2.46, p = 0.117; means {'correct': -0.0267, 'incorrect': 0.0213}
trial means: {'correct': {'init_res': -0.0393, 'new_res': -0.0161}, 'incorrect': {'init_res': 0.0288, 'new_res': 0.0141}}
Result: not reproduced. With the Methods' GLM the initial arm residual is higher on incorrect than correct delay only trials (+0.055, Tukey p = 0.043); the new arm does not differ (p = 0.70) and the initial minus new difference does not differ by outcome (p = 0.18). One of the three tests gives p below 0.05. The code's per-session GLM, a variant, gives no p below 0.05 (0.33, 0.93 and 0.41), and neither does the code's count of trials (0.096, 0.95 and 0.12); the round-1 grid gave p = 0.012 for the initial arm. On 51 degrees of freedom (sessions less levels, a deliberately small value in place of Kenward-Roger) the initial arm contrast gives p = 0.053.
fig7c-hpc-commitment-new-arm¶
The more committed the animal was to the initial arm at the update cue (view angle toward it), the larger the post-cue increase in hippocampal decoding of the new arm.
def commit_table(rule, RR=None):
rows = []
for r in (R if RR is None else RR):
if not P.included(r, "CA1", rule):
continue
d = r["dec"]["CA1"]; m = (d["update_type"] == 2) & (d["correct"] == 1)
sgn = np.where(d["turn_type"] == 1, 1.0, -1.0)
z = d["zones"]
rows.append(pd.DataFrame(dict(animal=r["subject"], session=r["session"], va=(d["va"] * sgn)[m],
d_new=(P.window_mean(z["new"], d["times"], 0, 1.5) - P.window_mean(z["new"], d["times"], -1.5, 0))[m],
d_init=(P.window_mean(z["init"], d["times"], 0, 1.5) - P.window_mean(z["init"], d["times"], -1.5, 0))[m])))
CM = pd.concat(rows, ignore_index=True).dropna()
return CM
CMS = {rule: commit_table(rule) for rule in ("final", "train")}
CM = CMS["final"]
CM["quartile"] = pd.qcut(CM.va, 4, labels=["Q1 toward new", "Q2", "Q3", "Q4 toward initial"])
for rule, cm in CMS.items():
for arm in ("d_new", "d_init"):
rho, p = stats.spearmanr(cm.va, cm[arm])
print(f"rule={rule} {arm}: Spearman rho = {rho:+.4f}, p = {p:.3g}, n = {len(cm)} trials (paper n = 1235)")
print("quartile means:\n", CM.groupby("quartile", observed=True)[["va", "d_new", "d_init"]].mean().round(4))
print("per animal rho (new arm):", {a: round(stats.spearmanr(g.va, g.d_new)[0], 3) for a, g in CM.groupby("animal")})
print("view angle at the cue, toward initial (rad): range %.3f to %.3f" % (CM.va.min(), CM.va.max()))
rule=final d_new: Spearman rho = +0.0769, p = 0.00674, n = 1241 trials (paper n = 1235)
rule=final d_init: Spearman rho = +0.0298, p = 0.294, n = 1241 trials (paper n = 1235)
rule=train d_new: Spearman rho = +0.0868, p = 0.00311, n = 1158 trials (paper n = 1235)
rule=train d_init: Spearman rho = +0.0310, p = 0.292, n = 1158 trials (paper n = 1235)
quartile means:
va d_new d_init
quartile
Q1 toward new -0.2810 0.0244 0.0225
Q2 0.0709 0.0446 0.0650
Q3 0.2363 0.0732 0.0709
Q4 toward initial 0.5336 0.0516 0.0293
per animal rho (new arm): {'S17': np.float64(-0.134), 'S20': np.float64(0.09), 'S25': np.float64(-0.048), 'S28': np.float64(0.253), 'S29': np.float64(0.112), 'S33': np.float64(0.167), 'S34': np.float64(0.114)}
view angle at the cue, toward initial (rad): range -0.698 to 0.698
Result: partially reproduced. The change in new arm decoding is positively correlated with view angle toward the initial arm (Spearman rho = +0.077, p = 0.0067, n = 1241), but rho is outside the tolerance of 0.1237 +/- 0.0124. The quartile means rise from 0.024 (toward new) to 0.073 and 0.052 in the two quartiles toward the initial arm. Per animal, rho is positive in 5 of 7. The code's count of trials gives rho = +0.087, p = 0.0031, and the round-1 grid gave rho = +0.057, p = 0.043.
fig7c-hpc-commitment-initial-arm¶
The change in hippocampal initial arm decoding after the update cue is not correlated with view angle at the cue.
rho, p = stats.spearmanr(CM.va, CM.d_init)
print(f"initial arm: Spearman rho = {rho:+.4f}, p = {p:.3g}, n = {len(CM)}")
rho, p = stats.spearmanr(CMS["train"].va, CMS["train"].d_init)
print(f"variant rule=train, initial arm: Spearman rho = {rho:+.4f}, p = {p:.3g}, n = {len(CMS['train'])}")
initial arm: Spearman rho = +0.0298, p = 0.294, n = 1241 variant rule=train, initial arm: Spearman rho = +0.0310, p = 0.292, n = 1158
Result: reproduced. The change in initial arm decoding is not correlated with view angle (rho = +0.030, p = 0.29, n = 1241), as in the paper (rho = 0.044, p = 0.12). The code's count of trials gives p = 0.29. On the round-1 grid the correlation was +0.058, p = 0.040, so this outcome depends on the grid.
Variant: the round-1 time grid¶
In round 1 the update-aligned decoding used 25 bins of 0.2 s from -2.5 to 2.5 s, so that one bin (-0.1 to 0.1 s) was centred on the cue and counted in the windows after it, and windows took the bins whose centres fall in [lo, hi) (0 to 1.5 s was then -0.1 to 1.5 s). The verifier pointed out that this bin straddles the cue. The grid above follows the code (_align_by_times, samples at -2.5, -2.3, ..., -0.1, 0.1, ..., 2.5 s, windows as calc_trial_by_trial_quant_data). The cell below repeats the deciding test of each claim on update-aligned windows with the round-1 grid, so that the dependence of each outcome on the grid can be seen. It does not decide any outcome.
# the deciding tests of the update-aligned claims, on the round-1 grid (variant; the grid above decides)
P.WINDOW_RULE = "round1"
rows1 = []
def add1(claim, test, c=None, p=None, est=None):
rows1.append(dict(claim=claim, test=test, estimate=round(float(est if c is None else c["estimate"]), 4),
p=float(p if c is None else c["p_tukey"])))
def outcome_quiet(T, ut):
d = T[T.update_type == ut]
L = P.long_format(d, ["init_res", "new_res"], name="arm"); L["pred"] = L.outcome + "|" + L.arm
return P.lme(L, "value", "pred")
try:
R1 = [dict(r, dec={k: dict(v, **r["dec_old"][k]) for k, v in r["dec"].items()}) for r in R]
print("round-1 grid, bin centres:", R1[0]["dec"]["CA1"]["times"].tolist())
T1 = P.trial_table(R1, "CA1", W, "final")
res, _ = arm_model(T1, [1, 2])
add1("fig2e-hpc-goal-increase", "ANOVA", p=res["p_anova"], est=np.nan)
for a in ("init", "new"):
add1("fig2e-hpc-goal-increase", f"switch - delay only, {a}", P.contrast(res, f"switch|{a}", f"delay only|{a}"))
d = T1[T1.update_type.isin([1, 2]) & (T1.correct == 1)].assign(diff=lambda x: x.init - x.new)
rd = P.lme(d, "diff", "type")
add1("fig2e-hpc-arms-equal", "LME initial minus new ~ trial type", p=rd["p_anova"], est=rd["emm"]["switch"] - rd["emm"]["delay only"])
for ty in ("delay only", "switch"):
sm_ = d[d.type == ty].groupby("session")["diff"].mean()
add1("fig2e-hpc-arms-equal", f"Wilcoxon of session means, {ty}", p=stats.wilcoxon(sm_).pvalue, est=sm_.mean())
res, _ = arm_model(T1, [2], cols=("retro", "init", "new"))
for a in ("init", "new"):
add1("sfig3c-goals-over-retrospective", f"{a} - retro, switch", P.contrast(res, f"switch|{a}", "switch|retro"))
res, _ = arm_model(T1, [1, 2], cols=("retro", "init", "new"))
add1("sfig3c-retrospective-unchanged", "retro, switch - delay only", P.contrast(res, "switch|retro", "delay only|retro"))
res, _ = arm_model(T1, [1, 2, 3])
for a in ("init", "new"):
add1("fig5d-stay-hpc-like-delay", f"stay - delay only, {a}", P.contrast(res, f"stay|{a}", f"delay only|{a}"))
for a in ("init", "new"):
add1("fig5d-stay-hpc-below-switch", f"stay - switch, {a}", P.contrast(res, f"stay|{a}", f"switch|{a}"))
res, _ = arm_model(T1, [1, 2, 3], cols=("init05", "new05"))
for a in ("new05", "init05"):
add1("sfig10-stay-transient-new-arm", f"stay - delay only, {a}", P.contrast(res, f"stay|{a}", f"delay only|{a}"))
T1p = P.trial_table(R1, "PFC", W, "final")
for lab, types in (("(a) switch and delay only", [1, 2]), ("(b) with stay", [1, 2, 3])):
res, _ = arm_model(T1p, types)
add1("fig2g-pfc-no-goal-increase", f"{lab}: ANOVA", p=res["p_anova"], est=np.nan)
for a in ("init", "new"):
add1("fig2g-pfc-no-goal-increase", f"{lab}: switch - delay only, {a}", P.contrast(res, f"switch|{a}", f"delay only|{a}"))
d = T1p[T1p.update_type.isin([1, 2]) & (T1p.correct == 1)].assign(diff=lambda x: x.init - x.new)
for ty in ("delay only", "switch"):
sm_ = d[d.type == ty].groupby("session")["diff"].mean()
add1("fig2g-pfc-no-goal-increase", f"Wilcoxon of session means, {ty}", p=stats.wilcoxon(sm_).pvalue, est=sm_.mean())
for a, b, lab in (("init05", "new05", "0 to 0.5 s"), ("init1", "new1", "0 to 1 s"), ("init", "new", "0 to 1.5 s"), ("init051", "new051", "0.5 to 1 s")):
res, _ = arm_model(T1p, [1, 2], cols=(a, b))
for z in (a, b):
add1("sfig5e-pfc-windows", f"{lab}: switch - delay only, {z}", P.contrast(res, f"switch|{z}", f"delay only|{z}"))
G1 = residuals(bin_table("CA1", RR=R1))
post1, pre1 = resid_trials(G1, 0, 1.5), resid_trials(G1, -1.5, 0)
rr = outcome_quiet(post1, 2)
add1("fig6b-hpc-new-lower-incorrect", "correct - incorrect, new, switch", P.contrast(rr, "correct|new_res", "incorrect|new_res"))
add1("fig6b-hpc-initial-no-difference", "correct - incorrect, initial, switch", P.contrast(rr, "correct|init_res", "incorrect|init_res"))
rr = outcome_quiet(pre1, 2)
add1("fig6-hpc-pre-cue-initial-higher-incorrect", "correct - incorrect, initial, -1.5 to 0 s", P.contrast(rr, "correct|init_res", "incorrect|init_res"))
rr = outcome_quiet(post1, 1)
for a in ("init_res", "new_res"):
add1("sfig12-delay-hpc-no-outcome-difference", f"correct - incorrect, {a}, delay only", P.contrast(rr, f"correct|{a}", f"incorrect|{a}"))
CM1 = commit_table("final", RR=R1)
for arm, cl in (("d_new", "fig7c-hpc-commitment-new-arm"), ("d_init", "fig7c-hpc-commitment-initial-arm")):
rho, pp = stats.spearmanr(CM1.va, CM1[arm])
add1(cl, f"Spearman rho, {arm}, n = {len(CM1)}", p=pp, est=rho)
finally:
P.WINDOW_RULE = "code"
V1 = pd.DataFrame(rows1)
print(V1.to_string(formatters={"p": "{:.3g}".format}))
round-1 grid, bin centres: [-2.4, -2.2, -2.0, -1.8, -1.6, -1.4, -1.2, -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4]
claim test estimate p 0 fig2e-hpc-goal-increase ANOVA NaN 2.44e-18 1 fig2e-hpc-goal-increase switch - delay only, init 0.0385 2.73e-12 2 fig2e-hpc-goal-increase switch - delay only, new 0.0288 1.77e-07 3 fig2e-hpc-arms-equal LME initial minus new ~ trial type 0.0099 0.172 4 fig2e-hpc-arms-equal Wilcoxon of session means, delay only -0.0073 0.269 5 fig2e-hpc-arms-equal Wilcoxon of session means, switch -0.0082 0.436 6 sfig3c-goals-over-retrospective init - retro, switch 0.0063 0.365 7 sfig3c-goals-over-retrospective new - retro, switch 0.0064 0.356 8 sfig3c-retrospective-unchanged retro, switch - delay only 0.0125 0.122 9 fig5d-stay-hpc-like-delay stay - delay only, init 0.0074 0.851 10 fig5d-stay-hpc-like-delay stay - delay only, new 0.0175 0.063 11 fig5d-stay-hpc-below-switch stay - switch, init -0.0313 2.34e-06 12 fig5d-stay-hpc-below-switch stay - switch, new -0.0116 0.377 13 sfig10-stay-transient-new-arm stay - delay only, new05 0.0241 0.0365 14 sfig10-stay-transient-new-arm stay - delay only, init05 0.0032 0.999 15 fig2g-pfc-no-goal-increase (a) switch and delay only: ANOVA NaN 0.038 16 fig2g-pfc-no-goal-increase (a) switch and delay only: switch - delay only, init 0.0044 0.738 17 fig2g-pfc-no-goal-increase (a) switch and delay only: switch - delay only, new 0.0116 0.0352 18 fig2g-pfc-no-goal-increase (b) with stay: ANOVA NaN 0.0743 19 fig2g-pfc-no-goal-increase (b) with stay: switch - delay only, init 0.0044 0.905 20 fig2g-pfc-no-goal-increase (b) with stay: switch - delay only, new 0.0115 0.0657 21 fig2g-pfc-no-goal-increase Wilcoxon of session means, delay only 0.0007 0.957 22 fig2g-pfc-no-goal-increase Wilcoxon of session means, switch -0.0081 0.0804 23 sfig5e-pfc-windows 0 to 0.5 s: switch - delay only, init05 -0.0005 1 24 sfig5e-pfc-windows 0 to 0.5 s: switch - delay only, new05 0.0106 0.15 25 sfig5e-pfc-windows 0 to 1 s: switch - delay only, init1 0.0015 0.99 26 sfig5e-pfc-windows 0 to 1 s: switch - delay only, new1 0.0137 0.0192 27 sfig5e-pfc-windows 0 to 1.5 s: switch - delay only, init 0.0044 0.738 28 sfig5e-pfc-windows 0 to 1.5 s: switch - delay only, new 0.0116 0.0352 29 sfig5e-pfc-windows 0.5 to 1 s: switch - delay only, init051 0.0043 0.91 30 sfig5e-pfc-windows 0.5 to 1 s: switch - delay only, new051 0.0184 0.0236 31 fig6b-hpc-new-lower-incorrect correct - incorrect, new, switch 0.0774 0.00114 32 fig6b-hpc-initial-no-difference correct - incorrect, initial, switch 0.0460 0.119 33 fig6-hpc-pre-cue-initial-higher-incorrect correct - incorrect, initial, -1.5 to 0 s -0.0822 1.21e-05 34 sfig12-delay-hpc-no-outcome-difference correct - incorrect, init_res, delay only -0.0635 0.0123 35 sfig12-delay-hpc-no-outcome-difference correct - incorrect, new_res, delay only -0.0137 0.913 36 fig7c-hpc-commitment-new-arm Spearman rho, d_new, n = 1241 0.0574 0.0434 37 fig7c-hpc-commitment-initial-arm Spearman rho, d_init, n = 1241 0.0583 0.0399
Theta phase: shared definitions¶
CA1 decoding in 25 ms bins over 1.5 s before and after the update cue (held-out delay only, switch and stay trials, the encoder of the 200 ms analyses). As a variant, the theta phase stored in the file for that channel, which the paper's code reads (general/lfp.py), is referenced the same way and every theta test is repeated with it. Theta comes from the LFP of the channel the files mark as ripple_channel (the CA1 pyramidal-layer channel chosen by sharp-wave ripple power, Methods). Phase is set from peaks and troughs of the 4 to 12 Hz equiripple-filtered LFP, and 0 is put at the 30-degree bin of maximal CA1 pyramidal-cell firing in each session (Methods, "Theta cycles and phase"). The half cycles are -pi to 0 and 0 to pi.
The computed and the stored phase agree closely in most sessions (printed below). Where they disagree (lowest mean cosine -0.49, session S20-210511), the pyramidal spikes are barely locked to theta (0.085 to 0.086 of spikes in the peak 30-degree bin, against 0.083 for uniform firing), so the reference phase of maximal firing is nearly arbitrary and the two estimates pick different references.
def theta_table(key, rule="final"):
rows = []
for r in R:
if not P.included(r, "CA1", rule) or "theta" not in r:
continue
th = dict(r["theta"]); th["phase"] = th[key]
for half, (lo, hi) in (("h1", (-np.pi, 0)), ("h2", (0, np.pi)), ("all", (-np.pi, np.pi))):
pm = (th["phase"] > lo) & (th["phase"] <= hi)
for win, (a, b) in (("post", (0, 1.5)), ("pre", (-1.5, 0))):
tm = (th["times"] >= a) & (th["times"] < b)
m = pm & tm[None, :]
with np.errstate(all="ignore"):
vals = {z: np.nanmean(np.where(m, th[z], np.nan), 1) for z in ("init", "new", "central", "home_window")}
rows.append(pd.DataFrame(dict(animal=r["subject"], session=r["session"], trial=th["trial"], update_type=th["update_type"],
correct=th["correct"], half=half, win=win, **vals)))
out = pd.concat(rows, ignore_index=True); out["type"] = out.update_type.map(P.TRIAL_TYPES)
return out
THS = {"computed": theta_table("phase"), "stored": theta_table("phase_stored"), "computed, rule=train": theta_table("phase", "train")}
TH = THS["computed"]
agree = [np.nanmean(np.cos(r["theta"]["phase"] - r["theta"]["phase_stored"])) for r in R if "theta" in r]
print("stored phase: unit as labelled", {r["theta"]["stored_unit"] for r in R if "theta" in r},
"; value range %.3f to %.3f" % (min(r["theta"]["stored_range"][0] for r in R if "theta" in r), max(r["theta"]["stored_range"][1] for r in R if "theta" in r)))
print("agreement of computed and stored phase at the decoding bins, mean cos(difference) per session: median %.3f, min %.3f" % (np.median(agree), np.min(agree)))
AG = pd.DataFrame([dict(session=r["session"], agree=a, ref_computed=np.degrees(r["theta"]["ref"]),
stored_peak_share=r["theta"]["spike_phase_hist_stored"].max() / r["theta"]["spike_phase_hist_stored"].sum(),
computed_peak_share=r["theta"]["spike_phase_hist"].max() / r["theta"]["spike_phase_hist"].sum())
for r, a in zip([r for r in R if "theta" in r], agree)]).sort_values("agree")
print("sessions with the lowest agreement (spike phase locking: share of pyramidal spikes in the peak 30-degree bin, uniform 0.083):")
print(AG.head(4).round(3).to_string(index=False))
chans = pd.DataFrame([dict(session=r["session"], channel=r["theta"]["channel"], location=r["theta"]["channel_location"],
ref_deg=np.degrees(r["theta"]["ref"]), peak_bin_share=r["theta"]["spike_phase_hist"].max() / r["theta"]["spike_phase_hist"].sum())
for r in R if "theta" in r])
print("sessions with theta:", len(chans), "; ripple channel location:", chans.location.value_counts().to_dict())
print("phase of maximal pyramidal firing (deg, per session): median %.0f, range %.0f to %.0f; share of spikes in the peak 30-degree bin: median %.3f (uniform 0.083)"
% (chans.ref_deg.median(), chans.ref_deg.min(), chans.ref_deg.max(), chans.peak_bin_share.median()))
for k, X in THS.items():
print(f"correct trials in the theta table ({k}):", X[(X.correct == 1) & (X.half == "h1") & (X.win == "post")].type.value_counts().to_dict(), "; sessions", X.session.nunique())
stored phase: unit as labelled {'degrees'} ; value range -3.142 to 3.142
agreement of computed and stored phase at the decoding bins, mean cos(difference) per session: median 0.975, min -0.493
sessions with the lowest agreement (spike phase locking: share of pyramidal spikes in the peak 30-degree bin, uniform 0.083):
session agree ref_computed stored_peak_share computed_peak_share
S20-210511 -0.493 135.0 0.086 0.085
S20-210516 0.478 75.0 0.090 0.089
S25-210907 0.489 165.0 0.092 0.093
S33-220420 0.828 165.0 0.096 0.100
sessions with theta: 59 ; ripple channel location: {np.str_('CA1'): 59}
phase of maximal pyramidal firing (deg, per session): median -75, range -165 to 165; share of spikes in the peak 30-degree bin: median 0.104 (uniform 0.083)
correct trials in the theta table (computed): {'switch': 1241, 'delay only': 871, 'stay': 530} ; sessions 55
correct trials in the theta table (stored): {'switch': 1241, 'delay only': 871, 'stay': 530} ; sessions 55
correct trials in the theta table (computed, rule=train): {'switch': 1158, 'delay only': 825, 'stay': 504} ; sessions 47
fig3c-theta-phase-segregation¶
After the update cue on switch trials, hippocampal non-local goal codes are strongest in the first half of the theta cycle and local codes in the second half.
def theta_loc_model(central, TH=TH):
d = TH[(TH.update_type == 2) & (TH.correct == 1) & (TH.win == "post") & TH.half.isin(["h1", "h2"])]
d = d.rename(columns={central: "centralzone"})
L = P.long_format(d[["animal", "session", "trial", "half", "init", "new", "centralzone"]], ["init", "new", "centralzone"], name="where")
L["pred"] = L.half + "|" + L["where"]
return P.lme(L, "value", "pred"), d
for central, lab in (("central", "(a) whole central arm"), ("home_window", "(b) central window around the update cue")):
res, d = theta_loc_model(central)
print(lab)
report(res, [("h1|init", "h1|centralzone"), ("h1|new", "h1|centralzone"), ("h2|centralzone", "h2|init"), ("h2|centralzone", "h2|new")])
print(" trial means:", d.groupby("half")[["init", "new", "centralzone"]].mean().round(4).to_dict("index"))
print("expected: initial 0.13/0.13, new 0.13/0.12, central 0.12/0.14 (-pi to 0 / 0 to pi)")
for src, vlab in (("stored", "the phase stored in the file (the paper's code)"), ("computed, rule=train", "computed phase, sessions under the code's 50-trial count")):
print(f"\nvariant: {vlab}")
for central in ("central", "home_window"):
res, d = theta_loc_model(central, THS[src])
report(res, [("h1|init", "h1|centralzone"), ("h1|new", "h1|centralzone"), ("h2|centralzone", "h2|init"), ("h2|centralzone", "h2|new")], label=central)
print(" trial means:", d.groupby("half")[["init", "new", "centralzone"]].mean().round(4).to_dict("index"))
(a) whole central arm
ANOVA F(5) = 32273.75, p = 0; n per level {'h1|centralzone': 1241, 'h1|init': 1241, 'h1|new': 1241, 'h2|centralzone': 1241, 'h2|init': 1241, 'h2|new': 1241}
model means: {'h1|centralzone': 0.6633, 'h1|init': 0.1293, 'h1|new': 0.1298, 'h2|centralzone': 0.6725, 'h2|init': 0.1273, 'h2|new': 0.1259}
h1|init - h1|centralzone: estimate -0.5340, z = -243.32, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
h1|new - h1|centralzone: estimate -0.5335, z = -243.09, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
h2|centralzone - h2|init: estimate +0.5452, z = +248.43, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
h2|centralzone - h2|new: estimate +0.5466, z = +249.06, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
trial means: {'h1': {'init': 0.1291, 'new': 0.1296, 'centralzone': 0.6631}, 'h2': {'init': 0.127, 'new': 0.1256, 'centralzone': 0.6722}}
(b) central window around the update cue
ANOVA F(5) = 119.79, p = 3.37e-127; n per level {'h1|centralzone': 1241, 'h1|init': 1241, 'h1|new': 1241, 'h2|centralzone': 1241, 'h2|init': 1241, 'h2|new': 1241}
model means: {'h1|centralzone': 0.1484, 'h1|init': 0.1292, 'h1|new': 0.1297, 'h2|centralzone': 0.151, 'h2|init': 0.1272, 'h2|new': 0.1258}
h1|init - h1|centralzone: estimate -0.0191, z = -13.08, Tukey p = 3.53e-13 (on 49 df: 8.88e-15)
h1|new - h1|centralzone: estimate -0.0186, z = -12.73, Tukey p = 3.53e-13 (on 49 df: 9.21e-15)
h2|centralzone - h2|init: estimate +0.0238, z = +16.27, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
h2|centralzone - h2|new: estimate +0.0252, z = +17.23, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
trial means: {'h1': {'init': 0.1291, 'new': 0.1296, 'centralzone': 0.1482}, 'h2': {'init': 0.127, 'new': 0.1256, 'centralzone': 0.1508}}
expected: initial 0.13/0.13, new 0.13/0.12, central 0.12/0.14 (-pi to 0 / 0 to pi)
variant: the phase stored in the file (the paper's code)
central ANOVA F(5) = 31860.89, p = 0; n per level {'h1|centralzone': 1241, 'h1|init': 1241, 'h1|new': 1241, 'h2|centralzone': 1241, 'h2|init': 1241, 'h2|new': 1241}
model means: {'h1|centralzone': 0.6629, 'h1|init': 0.1292, 'h1|new': 0.1297, 'h2|centralzone': 0.6727, 'h2|init': 0.1276, 'h2|new': 0.1262}
h1|init - h1|centralzone: estimate -0.5336, z = -241.69, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
h1|new - h1|centralzone: estimate -0.5332, z = -241.50, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
h2|centralzone - h2|init: estimate +0.5451, z = +246.89, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
h2|centralzone - h2|new: estimate +0.5465, z = +247.52, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
trial means: {'h1': {'init': 0.129, 'new': 0.1294, 'centralzone': 0.6626}, 'h2': {'init': 0.1273, 'new': 0.1259, 'centralzone': 0.6724}}
home_window ANOVA F(5) = 116.96, p = 3.85e-124; n per level {'h1|centralzone': 1241, 'h1|init': 1241, 'h1|new': 1241, 'h2|centralzone': 1241, 'h2|init': 1241, 'h2|new': 1241}
model means: {'h1|centralzone': 0.1477, 'h1|init': 0.1291, 'h1|new': 0.1295, 'h2|centralzone': 0.1516, 'h2|init': 0.1274, 'h2|new': 0.1261}
h1|init - h1|centralzone: estimate -0.0186, z = -12.60, Tukey p = 3.53e-13 (on 49 df: 9.55e-15)
h1|new - h1|centralzone: estimate -0.0182, z = -12.30, Tukey p = 3.53e-13 (on 49 df: 1.07e-14)
h2|centralzone - h2|init: estimate +0.0241, z = +16.34, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
h2|centralzone - h2|new: estimate +0.0255, z = +17.28, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
trial means: {'h1': {'init': 0.129, 'new': 0.1294, 'centralzone': 0.1476}, 'h2': {'init': 0.1273, 'new': 0.1259, 'centralzone': 0.1514}}
variant: computed phase, sessions under the code's 50-trial count
central ANOVA F(5) = 29464.33, p = 0; n per level {'h1|centralzone': 1158, 'h1|init': 1158, 'h1|new': 1158, 'h2|centralzone': 1158, 'h2|init': 1158, 'h2|new': 1158}
model means: {'h1|centralzone': 0.6632, 'h1|init': 0.1302, 'h1|new': 0.1307, 'h2|centralzone': 0.6739, 'h2|init': 0.1284, 'h2|new': 0.1267}
h1|init - h1|centralzone: estimate -0.5329, z = -232.15, Tukey p = 3.53e-13 (on 41 df: 0)
h1|new - h1|centralzone: estimate -0.5324, z = -231.93, Tukey p = 3.53e-13 (on 41 df: 0)
h2|centralzone - h2|init: estimate +0.5455, z = +237.63, Tukey p = 3.53e-13 (on 41 df: 0)
h2|centralzone - h2|new: estimate +0.5472, z = +238.38, Tukey p = 3.53e-13 (on 41 df: 0)
trial means: {'h1': {'init': 0.1295, 'new': 0.13, 'centralzone': 0.6624}, 'h2': {'init': 0.1276, 'new': 0.1259, 'centralzone': 0.6732}}
home_window ANOVA F(5) = 105.24, p = 1.78e-111; n per level {'h1|centralzone': 1158, 'h1|init': 1158, 'h1|new': 1158, 'h2|centralzone': 1158, 'h2|init': 1158, 'h2|new': 1158}
model means: {'h1|centralzone': 0.148, 'h1|init': 0.1297, 'h1|new': 0.1302, 'h2|centralzone': 0.1514, 'h2|init': 0.1279, 'h2|new': 0.1262}
h1|init - h1|centralzone: estimate -0.0183, z = -11.96, Tukey p = 3.53e-13 (on 41 df: 8.52e-14)
h1|new - h1|centralzone: estimate -0.0178, z = -11.64, Tukey p = 3.53e-13 (on 41 df: 2.09e-13)
h2|centralzone - h2|init: estimate +0.0235, z = +15.36, Tukey p = 3.53e-13 (on 41 df: 0)
h2|centralzone - h2|new: estimate +0.0252, z = +16.49, Tukey p = 3.53e-13 (on 41 df: 0)
trial means: {'h1': {'init': 0.1295, 'new': 0.13, 'centralzone': 0.1477}, 'h2': {'init': 0.1276, 'new': 0.1259, 'centralzone': 0.1511}}
Result: not reproduced. The central zone is decoded more than either goal arm in both half cycles under both readings (central window: first half central 0.148 against initial 0.129 and new 0.130; second half 0.151 against 0.127 and 0.126; all Tukey p at the precision floor), so the goal arms do not exceed central in the first half. The modulation goes the stated way, central higher and goal arms lower in the second half than in the first, and the goal arm values (0.129, 0.127, 0.130, 0.126) are within tolerance; the central values are not (whole arm 0.66 and 0.67, window 0.148 and 0.151, against 0.12 and 0.14). The phase stored in the file (central window 0.148 and 0.151) and the code's count of trials give the same pattern.
fig3b-theta-pre-post¶
At the theta timescale, goal arm decoding increases and central decoding decreases from before to after the update cue on switch trials.
for src, central, clab in [("computed", "central", "(a) whole central arm"), ("computed", "home_window", "(b) central window"),
("stored", "central", "variant, stored phase, (a)"), ("computed, rule=train", "central", "variant, rule=train, (a)")]:
TH = THS[src]
for half, hlab in (("h1", "first half cycle"), ("all", "whole cycle")):
d = TH[(TH.update_type == 2) & (TH.correct == 1) & (TH.half == half)].rename(columns={central: "centralzone"})
L = P.long_format(d[["animal", "session", "trial", "win", "init", "new", "centralzone"]], ["init", "new", "centralzone"], name="where")
L["pred"] = L.win + "|" + L["where"]
res = P.lme(L, "value", "pred")
print(f"{clab}, {hlab}")
report(res, [("post|init", "pre|init"), ("post|new", "pre|new"), ("post|centralzone", "pre|centralzone")])
if src == "computed" and central == "central" and half == "h1":
print(" trial means:", d.groupby("win")[["init", "new", "centralzone"]].mean().round(4).to_dict("index"))
print("expected: initial 0.11 -> 0.13, new 0.11 -> 0.13, central 0.15 -> 0.12")
(a) whole central arm, first half cycle
ANOVA F(5) = 38772.11, p = 0; n per level {'post|centralzone': 1241, 'post|init': 1241, 'post|new': 1241, 'pre|centralzone': 1241, 'pre|init': 1241, 'pre|new': 1241}
model means: {'post|centralzone': 0.6635, 'post|init': 0.1295, 'post|new': 0.13, 'pre|centralzone': 0.6989, 'pre|init': 0.1144, 'pre|new': 0.1149}
post|init - pre|init: estimate +0.0151, z = +7.28, Tukey p = 5.83e-12 (on 49 df: 3.64e-08)
post|new - pre|new: estimate +0.0151, z = +7.29, Tukey p = 5.46e-12 (on 49 df: 3.52e-08)
post|centralzone - pre|centralzone: estimate -0.0354, z = -17.04, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
trial means: {'post': {'init': 0.1291, 'new': 0.1296, 'centralzone': 0.6631}, 'pre': {'init': 0.114, 'new': 0.1145, 'centralzone': 0.6985}}
(a) whole central arm, whole cycle
ANOVA F(5) = 58953.73, p = 0; n per level {'post|centralzone': 1241, 'post|init': 1241, 'post|new': 1241, 'pre|centralzone': 1241, 'pre|init': 1241, 'pre|new': 1241}
model means: {'post|centralzone': 0.6678, 'post|init': 0.1283, 'post|new': 0.1278, 'pre|centralzone': 0.7011, 'pre|init': 0.114, 'pre|new': 0.1136}
post|init - pre|init: estimate +0.0143, z = +8.43, Tukey p = 3.54e-13 (on 49 df: 6.25e-10)
post|new - pre|new: estimate +0.0142, z = +8.38, Tukey p = 3.54e-13 (on 49 df: 7.54e-10)
post|centralzone - pre|centralzone: estimate -0.0333, z = -19.61, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
(b) central window, first half cycle
ANOVA F(5) = 487.91, p = 0; n per level {'post|centralzone': 1241, 'post|init': 1241, 'post|new': 1241, 'pre|centralzone': 1241, 'pre|init': 1241, 'pre|new': 1241}
model means: {'post|centralzone': 0.1494, 'post|init': 0.1302, 'post|new': 0.1308, 'pre|centralzone': 0.1769, 'pre|init': 0.1151, 'pre|new': 0.1156}
post|init - pre|init: estimate +0.0151, z = +10.03, Tukey p = 3.53e-13 (on 49 df: 2.7e-12)
post|new - pre|new: estimate +0.0151, z = +10.05, Tukey p = 3.53e-13 (on 49 df: 2.58e-12)
post|centralzone - pre|centralzone: estimate -0.0275, z = -18.30, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
(b) central window, whole cycle
ANOVA F(5) = 724.42, p = 0; n per level {'post|centralzone': 1241, 'post|init': 1241, 'post|new': 1241, 'pre|centralzone': 1241, 'pre|init': 1241, 'pre|new': 1241}
model means: {'post|centralzone': 0.15, 'post|init': 0.1285, 'post|new': 0.1281, 'pre|centralzone': 0.1803, 'pre|init': 0.1142, 'pre|new': 0.1139}
post|init - pre|init: estimate +0.0143, z = +10.69, Tukey p = 3.53e-13 (on 49 df: 3.19e-13)
post|new - pre|new: estimate +0.0142, z = +10.62, Tukey p = 3.53e-13 (on 49 df: 3.96e-13)
post|centralzone - pre|centralzone: estimate -0.0303, z = -22.66, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
variant, stored phase, (a), first half cycle
ANOVA F(5) = 38098.77, p = 0; n per level {'post|centralzone': 1241, 'post|init': 1241, 'post|new': 1241, 'pre|centralzone': 1241, 'pre|init': 1241, 'pre|new': 1241}
model means: {'post|centralzone': 0.6634, 'post|init': 0.1298, 'post|new': 0.1302, 'pre|centralzone': 0.6971, 'pre|init': 0.1153, 'pre|new': 0.1153}
post|init - pre|init: estimate +0.0145, z = +6.95, Tukey p = 6.02e-11 (on 49 df: 1.18e-07)
post|new - pre|new: estimate +0.0149, z = +7.12, Tukey p = 1.77e-11 (on 49 df: 6.38e-08)
post|centralzone - pre|centralzone: estimate -0.0337, z = -16.13, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
variant, stored phase, (a), whole cycle
ANOVA F(5) = 58953.73, p = 0; n per level {'post|centralzone': 1241, 'post|init': 1241, 'post|new': 1241, 'pre|centralzone': 1241, 'pre|init': 1241, 'pre|new': 1241}
model means: {'post|centralzone': 0.6678, 'post|init': 0.1283, 'post|new': 0.1278, 'pre|centralzone': 0.7011, 'pre|init': 0.114, 'pre|new': 0.1136}
post|init - pre|init: estimate +0.0143, z = +8.43, Tukey p = 3.54e-13 (on 49 df: 6.25e-10)
post|new - pre|new: estimate +0.0142, z = +8.38, Tukey p = 3.54e-13 (on 49 df: 7.54e-10)
post|centralzone - pre|centralzone: estimate -0.0333, z = -19.61, Tukey p = 3.53e-13 (on 49 df: 8.77e-15)
variant, rule=train, (a), first half cycle
ANOVA F(5) = 35320.32, p = 0; n per level {'post|centralzone': 1158, 'post|init': 1158, 'post|new': 1158, 'pre|centralzone': 1158, 'pre|init': 1158, 'pre|new': 1158}
model means: {'post|centralzone': 0.6636, 'post|init': 0.1306, 'post|new': 0.1311, 'pre|centralzone': 0.7005, 'pre|init': 0.115, 'pre|new': 0.1152}
post|init - pre|init: estimate +0.0156, z = +7.20, Tukey p = 1.03e-11 (on 41 df: 1.27e-07)
post|new - pre|new: estimate +0.0159, z = +7.31, Tukey p = 4.74e-12 (on 41 df: 8.9e-08)
post|centralzone - pre|centralzone: estimate -0.0369, z = -16.96, Tukey p = 3.53e-13 (on 41 df: 0)
variant, rule=train, (a), whole cycle
ANOVA F(5) = 54352.37, p = 0; n per level {'post|centralzone': 1158, 'post|init': 1158, 'post|new': 1158, 'pre|centralzone': 1158, 'pre|init': 1158, 'pre|new': 1158}
model means: {'post|centralzone': 0.6684, 'post|init': 0.1293, 'post|new': 0.1286, 'pre|centralzone': 0.703, 'pre|init': 0.1143, 'pre|new': 0.1138}
post|init - pre|init: estimate +0.0150, z = +8.46, Tukey p = 3.53e-13 (on 41 df: 2.29e-09)
post|new - pre|new: estimate +0.0148, z = +8.37, Tukey p = 3.54e-13 (on 41 df: 3.1e-09)
post|centralzone - pre|centralzone: estimate -0.0345, z = -19.52, Tukey p = 3.53e-13 (on 41 df: 0)
expected: initial 0.11 -> 0.13, new 0.11 -> 0.13, central 0.15 -> 0.12
Result: reproduced. Under every reading both goal arms increase from before to after the cue (first half cycle, whole central arm: initial 0.1140 to 0.1291, new 0.1145 to 0.1296, Tukey p = 5.8e-12 and 5.5e-12) and central decoding decreases (whole arm 0.70 to 0.66, central window 0.177 to 0.149 in model means, p at the precision floor). The goal arm values are within tolerance; the central values are not (paper 0.15 to 0.12), as the central zone of the paper is not known. The stored phase gives the same directions (p = 6.0e-11, 1.8e-11 and at the floor), and so does the code's count of trials.
sfig6-theta-switch-over-delay¶
At the theta timescale, goal arm decoding after the update cue is larger on switch than on delay only trials.
for src, arm in [("computed", "init"), ("computed", "new"), ("stored", "init"), ("stored", "new"), ("computed, rule=train", "init"), ("computed, rule=train", "new")]:
TH = THS[src]
print(f"phase {src}:")
d = TH[(TH.correct == 1) & (TH.win == "post") & TH.half.isin(["h1", "h2"])]
d = d.assign(pred=d.type + "|" + d.half)
res = P.lme(d, arm, "pred")
print(f"{arm} arm: trials {d[d.half == 'h1'].type.value_counts().to_dict()} (paper 1295 switch, 552 stay, 927 delay only)")
report(res, [("switch|h1", "delay only|h1"), ("switch|h2", "delay only|h2")])
phase computed:
init arm: trials {'switch': 1241, 'delay only': 871, 'stay': 530} (paper 1295 switch, 552 stay, 927 delay only)
ANOVA F(5) = 30.99, p = 1.18e-31; n per level {'delay only|h1': 871, 'delay only|h2': 871, 'stay|h1': 530, 'stay|h2': 530, 'switch|h1': 1241, 'switch|h2': 1241}
model means: {'delay only|h1': 0.1171, 'delay only|h2': 0.1134, 'stay|h1': 0.1186, 'stay|h2': 0.1187, 'switch|h1': 0.1294, 'switch|h2': 0.1274}
switch|h1 - delay only|h1: estimate +0.0124, z = +7.80, Tukey p = 4.55e-13 (on 49 df: 5.73e-09)
switch|h2 - delay only|h2: estimate +0.0140, z = +8.84, Tukey p = 3.53e-13 (on 49 df: 1.5e-10)
phase computed:
new arm: trials {'switch': 1241, 'delay only': 871, 'stay': 530} (paper 1295 switch, 552 stay, 927 delay only)
ANOVA F(5) = 20.09, p = 4.26e-20; n per level {'delay only|h1': 871, 'delay only|h2': 871, 'stay|h1': 530, 'stay|h2': 530, 'switch|h1': 1241, 'switch|h2': 1241}
model means: {'delay only|h1': 0.1189, 'delay only|h2': 0.1153, 'stay|h1': 0.1222, 'stay|h2': 0.1222, 'switch|h1': 0.1297, 'switch|h2': 0.1257}
switch|h1 - delay only|h1: estimate +0.0107, z = +6.75, Tukey p = 2.31e-10 (on 49 df: 2.36e-07)
switch|h2 - delay only|h2: estimate +0.0104, z = +6.58, Tukey p = 7.65e-10 (on 49 df: 4.42e-07)
phase stored:
init arm: trials {'switch': 1241, 'delay only': 871, 'stay': 530} (paper 1295 switch, 552 stay, 927 delay only)
ANOVA F(5) = 31.13, p = 8.29e-32; n per level {'delay only|h1': 871, 'delay only|h2': 871, 'stay|h1': 530, 'stay|h2': 530, 'switch|h1': 1241, 'switch|h2': 1241}
model means: {'delay only|h1': 0.1171, 'delay only|h2': 0.1133, 'stay|h1': 0.1196, 'stay|h2': 0.1179, 'switch|h1': 0.1293, 'switch|h2': 0.1276}
switch|h1 - delay only|h1: estimate +0.0122, z = +7.69, Tukey p = 5.97e-13 (on 49 df: 8.48e-09)
switch|h2 - delay only|h2: estimate +0.0143, z = +9.02, Tukey p = 3.53e-13 (on 49 df: 8.1e-11)
phase stored:
new arm: trials {'switch': 1241, 'delay only': 871, 'stay': 530} (paper 1295 switch, 552 stay, 927 delay only)
ANOVA F(5) = 19.71, p = 1.07e-19; n per level {'delay only|h1': 871, 'delay only|h2': 871, 'stay|h1': 530, 'stay|h2': 530, 'switch|h1': 1241, 'switch|h2': 1241}
model means: {'delay only|h1': 0.119, 'delay only|h2': 0.1151, 'stay|h1': 0.1225, 'stay|h2': 0.1221, 'switch|h1': 0.1294, 'switch|h2': 0.1259}
switch|h1 - delay only|h1: estimate +0.0105, z = +6.56, Tukey p = 8.76e-10 (on 49 df: 4.75e-07)
switch|h2 - delay only|h2: estimate +0.0108, z = +6.76, Tukey p = 2.23e-10 (on 49 df: 2.32e-07)
phase computed, rule=train:
init arm: trials {'switch': 1158, 'delay only': 825, 'stay': 504} (paper 1295 switch, 552 stay, 927 delay only)
ANOVA F(5) = 32.93, p = 1e-33; n per level {'delay only|h1': 825, 'delay only|h2': 825, 'stay|h1': 504, 'stay|h2': 504, 'switch|h1': 1158, 'switch|h2': 1158}
model means: {'delay only|h1': 0.1163, 'delay only|h2': 0.1124, 'stay|h1': 0.1175, 'stay|h2': 0.117, 'switch|h1': 0.1293, 'switch|h2': 0.1275}
switch|h1 - delay only|h1: estimate +0.0129, z = +7.85, Tukey p = 4.2e-13 (on 41 df: 1.55e-08)
switch|h2 - delay only|h2: estimate +0.0150, z = +9.11, Tukey p = 3.53e-13 (on 41 df: 3.11e-10)
phase computed, rule=train:
new arm: trials {'switch': 1158, 'delay only': 825, 'stay': 504} (paper 1295 switch, 552 stay, 927 delay only)
ANOVA F(5) = 18.54, p = 1.83e-18; n per level {'delay only|h1': 825, 'delay only|h2': 825, 'stay|h1': 504, 'stay|h2': 504, 'switch|h1': 1158, 'switch|h2': 1158}
model means: {'delay only|h1': 0.1191, 'delay only|h2': 0.1159, 'stay|h1': 0.1231, 'stay|h2': 0.1227, 'switch|h1': 0.1302, 'switch|h2': 0.1261}
switch|h1 - delay only|h1: estimate +0.0110, z = +6.70, Tukey p = 3.22e-10 (on 41 df: 6.28e-07)
switch|h2 - delay only|h2: estimate +0.0102, z = +6.19, Tukey p = 9.25e-09 (on 41 df: 3.32e-06)
Result: reproduced. For both arms the ANOVA (initial F(5) = 31.0, new F(5) = 20.1, p < 1e-19) and the switch against delay only contrasts in both half cycles give p < 1e-8 with switch higher, with either phase and with the code's count of trials (largest 9.25e-9, new arm, second half, code's count), and p < 1e-5 on the small degrees of freedom (41 or 49).
fig3d-new-arm-theta-modulated¶
After the update cue, decoding of the new goal arm differs between theta half cycles while decoding of the initial arm does not.
for src in ("computed", "stored", "computed, rule=train"):
TH = THS[src]
d = TH[(TH.update_type == 2) & (TH.correct == 1) & (TH.win == "post") & TH.half.isin(["h1", "h2"])]
for arm in ("new", "init", "central"):
res = P.lme(d, arm, "half")
print(f"phase {src}, {arm}: F({res['df1']}) = {res['F']:.2f}, p = {res['p_anova']:.3g}; first half {res['emm']['h1']:.4f}, second half {res['emm']['h2']:.4f}")
phase computed, new: F(1) = 7.91, p = 0.00491; first half 0.1286, second half 0.1246
phase computed, init: F(1) = 2.12, p = 0.145; first half 0.1287, second half 0.1266
phase computed, central: F(1) = 11.21, p = 0.000813; first half 0.6652, second half 0.6743 phase stored, new: F(1) = 5.95, p = 0.0147; first half 0.1284, second half 0.1249
phase stored, init: F(1) = 1.35, p = 0.246; first half 0.1285, second half 0.1269
phase stored, central: F(1) = 12.79, p = 0.000349; first half 0.6640, second half 0.6738 phase computed, rule=train, new: F(1) = 7.53, p = 0.00608; first half 0.1285, second half 0.1245 phase computed, rule=train, init: F(1) = 1.49, p = 0.222; first half 0.1290, second half 0.1272
phase computed, rule=train, central: F(1) = 14.32, p = 0.000154; first half 0.6664, second half 0.6772
Result: reproduced. On correct switch trials after the cue, the new arm differs between half cycles (0.1286 against 0.1246, p = 0.0049) and the initial arm does not (0.1287 against 0.1266, p = 0.15). With the stored phase, p = 0.015 and p = 0.25; with the code's count of trials, p = 0.0061 and p = 0.22.
Choice decoding (fig4a and the claims built on it): timing¶
The choice estimate is a per-session LSTM (S10): 10 units, a sigmoid dense unit, Adam with learning rate 0.1, batch 32, 20 epochs, on the unresampled behaviour (about 110 samples per second) padded to the longest trial, stratified 6-fold cross-validation repeated 3 times, so 18 models per session. Every claim on choice decoding (S11) decodes this estimate. The cell below builds the model as the paper's code does (Keras Normalization, LSTM(10, return_sequences=True), Dense(1, sigmoid)) on one session's delay only trials and times two epochs of one fold, to estimate the whole.
import tensorflow as tf
tf.keras.utils.set_random_seed(21)
i = int(ASSETS.index[ASSETS.session == "S25-210906"][0])
s = P.load_session(ASSETS.asset_id[i]); trl = P.final_trials(s); dly = trl[trl.update_type == 1]
X, Y = [], []
for _, rr in dly.iterrows():
i0, i1 = np.searchsorted(s["t"], [rr.start_time, rr.t_choice_made])
yy = s["xy"][i0:i1, 1]
X.append(np.c_[s["trans"][i0:i1], s["rot"][i0:i1], yy / yy.max(), s["view_angle"][i0:i1]])
Y.append(np.full(i1 - i0, float(rr.choice == 2)))
lens = np.array([len(x) for x in X]); keep = lens <= 2 * lens.mean() # [paper Methods] trials longer than twice the mean excluded
X = [x for x, k in zip(X, keep) if k]; Y = [y for y, k in zip(Y, keep) if k]
Tmax = max(len(x) for x in X)
Xp = tf.keras.preprocessing.sequence.pad_sequences(X, dtype="float64", padding="post", maxlen=Tmax)
Yp = tf.keras.preprocessing.sequence.pad_sequences(Y, dtype="float64", padding="post", maxlen=Tmax)
norm = tf.keras.layers.Normalization(axis=-1); norm.adapt(np.vstack(X))
model = tf.keras.Sequential([tf.keras.Input((Tmax, 4)), norm, tf.keras.layers.LSTM(10, return_sequences=True),
tf.keras.layers.Dense(1, activation="sigmoid")])
model.compile(optimizer=tf.keras.optimizers.Adam(0.1), loss="binary_crossentropy")
n5 = int(len(X) * 5 / 6)
t = time.time(); model.fit(Xp[:n5], Yp[:n5], batch_size=32, epochs=1, verbose=0); t_first = time.time() - t
t = time.time(); model.fit(Xp[:n5], Yp[:n5], batch_size=32, epochs=1, verbose=0); t_epoch = time.time() - t
dl = [int((r["trials"].update_type == 1).sum()) for r in R]
per_session = 18 * 20 * t_epoch / 60
whole = sum(per_session * d / len(dly) for d in dl)
print(f"session {ASSETS.session[i]}: {len(X)} delay only trials, longest {Tmax} samples (mean {lens.mean():.0f})")
print(f"one epoch on 5/6 of them: first {t_first:.1f} s, second {t_epoch:.1f} s")
ncpu = os.cpu_count()
print(f"estimate: {per_session:.1f} min for this session's 18 models x 20 epochs; scaled by delay only trial counts, "
f"{whole / 60:.1f} h for all 66 sessions, against a 60 min limit for the notebook")
print(f"this machine has {ncpu} cores; one session per core would take at best {whole / 60 / ncpu:.1f} h, "
f"{'over' if whole / ncpu > 60 else 'within'} the 60 min limit")
2026-11-02 22:33:25.228021: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
session S25-210906: 119 delay only trials, longest 3601 samples (mean 1889) one epoch on 5/6 of them: first 3.6 s, second 1.7 s estimate: 10.1 min for this session's 18 models x 20 epochs; scaled by delay only trial counts, 10.1 h for all 66 sessions, against a 60 min limit for the notebook this machine has 4 cores; one session per core would take at best 2.5 h, over the 60 min limit
Result: the choice-decoding claims are not run. The estimate printed above for all 66 sessions, in one process and at best on this machine's cores, is beyond the notebook's 60 min limit (the cell prints which), so fig4a-lstm-choice-estimate and every claim that decodes the choice estimate are blocked as too_large, as the protocol's rule for an estimate over the notebook limit says. Epoch times vary from run to run, so the hours printed change when the notebook is re-run.
fig6e-predict-outcome, CA1 half: timing¶
The post-update difference between initial and new goal codes predicts whether a switch trial is correct, above shuffled labels, with 61.43% accuracy from prefrontal choice decoding and 55.83% from hippocampal position decoding.
The PFC half decodes the LSTM choice estimate, which is not run (above), and the criterion judges both regions together, so the claim cannot be decided here. The CA1 half needs no LSTM: one feature per correct or incorrect switch trial (initial minus new, 0 to 1.5 s, raw values), the smaller class resampled with replacement to the size of the larger (random_state 123), an RBF SVM with C and gamma from a 10-iteration randomized search under leave-one-out (C from loguniform(1, 1000), gamma from loguniform(1e-4, 1)), accuracy by leave-one-out, and the same on shuffled labels 1000 times (criterion). The cell below builds the CA1 feature table, times one SVM fit for each of 10 (C, gamma) draws on the balanced trials, and estimates the whole procedure: per run 10 x N search fits and N accuracy fits, for the real labels and 1000 shuffles.
from sklearn.svm import SVC
from sklearn.utils import resample
from scipy.stats import loguniform
T6 = TAB[("CA1", "final")]
d6 = T6[T6.update_type == 2].assign(f=lambda x: x.init - x.new).dropna(subset=["f"])
cor, inc = d6[d6.correct == 1], d6[d6.correct == 0]
big, small = (cor, inc) if len(cor) >= len(inc) else (inc, cor)
B6 = pd.concat([big, resample(small, replace=True, n_samples=len(big), random_state=123)])
X6, y6 = B6[["f"]].to_numpy(), B6.correct.to_numpy()
print(f"CA1 switch trials: {len(cor)} correct, {len(inc)} incorrect (paper 1702 switch trials in all); balanced N = {len(X6)}")
print("feature by outcome (initial minus new, 0 to 1.5 s):", d6.groupby("correct").f.agg(["mean", "std", "count"]).round(4).to_dict("index"))
Cs = loguniform(1, 1000).rvs(10, random_state=123); gs = loguniform(1e-4, 1).rvs(10, random_state=124)
fit_t = []
for c_, g_ in zip(Cs, gs):
t = time.time(); SVC(C=c_, gamma=g_).fit(X6[:-1], y6[:-1]); fit_t.append(time.time() - t)
n_fit = (10 + 1) * len(X6)
print("seconds per fit for the 10 draws:", np.round(fit_t, 2).tolist())
h_real = n_fit * np.mean(fit_t) / 3600
print(f"estimate: {n_fit} fits per run, {h_real:.1f} h for the real labels alone and "
f"{1001 * h_real / 24:.0f} days with 1000 shuffles, single process, against a 60 min limit")
print(f"real labels alone: {'over' if h_real > 1 else 'within'} the limit; with 1000 shuffles: "
f"{'over' if 1001 * h_real > 1 else 'within'} the limit")
CA1 switch trials: 1241 correct, 395 incorrect (paper 1702 switch trials in all); balanced N = 2482
feature by outcome (initial minus new, 0 to 1.5 s): {0.0: {'mean': 0.0187, 'std': 0.1599, 'count': 395}, 1.0: {'mean': -0.0032, 'std': 0.1805, 'count': 1241}}
seconds per fit for the 10 draws: [0.14, 0.12, 0.12, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13] estimate: 27302 fits per run, 1.0 h for the real labels alone and 41 days with 1000 shuffles, single process, against a 60 min limit real labels alone: within the limit; with 1000 shuffles: over the limit
Result: not run. The CA1 half has 1241 correct and 395 incorrect switch trials, 2482 after balancing, so the paper's procedure (leave-one-out search and accuracy) needs 27302 fits per run. At the fit time printed above, the real labels alone take of the order of an hour, close to the 60 min limit (the cell prints on which side; fit times vary from run to run), and the 1000-shuffle permutation test the criterion asks for takes weeks. The PFC half needs the LSTM choice estimate, and the criterion judges both regions together. The claim stays blocked as too_large.
Summary¶
| Claim | Outcome |
|---|---|
| recordings | Partially reproduced |
| trial-mix | Not reproduced |
| task-timing | Reproduced |
| fig1b-above-chance | Reproduced |
| fig1b-window-performance | Reproduced |
| fig1d-heading-switch | Reproduced |
| fig5a-stay-performance | Reproduced |
| tuning-tiles-track | Reproduced |
| decoding-validation | Reproduced |
| fig2e-hpc-goal-increase | Reproduced |
| fig2e-hpc-arms-equal | Reproduced |
| sfig2e-goal-bias | Reproduced |
| sfig3c-goals-over-retrospective | Not reproduced |
| sfig3c-retrospective-unchanged | Not reproduced |
| sfig3ab-original-vs-update-cue | Partially reproduced |
| sfig2f-all-trials-encoder | Partially reproduced |
| sfig5f-pfc-wider-spread | Partially reproduced |
| sfig5g-ca1-more-goal-coding | Reproduced |
| fig2g-pfc-no-goal-increase | Not reproduced |
| sfig5e-pfc-windows | Not reproduced |
| fig3c-theta-phase-segregation | Not reproduced |
| fig3b-theta-pre-post | Reproduced |
| sfig6-theta-switch-over-delay | Reproduced |
| fig3d-new-arm-theta-modulated | Reproduced |
| fig5d-stay-hpc-like-delay | Reproduced |
| fig5d-stay-hpc-below-switch | Reproduced |
| sfig10-stay-transient-new-arm | Reproduced |
| fig6b-hpc-new-lower-incorrect | Reproduced |
| fig6b-hpc-initial-no-difference | Reproduced |
| fig6-hpc-pre-cue-initial-higher-incorrect | Reproduced |
| sfig12-delay-hpc-no-outcome-difference | Not reproduced |
| fig7c-hpc-commitment-new-arm | Partially reproduced |
| fig7c-hpc-commitment-initial-arm | Reproduced |
| fig4a-lstm-choice-estimate and 18 claims on choice decoding | Blocked: too large |
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. Decoding is a numpy implementation of pynapple's decode_1d (uniform prior). The ANOVA is a Wald test without Kenward-Roger degrees of freedom, and Tukey adjustment uses the studentized range with large degrees of freedom (Kenward-Roger needs R, which is not available here). Every contrast also prints its Tukey p on as many degrees of freedom as there are sessions less the levels, a deliberately small value, to show how much the degrees of freedom could move it. Window means weight each 0.2 s bin equally, as the code's mean over samples does. On the small degrees of freedom, three contrasts that decide outcomes cross 0.05: sfig3c-retrospective-unchanged (0.036 to 0.050), sfig12-delay-hpc-no-outcome-difference (0.043 to 0.053) and the new arm front half of sfig3ab-original-vs-update-cue (0.044 to 0.063); the main-rule tests of fig2g-pfc-no-goal-increase and sfig5e-pfc-windows stay below 0.05. Session inclusion follows the claims file's shared method S1 as a reader amended it in answer to this attempt's question: at least 50 final-task trials of the session, as the Methods say (55 CA1 and 46 PFC sessions, against the paper's 56 and 47). The code's count of the encoder training trials (47 and 37 sessions) is shown for every test; it would change two outcomes, sfig3c-retrospective-unchanged (p = 0.14 against 0.036) and sfig12-delay-hpc-no-outcome-difference (p = 0.096 against 0.043). Update-aligned decoding uses the code's time grid, 0.2 s bins with edges on the cue and centres at the code's sample times (-2.5, ..., -0.1, 0.1, ..., 2.5 s), and windows take bins by centre as the code does. The round-1 grid, with one bin centred on the cue and counted after it, is shown as a variant; it gives other outcomes for three claims (sfig3c-retrospective-unchanged, fig5d-stay-hpc-below-switch and fig7c-hpc-commitment-initial-arm), so those outcomes rest on the 0.1 s by which the two grids differ. It also changes the second test of fig2g-pfc-no-goal-increase under reading b, but reading a fails on both grids, so that outcome is not reproduced either way. The arm halves of sfig3ab follow the code's split; the spread of sfig5f follows the code's rule, with the first-crossing reading as a variant. Theta phase uses a Parks-McClellan band-pass on the LFP decimated to 200 Hz; the phase stored in the file, which the paper's code reads, gives the same outcomes. Position is labelled metres but is in virtual units, and view angle and the stored theta phase are labelled degrees but are in radians. The LSTM choice estimate was not run (timed above), so fig4a-lstm-choice-estimate and the 18 claims on choice decoding are blocked.
What was found about the dataset. The behaviour and trial tables reproduce the paper's counts exactly (7172 delay only, 1840 switch and 717 stay trials; 6252, 1002 and 117 windows of 15 trials). The units of five sessions (S20-210517, S28-211114, S29-211104, S29-211105, S34-220617; 633 units) carry no region or cell type, and the ch column cannot map them to a probe; with them, the unit total equals the paper's 6449. Position is labelled metres but is in virtual units (y up to 286), and view angle (-1.05 to 1.05) and the stored theta phase (-pi to pi) are labelled degrees but are in radians. The turn_type description {'right': 1, 'left': 2} disagrees with the data: on correct delay only trials, turn_type 1 trials end at negative x, the arm the paper's code calls left, and choice 1. The Methods' window of 40 trials for Figure 1b does not give the reported window counts; 15 trials, the code's default, does.