Fritsche, Solomon & de Lange (2022) on DANDI:000021¶
Paper: Fritsche, Solomon & de Lange (2022), "Brief Stimuli Cast a Persistent Long-Term Trace in Visual Cortex", J Neurosci 42(10):1999-2010, doi:10.1523/JNEUROSCI.1350-21.2021. The paper reuses the Allen Brain Observatory Visual Coding Neuropixels data.
Dataset: DANDI:000021 (Allen Institute, Visual Coding, Neuropixels, Brain Observatory 1.1 stimulus set), version 0.251116.2246, doi:10.48324/dandi.000021/0.251116.2246. The paper names the dandiset but no version. This is the only published version, and it is the most recent; the draft has the same 214 assets and size. It holds the 32 sessions (one per mouse) the paper describes, so no earlier version could match the claims file better.
Claims: claims/fritsche-2022.yaml, written from the version of record (PMC8916757; no supplement). The paper's code (doi:10.34973/kpt9-y956) is restricted and was not read.
Data are streamed from the archive; nothing is downloaded. Loading reduces each session to spike counts per unit and presentation (about 2 to 3 minutes for the 32 files with four processes).
| Claim | Tested |
|---|---|
| units-responsive-count | tested |
| fig1d-v1-1back | tested |
| fig1d-extrastriate-1back | tested |
| fig1d-thalamus-1back | tested |
| fig1e-consistent-across-mice | tested |
| fig2-v1-tuning-main-effect | tested |
| fig2-v1-tuning-interaction | tested |
| fig2-v1-adaptation-at-all-orientations | tested |
| fig2-thalamus-no-tuning-dependence | tested |
| fig3a-v1-long-term | tested |
| fig3a-v1-double-exponential | tested |
| fig3a-v1-half-life | tested |
| fig4-cumulative-adaptation | tested |
| fig4b-linear-accumulation | tested |
| fig3b-thalamus-short-term | tested |
| v1-vs-thalamus-welch | tested |
| fig3c-mice-long-term | tested |
| decay-cortex-double-better | tested |
| table1-extrastriate-tau-slow | tested |
| decay-thalamus-single | tested |
| fig5-repeat-suppression | tested |
| fig6c-static-v1-1back | tested |
| fig6c-static-other-areas-1back | tested |
| fig6d-static-consistent-across-mice | tested |
| fig7a-static-v1-long-term | tested |
| fig7b-static-cortex-decay | tested |
| fig7-static-lgn-single | tested |
| fig7b-static-areas-long-term | tested |
| fig7c-static-long-term-across-mice | tested |
| fig8-no-spurious-long-term | tested |
| robust-threshold-preferred-window | tested |
No claim is blocked.
import os
os.environ.setdefault("OMP_NUM_THREADS", "1")
os.environ.setdefault("OPENBLAS_NUM_THREADS", "1")
import itertools, resource, time, zlib, warnings
import numpy as np
import pandas as pd
from scipy import stats
import adaptation as A
pd.set_option("display.width", 200)
pd.set_option("display.max_columns", 40)
pd.set_option("display.max_rows", 200)
KEY = "fritsche-2022"
def seed(claim):
return zlib.crc32(f"{KEY}/{claim}".encode())
T0 = time.time()
assets = A.session_assets()
print(len(assets), "session files at version", A.VERSION)
S = A.load_all(assets)
print(f"loaded in {time.time() - T0:.0f} s; peak memory of this process "
f"{resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB")
32 session files at version 0.251116.2246
loaded in 133 s; peak memory of this process 3.26 GB
Data check¶
The dandiset's 214 assets are 32 session files and 182 per-probe LFP files; only the session files are used. Each session file holds the units table (with the AllenSDK quality metrics), the electrodes table (with the CCF area of each channel), and the stimulus tables of every stimulus, of which the drifting and static grating tables and the spontaneous (gray screen) epochs are used.
rows = []
for s in S:
m, dg, sg, u = s["meta"], s["dg"], s["sg"], s["units"]
rows.append(dict(
subject=m["subject_id"], session=m["session_id"], genotype=m["genotype"].split("/")[0],
sex=m["sex"], age=m["age"], units=len(u), good=int((u.quality == "good").sum()),
pass_metrics=int(u.passes_quality.sum()),
dg_rows=len(dg), dg_blank=int(dg.orientation.isna().sum()),
dg_blocks=dg.stimulus_block.nunique(), sg_rows=len(sg),
sg_blank=int(sg.orientation.isna().sum()), sg_blocks=sg.stimulus_block.nunique(),
spont_s=round(float((s["spont"].stop_time - s["spont"].start_time).sum())),
invalid_intervals=len(s["invalid"])))
sess = pd.DataFrame(rows)
print(sess.to_string())
print("\nsubjects", sess.subject.nunique(), "sessions", sess.session.nunique())
print(sess.genotype.value_counts().to_string())
print("\nsex", sess.sex.value_counts().to_dict())
subject session genotype sex age units good pass_metrics dg_rows dg_blank dg_blocks sg_rows sg_blank sg_blocks spont_s invalid_intervals
0 699733573 715093703 Sst-IRES-Cre M P118D 2779 2110 993 628 30 3 6000 189 3 1237 8
1 703279277 719161530 Sst-IRES-Cre M P122D 3232 1852 851 628 30 3 6000 195 3 1237 1
2 707296975 721123822 Pvalb-IRES-Cre M P125D 1603 1191 497 628 30 3 6000 196 3 1237 5
3 716813540 739448407 wt M P112D 2370 1704 703 630 30 3 6000 192 3 1237 4
4 717038285 732592105 wt M P100D 3076 2816 870 628 30 3 6000 193 3 1237 4
5 718643564 737581020 wt M P108D 2055 1463 640 630 30 3 6000 191 3 1237 9
6 719817799 744228101 wt M P122D 2695 1784 745 630 30 3 6000 194 3 1237 0
7 719828686 754312389 wt M P140D 1891 1193 553 630 30 3 6000 194 3 1237 1
8 722882751 743475441 wt M P121D 2133 1459 629 630 30 3 6000 194 3 1237 8
9 723627600 742951821 wt M P120D 3008 2175 1004 630 30 3 6000 194 3 1237 7
10 726141242 750332458 wt M P91D 3047 2127 997 630 30 3 6000 191 3 1237 0
11 726162193 750749662 wt M P92D 2489 1891 871 630 30 3 6000 196 3 1237 0
12 726170927 746083955 Pvalb-IRES-Cre F P98D 2098 1553 673 630 30 3 6000 192 3 1237 0
13 726298249 754829445 wt M P141D 2299 1799 908 630 30 3 6000 197 3 1237 0
14 730756767 757970808 wt M P106D 2422 1877 874 630 30 3 6000 195 3 1237 0
15 730760263 755434585 Vip-IRES-Cre M P100D 2127 1546 737 630 30 3 6000 193 3 1237 0
16 732548371 751348571 Vip-IRES-Cre F P93D 2645 2004 952 630 30 3 6000 196 3 1237 0
17 733457986 757216464 wt M P105D 2812 2120 1063 630 30 3 6000 193 3 1237 1
18 734865729 756029989 Sst-IRES-Cre M P96D 2169 1663 770 630 30 3 6000 195 3 1237 1
19 735109599 758798717 Sst-IRES-Cre M P102D 1702 1348 628 630 30 3 6000 191 3 1237 1
20 738651046 760693773 Sst-IRES-Cre F P110D 2285 1790 911 630 30 3 6000 196 3 1237 0
21 739783158 760345702 Pvalb-IRES-Cre M P103D 1784 1339 578 630 30 3 6000 189 3 1237 0
22 740268983 759883607 wt M P113D 1763 1349 550 630 30 3 6000 193 3 1237 0
23 742602884 763673393 wt M P126D 2455 1753 734 630 30 3 6000 195 3 1267 0
24 742714472 761418226 wt M P119D 2371 1726 815 630 30 3 6000 195 3 1267 0
25 744915196 762602078 Sst-IRES-Cre M P110D 2159 1314 584 630 30 3 6000 192 3 1267 0
26 745276220 762120172 Vip-IRES-Cre M P100D 2361 1648 820 630 30 3 6000 191 3 1267 0
27 757329617 773418906 Pvalb-IRES-Cre F P124D 1880 1394 635 630 30 3 6000 196 3 1237 0
28 769360771 791319847 Vip-IRES-Cre M P116D 2020 1445 656 630 30 3 6000 193 3 1267 0
29 772616820 799864342 wt M P129D 2249 1555 682 630 30 3 6000 195 3 1267 0
30 775876808 798911424 Vip-IRES-Cre F P110D 2525 1878 917 630 30 3 6000 194 3 1267 0
31 776061236 797828357 Pvalb-IRES-Cre M P107D 2154 1610 695 630 30 3 6000 196 3 1267 4
subjects 32 sessions 32
genotype
wt 16
Sst-IRES-Cre 6
Pvalb-IRES-Cre 5
Vip-IRES-Cre 5
sex {'M': 27, 'F': 5}
# Stimulus parameters, durations and spacing.
dg_all = pd.concat([s["dg"].assign(sess=i) for i, s in enumerate(S)])
sg_all = pd.concat([s["sg"].assign(sess=i) for i, s in enumerate(S)])
print("drifting directions", sorted(dg_all.orientation.dropna().unique()))
print("temporal frequencies", sorted(dg_all.temporal_frequency.dropna().unique()))
print("contrast", sorted(dg_all.contrast.dropna().unique()))
dur = dg_all.stop_time - dg_all.start_time
print(f"drifting duration {dur.min():.3f} to {dur.max():.3f} s")
isi = np.concatenate([np.diff(s["dg"].sort_values("start_time").start_time) for s in S])
print(f"drifting onset spacing within blocks: median {np.median(isi):.3f} s, "
f"10th to 90th percentile {np.percentile(isi, 10):.3f} to {np.percentile(isi, 90):.3f} s")
print("static orientations", sorted(sg_all.orientation.dropna().unique()))
print("static spatial frequencies", sorted(sg_all.spatial_frequency.dropna().unique()))
print("static phases", sorted(sg_all.phase.dropna().unique()))
sd = sg_all.stop_time - sg_all.start_time
print(f"static duration {sd.min():.3f} to {sd.max():.3f} s")
gaps = np.concatenate([np.diff(s["sg"].sort_values("start_time").start_time.values) for s in S])
print(f"static onset spacing: median {np.median(gaps):.4f} s, 99th percentile "
f"{np.percentile(gaps, 99):.4f} s, {np.sum(gaps > 1)} gaps over 1 s (between blocks)")
per = dg_all.dropna(subset=["orientation"]).groupby(["sess", "orientation", "temporal_frequency"]).size()
print("drifting presentations per direction and frequency per session:", per.min(), "to", per.max())
cnt = sg_all.dropna(subset=["orientation"]).groupby(["sess", "orientation", "spatial_frequency", "phase"]).size()
print("static presentations per condition per session:", cnt.min(), "to", cnt.max())
for i in [0, 1, 2]:
d = S[i]["dg"].dropna(subset=["orientation"])
print(sess.session[i], "drifting gratings", len(d), d.groupby("orientation").size().to_dict())
drifting directions [np.float64(0.0), np.float64(45.0), np.float64(90.0), np.float64(135.0), np.float64(180.0), np.float64(225.0), np.float64(270.0), np.float64(315.0)]
temporal frequencies [np.float64(1.0), np.float64(2.0), np.float64(4.0), np.float64(8.0), np.float64(15.0)]
contrast [np.float64(0.8)]
drifting duration 1.985 to 2.018 s
drifting onset spacing within blocks: median 3.003 s, 10th to 90th percentile 3.002 to 3.003 s
static orientations [np.float64(0.0), np.float64(30.0), np.float64(60.0), np.float64(90.0), np.float64(120.0), np.float64(150.0)]
static spatial frequencies [np.float64(0.02), np.float64(0.04), np.float64(0.08), np.float64(0.16), np.float64(0.32)]
static phases [np.float64(0.0), np.float64(0.25), np.float64(0.5), np.float64(0.75)]
static duration 0.200 to 0.317 s
static onset spacing: median 0.2502 s, 99th percentile 0.2502 s, 64 gaps over 1 s (between blocks)
drifting presentations per direction and frequency per session: 14 to 15
static presentations per condition per session: 41 to 50
715093703 drifting gratings 598 {0.0: 74, 45.0: 75, 90.0: 75, 135.0: 74, 180.0: 75, 225.0: 75, 270.0: 75, 315.0: 75}
719161530 drifting gratings 598 {0.0: 73, 45.0: 75, 90.0: 75, 135.0: 75, 180.0: 75, 225.0: 75, 270.0: 75, 315.0: 75}
721123822 drifting gratings 598 {0.0: 75, 45.0: 75, 90.0: 74, 135.0: 75, 180.0: 75, 225.0: 75, 270.0: 75, 315.0: 74}
# Invalid intervals and whether they overlap the grating epochs.
for i, s in enumerate(S):
inv = s["invalid"]
if len(inv) == 0:
continue
ep = {"dg": (s["dg"].start_time.min(), s["dg"].stop_time.max()),
"sg": (s["sg"].start_time.min(), s["sg"].stop_time.max())}
ov = {k: int(((inv.start_time < b) & (inv.stop_time > a)).sum()) for k, (a, b) in ep.items()}
print(sess.session[i], len(inv), "invalid intervals, overlapping drifting", ov["dg"],
"static", ov["sg"], "total length", round(float((inv.stop_time - inv.start_time).sum())), "s")
715093703 8 invalid intervals, overlapping drifting 4 static 4 total length 1717 s 719161530 1 invalid intervals, overlapping drifting 0 static 0 total length 12 s 721123822 5 invalid intervals, overlapping drifting 0 static 4 total length 486 s 739448407 4 invalid intervals, overlapping drifting 2 static 2 total length 127 s 732592105 4 invalid intervals, overlapping drifting 1 static 2 total length 296 s 737581020 9 invalid intervals, overlapping drifting 0 static 5 total length 365 s 754312389 1 invalid intervals, overlapping drifting 0 static 1 total length 32 s 743475441 8 invalid intervals, overlapping drifting 6 static 2 total length 849 s 742951821 7 invalid intervals, overlapping drifting 2 static 3 total length 876 s 757216464 1 invalid intervals, overlapping drifting 0 static 1 total length 2931 s 756029989 1 invalid intervals, overlapping drifting 0 static 1 total length 18 s 758798717 1 invalid intervals, overlapping drifting 0 static 0 total length 50 s 797828357 4 invalid intervals, overlapping drifting 3 static 1 total length 248 s
# Unit areas and the AllenSDK metrics.
U = pd.concat([s["units"].assign(sess=i) for i, s in enumerate(S)])
print("units", len(U), "quality labels", U.quality.value_counts().to_dict())
for c in ["isi_violations", "amplitude_cutoff", "presence_ratio", "firing_rate"]:
v = U[c].replace([np.inf, -np.inf], np.nan)
print(f"{c}: {v.min():.3g} to {v.max():.3g}, NaN {int(v.isna().sum())}")
print("units with no area label in the electrodes table", int(U.location.isna().sum()))
q = U[U.passes_quality & (U.quality == "good")]
print("pass metrics and labelled good:", len(q))
print(q.location.value_counts().head(30).to_string())
units 74658 quality labels {'good': 54476, 'noise': 20182}
isi_violations: 0 to 7.45e+04, NaN 0
amplitude_cutoff: 0 to 0.5, NaN 0
presence_ratio: 0.01 to 0.99, NaN 0
firing_rate: 9.58e-05 to 100, NaN 0
units with no area label in the electrodes table 0
pass metrics and labelled good: 22767
location
grey 3723
CA1 2587
VISp 2118
VISal 1617
VISam 1567
VISrl 1492
LP 1475
VISl 979
VISpm 927
LGd 911
DG 745
APN 688
VIS 686
SUB 484
CA3 371
PO 303
VPM 265
Eth 229
SGN 180
MGv 178
ProS 176
LGv 110
TH 109
MB 107
VISmma 104
POL 103
MGd 103
NOT 71
VISli 54
IGL 40
# Recordings deposited more than once: identical stimulus timing, or identical spike count
# vectors of units across or within sessions.
t0 = [round(float(s["dg"].start_time.min()), 4) for s in S]
print("distinct first drifting onsets", len(set(t0)), "of", len(S))
h = {}
dup_within, dup_across = 0, 0
for i, s in enumerate(S):
seen = set()
for k in range(s["dg_counts"].shape[0]):
v = np.r_[s["dg_counts"][k], s["sg_counts"][k]]
if v.sum() < 50:
continue
key = hash(v.tobytes())
if key in seen:
dup_within += 1
seen.add(key)
if key in h and h[key] != i:
dup_across += 1
h.setdefault(key, i)
print("units with identical count vectors: within a session", dup_within, "across sessions", dup_across)
distinct first drifting onsets 32 of 32
units with identical count vectors: within a session 0 across sessions 0
# Clock check. In each session, the orientation tuning of V1 units is estimated from even trials
# and tested on odd trials, with the true orientation labels and with labels shifted by whole
# presentations. A response locked to the table's onsets gives a positive index with the true
# labels only. The onset response (0 to 100 ms against the 100 ms before onset) is also given.
def tuning_index(c, ori, shift):
o = np.roll(ori, shift)
ok = ~np.isnan(o)
idx = np.flatnonzero(ok)
ev, od = idx[::2], idx[1::2]
oris = np.unique(o[ok])
me = np.stack([c[:, ev][:, o[ev] == x].mean(1) for x in oris], 1)
mo = np.stack([c[:, od][:, o[od] == x].mean(1) for x in oris], 1)
k = me.argmax(1)
pref = mo[np.arange(len(k)), k]
orth = mo[np.arange(len(k)), (k + len(oris) // 2) % len(oris)]
with np.errstate(invalid="ignore", divide="ignore"):
return np.nanmean((pref - orth) / (pref + orth))
clock = []
for i, s in enumerate(S):
v1 = (s["units"].location.values[s["sel"]] == "VISp")
if v1.sum() < 5:
clock.append(dict(session=sess.session[i], v1_units=int(v1.sum())))
continue
dg = s["dg"]
order = np.argsort(dg.start_time.values)
ori = np.mod(dg.orientation.values[order], 180)
c = s["dg_counts"][v1][:, order].astype(float)
sgo = np.argsort(s["sg"].start_time.values)
sori = np.mod(s["sg"].orientation.values[sgo], 180)
cs = s["sg_counts"][v1][:, sgo].astype(float)
on = s["dg_counts"][v1][:, ~np.isnan(dg.orientation.values)].mean()
pre = s["dg_pre"][v1][:, ~np.isnan(dg.orientation.values)].mean()
clock.append(dict(session=sess.session[i], v1_units=int(v1.sum()),
dg_true=tuning_index(c, ori, 0), dg_shift_p1=tuning_index(c, ori, 1),
dg_shift_m1=tuning_index(c, ori, -1),
sg_true=tuning_index(cs, sori, 0), sg_shift_p10=tuning_index(cs, sori, 10),
sg_shift_m10=tuning_index(cs, sori, -10),
onset_spikes=on, pre_spikes=pre))
clock = pd.DataFrame(clock)
print(clock.round(3).to_string())
c_ = clock.dropna()
m_dg = c_.dg_true - c_[["dg_shift_p1", "dg_shift_m1"]].max(axis=1)
m_sg = c_.sg_true - c_[["sg_shift_p10", "sg_shift_m10"]].max(axis=1)
print(f"sessions checked {len(c_)}; drifting: true labels above both shifts in {int((m_dg > 0).sum())}, "
f"margin {m_dg.min():.3f} to {m_dg.max():.3f}; static: in {int((m_sg > 0).sum())}, margin "
f"{m_sg.min():.3f} to {m_sg.max():.3f}; onset spikes above pre-onset in {int((c_.onset_spikes > c_.pre_spikes).sum())}")
session v1_units dg_true dg_shift_p1 dg_shift_m1 sg_true sg_shift_p10 sg_shift_m10 onset_spikes pre_spikes 0 715093703 62 0.304 0.039 0.019 0.224 -0.008 -0.002 0.953 0.555 1 719161530 56 0.337 0.079 0.031 0.217 0.013 -0.007 0.742 0.438 2 721123822 42 0.252 -0.035 0.001 0.174 -0.008 -0.002 1.052 0.637 3 739448407 21 0.161 -0.106 0.086 0.163 -0.008 -0.018 0.700 0.318 4 732592105 114 0.163 0.015 0.005 0.250 -0.023 -0.007 0.666 0.532 5 737581020 45 0.288 0.167 0.073 0.220 0.019 0.032 0.659 0.380 6 744228101 39 0.230 -0.019 -0.003 0.155 -0.002 0.012 0.740 0.382 7 754312389 113 0.254 0.033 -0.044 0.174 -0.001 -0.010 0.424 0.337 8 743475441 59 0.251 0.078 -0.035 0.132 -0.003 0.002 0.261 0.156 9 742951821 36 0.241 -0.067 -0.024 0.186 0.004 0.017 0.776 0.511 10 750332458 70 0.350 0.033 0.078 0.235 0.012 0.011 0.637 0.358 11 750749662 61 0.325 0.093 -0.083 0.198 -0.010 -0.003 0.582 0.292 12 746083955 14 0.179 0.141 -0.042 0.195 -0.004 0.005 1.227 0.837 13 754829445 102 0.252 0.032 0.045 0.213 0.010 -0.016 0.826 0.485 14 757970808 93 0.269 0.006 0.005 0.211 -0.017 0.007 0.476 0.288 15 755434585 89 0.194 0.023 -0.005 0.225 -0.012 -0.002 0.552 0.343 16 751348571 53 0.242 0.103 0.027 0.169 -0.003 -0.006 0.686 0.444 17 757216464 93 0.253 -0.011 0.005 0.227 0.004 -0.019 0.684 0.439 18 756029989 55 0.236 0.021 -0.110 0.216 -0.013 -0.011 0.738 0.454 19 758798717 47 0.250 -0.024 -0.046 0.231 -0.008 -0.010 0.855 0.546 20 760693773 99 0.364 -0.002 -0.047 0.265 0.003 0.003 0.469 0.360 21 760345702 85 0.274 0.085 0.027 0.276 -0.007 0.005 0.605 0.366 22 759883607 75 0.170 -0.002 0.018 0.207 -0.001 -0.002 0.670 0.393 23 763673393 79 0.199 0.038 0.019 0.231 -0.003 0.006 0.728 0.610 24 761418226 43 0.218 0.007 0.021 0.289 0.000 -0.014 0.849 0.563 25 762602078 86 0.417 0.092 0.032 0.328 -0.012 0.020 0.583 0.222 26 762120172 93 0.246 0.037 -0.021 0.276 -0.003 0.003 0.587 0.364 27 773418906 44 0.212 0.024 0.036 0.207 0.004 0.001 0.544 0.452 28 791319847 107 0.240 0.046 -0.030 0.223 -0.006 0.005 0.640 0.398 29 799864342 81 0.337 0.036 -0.040 0.309 0.005 -0.011 0.576 0.374 30 798911424 101 0.259 -0.022 0.019 0.272 -0.007 -0.003 0.597 0.389 31 797828357 92 0.236 0.041 -0.042 0.194 0.009 0.007 0.778 0.616 sessions checked 32; drifting: true labels above both shifts in 32, margin 0.038 to 0.366; static: in 32, margin 0.130 to 0.308; onset spikes above pre-onset in 32
Checks of the description against the data. The files hold 32 mice, one session each: 16 wild type, 6 Sst-IRES-Cre, 5 Pvalb-IRES-Cre and 5 Vip-IRES-Cre, as the paper says. Drifting gratings have the eight directions, five temporal frequencies and contrast 0.8 of the Methods, last 1.985 to 2.018 s and start every 3.003 s, in three blocks with 30 blank trials per session. Three sessions (715093703, 719161530, 721123822) hold 598 gratings, not 600; one or two conditions there have 14 presentations. Static gratings have the six orientations, five spatial frequencies and four phases, last 0.200 to 0.317 s (median spacing 0.2502 s) with no gap within a block, and there are 189 to 197 blank sweeps among 6000 presentations, about one in 31 (the Methods say roughly one in 25). The units table holds every sorted unit, 74658 in all, of which 20182 are labelled noise in a quality column that has no description; the AllenSDK quality metrics are in columns without descriptions or units. Every unit's peak channel has an area label; 3723 of the units that pass the metrics are on channels labelled grey and 686 on VIS, which name no area. No recording is deposited twice: the first drifting onsets differ in all 32 sessions, and no unit's count vector repeats within or across sessions. Thirteen sessions list invalid intervals, tagged with a probe, some of which overlap the grating epochs; the paper does not mention them and they are not applied here. A variant that leaves out the presentations inside them is shown after fig3b-thalamus-short-term. The clock of the spike times and the stimulus tables is consistent with one clock: in every session the V1 orientation tuning measured with the true labels exceeds that with labels shifted by one drifting or ten static presentations, and the 0 to 100 ms count exceeds the count in the 100 ms before onset.
Unit selection¶
Units pass the AllenSDK quality metrics (ISI violations <= 0.5, amplitude cutoff <= 0.1,
presence ratio >= 0.9; Methods, "Unit exclusion"). The NWB files also label 20182 of the 74658
units noise; the AllenSDK's units table leaves these out by default, which the Methods'
"default quality metrics of the AllenSDK" is read to include (an assumption; the variant
without it is shown). Responsiveness follows Methods, "Unit exclusion", with the readings of O4.
def select(s, stim, rule="mean_plus_sd", src="blank", by="orientation", thr=5.0, good=True,
win=None):
if stim == "dg":
c, sp, w = s["dg_counts"], s["sp100"], A.DG_WIN
elif win == A.SG_WIN_SHORT:
c, sp, w = s["sg_counts100"], s["sp100"], A.SG_WIN_SHORT
else:
c, sp, w = s["sg_counts"], s["sp250"], A.SG_WIN
table = s[stim]
pref_ori, pr, by_ori, oris = A.preferred(c, table, w, by)
gm, gs = A.gray_stats(c, table, sp, w, src)
r = A.responsive(pr, gm, gs, thr, rule)
if good:
r &= s["units"].quality.values[s["sel"]] == "good"
return r, pref_ori, by_ori, oris
def count_regions(stim, **kw):
loc = []
for s in S:
r = select(s, stim, **kw)[0]
loc.append(s["units"].location.values[s["sel"]][r])
return pd.Series(np.concatenate(loc)).value_counts()
units-responsive-count¶
The drifting grating analysis rests on 2365 visually responsive neurons in visual cortex and thalamus of 32 mice, with 562 in V1, 140 in LGN and 90 in LP.
Every reading of O4 is run: (a) over gray mean + 1 SD or (b) over 1 SD; gray from (c) the
blank trials or (d) the spontaneous epochs (100 ms bins); preferred orientation (e) pooled over
directions and temporal frequencies or (f) the best single condition. Each also without the
noise label filter. Unlabelled channels (grey, VIS) are not regions the paper names and are
listed apart. "Kept" is the set of the paper's eight regions with at least 50 units.
NAMED = set(A.AREA_NAMES)
rows = []
for good in [True, False]:
for rule, src, by in itertools.product(["mean_plus_sd", "sd"], ["blank", "spont"],
["orientation", "condition"]):
vc = count_regions("dg", rule=rule, src=src, by=by, good=good)
named = vc[vc.index.isin(NAMED)]
kept = named[named >= 50]
other50 = sorted(vc[(~vc.index.isin(NAMED)) & (vc >= 50)].index)
g = lambda k: int(named.get(k, 0))
tot = int(kept.sum())
ok = (abs(tot - 2365) <= 236.5 and abs(g("VISp") - 562) <= 56.2
and abs(g("LGd") - 140) <= 14 and abs(g("LP") - 90) <= 9 and len(kept) == 8)
rows.append(dict(good_only=good, O4=f"{'a' if rule == 'mean_plus_sd' else 'b'}"
f"{'c' if src == 'blank' else 'd'}{'e' if by == 'orientation' else 'f'}",
total=tot, V1=g("VISp"), LM=g("VISl"), AL=g("VISal"), RL=g("VISrl"),
PM=g("VISpm"), AM=g("VISam"), LGN=g("LGd"), LP=g("LP"),
named_kept=len(kept), other_labels_50=",".join(other50),
all_within_tolerance=ok))
counts_tab = pd.DataFrame(rows)
print(counts_tab.to_string())
print("\npaper: total 2365 (tolerance 236.5), V1 562 (56.2), LGN 140 (14), LP 90 (9)")
good_only O4 total V1 LM AL RL PM AM LGN LP named_kept other_labels_50 all_within_tolerance 0 True ace 2422 580 272 435 325 210 367 142 91 8 VIS,grey True 1 True acf 4548 934 425 715 627 372 637 350 488 8 APN,CA1,CA3,DG,Eth,LGv,PO,SUB,VIS,VPM,grey False 2 True ade 2214 529 234 392 279 208 348 145 79 8 VIS,grey False 3 True adf 4041 826 388 659 532 368 604 350 314 8 APN,CA1,DG,Eth,VIS,VPM,grey False 4 True bce 4457 890 394 679 585 386 668 434 421 8 APN,CA1,CA3,DG,Eth,LGv,PO,ProS,SUB,VIS,VPM,grey False 5 True bcf 7266 1268 604 1010 946 601 991 732 1114 8 APN,CA1,CA3,DG,Eth,LGv,MB,MGd,MGv,NOT,PO,POL,ProS,SGN,SUB,TH,VIS,VISmma,VPM,grey False 6 True bde 4208 847 375 657 558 375 649 411 336 8 APN,CA1,CA3,DG,Eth,LGv,PO,ProS,SUB,VIS,VPM,grey False 7 True bdf 7146 1228 598 1016 930 602 982 729 1061 8 APN,CA1,CA3,DG,Eth,LGv,MB,MGd,MGv,NOT,PO,POL,ProS,SGN,SUB,TH,VIS,VISmma,VPM,grey False 8 False ace 2518 606 284 450 335 216 377 149 101 8 VIS,grey False 9 False acf 4753 975 444 739 656 383 667 368 521 8 APN,CA1,CA3,DG,Eth,LGv,PO,SUB,VIS,VPM,grey False 10 False ade 2298 548 243 402 288 213 359 153 92 8 VIS,grey True 11 False adf 4224 863 403 682 559 380 629 370 338 8 APN,CA1,DG,Eth,VIS,VPM,grey False 12 False bce 4665 931 412 700 628 400 690 452 452 8 APN,CA1,CA3,DG,Eth,LGv,PO,ProS,SGN,SUB,VIS,VPM,grey False 13 False bcf 7626 1335 633 1048 1008 620 1033 775 1174 8 APN,CA1,CA3,DG,Eth,LGv,MB,MGd,MGv,NOT,PO,POL,ProS,SGN,SUB,TH,VIS,VISmma,VPM,grey False 14 False bde 4400 889 390 676 597 388 668 431 361 8 APN,CA1,CA3,DG,Eth,LGv,PO,ProS,SUB,VIS,VPM,grey False 15 False bdf 7485 1290 625 1054 990 620 1022 768 1116 8 APN,CA1,CA3,DG,Eth,LGv,MB,MGd,MGv,NOT,PO,POL,ProS,SGN,SUB,TH,VIS,VISmma,VPM,grey False paper: total 2365 (tolerance 236.5), V1 562 (56.2), LGN 140 (14), LP 90 (9)
The analyses below use the reading that the counts single out for both stimulus sets (see also
the static counts below): noise units left out, gray mean + 1 SD of the blank presentations,
preferred orientation pooled over the other stimulus parameters (O4 a, c, e).
Ratios use the main reading of O1 to O3: per unit the mean rate over all repeat trials over the mean over all orthogonal trials (O1a); the region value is exp(mean log ratio) (O2a); blank trials hold a position in the sequence and pairs are formed within each stimulus block (O3a, c). The other readings are shown for the 1-back values.
MAIN = dict(rule="mean_plus_sd", src="blank", by="orientation", good=True)
def build(stim, sel_kw=MAIN, blanks="hold", blocks="within", n_max=50, win=None, short_counts=False):
"""Per responsive unit: area, session index, n-back structures and preferred orientation."""
out = dict(area=[], sess=[], pref=[], nb=[], by_ori=[], oris=None)
for i, s in enumerate(S):
r, pref, by_ori, oris = select(s, stim, win=win, **sel_kw)
area = s["units"].area.values[s["sel"]]
r &= pd.notna(area)
if stim == "dg":
c = s["dg_counts"]
else:
c = s["sg_counts100"] if (win == A.SG_WIN_SHORT or short_counts) else s["sg_counts"]
nb, nb_oris = A.nback_rates(c[r], s[stim], n_max, blanks, blocks)
out["area"].append(area[r]); out["sess"].append(np.full(r.sum(), i))
out["pref"].append(pref[r]); out["nb"].append(nb); out["by_ori"].append(by_ori[r])
out["oris"] = nb_oris
out["area"] = np.concatenate(out["area"]); out["sess"] = np.concatenate(out["sess"])
out["pref"] = np.concatenate(out["pref"]); out["by_ori"] = np.concatenate(out["by_ori"])
out["nb"] = {k: np.concatenate([nb[k] for nb in out["nb"]]) for k in ["rs", "rn", "os", "on"]}
return out
t = time.time()
D = {}
for blanks, blocks in itertools.product(["hold", "remove"], ["within", "across"]):
D[("dg", blanks, blocks)] = build("dg", blanks=blanks, blocks=blocks)
D[("sg", blanks, blocks)] = build("sg", blanks=blanks, blocks=blocks)
print(f"n-back tables built in {time.time() - t:.0f} s")
DG, SG = D[("dg", "hold", "within")], D[("sg", "hold", "within")]
AR = {k: {h: A.ratios(v["nb"], h) for h in ["pooled", "per_ori", "per_ori_geo"]} for k, v in D.items()}
ar_dg, ar_sg = AR[("dg", "hold", "within")]["pooled"], AR[("sg", "hold", "within")]["pooled"]
for name, ar in [("drifting", ar_dg), ("static", ar_sg)]:
lr = np.log(ar)
print(f"{name}: {ar.shape[0]} units x {ar.shape[1]} n; non-finite log ratios {int((~np.isfinite(lr)).sum())}")
print(f" ratio range {np.nanmin(ar):.3f} to {np.nanmax(ar):.3f}")
print(" units per area", pd.Series(D[('dg' if name == 'drifting' else 'sg', 'hold', 'within')]['area']).value_counts().to_dict())
print("repeat pairs per unit at 1-back (drifting), median", np.median(DG["nb"]["rn"][:, 0].sum(1)),
"orthogonal", np.median(DG["nb"]["on"][:, 0].sum(1)))
print("repeat pairs per unit at 1-back (static), median", np.median(SG["nb"]["rn"][:, 0].sum(1)),
"orthogonal", np.median(SG["nb"]["on"][:, 0].sum(1)))
def onebak_table(stim):
rows = []
for (st, blanks, blocks), d in D.items():
if st != stim:
continue
for how in ["pooled", "per_ori", "per_ori_geo"]:
ar = AR[(st, blanks, blocks)][how]
for agg in ["geo", "mean"]:
row = dict(O1=how, O2=agg, blanks=blanks, blocks=blocks)
for a in A.CORTEX + A.THALAMUS:
x = ar[d["area"] == a, 0]
row[a] = round(A.region_value(x, agg), 3) if len(x) else np.nan
rows.append(row)
return pd.DataFrame(rows)
def region_stats(ar, area, n=0, regions=A.CORTEX + A.THALAMUS):
rows = []
for a in regions:
x = ar[area == a, n]
lr = np.log(x); lr = lr[np.isfinite(lr)]
if len(lr) < 2:
continue
t_, p, k = A.ttest_log(x)
ci = np.exp(lr.mean() + np.array([-1, 1]) * stats.t.ppf(0.975, k - 1) * lr.std(ddof=1) / np.sqrt(k))
rows.append(dict(area=a, n_units=k, ratio=np.exp(lr.mean()), ci_low=ci[0], ci_high=ci[1],
t=t_, p=p))
df = pd.DataFrame(rows)
df["p_fdr"] = A.fdr(df.p.values)[0]
return df
n-back tables built in 6 s
drifting: 2422 units x 50 n; non-finite log ratios 0
ratio range 0.138 to 5.699
units per area {'V1': 580, 'AL': 435, 'AM': 367, 'RL': 325, 'LM': 272, 'PM': 210, 'LGN': 142, 'LP': 91}
static: 1495 units x 50 n; non-finite log ratios 0
ratio range 0.442 to 1.524
units per area {'V1': 545, 'AL': 230, 'AM': 179, 'LM': 176, 'PM': 159, 'RL': 128, 'LGN': 61, 'LP': 17}
repeat pairs per unit at 1-back (drifting), median 144.0 orthogonal 139.0
repeat pairs per unit at 1-back (static), median 936.0 orthogonal 947.0
# Variant: the main analyses with `noise` units kept (O4 a, c, e otherwise), to show how much the
# adopted filter matters downstream.
NOISE_KW = dict(MAIN, good=False)
dgv = build("dg", sel_kw=NOISE_KW); sgv = build("sg", sel_kw=NOISE_KW)
arv, arsv = A.ratios(dgv["nb"], "pooled"), A.ratios(sgv["nb"], "pooled")
print("drifting 1-back, noise units kept:", {a: round(A.region_value(arv[dgv["area"] == a, 0]), 3) for a in A.CORTEX + A.THALAMUS})
print("static 1-back, noise units kept:", {a: round(A.region_value(arsv[sgv["area"] == a, 0]), 3) for a in A.CORTEX + A.THALAMUS})
for region in ["V1", "LGN", "LP"]:
lr = np.log(arv[dgv["area"] == region]); lr = np.where(np.isfinite(lr), lr, np.nan)
ps = [stats.ttest_1samp(lr[:, n][np.isfinite(lr[:, n])], 0).pvalue for n in range(10)]
adj, rej = A.fdr(ps)
m = np.nanmean(lr, 0)
sig = [n + 1 for n in range(10) if rej[n] and m[n] < 0]
dd, ss = A.fit_models(m, -1)
print(f"{region}, noise units kept: {int((dgv['area'] == region).sum())} units; significant n {sig}; "
f"double fit a_fast {100 * dd[0][0]:.2f}%, tau_fast {dd[0][1]:.3f}, a_slow {100 * dd[0][2]:.2f}%, "
f"tau_slow {dd[0][3]:.2f}; single tau {ss[0][1]:.3f}")
drifting 1-back, noise units kept: {'V1': 0.822, 'LM': 0.826, 'AL': 0.829, 'RL': 0.879, 'PM': 0.799, 'AM': 0.821, 'LGN': 0.93, 'LP': 0.837}
static 1-back, noise units kept: {'V1': 0.895, 'LM': 0.892, 'AL': 0.914, 'RL': 0.926, 'PM': 0.894, 'AM': 0.912, 'LGN': 0.956, 'LP': 0.893}
V1, noise units kept: 606 units; significant n [1, 2, 3, 4, 5, 6, 7, 8]; double fit a_fast 13.98%, tau_fast 0.838, a_slow 3.94%, tau_slow 6.93; single tau 1.511
LGN, noise units kept: 149 units; significant n [1, 7]; double fit a_fast 50.00%, tau_fast 0.777, a_slow -43.04%, tau_slow 0.88; single tau 0.000
LP, noise units kept: 101 units; significant n [1, 2]; double fit a_fast 17.09%, tau_fast 0.732, a_slow -0.62%, tau_slow 50.00; single tau 0.671
Result: reproduced. With noise units left out and the reading O4 a, c, e (over the gray mean + 1 SD of the blank trials, preferred orientation pooled), 2422 units are responsive in the eight regions (V1 580, LGN 142, LP 91), each count within tolerance, and all eight named regions have at least 50. Without the noise filter, reading a, d, e also matches (2298; V1 548, LGN 153, LP 92). Units on channels labelled grey or VIS also reach 50; they name no region and are not counted as regions. With noise units kept, the 1-back ratios of the eight regions move by at most 0.007 for either stimulus set and V1 stays significant to 8-back with a tau_slow of 6.93, but LGN gains a significant 7-back and its single-exponential tau falls to 0.000; the claims on the thalamic decay rest on the filter. Leaving out the presentations inside the files' invalid intervals (375 drifting presentations in 5 sessions, 7001 static in 10; variant after fig3b-thalamus-short-term) gives 2425 drifting-responsive units (V1 585, LGN 140, LP 94), all within tolerance.
fig1d-v1-1back¶
In V1 the immediate repetition of orientation reduces the early (0 to 100 ms) response to drifting gratings by 17%, a 1-back adaptation ratio of 0.83.
r1 = region_stats(ar_dg, DG["area"])
def show_p(df):
out = df.copy()
for c in [c for c in out.columns if c.startswith("p")]:
out[c] = out[c].map(lambda x: f"{x:.2g}")
return out.round(4).to_string()
print("main reading (O1a, O2a, O3a+c); CI is the t interval of the mean log ratio")
print(show_p(r1))
tab1 = onebak_table("dg")
print("\n1-back ratio under every reading of O1 to O3 (drifting)")
print(tab1.to_string())
v1 = tab1["V1"]
print(f"\nV1 range over readings {v1.min():.3f} to {v1.max():.3f}; readings inside [0.81, 0.84]: "
f"{int(((v1 >= 0.81) & (v1 <= 0.84)).sum())} of {len(v1)}")
for (st, bl, bk), d in D.items():
if st == "dg":
for how in ["pooled", "per_ori", "per_ori_geo"]:
t_, p, k = A.ttest_log(AR[(st, bl, bk)][how][d["area"] == "V1", 0])
print(f"V1 t test, {how}, {bl}, {bk}: t = {t_:.2f}, p = {p:.1e}, n = {k}")
print("by session: V1 ratio per mouse (units)")
v1m = pd.Series(ar_dg[DG["area"] == "V1", 0]).groupby(DG["sess"][DG["area"] == "V1"]).apply(
lambda x: f"{np.exp(np.log(x).mean()):.3f} ({len(x)})")
print(v1m.to_dict())
main reading (O1a, O2a, O3a+c); CI is the t interval of the mean log ratio
area n_units ratio ci_low ci_high t p p_fdr
0 V1 580 0.8212 0.8038 0.8390 -18.0175 6e-58 2.4e-57
1 LM 272 0.8282 0.8059 0.8511 -13.5744 2.2e-32 3.6e-32
2 AL 435 0.8284 0.8117 0.8453 -18.2521 1.2e-55 3.2e-55
3 RL 325 0.8756 0.8553 0.8964 -11.1220 1.5e-24 2e-24
4 PM 210 0.7949 0.7739 0.8166 -16.8612 7.7e-41 1.5e-40
5 AM 367 0.8193 0.8034 0.8355 -19.9991 1.2e-60 9.3e-60
6 LGN 142 0.9352 0.9117 0.9593 -5.2069 6.7e-07 6.7e-07
7 LP 91 0.8334 0.7926 0.8763 -7.2105 1.7e-10 1.9e-10
1-back ratio under every reading of O1 to O3 (drifting)
O1 O2 blanks blocks V1 LM AL RL PM AM LGN LP
0 pooled geo hold within 0.821 0.828 0.828 0.876 0.795 0.819 0.935 0.833
1 pooled mean hold within 0.848 0.849 0.847 0.896 0.810 0.834 0.946 0.855
2 per_ori geo hold within 0.871 0.877 0.905 0.955 0.857 0.884 0.954 0.859
3 per_ori mean hold within 0.924 0.931 0.944 1.015 0.892 0.923 0.963 0.881
4 per_ori_geo geo hold within 0.849 0.843 0.862 0.910 0.817 0.849 0.930 0.828
5 per_ori_geo mean hold within 0.884 0.878 0.887 0.945 0.839 0.874 0.940 0.851
6 pooled geo hold across 0.822 0.828 0.829 0.876 0.796 0.820 0.935 0.834
7 pooled mean hold across 0.849 0.850 0.848 0.897 0.811 0.835 0.946 0.856
8 per_ori geo hold across 0.872 0.878 0.906 0.953 0.862 0.885 0.954 0.858
9 per_ori mean hold across 0.926 0.931 0.945 1.011 0.897 0.923 0.963 0.881
10 per_ori_geo geo hold across 0.850 0.845 0.862 0.910 0.821 0.850 0.929 0.829
11 per_ori_geo mean hold across 0.885 0.878 0.887 0.944 0.842 0.875 0.939 0.851
12 pooled geo remove within 0.831 0.839 0.842 0.885 0.806 0.831 0.942 0.847
13 pooled mean remove within 0.856 0.858 0.858 0.905 0.820 0.845 0.952 0.867
14 per_ori geo remove within 0.879 0.891 0.914 0.962 0.870 0.901 0.959 0.873
15 per_ori mean remove within 0.929 0.943 0.951 1.024 0.903 0.944 0.969 0.894
16 per_ori_geo geo remove within 0.858 0.857 0.873 0.918 0.827 0.867 0.936 0.845
17 per_ori_geo mean remove within 0.890 0.888 0.896 0.952 0.849 0.894 0.945 0.866
18 pooled geo remove across 0.832 0.839 0.842 0.885 0.807 0.832 0.942 0.847
19 pooled mean remove across 0.856 0.858 0.859 0.905 0.822 0.845 0.952 0.867
20 per_ori geo remove across 0.880 0.892 0.914 0.961 0.871 0.901 0.959 0.872
21 per_ori mean remove across 0.931 0.942 0.951 1.020 0.904 0.943 0.968 0.892
22 per_ori_geo geo remove across 0.859 0.858 0.873 0.918 0.829 0.867 0.935 0.845
23 per_ori_geo mean remove across 0.891 0.889 0.896 0.951 0.850 0.894 0.945 0.865
V1 range over readings 0.821 to 0.931; readings inside [0.81, 0.84]: 4 of 24
V1 t test, pooled, hold, within: t = -18.02, p = 6.0e-58, n = 580
V1 t test, per_ori, hold, within: t = -9.29, p = 3.1e-19, n = 580
V1 t test, per_ori_geo, hold, within: t = -13.50, p = 2.5e-36, n = 580
V1 t test, pooled, hold, across: t = -17.96, p = 1.2e-57, n = 580
V1 t test, per_ori, hold, across: t = -9.18, p = 7.4e-19, n = 580
V1 t test, per_ori_geo, hold, across: t = -13.37, p = 9.8e-36, n = 580
V1 t test, pooled, remove, within: t = -18.00, p = 7.4e-58, n = 580
V1 t test, per_ori, remove, within: t = -9.05, p = 2.2e-18, n = 580
V1 t test, per_ori_geo, remove, within: t = -13.30, p = 2.1e-35, n = 580
V1 t test, pooled, remove, across: t = -17.95, p = 1.3e-57, n = 580
V1 t test, per_ori, remove, across: t = -8.94, p = 5.2e-18, n = 580
V1 t test, per_ori_geo, remove, across: t = -13.16, p = 8.4e-35, n = 580
by session: V1 ratio per mouse (units)
{0: '0.785 (22)', 1: '0.895 (21)', 2: '0.805 (21)', 3: '0.849 (9)', 4: '0.879 (19)', 5: '0.884 (13)', 6: '0.744 (14)', 7: '0.846 (19)', 8: '0.925 (5)', 9: '0.850 (11)', 10: '0.738 (18)', 11: '0.782 (22)', 12: '0.698 (2)', 13: '0.889 (34)', 14: '0.848 (22)', 15: '0.781 (20)', 16: '0.844 (14)', 17: '0.894 (26)', 18: '0.770 (12)', 19: '0.854 (13)', 20: '0.756 (18)', 21: '0.741 (26)', 22: '0.938 (13)', 23: '0.724 (13)', 24: '0.823 (16)', 25: '0.784 (32)', 26: '0.790 (22)', 27: '0.965 (7)', 28: '0.785 (29)', 29: '0.857 (23)', 30: '0.886 (23)', 31: '0.791 (21)'}
Result: reproduced. Under the main reading the V1 1-back ratio is 0.821 (t interval 0.804 to 0.839) over 580 units, t = -18.02, p = 6.0e-58, inside [0.81, 0.84]. Four of the 24 readings fall inside the interval, all with the pooled per-unit ratio (O1a) and the geometric region value (O2a); the per-orientation readings give 0.849 to 0.931.
fig1d-extrastriate-1back¶
Extrastriate areas show similar 1-back adaptation to drifting gratings, with ratios between 0.80 and 0.88, all significant.
Correction (O6): Benjamini-Hochberg over the eight areas (p_fdr above); Bonferroni over five
is shown as a variant.
ex = r1[r1.area.isin(["LM", "AL", "RL", "PM", "AM"])].copy()
ex["p_bonf5"] = np.minimum(ex.p * 5, 1)
print(show_p(ex))
print(f"\nmain reading: range {ex.ratio.min():.3f} to {ex.ratio.max():.3f}; all in [0.72, 0.968]: "
f"{bool(ex.ratio.between(0.72, 0.968).all())}; largest corrected p {ex.p_fdr.max():.1e}")
rng_tab = tab1[["O1", "O2", "blanks", "blocks"]].copy()
rng_tab["ex_min"] = tab1[["LM", "AL", "RL", "PM", "AM"]].min(axis=1)
rng_tab["ex_max"] = tab1[["LM", "AL", "RL", "PM", "AM"]].max(axis=1)
rng_tab["all_in_range"] = (rng_tab.ex_min >= 0.72) & (rng_tab.ex_max <= 0.968)
print(rng_tab.to_string())
area n_units ratio ci_low ci_high t p p_fdr p_bonf5
1 LM 272 0.8282 0.8059 0.8511 -13.5744 2.2e-32 3.6e-32 1.1e-31
2 AL 435 0.8284 0.8117 0.8453 -18.2521 1.2e-55 3.2e-55 6e-55
3 RL 325 0.8756 0.8553 0.8964 -11.1220 1.5e-24 2e-24 7.4e-24
4 PM 210 0.7949 0.7739 0.8166 -16.8612 7.7e-41 1.5e-40 3.8e-40
5 AM 367 0.8193 0.8034 0.8355 -19.9991 1.2e-60 9.3e-60 5.8e-60
main reading: range 0.795 to 0.876; all in [0.72, 0.968]: True; largest corrected p 2.0e-24
O1 O2 blanks blocks ex_min ex_max all_in_range
0 pooled geo hold within 0.795 0.876 True
1 pooled mean hold within 0.810 0.896 True
2 per_ori geo hold within 0.857 0.955 True
3 per_ori mean hold within 0.892 1.015 False
4 per_ori_geo geo hold within 0.817 0.910 True
5 per_ori_geo mean hold within 0.839 0.945 True
6 pooled geo hold across 0.796 0.876 True
7 pooled mean hold across 0.811 0.897 True
8 per_ori geo hold across 0.862 0.953 True
9 per_ori mean hold across 0.897 1.011 False
10 per_ori_geo geo hold across 0.821 0.910 True
11 per_ori_geo mean hold across 0.842 0.944 True
12 pooled geo remove within 0.806 0.885 True
13 pooled mean remove within 0.820 0.905 True
14 per_ori geo remove within 0.870 0.962 True
15 per_ori mean remove within 0.903 1.024 False
16 per_ori_geo geo remove within 0.827 0.918 True
17 per_ori_geo mean remove within 0.849 0.952 True
18 pooled geo remove across 0.807 0.885 True
19 pooled mean remove across 0.822 0.905 True
20 per_ori geo remove across 0.871 0.961 True
21 per_ori mean remove across 0.904 1.020 False
22 per_ori_geo geo remove across 0.829 0.918 True
23 per_ori_geo mean remove across 0.850 0.951 True
Result: reproduced. The five extrastriate ratios run from 0.795 (PM) to 0.876 (RL), inside [0.72, 0.968], and the largest corrected p is 2.0e-24. Every reading keeps all five inside the range except the four that average per-orientation ratios and take the arithmetic region mean.
fig1d-thalamus-1back¶
LGN and LP also show orientation-specific 1-back adaptation to drifting gratings, with ratios of 0.93 and 0.83.
th = r1[r1.area.isin(A.THALAMUS)]
print(show_p(th))
print("\npaper: LGN 0.93 [0.91, 0.96] p = 8e-7 (n = 140); LP 0.83 [0.79, 0.88] p = 3e-10 (n = 90)")
print(tab1[["O1", "O2", "blanks", "blocks", "LGN", "LP"]].to_string())
both = tab1.LGN.between(0.91, 0.96) & tab1.LP.between(0.79, 0.88)
print("readings with both inside their CIs:", int(both.sum()), "of", len(tab1))
area n_units ratio ci_low ci_high t p p_fdr
6 LGN 142 0.9352 0.9117 0.9593 -5.2069 6.7e-07 6.7e-07
7 LP 91 0.8334 0.7926 0.8763 -7.2105 1.7e-10 1.9e-10
paper: LGN 0.93 [0.91, 0.96] p = 8e-7 (n = 140); LP 0.83 [0.79, 0.88] p = 3e-10 (n = 90)
O1 O2 blanks blocks LGN LP
0 pooled geo hold within 0.935 0.833
1 pooled mean hold within 0.946 0.855
2 per_ori geo hold within 0.954 0.859
3 per_ori mean hold within 0.963 0.881
4 per_ori_geo geo hold within 0.930 0.828
5 per_ori_geo mean hold within 0.940 0.851
6 pooled geo hold across 0.935 0.834
7 pooled mean hold across 0.946 0.856
8 per_ori geo hold across 0.954 0.858
9 per_ori mean hold across 0.963 0.881
10 per_ori_geo geo hold across 0.929 0.829
11 per_ori_geo mean hold across 0.939 0.851
12 pooled geo remove within 0.942 0.847
13 pooled mean remove within 0.952 0.867
14 per_ori geo remove within 0.959 0.873
15 per_ori mean remove within 0.969 0.894
16 per_ori_geo geo remove within 0.936 0.845
17 per_ori_geo mean remove within 0.945 0.866
18 pooled geo remove across 0.942 0.847
19 pooled mean remove across 0.952 0.867
20 per_ori geo remove across 0.959 0.872
21 per_ori mean remove across 0.968 0.892
22 per_ori_geo geo remove across 0.935 0.845
23 per_ori_geo mean remove across 0.945 0.865
readings with both inside their CIs: 20 of 24
Result: reproduced. LGN 0.935 (t interval 0.912 to 0.959, 142 units) and LP 0.833 (0.793 to 0.876, 91 units) lie in the paper's intervals, both below 1 at p of the order of 1e-7 and 1e-10 (the table above). Twenty of the 24 readings put both inside.
fig1e-consistent-across-mice¶
The 1-back response reduction is consistent across mice, in thalamus and in cortex.
Per mouse (one session each), the mean over its responsive units of the 0 to 100 ms rate on 1-back repeat and orthogonal trials (Figure 1E legend). Readings: (a) every mouse has orthogonal above repeat; (b) a two-sided sign test across mice at p < 0.05.
def mouse_rates(d, group, ns, win):
"""Per session: mean over units of the repeat and orthogonal rates, trials pooled over the
n in `ns` (pooled) or rates averaged over n (averaged)."""
nb = d["nb"]; idx = np.array(ns) - 1
out = []
for pooled in [True, False]:
if pooled:
rep = nb["rs"][:, idx].sum((1, 2)) / nb["rn"][:, idx].sum((1, 2)) / win
orth = nb["os"][:, idx].sum((1, 2)) / nb["on"][:, idx].sum((1, 2)) / win
else:
rep = (nb["rs"][:, idx].sum(2) / nb["rn"][:, idx].sum(2)).mean(1) / win
orth = (nb["os"][:, idx].sum(2) / nb["on"][:, idx].sum(2)).mean(1) / win
m = np.isin(d["area"], group)
df = pd.DataFrame(dict(sess=d["sess"][m], rep=rep[m], orth=orth[m]))
g = df.groupby("sess").agg(rep=("rep", "mean"), orth=("orth", "mean"), units=("rep", "size"))
g["pooled"] = pooled
out.append(g)
return out
def consistency(g, label):
above = int((g.orth > g.rep).sum()); n = len(g)
p = stats.binomtest(above, n, 0.5).pvalue if n else np.nan
ok_a = above == n and n > 0
ok_b = (p < 0.05) and above > n / 2
print(f"{label}: {n} mice, {above} with orthogonal above repeat, sign test p = {p:.2g}, "
f"median orth - rep {np.median(g.orth - g.rep):.3f} Hz; (a) {ok_a}, (b) {ok_b}")
for k, row in g[g.orth <= g.rep].iterrows():
print(f" not above: session {S[k]['meta']['session_id']}, {int(row.units)} units, "
f"repeat {row.rep:.2f} Hz, orthogonal {row.orth:.2f} Hz")
return ok_a, ok_b
for grp, name in [(A.THALAMUS, "thalamus"), (A.CORTEX, "cortex")]:
g = mouse_rates(DG, grp, [1], A.DG_WIN)[0]
consistency(g, f"drifting 1-back, {name}")
print(f" rates {g[['rep', 'orth']].min().min():.2f} to {g[['rep', 'orth']].max().max():.2f} Hz")
drifting 1-back, thalamus: 23 mice, 21 with orthogonal above repeat, sign test p = 6.6e-05, median orth - rep 2.156 Hz; (a) False, (b) True not above: session 744228101, 4 units, repeat 15.97 Hz, orthogonal 15.61 Hz not above: session 754312389, 2 units, repeat 20.17 Hz, orthogonal 19.20 Hz rates 7.76 to 42.70 Hz
drifting 1-back, cortex: 32 mice, 32 with orthogonal above repeat, sign test p = 4.7e-10, median orth - rep 1.912 Hz; (a) True, (b) True rates 7.55 to 17.14 Hz
Result: partially reproduced. In cortex all 32 mice have the orthogonal rate above the repeat rate (sign test p = 4.7e-10), reading (a). In thalamus 21 of the 23 mice with thalamic units do (p = 6.6e-05), so only reading (b) holds there. The two mice that fail (a) have 4 and 2 thalamic units, with repeat rates 0.36 and 0.97 Hz above orthogonal.
fig2-v1-tuning-main-effect¶
In V1, 1-back adaptation is strongest when adaptor and test match the neuron's preferred orientation and weakens for less preferred orientations, a main effect of relative orientation.
Per region, OSI from the 0 to 100 ms rates to the preferred orientation and its orthogonal (Methods, equation 4), split into tertiles. Per unit, the 1-back ratio of each test orientation preceded by itself over preceded by its orthogonal, at 0, 45 and 90 degrees from preferred. Readings: ANOVA on (a) log ratios or (b) ratios; the 45 degree level (c) pools the trials of +45 and -45 or (d) averages their two ratios.
def tuning_cells(d, region):
m = d["area"] == region
nb = {k: v[m][:, 0, :] for k, v in d["nb"].items()} # 1-back, per current orientation
oris = d["oris"]; k = len(oris)
by_ori = d["by_ori"][m]
pi = np.array([int(np.flatnonzero(oris == p)[0]) for p in d["pref"][m]])
rows = np.arange(m.sum())
def ratio_at(j_list, pool=True):
if pool:
rs = sum(nb["rs"][rows, j] for j in j_list); rn = sum(nb["rn"][rows, j] for j in j_list)
os_ = sum(nb["os"][rows, j] for j in j_list); on = sum(nb["on"][rows, j] for j in j_list)
return (rs / rn) / (os_ / on)
return np.mean([(nb["rs"][rows, j] / nb["rn"][rows, j]) / (nb["os"][rows, j] / nb["on"][rows, j])
for j in j_list], 0)
half = k // 2
out = {}
for pool in [True, False]:
r0 = ratio_at([pi])
r45 = ratio_at([(pi + 1) % k, (pi - 1) % k], pool)
r90 = ratio_at([(pi + half) % k])
out[pool] = np.stack([r0, r45, r90], 1)
pref = by_ori[rows, pi]; orth = by_ori[rows, (pi + half) % k]
osi = (pref - orth) / (pref + orth)
tert = pd.qcut(pd.Series(osi).rank(method="first"), 3, labels=["low", "medium", "high"]).values
return out, osi, np.asarray(tert)
ANOVA = {}
CELLS = {}
for region in A.CORTEX + A.THALAMUS:
with np.errstate(divide="ignore", invalid="ignore"):
out, osi, tert = tuning_cells(DG, region)
for pool in [True, False]:
R = out[pool]
with np.errstate(divide="ignore", invalid="ignore"):
ok = np.all(np.isfinite(np.log(R)), 1)
CELLS[(region, pool)] = (R[ok], tert[ok], int((~ok).sum()))
for scale in ["log", "ratio"]:
Y = np.log(R[ok]) if scale == "log" else R[ok]
ANOVA[(region, pool, scale)] = A.mixed_anova(Y, tert[ok])
def anova_table(regions):
rows = []
for (region, pool, scale), r in ANOVA.items():
if region not in regions:
continue
R, tert, dropped = CELLS[(region, pool)]
gm = np.exp(np.log(R).mean(0))
rows.append(dict(region=region, level45="pooled (c)" if pool else "averaged (d)", scale=scale,
units=len(R), dropped=dropped,
F_rel=r["within"][0], p_rel=f"{r['within'][1]:.2g}",
F_int=r["interaction"][0], p_int=f"{r['interaction'][1]:.2g}",
df=f"{r['within'][2]},{r['within'][3]}",
ratio0=gm[0], ratio45=gm[1], ratio90=gm[2]))
return pd.DataFrame(rows)
print(anova_table(["V1"]).round(3).to_string())
R, tert, _ = CELLS[("V1", True)]
print("\nV1 ratio by tertile (rows) and relative orientation 0, 45, 90 (pooled 45):")
for t_ in ["low", "medium", "high"]:
print(t_, np.round(np.exp(np.log(R[tert == t_]).mean(0)), 3), "units", int((tert == t_).sum()))
print("\nother cortical areas, main effect and interaction (log, pooled 45):")
print(anova_table(["LM", "AL", "RL", "PM", "AM"]).query("scale == 'log' and level45 == 'pooled (c)'").round(3).to_string())
region level45 scale units dropped F_rel p_rel F_int p_int df ratio0 ratio45 ratio90 0 V1 pooled (c) log 502 78 19.972 3.1e-09 3.280 0.011 2,998 0.799 0.875 0.927 1 V1 pooled (c) ratio 502 78 27.918 1.6e-12 8.123 1.9e-06 2,998 0.799 0.875 0.927 2 V1 averaged (d) log 484 96 22.594 2.6e-10 2.987 0.018 2,962 0.802 0.918 0.923 3 V1 averaged (d) ratio 484 96 30.956 9.4e-14 8.739 6.3e-07 2,962 0.802 0.918 0.923 V1 ratio by tertile (rows) and relative orientation 0, 45, 90 (pooled 45): low [0.841 0.883 0.898] units 194 medium [0.792 0.878 0.918] units 192 high [0.745 0.857 0.993] units 116 other cortical areas, main effect and interaction (log, pooled 45): region level45 scale units dropped F_rel p_rel F_int p_int df ratio0 ratio45 ratio90 0 LM pooled (c) log 250 22 3.821 0.023 1.117 0.35 2,494 0.816 0.851 0.892 4 AL pooled (c) log 413 22 9.853 5.9e-05 5.580 0.0002 2,820 0.826 0.864 0.922 8 RL pooled (c) log 300 25 24.696 5e-11 7.897 3.3e-06 2,594 0.843 0.889 1.029 12 PM pooled (c) log 200 10 3.663 0.027 5.136 0.00048 2,394 0.790 0.806 0.867 16 AM pooled (c) log 349 18 4.959 0.0073 6.340 5.2e-05 2,692 0.807 0.856 0.875
Result: reproduced. In V1 the main effect of relative orientation is significant under all four readings (p = 3.1e-09 on log ratios with the 45 degree trials pooled, 9.4e-14 to 2.6e-10 under the others), and the 0 degree ratio is the lowest (0.799 against 0.875 at 45 and 0.927 at 90). 78 of 580 V1 units (96 with averaged 45) are left out for a cell with no spikes, so the ANOVA has 502 units.
fig2-v1-tuning-interaction¶
The dependence of V1 adaptation on relative orientation is strongest in highly orientation-selective neurons (interaction of relative orientation and OSI).
for pool in [True, False]:
R, tert, _ = CELLS[("V1", pool)]
for scale in ["log", "ratio"]:
r = ANOVA[("V1", pool, scale)]["interaction"]
spread = {t_: float(np.ptp(np.exp(np.log(R[tert == t_]).mean(0)))) for t_ in ["low", "medium", "high"]}
print(f"45 {'pooled' if pool else 'averaged'}, {scale}: interaction F = {r[0]:.2f}, p = {r[1]:.2g}; "
f"spread of ratios over relative orientation by tertile {np.round(list(spread.values()), 3)}; "
f"largest in high: {max(spread, key=spread.get) == 'high'}")
45 pooled, log: interaction F = 3.28, p = 0.011; spread of ratios over relative orientation by tertile [0.057 0.125 0.248]; largest in high: True 45 pooled, ratio: interaction F = 8.12, p = 1.9e-06; spread of ratios over relative orientation by tertile [0.057 0.125 0.248]; largest in high: True 45 averaged, log: interaction F = 2.99, p = 0.018; spread of ratios over relative orientation by tertile [0.068 0.136 0.236]; largest in high: True 45 averaged, ratio: interaction F = 8.74, p = 6.3e-07; spread of ratios over relative orientation by tertile [0.068 0.136 0.236]; largest in high: True
Result: reproduced. The interaction of relative orientation and OSI tertile has p = 0.011 (log, pooled 45; 6.3e-07 to 0.018 under the other readings), and the spread of ratios over relative orientation grows from 0.057 (low) to 0.125 (medium) to 0.248 (high OSI).
fig2-v1-adaptation-at-all-orientations¶
V1 neurons adapt for all adaptor orientations relative to their preference, except nonpreferred (90 degree) adaptor and test in the most selective units.
Per cell of tertile and relative orientation, a t test of log ratios against zero, corrected by Benjamini-Hochberg (O6) over (a) the nine V1 cells or (b) all 72 cells of the eight areas; Bonferroni as a variant.
def cell_tests(pool):
rows = []
for region in A.CORTEX + A.THALAMUS:
R, tert, _ = CELLS[(region, pool)]
for t_ in ["low", "medium", "high"]:
for j, rel in enumerate([0, 45, 90]):
x = np.log(R[tert == t_, j])
tt = stats.ttest_1samp(x, 0)
rows.append(dict(region=region, tertile=t_, rel=rel, n=len(x), ratio=np.exp(x.mean()),
t=tt.statistic, p=tt.pvalue))
df = pd.DataFrame(rows)
df["p_bh_all"] = A.fdr(df.p.values)[0]
df["p_bonf_all"] = np.minimum(df.p * len(df), 1)
v = df.region == "V1"
df.loc[v, "p_bh_v1"] = A.fdr(df.p[v].values)[0]
df.loc[v, "p_bonf_v1"] = np.minimum(df.p[v] * 9, 1)
return df
for pool in [True, False]:
ct = cell_tests(pool)
v = ct[ct.region == "V1"].copy()
print(f"45 {'pooled (c)' if pool else 'averaged (d)'}")
show = v.copy()
for c in ["p", "p_bh_all", "p_bonf_all", "p_bh_v1", "p_bonf_v1"]:
show[c] = show[c].map(lambda x: f"{x:.2g}")
print(show.round(3).to_string())
for col in ["p_bh_v1", "p_bh_all", "p_bonf_v1", "p_bonf_all"]:
other = v[~((v.tertile == "high") & (v.rel == 90))]
hi90 = v[(v.tertile == "high") & (v.rel == 90)].iloc[0]
n_ok = int(((other[col] < 0.05) & (other.ratio < 1)).sum())
print(f" {col}: {n_ok} of 8 other cells below 1 at corrected p < 0.05; high OSI at 90: "
f"ratio {hi90.ratio:.3f}, corrected p {hi90[col]:.2g}")
45 pooled (c) region tertile rel n ratio t p p_bh_all p_bonf_all p_bh_v1 p_bonf_v1 0 V1 low 0 194 0.841 -8.802 7.6e-16 9.1e-15 5.5e-14 3.4e-15 6.8e-15 1 V1 low 45 194 0.883 -6.419 1e-09 3.1e-09 7.5e-08 2.3e-09 9.3e-09 2 V1 low 90 194 0.898 -5.206 4.9e-07 1.1e-06 3.5e-05 7.4e-07 4.4e-06 3 V1 medium 0 192 0.792 -12.213 1e-25 7.2e-24 7.2e-24 9e-25 9e-25 4 V1 medium 45 192 0.878 -5.803 2.7e-08 6.4e-08 1.9e-06 4.8e-08 2.4e-07 5 V1 medium 90 192 0.918 -2.591 0.01 0.013 0.74 0.012 0.093 6 V1 high 0 116 0.745 -9.092 3.4e-15 3.5e-14 2.4e-13 1e-14 3e-14 7 V1 high 45 116 0.857 -2.908 0.0044 0.0059 0.31 0.0056 0.039 8 V1 high 90 116 0.993 -0.097 0.92 0.92 1 0.92 1 p_bh_v1: 8 of 8 other cells below 1 at corrected p < 0.05; high OSI at 90: ratio 0.993, corrected p 0.92 p_bh_all: 8 of 8 other cells below 1 at corrected p < 0.05; high OSI at 90: ratio 0.993, corrected p 0.92 p_bonf_v1: 7 of 8 other cells below 1 at corrected p < 0.05; high OSI at 90: ratio 0.993, corrected p 1 p_bonf_all: 6 of 8 other cells below 1 at corrected p < 0.05; high OSI at 90: ratio 0.993, corrected p 1
45 averaged (d)
region tertile rel n ratio t p p_bh_all p_bonf_all p_bh_v1 p_bonf_v1 0 V1 low 0 193 0.845 -8.755 1.1e-15 1.9e-14 7.6e-14 4.7e-15 9.5e-15 1 V1 low 45 193 0.913 -4.868 2.3e-06 5.4e-06 0.00017 4.2e-06 2.1e-05 2 V1 low 90 193 0.901 -5.085 8.7e-07 2.1e-06 6.3e-05 2e-06 7.8e-06 3 V1 medium 0 188 0.794 -12.008 5.4e-25 3.9e-23 3.9e-23 4.9e-24 4.9e-24 4 V1 medium 45 188 0.931 -2.807 0.0055 0.0085 0.4 0.0083 0.05 5 V1 medium 90 188 0.917 -2.590 0.01 0.015 0.74 0.013 0.093 6 V1 high 0 103 0.742 -8.539 1.4e-13 1.6e-12 9.8e-12 4.1e-13 1.2e-12 7 V1 high 45 103 0.906 -1.777 0.079 0.099 1 0.088 0.71 8 V1 high 90 103 0.978 -0.281 0.78 0.8 1 0.78 1 p_bh_v1: 7 of 8 other cells below 1 at corrected p < 0.05; high OSI at 90: ratio 0.978, corrected p 0.78 p_bh_all: 7 of 8 other cells below 1 at corrected p < 0.05; high OSI at 90: ratio 0.978, corrected p 0.8 p_bonf_v1: 6 of 8 other cells below 1 at corrected p < 0.05; high OSI at 90: ratio 0.978, corrected p 1 p_bonf_all: 5 of 8 other cells below 1 at corrected p < 0.05; high OSI at 90: ratio 0.978, corrected p 1
# Units left out of Figure 2's analysis, by OSI tertile and the relative orientation whose ratio
# is not finite in log (a zero repeat or orthogonal rate), with 45 degrees pooled.
with np.errstate(divide="ignore", invalid="ignore"):
out_v1, osi_v1, tert_v1 = tuning_cells(DG, "V1")
R_all = out_v1[True]
bad = ~np.isfinite(np.log(R_all))
rows = []
for t_ in ["low", "medium", "high"]:
m = tert_v1 == t_
rows.append(dict(tertile=t_, units=int(m.sum()), kept=int((m & ~bad.any(1)).sum()),
**{f"not_finite_{rel}": int(bad[m, j].sum()) for j, rel in enumerate([0, 45, 90])},
**{f"repeat_zero_{rel}": int((m & (R_all[:, j] == 0)).sum()) for j, rel in enumerate([0, 45, 90])}))
print("V1, 45 pooled:"); print(pd.DataFrame(rows).to_string(index=False))
# The high-OSI 90 degree cell on the ratio scale, units with a zero repeat rate kept (ratio 0);
# a zero orthogonal rate gives no ratio and is left out.
hi = (tert_v1 == "high")
x90 = R_all[hi, 2]
fin = np.isfinite(x90)
tt = stats.ttest_1samp(x90[fin], 1.0)
print(f"high OSI, 90 degrees, ratio scale with zero-repeat units kept: {int(fin.sum())} units "
f"({int((x90[fin] == 0).sum())} at 0, {int((~fin).sum())} with no ratio), mean ratio {x90[fin].mean():.3f}, "
f"t = {tt.statistic:.2f}, p = {tt.pvalue:.2g}")
x90k = R_all[hi & ~bad.any(1), 2]
tt = stats.ttest_1samp(np.log(x90k), 0)
print(f"high OSI, 90 degrees, as analysed (log, units with any zero cell left out): {len(x90k)} units, "
f"ratio {np.exp(np.log(x90k).mean()):.3f}, p = {tt.pvalue:.2g}")
# Variant: tertiles formed after the units with a non-finite cell are left out, so that they are
# equal in the analysis.
keep = ~bad.any(1)
tert2 = np.asarray(pd.qcut(pd.Series(osi_v1[keep]).rank(method="first"), 3, labels=["low", "medium", "high"]).values)
R2 = R_all[keep]
for scale in ["log", "ratio"]:
Y = np.log(R2) if scale == "log" else R2
an = A.mixed_anova(Y, tert2)
print(f"tertiles after exclusion, {scale}: main effect p = {an['within'][1]:.2g}, interaction p = {an['interaction'][1]:.2g}")
rows = []
for t_ in ["low", "medium", "high"]:
for j, rel in enumerate([0, 45, 90]):
x = np.log(R2[tert2 == t_, j]); tt = stats.ttest_1samp(x, 0)
rows.append(dict(tertile=t_, rel=rel, n=len(x), ratio=np.exp(x.mean()), p=tt.pvalue))
c2 = pd.DataFrame(rows); c2["p_bh_v1"] = A.fdr(c2.p.values)[0]
print(c2.round(4).to_string(index=False))
other = c2[~((c2.tertile == "high") & (c2.rel == 90))]
print(" other cells below 1 at BH p < 0.05:", int(((other.p_bh_v1 < 0.05) & (other.ratio < 1)).sum()), "of 8; high 90 BH p",
round(float(c2[(c2.tertile == "high") & (c2.rel == 90)].p_bh_v1.iloc[0]), 3))
spread = {t_: float(np.ptp(c2[c2.tertile == t_].ratio)) for t_ in ["low", "medium", "high"]}
print(" spread over relative orientation by tertile", {k: round(v, 3) for k, v in spread.items()})
V1, 45 pooled:
tertile units kept not_finite_0 not_finite_45 not_finite_90 repeat_zero_0 repeat_zero_45 repeat_zero_90
low 194 194 0 0 0 0 0 0
medium 193 192 0 1 0 0 0 0
high 193 116 0 23 70 0 13 18
high OSI, 90 degrees, ratio scale with zero-repeat units kept: 141 units (18 at 0, 52 with no ratio), mean ratio 1.116, t = 1.38, p = 0.17
high OSI, 90 degrees, as analysed (log, units with any zero cell left out): 116 units, ratio 0.993, p = 0.92
tertiles after exclusion, log: main effect p = 3.3e-09, interaction p = 0.033
tertiles after exclusion, ratio: main effect p = 2e-12, interaction p = 0.00011
tertile rel n ratio p p_bh_v1
low 0 168 0.8483 0.0000 0.0000
low 45 168 0.8880 0.0000 0.0000
low 90 168 0.9184 0.0001 0.0001
medium 0 167 0.7902 0.0000 0.0000
medium 45 167 0.8844 0.0000 0.0000
medium 90 167 0.8911 0.0009 0.0010
high 0 167 0.7618 0.0000 0.0000
high 45 167 0.8531 0.0001 0.0002
high 90 167 0.9734 0.6190 0.6190
other cells below 1 at BH p < 0.05: 8 of 8; high 90 BH p 0.619
spread over relative orientation by tertile {'low': 0.07, 'medium': 0.101, 'high': 0.212}
Result: reproduced. With the 45 degree trials pooled and Benjamini-Hochberg over the nine V1 cells, all eight other cells are below 1 at corrected p < 0.05 (largest 0.012, medium OSI at 90 degrees), and the high OSI cell at 90 degrees is not (ratio 0.993, p = 0.92). The same holds with the family of all 72 cells. With Bonferroni 7 (V1 family) or 6 (all cells) of 8 pass, and with the 45 degree ratios averaged 7 of 8 pass under Benjamini-Hochberg. The units left out of Figure 2's analysis are almost all in the high OSI tertile (77 of 193, for a zero rate at 45 or 90 degrees; 1 of 193 in the medium tertile, none in the low), so that tertile has 116 units. With tertiles formed after the exclusion (168, 167, 167 units) all eight other cells are below 1 at corrected p < 0.05 and the high OSI cell at 90 degrees is not (0.973, p = 0.62); on the ratio scale, keeping every high OSI unit with a 90 degree ratio, 18 of them 0 (no repeat spikes), gives a mean ratio of 1.116 over 141 units, p = 0.17 against 1 (52 units have no orthogonal spikes and so no ratio). The main effect (p = 3.3e-09) and the interaction (p = 0.033 on log ratios) also stay significant with the re-formed tertiles, and the spread over relative orientation is still largest in the high tertile (0.212, against 0.070 and 0.101).
fig2-thalamus-no-tuning-dependence¶
In LGN and LP, 1-back adaptation does not depend on the adaptor and test orientation relative to preference, nor does that dependence interact with orientation selectivity.
A claim of absence, judged on the paper's test: the 3 x 3 mixed ANOVA at alpha 0.05, in the main reading of the V1 claim (log ratios, pooled 45 degrees); the other readings are shown.
print(anova_table(A.THALAMUS).round(3).to_string())
for region in A.THALAMUS:
R, tert, _ = CELLS[(region, True)]
for t_ in ["low", "medium", "high"]:
print(region, t_, "ratios at 0, 45, 90:", np.round(np.exp(np.log(R[tert == t_]).mean(0)), 3),
"units", int((tert == t_).sum()))
region level45 scale units dropped F_rel p_rel F_int p_int df ratio0 ratio45 ratio90 0 LGN pooled (c) log 142 0 2.174 0.12 1.367 0.25 2,278 0.918 0.959 0.908 1 LGN pooled (c) ratio 142 0 1.281 0.28 1.217 0.3 2,278 0.918 0.959 0.908 2 LGN averaged (d) log 142 0 2.646 0.073 1.334 0.26 2,278 0.918 0.964 0.908 3 LGN averaged (d) ratio 142 0 1.753 0.18 1.203 0.31 2,278 0.918 0.964 0.908 4 LP pooled (c) log 91 0 0.099 0.91 0.187 0.95 2,176 0.829 0.835 0.819 5 LP pooled (c) ratio 91 0 0.120 0.89 0.367 0.83 2,176 0.829 0.835 0.819 6 LP averaged (d) log 91 0 0.413 0.66 0.180 0.95 2,176 0.829 0.852 0.819 7 LP averaged (d) ratio 91 0 0.296 0.74 0.357 0.84 2,176 0.829 0.852 0.819 LGN low ratios at 0, 45, 90: [0.885 0.907 0.879] units 48 LGN medium ratios at 0, 45, 90: [0.883 0.985 0.938] units 47 LGN high ratios at 0, 45, 90: [0.991 0.987 0.91 ] units 47 LP low ratios at 0, 45, 90: [0.85 0.863 0.826] units 31 LP medium ratios at 0, 45, 90: [0.841 0.833 0.806] units 30 LP high ratios at 0, 45, 90: [0.795 0.811 0.826] units 30
Result: reproduced. On the paper's test (log ratios, pooled 45 degrees) neither LGN (main effect F = 2.17, p = 0.12; interaction F = 1.37, p = 0.25) nor LP (F = 0.10, p = 0.91; F = 0.19, p = 0.95) shows an effect at 0.05. No reading reaches 0.05; the smallest p is 0.073 (LGN main effect, averaged 45, log). The LGN ratios per cell run from 0.879 to 0.991 and LP from 0.795 to 0.863.
fig3a-v1-long-term¶
V1 neurons adapt significantly to drifting gratings seen up to eight presentations (22 s) earlier, despite intervening stimuli.
t tests of unit log ratios against zero for n = 1 to 10, Benjamini-Hochberg at 0.05 per region (Methods). Every reading of O1 and O3 is run.
def nback_tests(ar, area, region, n_range):
x = ar[area == region]
ps, ts, ms = [], [], []
for n in n_range:
t_, p, k = A.ttest_log(x[:, n - 1])
ps.append(p); ts.append(t_)
lr = np.log(x[:, n - 1]); ms.append(np.exp(lr[np.isfinite(lr)].mean()))
adj, rej = A.fdr(ps)
sig = [n for n, r_, m in zip(n_range, rej, ms) if r_ and m < 1]
return pd.DataFrame(dict(n=list(n_range), ratio=ms, t=ts, p=ps, p_fdr=adj, sig=rej)), sig
def readings_sig(stim, region, n_range):
rows = []
for (st, bl, bk), d in D.items():
if st != stim:
continue
for how in ["pooled", "per_ori", "per_ori_geo"]:
_, sig = nback_tests(AR[(st, bl, bk)][how], d["area"], region, n_range)
rows.append(dict(O1=how, blanks=bl, blocks=bk, significant=sig,
largest=max(sig) if sig else 0))
return pd.DataFrame(rows)
tv1, sig_v1 = nback_tests(ar_dg, DG["area"], "V1", range(1, 11))
show = tv1.copy(); show[["p", "p_fdr"]] = show[["p", "p_fdr"]].map(lambda x: f"{x:.2g}")
print(show.round(4).to_string())
print("main reading: significant n", sig_v1, "largest", max(sig_v1))
rs_v1 = readings_sig("dg", "V1", range(1, 11))
print(rs_v1.to_string())
# By session: the number of mice whose V1 units' mean 8-back log ratio is below zero.
lr8 = np.log(ar_dg[DG["area"] == "V1", 7])
by = pd.Series(lr8).groupby(DG["sess"][DG["area"] == "V1"]).mean()
print(f"8-back: {int((by < 0).sum())} of {len(by)} mice with mean V1 log ratio below zero")
n ratio t p p_fdr sig 0 1 0.8212 -18.0175 6e-58 6e-57 True 1 2 0.9177 -10.9424 1.8e-25 9.2e-25 True 2 3 0.9795 -2.9629 0.0032 0.0053 True 3 4 0.9651 -4.9326 1.1e-06 3.5e-06 True 4 5 0.9734 -3.8115 0.00015 0.00038 True 5 6 0.9785 -3.0583 0.0023 0.0047 True 6 7 0.9800 -2.8000 0.0053 0.0075 True 7 8 0.9836 -2.3860 0.017 0.022 True 8 9 0.9870 -1.7469 0.081 0.09 False 9 10 1.0095 1.2502 0.21 0.21 False main reading: significant n [1, 2, 3, 4, 5, 6, 7, 8] largest 8
O1 blanks blocks significant largest 0 pooled hold within [1, 2, 3, 4, 5, 6, 7, 8] 8 1 per_ori hold within [1, 2] 2 2 per_ori_geo hold within [1, 2, 3, 4, 5, 6, 7, 8] 8 3 pooled hold across [1, 2, 3, 4, 5, 6, 7, 8] 8 4 per_ori hold across [1, 2] 2 5 per_ori_geo hold across [1, 2, 3, 4, 5, 6, 7, 8] 8 6 pooled remove within [1, 2, 3, 4, 5, 8] 8 7 per_ori remove within [1, 2] 2 8 per_ori_geo remove within [1, 2, 4, 5] 5 9 pooled remove across [1, 2, 3, 4, 5, 8] 8 10 per_ori remove across [1, 2] 2 11 per_ori_geo remove across [1, 2, 4, 5, 8] 8 8-back: 22 of 32 mice with mean V1 log ratio below zero
Result: reproduced. Under the main reading V1 adaptation is significant at every n from 1 to 8 and not at 9 or 10 (8-back ratio 0.984), so the largest significant n is 8. Seven of 12 readings give 8; the four per-orientation arithmetic readings stop at 2, and one geometric reading at 5. In 22 of 32 mice the mean V1 8-back log ratio is below zero.
fig3a-v1-double-exponential¶
The decay of V1 adaptation over n-back trials is captured by a double exponential with a fast (13.99%, 0.85 trials) and a slow (3.45%, 6.82 trials) component.
Least squares on log ratios against the log of the model, n = 1 to 50, bounds of the Methods (O5). The fit to the region's mean log ratio (O5a) and to every unit's log ratio (O5b) have the same estimates here, as every unit has a finite value at every n; they differ only in the F test below. Sign reading (a) both terms reduce the response; (b) as printed.
def mean_log(ar, area, region):
lr = np.log(ar[area == region])
return lr, lr.mean(0)
def fits_for(ar, area, regions):
rows = {}
for region in regions:
lr, m = mean_log(ar, area, region)
for sign in (-1, 1):
d, s = A.fit_models(m, sign)
F, p = A.ftest(s[1], d[1], len(m))
# unit-level F test (O5b): residuals of every unit's log ratio about the model
n = np.arange(1, len(m) + 1)
rss_d = float(np.sum((lr - np.log(A.model_double(n, *d[0], sign=sign))) ** 2))
rss_s = float(np.sum((lr - np.log(A.model_single(n, *s[0]))) ** 2))
Fu, pu = A.ftest(rss_s, rss_d, lr.size)
rows[(region, sign)] = dict(region=region, sign="minus (a)" if sign < 0 else "plus (b)",
a_fast=100 * d[0][0], tau_fast=d[0][1], a_slow=100 * d[0][2],
tau_slow=d[0][3], a_single=100 * s[0][0], tau_single=s[0][1],
F=F, p_F=p, F_units=Fu, p_F_units=pu,
double_on_bound=A.on_bound(d[0], A.B_D),
single_on_bound=A.on_bound(s[0], A.B_S))
return rows
FIT_DG = fits_for(ar_dg, DG["area"], A.CORTEX + A.THALAMUS)
def fit_table(F_, regions):
df = pd.DataFrame([v for (r, s), v in F_.items() if r in regions])
for c in ["p_F", "p_F_units"]:
df[c] = df[c].map(lambda x: f"{x:.2g}")
return df
print(fit_table(FIT_DG, ["V1"]).round(3).to_string())
v = FIT_DG[("V1", -1)]
ci = {"a_fast": (10.73, 16.14), "tau_fast": (0.59, 1.13), "a_slow": (1.71, 6.64), "tau_slow": (3.39, 13.5)}
for k_, (lo, hi) in ci.items():
print(f"{k_}: {v[k_]:.3f} against Table 1 CI [{lo}, {hi}]: inside {lo <= v[k_] <= hi}")
vb = FIT_DG[("V1", 1)]
print(f"sign reading (b): a_slow {vb['a_slow']:.3f}% (the same curve with the slow amplitude's sign flipped)")
fit_rows = []
for (st, bl, bk), d in D.items():
if st != "dg":
continue
for how in ["pooled", "per_ori", "per_ori_geo"]:
ar = AR[(st, bl, bk)][how]
lr = np.log(ar[d["area"] == "V1"])
lr = np.where(np.isfinite(lr), lr, np.nan)
dd, ss = A.fit_models(np.nanmean(lr, 0), -1)
inside = all(lo <= x <= hi for x, (lo, hi) in zip(
[100 * dd[0][0], dd[0][1], 100 * dd[0][2], dd[0][3]], ci.values()))
fit_rows.append(dict(O1=how, blanks=bl, blocks=bk, a_fast=100 * dd[0][0], tau_fast=dd[0][1],
a_slow=100 * dd[0][2], tau_slow=dd[0][3], all_inside=inside))
print(pd.DataFrame(fit_rows).round(3).to_string())
region sign a_fast tau_fast a_slow tau_slow a_single tau_single F p_F F_units p_F_units double_on_bound single_on_bound 0 V1 minus (a) 14.209 0.816 3.755 6.714 17.558 1.415 7.495 0.0015 12.395 4.2e-06 False False 1 V1 plus (b) 14.208 0.816 -3.756 6.714 17.558 1.415 7.495 0.0015 12.395 4.2e-06 False False a_fast: 14.209 against Table 1 CI [10.73, 16.14]: inside True tau_fast: 0.816 against Table 1 CI [0.59, 1.13]: inside True a_slow: 3.755 against Table 1 CI [1.71, 6.64]: inside True tau_slow: 6.714 against Table 1 CI [3.39, 13.5]: inside True sign reading (b): a_slow -3.756% (the same curve with the slow amplitude's sign flipped)
O1 blanks blocks a_fast tau_fast a_slow tau_slow all_inside 0 pooled hold within 14.209 0.816 3.755 6.714 True 1 per_ori hold within 13.523 1.429 -1.036 50.000 False 2 per_ori_geo hold within 11.110 0.670 4.002 6.524 True 3 pooled hold across 14.360 0.829 3.524 6.599 True 4 per_ori hold across 13.612 1.664 -1.510 50.000 False 5 per_ori_geo hold across 11.060 0.667 3.936 6.621 True 6 pooled remove within 13.087 0.802 3.852 6.443 True 7 per_ori remove within 12.951 1.384 -1.131 50.000 False 8 per_ori_geo remove within 11.494 0.748 2.747 8.193 True 9 pooled remove across 13.338 0.820 3.542 6.428 True 10 per_ori remove across 13.088 1.468 -1.509 50.000 False 11 per_ori_geo remove across 11.704 0.764 2.414 8.407 True
Result: reproduced. The fit gives a_fast 14.21%, tau_fast 0.816 trials, a_slow 3.76% and tau_slow 6.71 trials, each inside its Table 1 interval, under sign reading (a). Reading (b) fits the same curve with a_slow = -3.76%, which is outside its interval as a signed value. Eight of 12 readings of O1 and O3 put all four inside; the per-orientation arithmetic readings put tau_slow on its bound of 50.
fig3a-v1-half-life¶
Adaptation in this study has a half-life of about 14 s; read here as the slow V1 component for drifting gratings.
tau_slow x 3 s per trial x ln 2 (criterion).
trial_s = float(np.median(isi))
hl = FIT_DG[("V1", -1)]["tau_slow"] * 3 * np.log(2)
print(f"tau_slow {FIT_DG[('V1', -1)]['tau_slow']:.3f} trials; half-life {hl:.2f} s with 3 s per trial "
f"(measured median onset spacing {trial_s:.3f} s gives {FIT_DG[('V1', -1)]['tau_slow'] * trial_s * np.log(2):.2f} s)")
print(f"inside 14 +- 1.4 s: {abs(hl - 14) <= 1.4}")
tau_slow 6.714 trials; half-life 13.96 s with 3 s per trial (measured median onset spacing 3.003 s gives 13.97 s) inside 14 +- 1.4 s: True
Result: reproduced. tau_slow of 6.714 trials at 3 s per trial gives a half-life of 13.96 s, within 14 +- 1.4 s (13.97 s with the measured 3.003 s spacing).
fig4-cumulative-adaptation¶
Taken together, 2- to 8-back stimuli would reduce the V1 response by 19%, more than the 17% reduction from the 1-back stimulus, assuming linear accumulation.
rows = []
for (st, bl, bk), d in D.items():
if st != "dg":
continue
for how in ["pooled", "per_ori", "per_ori_geo"]:
ar = AR[(st, bl, bk)][how]
for agg in ["geo", "mean"]:
rv = [A.region_value(ar[d["area"] == "V1", n], agg) for n in range(8)]
cum = 100 * (1 - np.prod(rv[1:8])); one = 100 * (1 - rv[0])
rows.append(dict(O1=how, O2=agg, blanks=bl, blocks=bk, one_back=one, cumulative_2_8=cum,
both_within=abs(cum - 19) <= 1.9 and abs(one - 17) <= 1.7,
cum_exceeds=cum > one))
cum_tab = pd.DataFrame(rows)
print(cum_tab.round(2).to_string())
print("main reading (row 0): 1-back", round(cum_tab.one_back[0], 2), "% and 2- to 8-back", round(cum_tab.cumulative_2_8[0], 2), "%")
O1 O2 blanks blocks one_back cumulative_2_8 both_within cum_exceeds 0 pooled geo hold within 17.88 20.36 True True 1 pooled mean hold within 15.16 11.61 False False 2 per_ori geo hold within 12.87 10.02 False False 3 per_ori mean hold within 7.56 -17.97 False False 4 per_ori_geo geo hold within 15.07 19.64 False True 5 per_ori_geo mean hold within 11.60 5.06 False False 6 pooled geo hold across 17.80 19.59 True True 7 pooled mean hold across 15.09 10.83 False False 8 per_ori geo hold across 12.76 10.00 False False 9 per_ori mean hold across 7.43 -17.85 False False 10 per_ori_geo geo hold across 14.95 19.52 False True 11 per_ori_geo mean hold across 11.47 4.87 False False 12 pooled geo remove within 16.86 19.83 True True 13 pooled mean remove within 14.41 10.74 False False 14 per_ori geo remove within 12.12 7.94 False False 15 per_ori mean remove within 7.06 -21.10 False False 16 per_ori_geo geo remove within 14.19 16.17 False True 17 per_ori_geo mean remove within 10.99 0.76 False False 18 pooled geo remove across 16.80 18.89 True True 19 pooled mean remove across 14.35 9.85 False False 20 per_ori geo remove across 11.99 6.99 False False 21 per_ori mean remove across 6.92 -22.24 False False 22 per_ori_geo geo remove across 14.06 15.35 False True 23 per_ori_geo mean remove across 10.85 -0.06 False False main reading (row 0): 1-back 17.88 % and 2- to 8-back 20.36 %
Result: reproduced. Under the main reading the 1-back reduction is 17.88% and the cumulative 2- to 8-back reduction 20.36%, both within tolerance, and the cumulative one is larger. The four pooled geometric readings all match (18.89 to 20.36% against 16.80 to 17.88%); the arithmetic and per-orientation readings do not.
fig4b-linear-accumulation¶
When two adjacent past stimuli both had the current orientation, the observed adaptation roughly matches that predicted by multiplying the single n-back effects.
Observed: rate when the n-back and (n+1)-back gratings both had the current orientation over (c) the rate when both were orthogonal, or (d) the n-back orthogonal and the (n+1)-back any orientation. Predicted: the product of the region's single n-back and (n+1)-back ratios. Pairs (a) 1-2 or (b) every pair from 1-2 to 7-8. 95% CI of the observed ratio by bootstrap over V1 units (1000 resamples, the claim's seed).
def pair_ratios(region, blanks="hold", blocks="within"):
out = {"c": [], "d": []}
for i, s in enumerate(S):
r = select(s, "dg", **MAIN)[0]
area = s["units"].area.values[s["sel"]]
r &= area == region
if r.sum() == 0:
continue
ori, blk, order = A.sequence(s["dg"], None, blanks, blocks)
c = s["dg_counts"][r][:, order].astype(float)
per = {"c": [], "d": []}
for n in range(1, 8):
cur = ori[n + 1:]
p1 = ori[1: len(ori) - n] # n-back of position i is i - n
p2 = ori[: len(ori) - n - 1] # (n+1)-back
same = (blk[n + 1:] == blk[: len(ori) - n - 1])
def rel(a, b):
dlt = np.abs(a - b); return np.minimum(dlt, 180 - dlt)
v = same & ~np.isnan(cur) & ~np.isnan(p1) & ~np.isnan(p2)
both_rep = v & (rel(cur, p1) == 0) & (rel(cur, p2) == 0)
both_orth = v & (rel(cur, p1) == 90) & (rel(cur, p2) == 90)
n_orth = v & (rel(cur, p1) == 90)
cc = c[:, n + 1:]
rep = cc[:, both_rep].mean(1)
per["c"].append(rep / cc[:, both_orth].mean(1))
per["d"].append(rep / cc[:, n_orth].mean(1))
for k in per:
out[k].append(np.stack(per[k], 1))
return {k: np.concatenate(v) for k, v in out.items()}
PR = pair_ratios("V1")
rng = np.random.default_rng(seed("fig4b-linear-accumulation"))
single = [A.region_value(ar_dg[DG["area"] == "V1", n], "geo") for n in range(8)]
def boot_ci(lr, rng, n_boot=1000):
U = len(lr)
b = np.array([lr[rng.integers(0, U, U)].mean() for _ in range(n_boot)])
return np.exp(np.percentile(b, [2.5, 97.5]))
def fig4b_eval(rng, verbose=True):
res = {}
for base in ["c", "d"]:
lr = np.log(PR[base])
rows = []
for n in range(1, 8):
x = lr[:, n - 1]; ok = np.isfinite(x)
lo, hi = boot_ci(x[ok], rng)
pred = single[n - 1] * single[n]
rows.append(dict(pair=f"{n}-{n + 1}", units=int(ok.sum()), dropped=int((~ok).sum()),
observed=np.exp(x[ok].mean()), ci_low=lo, ci_high=hi, predicted=pred,
inside=lo <= pred <= hi))
res[base] = pd.DataFrame(rows)
return res
F4 = fig4b_eval(rng)
for base, df in F4.items():
print(f"baseline ({base})"); print(df.round(4).to_string())
print(f" (a) pair 1-2 inside: {bool(df.inside.iloc[0])}; (b) all pairs inside: {bool(df.inside.all())} "
f"({int(df.inside.sum())} of 7)")
for k in [1000, 2000, 3000, 4000]:
alt = fig4b_eval(np.random.default_rng(seed("fig4b-linear-accumulation") + k))
print(f"seed + {k}: inside per pair, baseline (c) {alt['c'].inside.astype(int).tolist()}, "
f"(d) {alt['d'].inside.astype(int).tolist()}")
/tmp/ipykernel_2525/3240907760.py:25: RuntimeWarning: divide by zero encountered in divide per["c"].append(rep / cc[:, both_orth].mean(1)) /tmp/ipykernel_2525/83981602.py:11: RuntimeWarning: divide by zero encountered in log lr = np.log(PR[base])
baseline (c) pair units dropped observed ci_low ci_high predicted inside 0 1-2 578 2 0.7648 0.7381 0.7925 0.7536 True 1 2-3 579 1 0.8985 0.8709 0.9270 0.8989 True 2 3-4 580 0 0.9546 0.9262 0.9853 0.9453 True 3 4-5 580 0 0.9259 0.8982 0.9503 0.9394 True 4 5-6 580 0 0.9525 0.9244 0.9832 0.9524 True 5 6-7 579 1 0.9503 0.9227 0.9782 0.9589 True 6 7-8 579 1 0.9585 0.9292 0.9896 0.9639 True (a) pair 1-2 inside: True; (b) all pairs inside: True (7 of 7) baseline (d) pair units dropped observed ci_low ci_high predicted inside 0 1-2 578 2 0.7882 0.7649 0.8105 0.7536 False 1 2-3 579 1 0.8976 0.8745 0.9223 0.8989 True 2 3-4 580 0 0.9489 0.9271 0.9715 0.9453 True 3 4-5 580 0 0.9256 0.9028 0.9482 0.9394 True 4 5-6 580 0 0.9493 0.9255 0.9736 0.9524 True 5 6-7 579 1 0.9375 0.9142 0.9606 0.9589 True 6 7-8 580 0 0.9458 0.9218 0.9691 0.9639 True (a) pair 1-2 inside: False; (b) all pairs inside: False (6 of 7) seed + 1000: inside per pair, baseline (c) [1, 1, 1, 1, 1, 1, 1], (d) [0, 1, 1, 1, 1, 1, 1]
/tmp/ipykernel_2525/83981602.py:11: RuntimeWarning: divide by zero encountered in log lr = np.log(PR[base]) /tmp/ipykernel_2525/83981602.py:11: RuntimeWarning: divide by zero encountered in log lr = np.log(PR[base])
seed + 2000: inside per pair, baseline (c) [1, 1, 1, 1, 1, 1, 1], (d) [0, 1, 1, 1, 1, 1, 1] seed + 3000: inside per pair, baseline (c) [1, 1, 1, 1, 1, 1, 1], (d) [0, 1, 1, 1, 1, 1, 1]
/tmp/ipykernel_2525/83981602.py:11: RuntimeWarning: divide by zero encountered in log lr = np.log(PR[base]) /tmp/ipykernel_2525/83981602.py:11: RuntimeWarning: divide by zero encountered in log lr = np.log(PR[base])
seed + 4000: inside per pair, baseline (c) [1, 1, 1, 1, 1, 1, 1], (d) [0, 1, 1, 1, 1, 1, 1]
Result: reproduced. With the both-orthogonal baseline (c) the predicted ratio lies inside the bootstrapped 95% interval of the observed one for all seven pairs from 1-2 to 7-8 (1-2: observed 0.765, interval 0.738 to 0.793, predicted 0.754), so readings (a) and (b) both hold, under all five seeds. With baseline (d) six of seven pairs hold and pair 1-2 does not (0.788, 0.765 to 0.811, predicted 0.754), under all five seeds.
fig3b-thalamus-short-term¶
Adaptation to drifting gratings in the thalamus is limited to the 1-back trial in LGN and the 2-back trial in LP, while cortical areas stay significant for about 6 to 8 trials.
rows = []
for region in A.CORTEX + A.THALAMUS:
df, sig = nback_tests(ar_dg, DG["area"], region, range(1, 11))
rows.append(dict(region=region, significant=sig, largest=max(sig) if sig else 0,
ratios_1_10=np.round(df.ratio.values, 3).tolist()))
sig_tab = pd.DataFrame(rows)
print(sig_tab.to_string())
for region in A.THALAMUS + ["RL"]:
print(region, "under every reading of O1 and O3:")
print(readings_sig("dg", region, range(1, 11)).to_string())
# Significance regardless of direction (a two-tailed test can also find a ratio above 1).
for region in A.THALAMUS:
df, _ = nback_tests(ar_dg, DG["area"], region, range(1, 11))
print(region, "significant in either direction:", df.n[df.sig].tolist(),
"ratios there", np.round(df.ratio[df.sig].values, 3).tolist())
rows = []
for (st, bl, bk), d in D.items():
if st != "dg":
continue
for how in ["pooled", "per_ori", "per_ori_geo"]:
ar = AR[(st, bl, bk)][how]
lg = {}
for region in A.CORTEX + A.THALAMUS:
df, sig = nback_tests(ar, d["area"], region, range(1, 11))
lg[region] = max(sig) if sig else 0
lg[region + "_any"] = df.n[df.sig].tolist()
ok = (lg["LGN"] <= 1 and lg["LP"] <= 2 and all(lg[c] >= 6 for c in A.CORTEX))
rows.append(dict(O1=how, blanks=bl, blocks=bk, **{k: v for k, v in lg.items() if not k.endswith("_any")},
LGN_any=lg["LGN_any"], LP_any=lg["LP_any"], criterion_met=ok))
print(pd.DataFrame(rows).to_string())
region significant largest ratios_1_10
0 V1 [1, 2, 3, 4, 5, 6, 7, 8] 8 [0.821, 0.918, 0.98, 0.965, 0.973, 0.979, 0.98, 0.984, 0.987, 1.01]
1 LM [1, 2, 5, 7, 8] 8 [0.828, 0.951, 0.979, 0.986, 0.977, 0.99, 0.975, 0.979, 1.005, 1.001]
2 AL [1, 2, 3, 4, 5, 7] 7 [0.828, 0.951, 0.955, 0.962, 0.977, 0.989, 0.976, 0.989, 1.0, 0.996]
3 RL [1, 2, 3, 4, 5] 5 [0.876, 0.941, 0.966, 0.97, 0.97, 0.981, 0.988, 0.988, 1.015, 1.013]
4 PM [1, 2, 3, 4, 5, 7] 7 [0.795, 0.946, 0.962, 0.96, 0.963, 0.987, 0.962, 1.0, 1.01, 1.01]
5 AM [1, 2, 3, 4, 5, 6] 6 [0.819, 0.933, 0.958, 0.961, 0.977, 0.979, 0.989, 0.991, 0.996, 1.003]
6 LGN [1] 1 [0.935, 1.003, 1.005, 1.018, 0.989, 0.998, 0.972, 0.984, 1.021, 1.007]
7 LP [1, 2] 2 [0.833, 0.939, 1.03, 1.003, 1.007, 1.014, 0.988, 1.002, 1.014, 0.993]
LGN under every reading of O1 and O3:
O1 blanks blocks significant largest
0 pooled hold within [1] 1
1 per_ori hold within [1] 1
2 per_ori_geo hold within [1] 1
3 pooled hold across [1] 1
4 per_ori hold across [1] 1
5 per_ori_geo hold across [1] 1
6 pooled remove within [1, 7] 7
7 per_ori remove within [1] 1
8 per_ori_geo remove within [1, 7] 7
9 pooled remove across [1, 7] 7
10 per_ori remove across [1] 1
11 per_ori_geo remove across [1, 7] 7
LP under every reading of O1 and O3:
O1 blanks blocks significant largest
0 pooled hold within [1, 2] 2
1 per_ori hold within [1] 1
2 per_ori_geo hold within [1, 2] 2
3 pooled hold across [1, 2] 2
4 per_ori hold across [1] 1
5 per_ori_geo hold across [1, 2] 2
6 pooled remove within [1, 2] 2
7 per_ori remove within [1] 1
8 per_ori_geo remove within [1, 2] 2
9 pooled remove across [1, 2] 2
10 per_ori remove across [1] 1
11 per_ori_geo remove across [1, 2] 2
RL under every reading of O1 and O3:
O1 blanks blocks significant largest 0 pooled hold within [1, 2, 3, 4, 5] 5 1 per_ori hold within [1] 1 2 per_ori_geo hold within [1, 2, 3, 4, 5, 6] 6 3 pooled hold across [1, 2, 3, 4, 5, 6] 6 4 per_ori hold across [1] 1 5 per_ori_geo hold across [1, 2, 3, 4, 5] 5 6 pooled remove within [1, 2, 3, 4, 5] 5 7 per_ori remove within [] 0 8 per_ori_geo remove within [1, 2, 3, 5] 5 9 pooled remove across [1, 2, 3, 4, 5] 5 10 per_ori remove across [] 0 11 per_ori_geo remove across [1, 2, 3, 5] 5 LGN significant in either direction: [1] ratios there [0.935] LP significant in either direction: [1, 2, 3] ratios there [0.833, 0.939, 1.03]
O1 blanks blocks V1 LM AL RL PM AM LGN LP LGN_any LP_any criterion_met 0 pooled hold within 8 8 7 5 7 6 1 2 [1] [1, 2, 3] False 1 per_ori hold within 2 1 1 1 1 1 1 1 [1, 2, 3, 4, 9, 10] [1, 3, 6] False 2 per_ori_geo hold within 8 7 5 6 7 4 1 2 [1, 9] [1, 2] False 3 pooled hold across 8 8 7 6 7 6 1 2 [1, 9] [1, 2] True 4 per_ori hold across 2 1 1 1 1 1 1 1 [1, 2, 3, 4, 9, 10] [1, 3, 6] False 5 per_ori_geo hold across 8 7 6 5 7 4 1 2 [1, 9] [1, 2] False 6 pooled remove within 8 10 7 5 7 8 7 2 [1, 7] [1, 2, 3] False 7 per_ori remove within 2 1 1 0 1 2 1 1 [1, 3, 4, 9] [1, 3, 6] False 8 per_ori_geo remove within 5 4 5 5 7 6 7 2 [1, 7] [1, 2] False 9 pooled remove across 8 10 7 5 7 8 7 2 [1, 7] [1, 2, 3] False 10 per_ori remove across 2 1 1 0 1 2 1 1 [1, 3, 4, 9] [1, 3, 5, 6] False 11 per_ori_geo remove across 8 4 5 5 4 6 7 2 [1, 7] [1, 2] False
# Two-sided reading: an n counts when its corrected p < 0.05 in either direction. Per reading of
# O1 and O3, the largest such n per area, the n with a ratio above 1, and the criterion and its
# partial rule under this reading.
rows = []
for (st, bl, bk), d in D.items():
if st != "dg":
continue
for how in ["pooled", "per_ori", "per_ori_geo"]:
ar = AR[(st, bl, bk)][how]
two, above = {}, {}
for region in A.CORTEX + A.THALAMUS:
df, _ = nback_tests(ar, d["area"], region, range(1, 11))
s2 = df.n[df.sig].tolist()
two[region] = max(s2) if s2 else 0
above[region] = df.n[df.sig & (df.ratio > 1)].tolist()
ok2 = two["LGN"] <= 1 and two["LP"] <= 2 and all(two[c] >= 6 for c in A.CORTEX)
def later(region, limit):
df, _ = nback_tests(ar, d["area"], region, range(1, 11))
return [n for n in df.n[df.sig] if n > limit]
extra = later("LGN", 1) + later("LP", 2)
part2 = (not ok2) and len(extra) == 1 and all(two[c] >= 6 for c in A.CORTEX)
rows.append(dict(O1=how, blanks=bl, blocks=bk, **{f"{r}_2s": two[r] for r in A.CORTEX + A.THALAMUS},
above_1={r: v for r, v in above.items() if v}, met_2s=ok2, partial_2s=part2))
print(pd.DataFrame(rows).to_string())
df, _ = nback_tests(AR[("dg", "hold", "across")]["pooled"], D[("dg", "hold", "across")]["area"], "LGN", range(1, 11))
print("LGN, pooled ratio, blanks held, pairs across blocks:")
print(df.assign(p=df.p.map(lambda x: f"{x:.2g}"), p_fdr=df.p_fdr.map(lambda x: f"{x:.2g}")).round(4).to_string(index=False))
# The same with `noise` units kept (O4 a, c, e otherwise), for every reading of O1 and O3: the
# largest n with significant adaptation (ratio below 1) and in either direction, per area.
rows = []
for bl, bk in itertools.product(["hold", "remove"], ["within", "across"]):
dn = build("dg", sel_kw=NOISE_KW, blanks=bl, blocks=bk)
for how in ["pooled", "per_ori", "per_ori_geo"]:
ar = A.ratios(dn["nb"], how)
one, two = {}, {}
for region in A.CORTEX + A.THALAMUS:
df, sig = nback_tests(ar, dn["area"], region, range(1, 11))
one[region] = max(sig) if sig else 0
s2 = df.n[df.sig].tolist(); two[region] = max(s2) if s2 else 0
ok1 = one["LGN"] <= 1 and one["LP"] <= 2 and all(one[c] >= 6 for c in A.CORTEX)
ok2 = two["LGN"] <= 1 and two["LP"] <= 2 and all(two[c] >= 6 for c in A.CORTEX)
rows.append(dict(O1=how, blanks=bl, blocks=bk, **one, LGN_2s=two["LGN"], LP_2s=two["LP"],
met=ok1, met_2s=ok2))
print("noise units kept:")
print(pd.DataFrame(rows).to_string())
O1 blanks blocks V1_2s LM_2s AL_2s RL_2s PM_2s AM_2s LGN_2s LP_2s above_1 met_2s partial_2s
0 pooled hold within 8 8 7 5 7 6 1 3 {'LP': [3]} False False
1 per_ori hold within 2 1 1 9 9 9 10 6 {'RL': [8, 9], 'PM': [9], 'AM': [9], 'LGN': [2, 3, 4, 9, 10], 'LP': [3, 6]} False False
2 per_ori_geo hold within 8 7 5 6 7 4 9 2 {'LGN': [9]} False False
3 pooled hold across 8 8 7 6 7 6 9 2 {'LGN': [9]} False True
4 per_ori hold across 2 1 1 9 9 9 10 6 {'RL': [8, 9], 'PM': [9], 'AM': [9], 'LGN': [2, 3, 4, 9, 10], 'LP': [3, 6]} False False
5 per_ori_geo hold across 8 7 6 5 7 4 9 2 {'LGN': [9]} False False
6 pooled remove within 8 10 7 5 7 8 7 3 {'LP': [3]} False False
7 per_ori remove within 2 3 1 9 9 9 9 6 {'LM': [3], 'RL': [9], 'PM': [6, 8, 9], 'AM': [9], 'LGN': [3, 4, 9], 'LP': [3, 6]} False False
8 per_ori_geo remove within 5 4 5 5 7 6 7 2 {} False False
9 pooled remove across 8 10 7 5 7 8 7 3 {'LP': [3]} False False
10 per_ori remove across 2 3 1 9 9 9 9 6 {'LM': [3], 'RL': [7, 9], 'PM': [6, 8, 9], 'AM': [5, 7, 8, 9], 'LGN': [3, 4, 9], 'LP': [3, 5, 6]} False False
11 per_ori_geo remove across 8 4 5 5 4 6 7 2 {} False False
LGN, pooled ratio, blanks held, pairs across blocks:
n ratio t p p_fdr sig
1 0.9354 -5.1950 7e-07 7e-06 True
2 1.0028 0.2710 0.79 0.79 False
3 1.0032 0.3208 0.75 0.79 False
4 1.0165 1.6175 0.11 0.22 False
5 0.9876 -1.2213 0.22 0.37 False
6 0.9936 -0.6971 0.49 0.61 False
7 0.9766 -2.1584 0.033 0.11 False
8 0.9841 -1.7893 0.076 0.19 False
9 1.0238 2.6199 0.0098 0.049 True
10 1.0093 1.0042 0.32 0.45 False
noise units kept:
O1 blanks blocks V1 LM AL RL PM AM LGN LP LGN_2s LP_2s met met_2s
0 pooled hold within 8 8 7 5 7 6 7 2 9 3 False False
1 per_ori hold within 2 1 1 0 1 1 1 1 10 5 False False
2 per_ori_geo hold within 8 7 5 6 7 4 1 2 9 2 False False
3 pooled hold across 8 8 7 5 7 6 1 2 9 3 False False
4 per_ori hold across 2 1 1 1 1 1 1 1 10 6 False False
5 per_ori_geo hold across 8 7 6 5 7 4 1 2 9 2 False False
6 pooled remove within 8 10 7 5 7 8 7 2 7 3 False False
7 per_ori remove within 2 1 1 0 1 2 1 1 9 6 False False
8 per_ori_geo remove within 5 4 5 5 7 6 7 2 7 2 False False
9 pooled remove across 8 10 7 5 7 8 7 2 7 3 False False
10 per_ori remove across 2 1 1 0 1 2 1 1 9 6 False False
11 per_ori_geo remove across 8 4 5 5 7 6 7 2 9 2 False False
# Variant: presentations that overlap an invalid interval of their session left out, as current
# trials and from the responsiveness test (they still count as the n-back stimulus). All units of
# the session are treated so, whichever probe the interval names: a superset of a per-probe rule.
def invalid_mask(s, stim):
t, inv = s[stim], s["invalid"]
bad = np.zeros(len(t), bool)
for a, b in zip(getattr(inv, "start_time", []), getattr(inv, "stop_time", [])):
bad |= (t.start_time.values < b) & (t.stop_time.values > a)
return ~bad
def build_valid(stim, blocks="within"):
out = dict(area=[], nb=[])
for i, s in enumerate(S):
ok = invalid_mask(s, stim)
c = s["dg_counts"] if stim == "dg" else s["sg_counts"]
sp = s["sp100"] if stim == "dg" else s["sp250"]
w = A.DG_WIN if stim == "dg" else A.SG_WIN
table = s[stim]
_, pr, _, _ = A.preferred(c[:, ok], table[ok], w, "orientation")
gm, gs = A.gray_stats(c[:, ok], table[ok], sp, w, "blank")
r = A.responsive(pr, gm, gs, 5.0, "mean_plus_sd") & (s["units"].quality.values[s["sel"]] == "good")
area = s["units"].area.values[s["sel"]]
r &= pd.notna(area)
nb, _ = A.nback_rates(c[r], table, 50, "hold", blocks, valid=ok)
out["area"].append(area[r]); out["nb"].append(nb)
out["area"] = np.concatenate(out["area"])
out["nb"] = {k: np.concatenate([nb[k] for nb in out["nb"]]) for k in ["rs", "rn", "os", "on"]}
return out
for stim, base, ar_b in [("dg", DG, ar_dg), ("sg", SG, ar_sg)]:
n_bad = [int((~invalid_mask(s, stim)).sum()) for s in S]
print(f"{'drifting' if stim == 'dg' else 'static'}: presentations in invalid intervals, "
f"{sum(n_bad)} in {sum(x > 0 for x in n_bad)} sessions (largest {max(n_bad)} in one session)")
dv = build_valid(stim)
arv_ = A.ratios(dv["nb"], "pooled")
rows = []
for a in A.CORTEX + A.THALAMUS:
rows.append(dict(area=a, units=int((base["area"] == a).sum()), units_valid=int((dv["area"] == a).sum()),
ratio1=round(A.region_value(ar_b[base["area"] == a, 0]), 4),
ratio1_valid=round(A.region_value(arv_[dv["area"] == a, 0]), 4)))
print(pd.DataFrame(rows).to_string(index=False))
print(" total responsive units", len(base["area"]), "->", len(dv["area"]))
n_fam = 10 if stim == "dg" else 20
for region in ["V1", "LGN", "LP", "RL"]:
_, sig_b = nback_tests(ar_b, base["area"], region, range(1, n_fam + 1))
_, sig_v = nback_tests(arv_, dv["area"], region, range(1, n_fam + 1))
print(f" {region}: significant n (family 1 to {n_fam}) {sig_b} -> {sig_v}")
# fig3b under this variant, pairs within blocks (main) and across blocks.
for blocks in ["within", "across"]:
dv = build_valid("dg", blocks)
arv_ = A.ratios(dv["nb"], "pooled")
lg = {}
for region in A.CORTEX + A.THALAMUS:
_, sig = nback_tests(arv_, dv["area"], region, range(1, 11))
lg[region] = max(sig) if sig else 0
ok = lg["LGN"] <= 1 and lg["LP"] <= 2 and all(lg[c] >= 6 for c in A.CORTEX)
print(f"fig3b, invalid presentations left out, pairs {blocks} blocks: largest significant n {lg}; criterion met {ok}")
drifting: presentations in invalid intervals, 375 in 5 sessions (largest 181 in one session)
area units units_valid ratio1 ratio1_valid V1 580 585 0.8212 0.8211 LM 272 271 0.8282 0.8322 AL 435 434 0.8284 0.8282 RL 325 324 0.8756 0.8708 PM 210 209 0.7949 0.7963 AM 367 368 0.8193 0.8223 LGN 142 140 0.9352 0.9430 LP 91 94 0.8334 0.8471 total responsive units 2422 -> 2425 V1: significant n (family 1 to 10) [1, 2, 3, 4, 5, 6, 7, 8] -> [1, 2, 3, 4, 5, 6, 7, 8] LGN: significant n (family 1 to 10) [1] -> [1, 7] LP: significant n (family 1 to 10) [1, 2] -> [1] RL: significant n (family 1 to 10) [1, 2, 3, 4, 5] -> [1, 2, 3, 4, 5, 6] static: presentations in invalid intervals, 7001 in 10 sessions (largest 3320 in one session)
area units units_valid ratio1 ratio1_valid V1 545 561 0.8968 0.8950 LM 176 171 0.8913 0.8889 AL 230 232 0.9102 0.9095 RL 128 126 0.9297 0.9313 PM 159 159 0.8957 0.8961 AM 179 180 0.9102 0.9108 LGN 61 59 0.9569 0.9568 LP 17 16 0.9002 0.8967 total responsive units 1495 -> 1504 V1: significant n (family 1 to 20) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 17, 18, 20] -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 16, 18, 20] LGN: significant n (family 1 to 20) [1, 2, 5] -> [1, 2, 4, 5] LP: significant n (family 1 to 20) [1, 9] -> [] RL: significant n (family 1 to 20) [1, 2, 3, 4, 5, 7, 9, 16, 17] -> [1, 2, 3, 4, 5, 6, 7, 9, 16, 17, 20]
fig3b, invalid presentations left out, pairs within blocks: largest significant n {'V1': 8, 'LM': 8, 'AL': 7, 'RL': 6, 'PM': 7, 'AM': 6, 'LGN': 7, 'LP': 1}; criterion met False
fig3b, invalid presentations left out, pairs across blocks: largest significant n {'V1': 8, 'LM': 8, 'AL': 7, 'RL': 6, 'PM': 7, 'AM': 6, 'LGN': 1, 'LP': 1}; criterion met True
Result: reproduced, resting on an assumption. Counting significant adaptation (a corrected p < 0.05 with the ratio below 1), the reading with pairs formed across blocks (O1a, O3a, d) meets the criterion: LGN only at 1-back, LP to 2-back, and every cortical area to 6-back or further (V1 8, LM 8, AL 7, RL 6, PM 7, AM 6). RL is at the threshold of 6. Under the main reading (pairs within blocks) RL stops at 5-back and the criterion fails; no other of the 12 readings meets it. Counting significance in either direction (the two-sided table), no reading meets the criterion: under the across-blocks reading LGN is also significant at 9-back (ratio 1.024, corrected p = 0.049), so only the partial rule holds there, and under the main reading LP is significant at 3-back (ratio 1.03) while RL stops at 5. The outcome therefore rests on reading Figure 3B's black borders as marking adaptation, ratios below 1, which the legend's "exerted significant adaptation effect" for panel A and the Results' "adaptation ... appeared to be limited" support; read two-sided, it would be partially reproduced. With the presentations inside invalid intervals left out, the across-blocks reading still meets the criterion (LGN 1, LP 1, RL 6), and under the main reading LGN gains a significant 7-back. With noise units kept, no reading of O1 and O3 meets the criterion or its partial rule: under the across-blocks reading RL stops at 5-back (LGN 1, LP 2), and under the main reading LGN is significant at 7-back. The outcome therefore also rests on the noise filter.
v1-vs-thalamus-welch¶
Adaptation to remote stimuli is stronger in V1 than in LGN (2-, 4- and 9-back) and LP (3-back), even after normalizing to each region's 1-back adaptation.
Per n, a two-sided Welch t test of unit values in V1 against LGN and against LP. Values: the unnormalized log ratio, (a) each unit's n-back log ratio divided by its own 1-back log ratio, (b) divided by its region's mean 1-back log ratio. Normalized values are signed so that larger means more adaptation; for the unnormalized log ratio, more negative is more adaptation. n in (c) 2 to 10 or (d) 2 to 50, Benjamini-Hochberg within each pair of regions (O6).
lr_dg = np.log(ar_dg)
def welch(region, norm, n_max):
a = lr_dg[DG["area"] == "V1"]; b = lr_dg[DG["area"] == region]
if norm == "unit":
a = a / a[:, [0]]; b = b / b[:, [0]]
elif norm == "region":
a = a / a[:, 0].mean(); b = b / b[:, 0].mean()
else:
a, b = -a, -b
ns = list(range(2, n_max + 1))
res = [stats.ttest_ind(a[:, n - 1], b[:, n - 1], equal_var=False) for n in ns]
t_ = np.array([r.statistic for r in res]); p = np.array([r.pvalue for r in res])
adj = A.fdr(p)[0]
stronger = [n for n, tt, q in zip(ns, t_, adj) if q < 0.05 and tt > 0]
weaker = [n for n, tt, q in zip(ns, t_, adj) if q < 0.05 and tt < 0]
return pd.DataFrame(dict(n=ns, t=t_, p=p, p_fdr=adj)), stronger, weaker
rows = []
for norm in ["none", "unit", "region"]:
for n_max in [10, 50]:
_, sL, wL = welch("LGN", norm, n_max)
_, sP, wP = welch("LP", norm, n_max)
hits = [n in sL for n in (2, 4, 9)] + [3 in sP]
rows.append(dict(normalization=norm, n_range=f"2-{n_max}", V1_stronger_than_LGN=sL,
V1_stronger_than_LP=sP, V1_weaker_LGN=wL, V1_weaker_LP=wP,
of_four=int(sum(hits))))
print(pd.DataFrame(rows).to_string())
df, _, _ = welch("LGN", "region", 10)
print("\nV1 against LGN, normalized by region (b), n = 2 to 10")
print(df.assign(p=df.p.map(lambda x: f"{x:.2g}"), p_fdr=df.p_fdr.map(lambda x: f"{x:.2g}")).round(3).to_string())
df, _, _ = welch("LP", "region", 10)
print("\nV1 against LP, normalized by region (b), n = 2 to 10")
print(df.assign(p=df.p.map(lambda x: f"{x:.2g}"), p_fdr=df.p_fdr.map(lambda x: f"{x:.2g}")).round(3).to_string())
u1 = lr_dg[:, 0]
print(f"\nunit 1-back log ratios within 0.02 of zero (unstable under (a)): "
f"{int((np.abs(u1[DG['area'] == 'V1']) < 0.02).sum())} V1, {int((np.abs(u1[DG['area'] == 'LGN']) < 0.02).sum())} LGN, "
f"{int((np.abs(u1[DG['area'] == 'LP']) < 0.02).sum())} LP")
normalization n_range V1_stronger_than_LGN V1_stronger_than_LP V1_weaker_LGN V1_weaker_LP of_four
0 none 2-10 [2, 4, 9] [3, 4] [] [] 4
1 none 2-50 [2, 4] [3] [] [44] 3
2 unit 2-10 [] [] [] [] 0
3 unit 2-50 [] [] [] [] 0
4 region 2-10 [2, 4, 9] [3] [] [] 4
5 region 2-50 [] [3] [] [44] 1
V1 against LGN, normalized by region (b), n = 2 to 10
n t p p_fdr
0 2 3.020 0.0029 0.021
1 3 1.161 0.25 0.37
2 4 2.874 0.0046 0.021
3 5 -0.152 0.88 0.88
4 6 0.588 0.56 0.72
5 7 -1.890 0.061 0.14
6 8 -1.192 0.23 0.37
7 9 2.719 0.0073 0.022
8 10 0.426 0.67 0.75
V1 against LP, normalized by region (b), n = 2 to 10
n t p p_fdr
0 2 0.954 0.34 0.41
1 3 3.774 0.00023 0.002
2 4 2.508 0.013 0.06
3 5 1.946 0.054 0.12
4 6 2.118 0.036 0.11
5 7 0.488 0.63 0.63
6 8 1.067 0.29 0.41
7 9 1.425 0.16 0.28
8 10 -0.914 0.36 0.41
unit 1-back log ratios within 0.02 of zero (unstable under (a)): 38 V1, 11 LGN, 8 LP
Result: reproduced. With n = 2 to 10 and correction within each pair of regions, V1 adaptation is stronger than LGN at exactly 2, 4 and 9 back and than LP at 3 back, both without normalization (and also LP at 4) and with each region's 1-back mean as the normalization (b). Normalizing each unit by its own 1-back log ratio (a) finds no difference; 38 V1, 11 LGN and 8 LP units have a 1-back log ratio within 0.02 of zero, which makes that measure unstable. Over n = 2 to 50, 3 of the four remain unnormalized and 1 with reading (b).
fig3c-mice-long-term¶
Long-term (4- to 8-back) adaptation is consistent across mice in cortex but not in thalamus.
for pooled_i, lab in [(0, "trials pooled over 4 to 8"), (1, "rates averaged over 4 to 8")]:
gC = mouse_rates(DG, A.CORTEX, range(4, 9), A.DG_WIN)[pooled_i]
gT = mouse_rates(DG, A.THALAMUS, range(4, 9), A.DG_WIN)[pooled_i]
print(lab)
ca = consistency(gC, " cortex")
ta = consistency(gT, " thalamus")
print(f" cortex meets (a) or (b): {ca[0] or ca[1]}; thalamus meets neither: {not (ta[0] or ta[1])}")
trials pooled over 4 to 8 cortex: 32 mice, 31 with orthogonal above repeat, sign test p = 1.5e-08, median orth - rep 0.229 Hz; (a) False, (b) True not above: session 754829445, 62 units, repeat 13.08 Hz, orthogonal 13.05 Hz thalamus: 23 mice, 14 with orthogonal above repeat, sign test p = 0.4, median orth - rep 0.073 Hz; (a) False, (b) False not above: session 715093703, 41 units, repeat 19.05 Hz, orthogonal 19.05 Hz not above: session 750332458, 2 units, repeat 34.45 Hz, orthogonal 34.41 Hz not above: session 750749662, 9 units, repeat 41.20 Hz, orthogonal 41.00 Hz not above: session 746083955, 16 units, repeat 27.85 Hz, orthogonal 27.77 Hz not above: session 754829445, 24 units, repeat 18.85 Hz, orthogonal 18.62 Hz not above: session 791319847, 3 units, repeat 9.71 Hz, orthogonal 9.42 Hz not above: session 799864342, 8 units, repeat 27.59 Hz, orthogonal 27.20 Hz not above: session 798911424, 2 units, repeat 17.15 Hz, orthogonal 16.67 Hz not above: session 797828357, 4 units, repeat 11.83 Hz, orthogonal 11.14 Hz cortex meets (a) or (b): True; thalamus meets neither: True rates averaged over 4 to 8 cortex: 32 mice, 30 with orthogonal above repeat, sign test p = 2.5e-07, median orth - rep 0.232 Hz; (a) False, (b) True not above: session 754829445, 62 units, repeat 13.07 Hz, orthogonal 13.03 Hz not above: session 763673393, 33 units, repeat 10.78 Hz, orthogonal 10.77 Hz thalamus: 23 mice, 14 with orthogonal above repeat, sign test p = 0.4, median orth - rep 0.082 Hz; (a) False, (b) False not above: session 721123822, 16 units, repeat 17.87 Hz, orthogonal 17.86 Hz not above: session 750332458, 2 units, repeat 34.45 Hz, orthogonal 34.42 Hz not above: session 750749662, 9 units, repeat 41.21 Hz, orthogonal 41.03 Hz not above: session 746083955, 16 units, repeat 27.88 Hz, orthogonal 27.76 Hz not above: session 754829445, 24 units, repeat 18.83 Hz, orthogonal 18.59 Hz not above: session 791319847, 3 units, repeat 9.72 Hz, orthogonal 9.42 Hz not above: session 799864342, 8 units, repeat 27.58 Hz, orthogonal 27.18 Hz not above: session 798911424, 2 units, repeat 17.14 Hz, orthogonal 16.62 Hz not above: session 797828357, 4 units, repeat 11.83 Hz, orthogonal 11.15 Hz cortex meets (a) or (b): True; thalamus meets neither: True
Result: reproduced. For 4- to 8-back, 31 of 32 mice (pooled trials; 30 with averaged rates) have the cortical orthogonal rate above the repeat rate (sign test p = 1.5e-08), so cortex meets (b). In thalamus 14 of 23 mice do (p = 0.4), so neither reading holds, as the claim expects.
decay-cortex-double-better¶
Recovery from adaptation to drifting gratings in cortical areas is better fit by a double than a single exponential, in all areas but RL.
F tests of the nested fits (O5): on the region's mean log ratio over n = 1 to 50 (O5a, 50 observations) and on every unit's log ratio (O5b).
ft = fit_table(FIT_DG, A.CORTEX)
print(ft[ft.sign == "minus (a)"].round(3).to_string())
for col in ["p_F", "p_F_units"]:
pv = {r: float(FIT_DG[(r, -1)][col]) for r in A.CORTEX}
print(f"{col}: below 0.05 in V1, LM, AL, PM, AM: {all(pv[r] < 0.05 for r in ['V1', 'LM', 'AL', 'PM', 'AM'])}; "
f"RL p = {pv['RL']:.2g}")
region sign a_fast tau_fast a_slow tau_slow a_single tau_single F p_F F_units p_F_units double_on_bound single_on_bound 0 V1 minus (a) 14.209 0.816 3.755 6.714 17.558 1.415 7.495 0.0015 12.395 4.2e-06 False False 2 LM minus (a) 13.846 0.508 3.344 5.662 17.047 0.907 4.475 0.017 6.189 0.0021 False False 4 AL minus (a) 10.287 0.032 6.877 3.929 16.365 1.381 11.663 8e-05 19.229 4.5e-09 False False 6 RL minus (a) 4.285 0.269 8.155 2.827 11.834 1.953 1.542 0.22 2.148 0.12 False False 8 PM minus (a) 13.579 0.007 6.928 4.274 19.957 1.104 6.196 0.0041 13.672 1.2e-06 False False 10 AM minus (a) 9.646 0.342 8.428 3.232 17.437 1.465 4.997 0.011 10.067 4.3e-05 False False p_F: below 0.05 in V1, LM, AL, PM, AM: True; RL p = 0.22 p_F_units: below 0.05 in V1, LM, AL, PM, AM: True; RL p = 0.12
Result: reproduced. The F test favours the double exponential in V1 (p = 0.0015), LM (0.017), AL (8.0e-05), PM (0.0041) and AM (0.011) on the region means, and in all five also with every unit's values (p = 4.5e-09 to 0.0021). RL is not significant (p = 0.22, units 0.12), as in the paper (0.072). Two of the five p values (LM, AM) are above the paper's bound of 0.006.
table1-extrastriate-tau-slow¶
Recovery from adaptation to drifting gratings is slowest in V1 (tau_slow 6.82 trials), and relatively similar in extrastriate areas, whose slow time constants range from 3.12 to 5.52 trials with all 95% CIs overlapping.
Bootstrap of the double-exponential fit (O5): units resampled with replacement 1000 times, fits on a bound discarded, 2.5 and 97.5 percentiles (Methods). The claim's seed, and four more for the seed's effect.
T1 = {"V1": (3.39, 13.5), "AL": (3.1, 5.94), "AM": (2.37, 6.5), "LM": (3.42, 10.6),
"PM": (2.75, 9.28), "RL": (2.19, 34.41)}
T1_other = {"V1": [(10.73, 16.14), (0.59, 1.13), (1.71, 6.64)], "AL": [(8.14, 12.71), (1e-3, 0.47), (4.90, 8.54)],
"AM": [(6.88, 14.30), (5e-3, 0.87), (3.83, 11.04)], "LM": [(10.37, 16.07), (0.02, 0.72), (1.89, 5.84)],
"PM": [(10.43, 16.32), (2e-3, 0.45), (3.91, 9.26)], "RL": [(1.97, 12.00), (5e-3, 1.83), (0.7, 9.82)]}
t = time.time()
base_seed = seed("table1-extrastriate-tau-slow")
tasks = [(np.log(ar_dg[DG["area"] == r]), "double", base_seed + k) for k in [0, 1000, 2000, 3000, 4000] for r in A.CORTEX]
BOOT_DG = dict(zip([(k, r) for k in [0, 1000, 2000, 3000, 4000] for r in A.CORTEX], A.bootstrap_many(tasks)))
print(f"bootstraps in {time.time() - t:.0f} s")
def overlap_all(cis):
lo = max(c[0] for c in cis.values()); hi = min(c[1] for c in cis.values())
return lo <= hi
for k in [0, 1000, 2000, 3000, 4000]:
cis = {r: tuple(np.percentile(BOOT_DG[(k, r)][0][:, 3], [2.5, 97.5])) for r in A.CORTEX}
if k == 0:
rows = []
for r in A.CORTEX:
b, dropped = BOOT_DG[(0, r)]
ci4 = np.percentile(b, [2.5, 97.5], 0)
est = FIT_DG[(r, -1)]
rows.append(dict(region=r, tau_slow=est["tau_slow"], boot_low=ci4[0, 3], boot_high=ci4[1, 3],
table1_ci=T1[r], inside=T1[r][0] <= est["tau_slow"] <= T1[r][1],
a_fast=est["a_fast"], a_fast_in=T1_other[r][0][0] <= est["a_fast"] <= T1_other[r][0][1],
tau_fast=est["tau_fast"], tau_fast_in=T1_other[r][1][0] <= est["tau_fast"] <= T1_other[r][1][1],
a_slow=est["a_slow"], a_slow_in=T1_other[r][2][0] <= est["a_slow"] <= T1_other[r][2][1],
kept=len(b), dropped=dropped))
t1 = pd.DataFrame(rows)
print(t1.round(3).to_string())
ex5 = t1[t1.region != "V1"]
print(f"extrastriate tau_slow inside Table 1 CI: {int(ex5.inside.sum())} of 5; "
f"range {ex5.tau_slow.min():.2f} to {ex5.tau_slow.max():.2f}; V1 largest of six: "
f"{t1.tau_slow.idxmax() == 0}")
print(f"seed + {k}: all six bootstrapped tau_slow CIs overlap: {overlap_all(cis)}; "
f"CIs {', '.join(f'{r} [{c[0]:.2f}, {c[1]:.2f}]' for r, c in cis.items())}")
bootstraps in 166 s region tau_slow boot_low boot_high table1_ci inside a_fast a_fast_in tau_fast tau_fast_in a_slow a_slow_in kept dropped 0 V1 6.714 3.788 11.588 (3.39, 13.5) True 14.209 True 0.816 True 3.755 True 1000 0 1 LM 5.662 3.131 11.934 (3.42, 10.6) True 13.846 True 0.508 True 3.344 True 995 5 2 AL 3.929 2.879 6.411 (3.1, 5.94) True 10.287 True 0.032 True 6.877 True 1000 0 3 RL 2.827 1.967 35.112 (2.19, 34.41) True 4.285 True 0.269 True 8.155 True 977 23 4 PM 4.274 2.454 12.771 (2.75, 9.28) True 13.579 True 0.007 True 6.928 True 999 1 5 AM 3.232 2.276 5.949 (2.37, 6.5) True 9.646 True 0.342 True 8.428 True 1000 0 extrastriate tau_slow inside Table 1 CI: 5 of 5; range 2.83 to 5.66; V1 largest of six: True seed + 0: all six bootstrapped tau_slow CIs overlap: True; CIs V1 [3.79, 11.59], LM [3.13, 11.93], AL [2.88, 6.41], RL [1.97, 35.11], PM [2.45, 12.77], AM [2.28, 5.95] seed + 1000: all six bootstrapped tau_slow CIs overlap: True; CIs V1 [3.88, 11.08], LM [3.37, 11.92], AL [2.78, 6.71], RL [2.01, 33.53], PM [2.54, 13.65], AM [2.34, 5.43] seed + 2000: all six bootstrapped tau_slow CIs overlap: True; CIs V1 [3.92, 11.58], LM [3.18, 13.92], AL [2.83, 6.38], RL [1.95, 32.23], PM [2.41, 15.53], AM [2.33, 5.78] seed + 3000: all six bootstrapped tau_slow CIs overlap: True; CIs V1 [3.76, 11.77], LM [3.55, 13.39], AL [2.85, 5.94], RL [1.80, 33.52], PM [2.35, 12.39], AM [2.35, 5.61] seed + 4000: all six bootstrapped tau_slow CIs overlap: True; CIs V1 [3.83, 11.29], LM [3.38, 15.45], AL [2.88, 6.78], RL [1.98, 34.42], PM [2.48, 13.63], AM [2.30, 5.68]
Result: reproduced. The five extrastriate tau_slow (AL 3.93, AM 3.23, LM 5.66, PM 4.27, RL 2.83 trials) are each inside their Table 1 intervals, and the six bootstrapped intervals overlap under all five seeds. V1's tau_slow (6.71) is the largest of the six. All a_fast, tau_fast and a_slow estimates are inside their Table 1 intervals too.
decay-thalamus-single¶
Recovery in LGN and LP is best described by a single exponential with very short time constants (0.02 and 0.71 trials).
print(fit_table(FIT_DG, A.THALAMUS).round(4).to_string())
lims = {"LGN": [(0.004, 0.63), (4.04, 8.85)], "LP": [(0.03, 0.93), (12.68, 21.02)]}
for r in A.THALAMUS:
e = FIT_DG[(r, -1)]
print(f"{r}: tau {e['tau_single']:.3f} in {lims[r][0]}: {lims[r][0][0] <= e['tau_single'] <= lims[r][0][1]}; "
f"a {e['a_single']:.2f}% in {lims[r][1]}: {lims[r][1][0] <= e['a_single'] <= lims[r][1][1]}; "
f"F test p (mean) {e['p_F']:.2g}, (units) {e['p_F_units']:.2g}")
bt = A.bootstrap_many([(np.log(ar_dg[DG["area"] == r]), "single", seed("decay-thalamus-single")) for r in A.THALAMUS])
for r, (b, dropped) in zip(A.THALAMUS, bt):
print(f"{r} bootstrap (seed of the claim): tau CI [{np.percentile(b[:, 1], 2.5):.3f}, {np.percentile(b[:, 1], 97.5):.3f}], "
f"a CI [{100 * np.percentile(b[:, 0], 2.5):.2f}, {100 * np.percentile(b[:, 0], 97.5):.2f}]%, dropped {dropped}")
region sign a_fast tau_fast a_slow tau_slow a_single tau_single F p_F F_units p_F_units double_on_bound single_on_bound 0 LGN minus (a) 50.0000 0.7480 -43.5088 0.8541 6.4810 0.0311 0.2065 0.81 0.4718 0.62 True False 1 LGN plus (b) 49.9999 0.7481 43.5088 0.8542 6.4810 0.0311 0.2065 0.81 0.4718 0.62 True False 2 LP minus (a) 17.5020 0.7764 -0.6448 50.0000 16.8451 0.7122 0.5772 0.57 1.6536 0.19 True False 3 LP plus (b) 17.5020 0.7764 0.6448 50.0000 16.8451 0.7122 0.5772 0.57 1.6536 0.19 True False LGN: tau 0.031 in (0.004, 0.63): True; a 6.48% in (4.04, 8.85): True; F test p (mean) 0.81, (units) 0.62 LP: tau 0.712 in (0.03, 0.93): True; a 16.85% in (12.68, 21.02): True; F test p (mean) 0.57, (units) 0.19
LGN bootstrap (seed of the claim): tau CI [0.004, 0.611], a CI [4.21, 8.83]%, dropped 0 LP bootstrap (seed of the claim): tau CI [0.490, 0.943], a CI [12.90, 21.24]%, dropped 0
Result: reproduced, resting on an assumption. The F test does not favour the double exponential in LGN (p = 0.81) or LP (p = 0.57; 0.62 and 0.19 with unit values), and the single exponential gives LGN tau 0.031 trials and a 6.48%, LP tau 0.712 and a 16.85%, each inside its Table 1 interval. The double-exponential fits reach a bound in both. With noise units kept (variant above) the LGN tau falls to 0.000, so the outcome rests on that filter.
fig5-repeat-suppression¶
Against a blank baseline, both repeated and orthogonal 1-back gratings suppress cortical responses, but only the suppression by repeated orientations persists, up to eight trials back.
All cortical units pooled. Per unit and n, the rate when the n-back trial was a repeat over the rate when it was a blank, and orthogonal over blank; repeat and orthogonal trials are subsampled per session to the number of n-back blank trials (Methods). Blanks hold positions (O3a), pairs within blocks. Readings of "significant": (a) the bootstrapped 95% CI over units excludes 1; (b) t tests of log ratios against zero, n = 1 to 10, Benjamini-Hochberg.
def blank_ratios(rng, n_max=10):
rep_all, orth_all = [], []
for i, s in enumerate(S):
r = select(s, "dg", **MAIN)[0]
area = s["units"].area.values[s["sel"]]
r &= np.isin(area, A.CORTEX)
if r.sum() == 0:
continue
ori, blk, order = A.sequence(s["dg"], None, "hold", "within")
c = s["dg_counts"][r][:, order].astype(float)
R, O = np.full((r.sum(), n_max), np.nan), np.full((r.sum(), n_max), np.nan)
for n in range(1, n_max + 1):
rep, orth, blank = A.pair_masks(ori, blk, n)
cc = c[:, n:]
nb_ = int(blank.sum())
ri = rng.choice(np.flatnonzero(rep), nb_, replace=False)
oi = rng.choice(np.flatnonzero(orth), nb_, replace=False)
b = cc[:, blank].mean(1)
with np.errstate(divide="ignore", invalid="ignore"):
R[:, n - 1] = cc[:, ri].mean(1) / b
O[:, n - 1] = cc[:, oi].mean(1) / b
rep_all.append(R); orth_all.append(O)
return np.concatenate(rep_all), np.concatenate(orth_all)
def fig5_eval(R, O, rng_boot):
rows = []
for name, X in [("repeat/blank", R), ("orthogonal/blank", O)]:
with np.errstate(divide="ignore", invalid="ignore"):
lr = np.log(X)
ps = []
for n in range(1, X.shape[1] + 1):
x = lr[:, n - 1]; x = x[np.isfinite(x)]
lo, hi = boot_ci(x, rng_boot, 1000)
p = stats.ttest_1samp(x, 0).pvalue; ps.append(p)
rows.append(dict(ratio=name, n=n, units=len(x), dropped=int(np.sum(~np.isfinite(lr[:, n - 1]))), value=np.exp(x.mean()), ci_low=lo, ci_high=hi, p=p))
df = pd.DataFrame(rows)
for name in ["repeat/blank", "orthogonal/blank"]:
m = df.ratio == name
df.loc[m, "p_fdr"] = A.fdr(df.p[m].values)[0]
df["below_ci"] = df.ci_high < 1
df["below_t"] = (df.p_fdr < 0.05) & (df.value < 1)
return df
def fig5_criterion(df, col):
r = df[df.ratio == "repeat/blank"].set_index("n"); o = df[df.ratio == "orthogonal/blank"].set_index("n")
ok = (r.value[1] < 1 and o.value[1] < 1 and not o[col].loc[2:10].any()
and bool(r[col][8]) and int(r[col].loc[2:8].sum()) >= 4)
return ok, r[col].loc[1:10].astype(int).tolist(), o[col].loc[1:10].astype(int).tolist()
s5 = seed("fig5-repeat-suppression")
blank_counts = [int(A.pair_masks(*A.sequence(s["dg"], None, "hold", "within")[:2], 1)[2].sum()) for s in S]
print("1-back blank trials per session:", min(blank_counts), "to", max(blank_counts))
R5, O5 = blank_ratios(np.random.default_rng(s5))
df5 = fig5_eval(R5, O5, np.random.default_rng(s5 + 1))
show = df5.copy(); show[["p", "p_fdr"]] = show[["p", "p_fdr"]].map(lambda x: f"{x:.2g}")
print(show.round(4).to_string())
for col, lab in [("below_ci", "(a) bootstrap CI"), ("below_t", "(b) t test with FDR")]:
ok, rr, oo = fig5_criterion(df5, col)
print(f"{lab}: criterion met {ok}; repeat below 1 at n=1..10 {rr}; orthogonal {oo}")
for k in [1000, 2000, 3000, 4000]:
Rk, Ok = blank_ratios(np.random.default_rng(s5 + k))
dk = fig5_eval(Rk, Ok, np.random.default_rng(s5 + k + 1))
print(f"seed + {k}: (a) {fig5_criterion(dk, 'below_ci')}, (b) {fig5_criterion(dk, 'below_t')}")
# Variant: 100 subsampling draws, the unit ratios averaged in log over draws.
rngv = np.random.default_rng(s5 + 2)
acc_r, acc_o = [], []
for _ in range(100):
Rk, Ok = blank_ratios(rngv)
with np.errstate(divide="ignore", invalid="ignore"):
acc_r.append(np.log(Rk)); acc_o.append(np.log(Ok))
with warnings.catch_warnings():
warnings.simplefilter("ignore", RuntimeWarning)
Rv = np.exp(np.nanmean(np.where(np.isfinite(acc_r), acc_r, np.nan), 0))
Ov = np.exp(np.nanmean(np.where(np.isfinite(acc_o), acc_o, np.nan), 0))
dv = fig5_eval(Rv, Ov, np.random.default_rng(s5 + 3))
print("100 draws:", "(a)", fig5_criterion(dv, "below_ci"), "(b)", fig5_criterion(dv, "below_t"))
print(dv[["ratio", "n", "value", "ci_low", "ci_high"]].round(4).to_string())
1-back blank trials per session: 24 to 30
ratio n units dropped value ci_low ci_high p p_fdr below_ci below_t 0 repeat/blank 1 2186 3 0.7574 0.7423 0.7713 7.9e-154 7.9e-153 True True 1 repeat/blank 2 2185 4 0.9154 0.9010 0.9301 1.4e-25 6.8e-25 True True 2 repeat/blank 3 2184 5 0.9680 0.9518 0.9842 6.7e-05 0.00017 True True 3 repeat/blank 4 2189 0 0.9684 0.9537 0.9828 6.3e-05 0.00017 True True 4 repeat/blank 5 2187 2 0.9810 0.9643 0.9975 0.031 0.052 True False 5 repeat/blank 6 2187 2 0.9856 0.9715 1.0022 0.076 0.085 False False 6 repeat/blank 7 2187 2 0.9692 0.9537 0.9859 0.00018 0.00035 True True 7 repeat/blank 8 2184 5 0.9987 0.9839 1.0152 0.87 0.87 False False 8 repeat/blank 9 2185 4 0.9841 0.9695 0.9992 0.046 0.058 True False 9 repeat/blank 10 2186 3 1.0167 1.0012 1.0330 0.043 0.058 False False 10 orthogonal/blank 1 2189 0 0.9223 0.9086 0.9371 1.4e-23 1.4e-22 True True 11 orthogonal/blank 2 2186 3 0.9716 0.9571 0.9859 0.00018 0.00089 True True 12 orthogonal/blank 3 2184 5 1.0131 0.9975 1.0286 0.097 0.24 False False 13 orthogonal/blank 4 2187 2 0.9833 0.9688 0.9983 0.033 0.11 True False 14 orthogonal/blank 5 2183 6 0.9973 0.9789 1.0156 0.77 0.85 False False 15 orthogonal/blank 6 2189 0 1.0013 0.9869 1.0173 0.86 0.86 False False 16 orthogonal/blank 7 2186 3 0.9973 0.9803 1.0134 0.75 0.85 False False 17 orthogonal/blank 8 2183 6 0.9888 0.9727 1.0044 0.18 0.35 False False 18 orthogonal/blank 9 2187 2 0.9952 0.9795 1.0103 0.55 0.79 False False 19 orthogonal/blank 10 2187 2 0.9927 0.9779 1.0097 0.38 0.63 False False (a) bootstrap CI: criterion met False; repeat below 1 at n=1..10 [1, 1, 1, 1, 1, 0, 1, 0, 1, 0]; orthogonal [1, 1, 0, 1, 0, 0, 0, 0, 0, 0] (b) t test with FDR: criterion met False; repeat below 1 at n=1..10 [1, 1, 1, 1, 0, 0, 1, 0, 0, 0]; orthogonal [1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
seed + 1000: (a) (False, [1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0]), (b) (False, [1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0])
seed + 2000: (a) (False, [1, 1, 0, 1, 1, 1, 1, 0, 0, 0], [1, 1, 0, 1, 0, 0, 0, 0, 1, 1]), (b) (False, [1, 1, 0, 1, 1, 1, 1, 0, 0, 0], [1, 1, 0, 1, 0, 0, 0, 0, 1, 1])
seed + 3000: (a) (False, [1, 1, 1, 1, 1, 0, 0, 1, 1, 0], [1, 1, 0, 0, 0, 0, 0, 1, 1, 0]), (b) (False, [1, 1, 1, 1, 1, 0, 0, 1, 1, 0], [1, 1, 0, 0, 0, 0, 0, 1, 1, 0])
seed + 4000: (a) (False, [1, 1, 1, 1, 1, 0, 1, 1, 1, 0], [1, 1, 0, 0, 0, 0, 0, 0, 1, 0]), (b) (False, [1, 1, 1, 1, 1, 0, 1, 1, 1, 0], [1, 1, 0, 0, 0, 0, 0, 0, 1, 0])
100 draws: (a) (False, [1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 1, 0]) (b) (False, [1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0])
ratio n value ci_low ci_high
0 repeat/blank 1 0.7588 0.7471 0.7705
1 repeat/blank 2 0.9155 0.9054 0.9271
2 repeat/blank 3 0.9700 0.9585 0.9815
3 repeat/blank 4 0.9578 0.9465 0.9679
4 repeat/blank 5 0.9745 0.9612 0.9883
5 repeat/blank 6 0.9798 0.9678 0.9914
6 repeat/blank 7 0.9771 0.9653 0.9888
7 repeat/blank 8 0.9813 0.9697 0.9938
8 repeat/blank 9 0.9888 0.9766 1.0020
9 repeat/blank 10 1.0033 0.9912 1.0156
10 orthogonal/blank 1 0.9197 0.9089 0.9313
11 orthogonal/blank 2 0.9781 0.9660 0.9899
12 orthogonal/blank 3 1.0041 0.9918 1.0169
13 orthogonal/blank 4 0.9901 0.9790 1.0017
14 orthogonal/blank 5 1.0026 0.9900 1.0165
15 orthogonal/blank 6 0.9977 0.9865 1.0104
16 orthogonal/blank 7 0.9972 0.9855 1.0101
17 orthogonal/blank 8 0.9944 0.9826 1.0066
18 orthogonal/blank 9 0.9876 0.9758 0.9998
19 orthogonal/blank 10 0.9988 0.9865 1.0120
# Session (cluster) bootstrap: units of one session share one trial subsample, so sessions are
# resampled with replacement, with all their units, 2000 times.
sess5 = np.concatenate([np.full(int((select(s, "dg", **MAIN)[0] & np.isin(s["units"].area.values[s["sel"]], A.CORTEX)).sum()), i)
for i, s in enumerate(S)])
assert len(sess5) == len(R5)
def cluster_ci(X, n, rng, n_boot=2000):
with np.errstate(divide="ignore", invalid="ignore"):
lr = np.log(X[:, n - 1])
ok = np.isfinite(lr); lr, ss = lr[ok], sess5[ok]
ids = np.unique(ss)
sums = np.array([lr[ss == k].sum() for k in ids]); cnt = np.array([(ss == k).sum() for k in ids])
b = []
for _ in range(n_boot):
j = rng.integers(0, len(ids), len(ids))
b.append(sums[j].sum() / cnt[j].sum())
return np.exp(lr.mean()), *np.exp(np.percentile(b, [2.5, 97.5]))
rngc = np.random.default_rng(s5 + 4)
rows = []
for lab, (Rx, Ox) in [("claim's draw", (R5, O5)), ("100 draws", (Rv, Ov))]:
for name, X in [("repeat/blank", Rx), ("orthogonal/blank", Ox)]:
for n in range(1, 11):
v, lo, hi = cluster_ci(X, n, rngc)
rows.append(dict(subsample=lab, ratio=name, n=n, value=v, ci_low=lo, ci_high=hi, below=hi < 1))
dc = pd.DataFrame(rows)
for lab in ["claim's draw", "100 draws"]:
x = dc[dc.subsample == lab]
r = x[x.ratio == "repeat/blank"].set_index("n"); o = x[x.ratio == "orthogonal/blank"].set_index("n")
ok = (r.value[1] < 1 and o.value[1] < 1 and not o.below.loc[2:10].any() and bool(r.below[8]) and int(r.below.loc[2:8].sum()) >= 4)
print(f"{lab}, session bootstrap: criterion met {ok}; repeat below 1 at n=1..10 {r.below.astype(int).tolist()}; "
f"orthogonal {o.below.astype(int).tolist()}")
print(f" orthogonal/blank 2-back {o.value[2]:.4f} ({o.ci_low[2]:.4f} to {o.ci_high[2]:.4f}); "
f"repeat/blank 8-back {r.value[8]:.4f} ({r.ci_low[8]:.4f} to {r.ci_high[8]:.4f})")
claim's draw, session bootstrap: criterion met False; repeat below 1 at n=1..10 [1, 1, 1, 1, 0, 0, 1, 0, 0, 0]; orthogonal [1, 1, 0, 0, 0, 0, 0, 0, 0, 0] orthogonal/blank 2-back 0.9716 (0.9490 to 0.9941); repeat/blank 8-back 0.9987 (0.9747 to 1.0239) 100 draws, session bootstrap: criterion met False; repeat below 1 at n=1..10 [1, 1, 1, 1, 1, 0, 1, 0, 0, 0]; orthogonal [1, 1, 0, 0, 0, 0, 0, 0, 0, 0] orthogonal/blank 2-back 0.9781 (0.9609 to 0.9957); repeat/blank 8-back 0.9813 (0.9595 to 1.0023)
Result: not reproduced. Against blank trials both 1-back ratios are below 1 (repeat 0.757, orthogonal 0.922), and repeat suppression lasts longer than orthogonal suppression: by the t tests repeat is significant at 1 to 4 and 7, orthogonal at 1 and 2. The criterion requires orthogonal over blank not below 1 at any n from 2 to 10, and it is below 1 at 2-back (0.972) under both readings, under all five seeds, averaged over 100 subsampling draws (0.978), and with the session bootstrap (0.949 to 0.994 for the claim's draw, 0.961 to 0.996 for the 100 draws). Repeat over blank is not significant at 8-back under the claim's seed (0.999); it is with the 100 draws by the unit bootstrap and the t tests, but not by the session bootstrap (0.960 to 1.002). The criterion gives no partial rule, and the part that fails is the claim's central contrast, that orthogonal suppression is limited to the 1-back trial.
fig6c-static-v1-1back¶
With brief back-to-back static gratings, orientation repetition reduces the V1 response over 0 to 250 ms, a 1-back ratio of 0.90.
Rates and responsiveness over 0 to 250 ms; orthogonal is 90 degrees apart; spatial frequency and phase pooled; blank sweeps hold positions (O3 with blank sweeps in place of blank trials).
rows = []
for good in [True, False]:
for src in ["blank", "spont"]:
vc = count_regions("sg", rule="mean_plus_sd", src=src, by="orientation", good=good)
rows.append(dict(good_only=good, gray=src, **{A.AREA_NAMES[k]: int(vc.get(k, 0)) for k in A.AREA_NAMES},
other_labels_50=",".join(sorted(vc[(~vc.index.isin(NAMED)) & (vc >= 50)].index))))
print("static responsive units (O4 a, e), by gray source and noise filter")
print(pd.DataFrame(rows).to_string())
print("paper: V1 530 (tolerance 53), LGN 60 (6), LP 16 (1.6)")
r6 = region_stats(ar_sg, SG["area"])
show = r6.copy(); show[["p", "p_fdr"]] = show[["p", "p_fdr"]].map(lambda x: f"{x:.2g}")
print(show.round(4).to_string())
tab6 = onebak_table("sg")
print(tab6.to_string())
print("readings with V1 in [0.89, 0.91]:", int(tab6.V1.between(0.89, 0.91).sum()), "of", len(tab6))
static responsive units (O4 a, e), by gray source and noise filter
good_only gray V1 LM AL RL PM AM LGN LP other_labels_50
0 True blank 545 176 230 128 159 179 61 17
1 True spont 553 209 358 230 238 356 80 43 VIS,grey
2 False blank 564 184 237 133 163 186 68 22 grey
3 False spont 575 217 369 240 243 373 88 55 VIS,grey
paper: V1 530 (tolerance 53), LGN 60 (6), LP 16 (1.6)
area n_units ratio ci_low ci_high t p p_fdr
0 V1 545 0.8968 0.8886 0.9049 -23.5612 4e-85 3.2e-84
1 LM 176 0.8913 0.8749 0.9079 -12.2573 2.5e-25 6.6e-25
2 AL 230 0.9102 0.8965 0.9241 -12.1887 1.1e-26 4.6e-26
3 RL 128 0.9297 0.9094 0.9504 -6.5570 1.3e-09 1.7e-09
4 PM 159 0.8957 0.8768 0.9150 -10.1917 4.6e-19 7.4e-19
5 AM 179 0.9102 0.8964 0.9243 -12.0898 6e-25 1.2e-24
6 LGN 61 0.9569 0.9305 0.9840 -3.1534 0.0025 0.0029
7 LP 17 0.9002 0.8414 0.9631 -3.2980 0.0045 0.0045
O1 O2 blanks blocks V1 LM AL RL PM AM LGN LP
0 pooled geo hold within 0.897 0.891 0.910 0.930 0.896 0.910 0.957 0.900
1 pooled mean hold within 0.902 0.898 0.916 0.937 0.904 0.915 0.962 0.907
2 per_ori geo hold within 0.861 0.856 0.878 0.878 0.855 0.865 0.960 0.903
3 per_ori mean hold within 0.868 0.864 0.887 0.885 0.863 0.871 0.966 0.910
4 per_ori_geo geo hold within 0.796 0.812 0.828 0.804 0.782 0.794 0.945 0.893
5 per_ori_geo mean hold within 0.814 0.827 0.841 0.819 0.800 0.810 0.953 0.899
6 pooled geo hold across 0.897 0.891 0.910 0.930 0.896 0.910 0.957 0.900
7 pooled mean hold across 0.902 0.898 0.916 0.937 0.904 0.915 0.962 0.907
8 per_ori geo hold across 0.861 0.856 0.878 0.878 0.855 0.865 0.959 0.903
9 per_ori mean hold across 0.867 0.864 0.887 0.885 0.863 0.871 0.966 0.910
10 per_ori_geo geo hold across 0.796 0.812 0.828 0.804 0.782 0.794 0.945 0.893
11 per_ori_geo mean hold across 0.814 0.827 0.841 0.819 0.800 0.810 0.952 0.899
12 pooled geo remove within 0.898 0.892 0.911 0.929 0.898 0.913 0.957 0.901
13 pooled mean remove within 0.903 0.899 0.917 0.936 0.906 0.918 0.963 0.907
14 per_ori geo remove within 0.862 0.858 0.879 0.876 0.856 0.867 0.960 0.903
15 per_ori mean remove within 0.869 0.866 0.887 0.883 0.864 0.873 0.967 0.910
16 per_ori_geo geo remove within 0.799 0.816 0.831 0.805 0.785 0.798 0.946 0.893
17 per_ori_geo mean remove within 0.817 0.829 0.843 0.821 0.803 0.814 0.954 0.899
18 pooled geo remove across 0.898 0.893 0.911 0.929 0.898 0.913 0.957 0.900
19 pooled mean remove across 0.903 0.899 0.917 0.935 0.906 0.918 0.963 0.907
20 per_ori geo remove across 0.862 0.858 0.879 0.876 0.856 0.867 0.960 0.903
21 per_ori mean remove across 0.869 0.866 0.887 0.883 0.864 0.873 0.966 0.909
22 per_ori_geo geo remove across 0.799 0.816 0.831 0.805 0.785 0.798 0.946 0.893
23 per_ori_geo mean remove across 0.817 0.829 0.843 0.821 0.803 0.814 0.953 0.899
readings with V1 in [0.89, 0.91]: 8 of 24
Result: reproduced. Over 0 to 250 ms the V1 static 1-back ratio is 0.897 (t interval 0.889 to 0.905) over 545 units, p = 4e-85, inside [0.89, 0.91], and 545 is within 53 of 530. LGN 61 and LP 17 units match the paper's 60 and 16 with the same selection.
fig6c-static-other-areas-1back¶
Extrastriate areas show similar 1-back adaptation to static gratings (0.89 to 0.93), and the few responsive LGN and LP neurons also adapt (0.93 and 0.85).
ex6 = r6[r6.area.isin(["LM", "AL", "RL", "PM", "AM"])]
print(f"extrastriate: {ex6.ratio.min():.3f} to {ex6.ratio.max():.3f}, all in [0.801, 1.023]: "
f"{bool(ex6.ratio.between(0.801, 1.023).all())}, largest corrected p {ex6.p_fdr.max():.2g}")
for a_, (lo, hi), n_paper in [("LGN", (0.93 - 0.093, 0.98), 60), ("LP", (0.85 - 0.085, 0.96), 16)]:
row = r6[r6.area == a_].iloc[0]
print(f"{a_}: ratio {row.ratio:.3f}, widened CI [{lo:.3f}, {hi}], match {lo <= row.ratio <= hi}; "
f"p {row.p:.2g} (corrected {row.p_fdr:.2g}); units {row.n_units} against {n_paper}")
tab6["ex_min"] = tab6[["LM", "AL", "RL", "PM", "AM"]].min(axis=1)
tab6["ex_max"] = tab6[["LM", "AL", "RL", "PM", "AM"]].max(axis=1)
print(tab6[["O1", "O2", "blanks", "blocks", "ex_min", "ex_max", "LGN", "LP"]].to_string())
extrastriate: 0.891 to 0.930, all in [0.801, 1.023]: True, largest corrected p 1.7e-09
LGN: ratio 0.957, widened CI [0.837, 0.98], match True; p 0.0025 (corrected 0.0029); units 61 against 60
LP: ratio 0.900, widened CI [0.765, 0.96], match True; p 0.0045 (corrected 0.0045); units 17 against 16
O1 O2 blanks blocks ex_min ex_max LGN LP
0 pooled geo hold within 0.891 0.930 0.957 0.900
1 pooled mean hold within 0.898 0.937 0.962 0.907
2 per_ori geo hold within 0.855 0.878 0.960 0.903
3 per_ori mean hold within 0.863 0.887 0.966 0.910
4 per_ori_geo geo hold within 0.782 0.828 0.945 0.893
5 per_ori_geo mean hold within 0.800 0.841 0.953 0.899
6 pooled geo hold across 0.891 0.930 0.957 0.900
7 pooled mean hold across 0.898 0.937 0.962 0.907
8 per_ori geo hold across 0.855 0.878 0.959 0.903
9 per_ori mean hold across 0.863 0.887 0.966 0.910
10 per_ori_geo geo hold across 0.782 0.828 0.945 0.893
11 per_ori_geo mean hold across 0.800 0.841 0.952 0.899
12 pooled geo remove within 0.892 0.929 0.957 0.901
13 pooled mean remove within 0.899 0.936 0.963 0.907
14 per_ori geo remove within 0.856 0.879 0.960 0.903
15 per_ori mean remove within 0.864 0.887 0.967 0.910
16 per_ori_geo geo remove within 0.785 0.831 0.946 0.893
17 per_ori_geo mean remove within 0.803 0.843 0.954 0.899
18 pooled geo remove across 0.893 0.929 0.957 0.900
19 pooled mean remove across 0.899 0.935 0.963 0.907
20 per_ori geo remove across 0.856 0.879 0.960 0.903
21 per_ori mean remove across 0.864 0.887 0.966 0.909
22 per_ori_geo geo remove across 0.785 0.831 0.946 0.893
23 per_ori_geo mean remove across 0.803 0.843 0.953 0.899
Result: reproduced. Extrastriate ratios run from 0.891 to 0.930 (largest corrected p 1.7e-09); LGN 0.957 (p = 0.0025) and LP 0.900 (p = 0.0045) are inside their widened intervals, and the counts (61, 17) are within tolerance.
fig6d-static-consistent-across-mice¶
Static grating 1-back adaptation is consistent across mice.
for grp, name in [(A.THALAMUS, "thalamus"), (A.CORTEX, "cortex")]:
g = mouse_rates(SG, grp, [1], A.SG_WIN)[0]
consistency(g, f"static 1-back, {name}")
static 1-back, thalamus: 17 mice, 15 with orthogonal above repeat, sign test p = 0.0023, median orth - rep 0.555 Hz; (a) False, (b) True not above: session 751348571, 2 units, repeat 36.08 Hz, orthogonal 35.74 Hz not above: session 761418226, 2 units, repeat 23.61 Hz, orthogonal 23.52 Hz static 1-back, cortex: 32 mice, 32 with orthogonal above repeat, sign test p = 4.7e-10, median orth - rep 0.969 Hz; (a) True, (b) True
Result: partially reproduced. All 32 mice have the cortical orthogonal rate above the repeat rate (p = 4.7e-10); in thalamus 15 of 17 mice do (p = 0.0023), so only reading (b) holds there.
fig7a-static-v1-long-term¶
After brief static gratings V1 adaptation persists for stimuli up to 20 presentations (5 s) back, with a double exponential decay whose slow time constant is 9.12 trials.
FDR family (a) n = 1 to 20 or (b) 1 to 50; fits as for drifting gratings.
FIT_SG = fits_for(ar_sg, SG["area"], A.CORTEX + A.THALAMUS)
for n_max in [20, 50]:
df, sig = nback_tests(ar_sg, SG["area"], "V1", range(1, n_max + 1))
print(f"family 1-{n_max}: significant n {sig}; largest {max(sig)}; 20-back significant {20 in sig}; "
f"20-back ratio {df.ratio[19]:.4f}, corrected p {df.p_fdr[19]:.2g}")
print(fit_table(FIT_SG, ["V1"]).round(3).to_string())
ci2 = {"a_fast": (7.11, 9.23), "tau_fast": (0.37, 0.71), "a_slow": (1.33, 2.91), "tau_slow": (6.09, 14.82)}
e = FIT_SG[("V1", -1)]
for k_, (lo, hi) in ci2.items():
print(f"{k_}: {e[k_]:.3f} in Table 2 CI [{lo}, {hi}]: {lo <= e[k_] <= hi}")
rs7 = readings_sig("sg", "V1", range(1, 21))
print("family 1-20 under every reading of O1 and O3:"); print(rs7.to_string())
family 1-20: significant n [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 17, 18, 20]; largest 20; 20-back significant True; 20-back ratio 0.9912, corrected p 9.3e-05
family 1-50: significant n [1, 2, 3, 4, 5, 6, 7, 9, 10, 13, 17, 18, 20, 26, 41, 46, 49]; largest 49; 20-back significant True; 20-back ratio 0.9912, corrected p 0.00023
region sign a_fast tau_fast a_slow tau_slow a_single tau_single F p_F F_units p_F_units double_on_bound single_on_bound
0 V1 minus (a) 8.255 0.533 2.065 9.47 10.015 1.168 46.33 9.5e-12 89.001 3e-39 False False
1 V1 plus (b) 8.255 0.533 -2.065 9.47 10.015 1.168 46.33 9.5e-12 89.001 3e-39 False False
a_fast: 8.255 in Table 2 CI [7.11, 9.23]: True
tau_fast: 0.533 in Table 2 CI [0.37, 0.71]: True
a_slow: 2.065 in Table 2 CI [1.33, 2.91]: True
tau_slow: 9.470 in Table 2 CI [6.09, 14.82]: True
family 1-20 under every reading of O1 and O3:
O1 blanks blocks significant largest
0 pooled hold within [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 17, 18, 20] 20
1 per_ori hold within [1, 2, 3] 3
2 per_ori_geo hold within [1, 2, 3, 4, 5, 6, 7, 9, 10] 10
3 pooled hold across [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 17, 18, 20] 20
4 per_ori hold across [1, 2, 3] 3
5 per_ori_geo hold across [1, 2, 3, 4, 5, 6, 7, 9, 10, 20] 20
6 pooled remove within [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16, 17, 19] 19
7 per_ori remove within [1, 2, 3] 3
8 per_ori_geo remove within [1, 2, 3, 5, 6, 9, 17] 17
9 pooled remove across [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16, 17, 19] 19
10 per_ori remove across [1, 2, 3, 5] 5
11 per_ori_geo remove across [1, 2, 3, 5, 6, 9, 12, 17] 17
Result: reproduced. With the FDR family n = 1 to 20 (a), V1 adaptation is significant at 20-back (ratio 0.991, corrected p = 9.3e-05), the largest significant n; with 1 to 50 (b) the largest is 49, outside 18 to 22. The fit gives a_fast 8.26%, tau_fast 0.533, a_slow 2.07% and tau_slow 9.47 trials, all inside their Table 2 intervals.
fig7b-static-cortex-decay¶
Extrastriate areas show similar decay after static gratings, with slow time constants from 6.54 (AM) to 21.78 trials (PM), all better fit by a double exponential.
T2 = {"V1": (6.09, 14.82), "AL": (5.24, 39.75), "AM": (3.82, 19.11), "LM": (5.42, 13.36),
"PM": (13.07, 37.0), "RL": (10.99, 37.51)}
ft2 = fit_table(FIT_SG, A.CORTEX)
print(ft2[ft2.sign == "minus (a)"].round(3).to_string())
t = time.time()
b7 = seed("fig7b-static-cortex-decay")
tasks = [(np.log(ar_sg[SG["area"] == r]), "double", b7 + k) for k in [0, 1000, 2000, 3000, 4000] for r in A.CORTEX]
BOOT_SG = dict(zip([(k, r) for k in [0, 1000, 2000, 3000, 4000] for r in A.CORTEX], A.bootstrap_many(tasks)))
print(f"bootstraps in {time.time() - t:.0f} s")
for k in [0, 1000, 2000, 3000, 4000]:
cis = {r: tuple(np.percentile(BOOT_SG[(k, r)][0][:, 3], [2.5, 97.5])) for r in A.CORTEX}
inside = {r: T2[r][0] <= FIT_SG[(r, -1)]["tau_slow"] <= T2[r][1] for r in A.CORTEX}
print(f"seed + {k}: CIs {', '.join(f'{r} [{c[0]:.2f}, {c[1]:.2f}]' for r, c in cis.items())}; "
f"all overlap {overlap_all(cis)}; dropped {[BOOT_SG[(k, r)][1] for r in A.CORTEX]}")
print("tau_slow inside Table 2 CI:", inside)
print("F test p (mean):", {r: FIT_SG[(r, -1)]["p_F"] for r in A.CORTEX})
print("F test p (units):", {r: FIT_SG[(r, -1)]["p_F_units"] for r in A.CORTEX})
region sign a_fast tau_fast a_slow tau_slow a_single tau_single F p_F F_units p_F_units double_on_bound single_on_bound 0 V1 minus (a) 8.255 0.533 2.065 9.470 10.015 1.168 46.330 9.5e-12 89.001 3e-39 False False 2 LM minus (a) 7.992 0.395 2.883 8.240 10.282 1.377 32.271 1.7e-09 50.631 1.4e-22 False False 4 AL minus (a) 7.334 0.649 1.610 13.582 8.429 1.508 20.074 5.4e-07 41.893 7.4e-19 False False 6 RL minus (a) 5.603 0.685 1.437 19.696 6.332 1.973 22.730 1.4e-07 25.248 1.2e-11 False False 8 PM minus (a) 8.673 0.626 1.732 19.072 9.903 1.381 25.543 3.5e-08 55.761 8.9e-25 False False 10 AM minus (a) 6.145 0.471 2.831 6.287 8.353 1.694 14.441 1.4e-05 22.939 1.2e-10 False False
bootstraps in 155 s
seed + 0: CIs V1 [6.64, 14.75], LM [5.41, 14.45], AL [5.36, 38.26], RL [10.63, 39.36], PM [11.71, 31.26], AM [3.45, 18.91]; all overlap True; dropped [0, 0, 27, 12, 0, 2]
seed + 1000: CIs V1 [6.47, 14.08], LM [5.64, 14.61], AL [5.25, 39.52], RL [10.84, 37.59], PM [11.20, 31.35], AM [3.61, 19.57]; all overlap True; dropped [0, 0, 32, 15, 0, 0]
seed + 2000: CIs V1 [6.65, 14.57], LM [5.67, 14.19], AL [5.16, 39.03], RL [11.18, 37.28], PM [11.28, 30.79], AM [3.54, 17.48]; all overlap True; dropped [0, 1, 30, 3, 1, 1]
seed + 3000: CIs V1 [6.47, 14.21], LM [5.53, 14.65], AL [5.09, 40.06], RL [11.27, 38.16], PM [11.80, 29.65], AM [3.57, 19.10]; all overlap True; dropped [0, 0, 41, 9, 0, 2]
seed + 4000: CIs V1 [6.59, 14.64], LM [5.52, 14.64], AL [5.16, 38.51], RL [11.00, 36.49], PM [11.44, 31.22], AM [3.60, 19.08]; all overlap True; dropped [0, 0, 30, 13, 0, 0]
tau_slow inside Table 2 CI: {'V1': np.True_, 'LM': np.True_, 'AL': np.True_, 'RL': np.True_, 'PM': np.True_, 'AM': np.True_}
F test p (mean): {'V1': 9.516989975756288e-12, 'LM': 1.7473491767002901e-09, 'AL': 5.406211228883844e-07, 'RL': 1.3648333262167052e-07, 'PM': 3.4572915030717065e-08, 'AM': 1.357499223567127e-05}
F test p (units): {'V1': 2.9724908793460725e-39, 'LM': 1.3707080118906925e-22, 'AL': 7.44994821090876e-19, 'RL': 1.197046601186678e-11, 'PM': 8.945571888944375e-25, 'AM': 1.1571338181894023e-10}
Result: reproduced. Every cortical area favours the double exponential (F test p from 9.5e-12 to 1.4e-05), every extrastriate tau_slow (AL 13.58, AM 6.29, LM 8.24, PM 19.07, RL 19.70) is inside its Table 2 interval, and the six bootstrapped intervals overlap under all five seeds. One p value (AM, 1.4e-05) is above the paper's bound of 1e-5.
fig7-static-lgn-single¶
After static gratings LGN is better described by a single exponential with a shorter time constant (2.93 trials), and the cortex and thalamus difference is less pronounced than for drifting gratings.
e = FIT_SG[("LGN", -1)]
print(fit_table(FIT_SG, ["LGN"]).round(4).to_string())
print(f"LGN single: tau {e['tau_single']:.3f} in [1.36, 7.32]: {1.36 <= e['tau_single'] <= 7.32}; "
f"a {e['a_single']:.2f}% in [1.80, 6.59]: {1.80 <= e['a_single'] <= 6.59}; F test p {e['p_F']:.2g} "
f"(units {e['p_F_units']:.2g})")
print(f"reported only: LGN tau static {e['tau_single']:.2f} against drifting {FIT_DG[('LGN', -1)]['tau_single']:.3f} trials")
region sign a_fast tau_fast a_slow tau_slow a_single tau_single F p_F F_units p_F_units double_on_bound single_on_bound 0 LGN minus (a) 3.8661 2.0254 0.3306 50.0 4.0038 2.7712 1.6474 0.2 1.9733 0.14 True False 1 LGN plus (b) 3.8661 2.0254 -0.3306 50.0 4.0038 2.7712 1.6474 0.2 1.9733 0.14 True False LGN single: tau 2.771 in [1.36, 7.32]: True; a 4.00% in [1.80, 6.59]: True; F test p 0.2 (units 0.14) reported only: LGN tau static 2.77 against drifting 0.031 trials
Result: reproduced. In LGN the F test does not favour the double exponential (p = 0.20; 0.14 with unit values), and the single exponential gives tau 2.77 trials and a 4.00%, inside their Table 2 intervals. As reported only, the LGN static tau (2.77) is longer than the drifting one (0.031).
fig7b-static-areas-long-term¶
After static gratings, cortical areas show significant adaptation to orientations presented up to 20 trials back, whereas in the thalamus long-term adaptation is less evident.
rows = []
for n_max in [20, 50]:
lg = {}
for region in A.CORTEX + A.THALAMUS:
df, sig = nback_tests(ar_sg, SG["area"], region, range(1, n_max + 1))
lg[region] = max(sig) if sig else 0
rows.append(dict(family=f"1-{n_max}", region=region, largest=lg[region], significant=sig))
cort = [lg[r] for r in A.CORTEX]
some = any(18 <= x <= 22 for x in cort); every = all(18 <= x <= 22 for x in cort)
thal = all(lg[t_] < min(cort) for t_ in A.THALAMUS)
print(f"family 1-{n_max}: cortical largest {dict(zip(A.CORTEX, cort))}; thalamic {lg['LGN']}, {lg['LP']}; "
f"(c) some area in 18-22 {some}; (d) every area {every}; thalamus below every cortical area {thal}")
print(pd.DataFrame(rows).to_string())
family 1-20: cortical largest {'V1': 20, 'LM': 15, 'AL': 20, 'RL': 17, 'PM': 20, 'AM': 20}; thalamic 5, 9; (c) some area in 18-22 True; (d) every area False; thalamus below every cortical area True
family 1-50: cortical largest {'V1': 49, 'LM': 49, 'AL': 49, 'RL': 47, 'PM': 46, 'AM': 22}; thalamic 2, 0; (c) some area in 18-22 True; (d) every area False; thalamus below every cortical area True
family region largest significant
0 1-20 V1 20 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 17, 18, 20]
1 1-20 LM 15 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 15]
2 1-20 AL 20 [1, 2, 3, 4, 5, 6, 7, 9, 10, 15, 18, 20]
3 1-20 RL 17 [1, 2, 3, 4, 5, 7, 9, 16, 17]
4 1-20 PM 20 [1, 2, 3, 4, 5, 6, 7, 9, 10, 16, 20]
5 1-20 AM 20 [1, 2, 3, 4, 5, 6, 7, 9, 15, 20]
6 1-20 LGN 5 [1, 2, 5]
7 1-20 LP 9 [1, 9]
8 1-50 V1 49 [1, 2, 3, 4, 5, 6, 7, 9, 10, 13, 17, 18, 20, 26, 41, 46, 49]
9 1-50 LM 49 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 15, 42, 49]
10 1-50 AL 49 [1, 2, 3, 4, 5, 6, 7, 9, 10, 15, 18, 20, 27, 33, 42, 43, 49]
11 1-50 RL 47 [1, 2, 3, 4, 5, 7, 9, 16, 17, 47]
12 1-50 PM 46 [1, 2, 3, 4, 5, 6, 7, 9, 10, 16, 20, 22, 23, 30, 33, 43, 46]
13 1-50 AM 22 [1, 2, 3, 4, 5, 6, 7, 9, 15, 22]
14 1-50 LGN 2 [2]
15 1-50 LP 0 []
Result: reproduced. With the family 1 to 20, V1, AL, PM and AM are significant at 20-back and LM and RL stop at 15 and 17, so reading (c), some area in 18 to 22, holds and (d), every area, does not. LGN (largest 5) and LP (9) stay below every cortical area. With the family 1 to 50, five cortical areas reach 46 to 49.
fig7c-static-long-term-across-mice¶
Long-term adaptation to static gratings (5- to 20-back) is consistent across mice.
for pooled_i, lab in [(0, "trials pooled over 5 to 20"), (1, "rates averaged over 5 to 20")]:
print(lab)
consistency(mouse_rates(SG, A.CORTEX, range(5, 21), A.SG_WIN)[pooled_i], " (a) cortex")
consistency(mouse_rates(SG, ["V1"], range(5, 21), A.SG_WIN)[pooled_i], " (b) V1")
consistency(mouse_rates(SG, A.THALAMUS, range(5, 21), A.SG_WIN)[pooled_i], " thalamus (reported only)")
trials pooled over 5 to 20 (a) cortex: 32 mice, 30 with orthogonal above repeat, sign test p = 2.5e-07, median orth - rep 0.073 Hz; (a) False, (b) True not above: session 763673393, 34 units, repeat 11.99 Hz, orthogonal 11.90 Hz not above: session 791319847, 54 units, repeat 10.96 Hz, orthogonal 10.96 Hz
(b) V1: 32 mice, 29 with orthogonal above repeat, sign test p = 2.6e-06, median orth - rep 0.087 Hz; (a) False, (b) True not above: session 763673393, 21 units, repeat 14.86 Hz, orthogonal 14.73 Hz not above: session 791319847, 31 units, repeat 12.16 Hz, orthogonal 12.14 Hz not above: session 797828357, 17 units, repeat 8.53 Hz, orthogonal 8.52 Hz thalamus (reported only): 17 mice, 11 with orthogonal above repeat, sign test p = 0.33, median orth - rep 0.061 Hz; (a) False, (b) False not above: session 750749662, 2 units, repeat 34.99 Hz, orthogonal 34.99 Hz not above: session 754829445, 4 units, repeat 9.44 Hz, orthogonal 9.37 Hz not above: session 755434585, 2 units, repeat 13.30 Hz, orthogonal 13.22 Hz not above: session 763673393, 6 units, repeat 30.90 Hz, orthogonal 30.85 Hz not above: session 761418226, 2 units, repeat 23.17 Hz, orthogonal 23.00 Hz not above: session 799864342, 9 units, repeat 14.55 Hz, orthogonal 14.46 Hz rates averaged over 5 to 20 (a) cortex: 32 mice, 30 with orthogonal above repeat, sign test p = 2.5e-07, median orth - rep 0.072 Hz; (a) False, (b) True not above: session 763673393, 34 units, repeat 11.99 Hz, orthogonal 11.90 Hz not above: session 791319847, 54 units, repeat 10.96 Hz, orthogonal 10.96 Hz (b) V1: 32 mice, 29 with orthogonal above repeat, sign test p = 2.6e-06, median orth - rep 0.086 Hz; (a) False, (b) True not above: session 763673393, 21 units, repeat 14.86 Hz, orthogonal 14.73 Hz not above: session 791319847, 31 units, repeat 12.16 Hz, orthogonal 12.14 Hz not above: session 797828357, 17 units, repeat 8.53 Hz, orthogonal 8.52 Hz thalamus (reported only): 17 mice, 12 with orthogonal above repeat, sign test p = 0.14, median orth - rep 0.064 Hz; (a) False, (b) False not above: session 754829445, 4 units, repeat 9.44 Hz, orthogonal 9.37 Hz not above: session 755434585, 2 units, repeat 13.30 Hz, orthogonal 13.22 Hz not above: session 763673393, 6 units, repeat 30.90 Hz, orthogonal 30.86 Hz not above: session 761418226, 2 units, repeat 23.16 Hz, orthogonal 23.00 Hz not above: session 799864342, 9 units, repeat 14.55 Hz, orthogonal 14.46 Hz
Result: partially reproduced. For 5- to 20-back, 30 of 32 mice have the cortical orthogonal rate above the repeat rate (p = 2.5e-07) and 29 of 32 for V1 (p = 2.6e-06), so (b) holds and (a) does not under both readings of the group.
fig8-no-spurious-long-term¶
A simulated neuron with only 1-back adaptation, shown the experiments' own stimulus sequences, shows no spurious adaptation to stimuli further back, for drifting or static gratings.
For each session's sequence (blanks holding positions, pairs within blocks), a neuron that responds equally to every grating, reduced by the empirical V1 1-back ratio of that stimulus set when the 1-back grating had the same orientation (Figure 8 legend). Noise readings: (a) Poisson counts at the V1 median rate on orthogonal 1-back trials, the claim's seed; (b) no noise. The simulated responses are analysed as the data (pooled ratio per n). 95% CI across the 32 sequences (t interval of the mean log ratio). Ranges of n: (c) 2 to 10, (d) 2 to 50.
def simulate(stim, truth, rate, win, rng, noise):
out = []
for s in S:
table = s[stim]
ori, blk, order = A.sequence(table, None, "hold", "within")
rep1 = np.zeros(len(ori), bool)
r_, o_, b_ = A.pair_masks(ori, blk, 1)
rep1[1:] = r_
lam = rate * win * np.where(rep1, truth, 1.0)
c = rng.poisson(lam) if noise else lam
counts = np.zeros(len(table)); counts[order] = c
nb, _ = A.nback_rates(counts[None, :], table, 50, "hold", "within")
out.append(np.log(A.ratios(nb, "pooled")[0]))
return np.array(out)
s8 = seed("fig8-no-spurious-long-term")
def sim_eval(L, truth):
L = np.where(np.isfinite(L), L, np.nan)
m = np.nanmean(L, 0); se = np.nanstd(L, 0, ddof=1) / np.sqrt(np.sum(np.isfinite(L), 0))
lo, hi = np.exp(m - stats.t.ppf(0.975, 31) * se), np.exp(m + stats.t.ppf(0.975, 31) * se)
ok1 = lo[0] - 1e-9 <= truth <= hi[0] + 1e-9
exc = [n for n in range(2, 51) if not (lo[n - 1] <= 1 <= hi[n - 1])]
return dict(one_back=np.exp(m[0]), one_low=lo[0], one_high=hi[0], truth_in=ok1,
excl_2_10=[n for n in exc if n <= 10], excl_2_50=exc,
excl_2_10_ratios=[round(float(np.exp(m[n - 1])), 4) for n in exc if n <= 10],
min_2_50=np.exp(m[1:]).min(), max_2_50=np.exp(m[1:]).max(),
max_dev_2_10=float(np.max(np.abs(np.exp(m[1:10]) - 1))))
SIM = {}
for stim, ar, d, win in [("dg", ar_dg, DG, A.DG_WIN), ("sg", ar_sg, SG, A.SG_WIN)]:
truth = A.region_value(ar[d["area"] == "V1", 0], "geo")
v1 = d["area"] == "V1"
rate = float(np.median(d["nb"]["os"][v1, 0].sum(1) / d["nb"]["on"][v1, 0].sum(1) / win))
print(f"{'drifting' if stim == 'dg' else 'static'}: ground truth {truth:.4f}, rate {rate:.2f} Hz")
for noise, k in [(True, 0), (True, 1000), (True, 2000), (True, 3000), (True, 4000), (False, 0)]:
L = simulate(stim, truth, rate, win, np.random.default_rng(s8 + k + (0 if stim == "dg" else 1)), noise)
SIM[(stim, noise, k)] = r_ = sim_eval(L, truth)
print(f" {'Poisson, seed + ' + str(k) if noise else 'no noise'}: " + ", ".join(
f"{a}={round(b, 4) if isinstance(b, float) else b}" for a, b in r_.items()))
def fig8_reading(noise, k, rng_n):
res = {}
for stim in ["dg", "sg"]:
r_ = SIM[(stim, noise, k)]
ex = r_["excl_2_10"] if rng_n == "c" else r_["excl_2_50"]
res[stim] = r_["truth_in"] and not ex
return res["dg"] and res["sg"]
for noise in [True, False]:
for rng_n in ["c", "d"]:
ks = [0, 1000, 2000, 3000, 4000] if noise else [0]
print(f"reading ({'a' if noise else 'b'}, {rng_n}): criterion met under seed +k: "
+ ", ".join(f"{k}: {fig8_reading(noise, k, rng_n)}" for k in ks))
for noise in [True, False]:
part = all(len(SIM[(st, noise, 0)]["excl_2_10"]) <= 1 and all(abs(x - 1) <= 0.01 for x in SIM[(st, noise, 0)]["excl_2_10_ratios"]) for st in ["dg", "sg"])
print(f"partial rule (no more than one n in 2-10 excluding 1, within 0.01 of 1), {'Poisson' if noise else 'no noise'}: {part}")
drifting: ground truth 0.8212, rate 9.97 Hz
Poisson, seed + 0: one_back=0.8032, one_low=0.7694, one_high=0.8385, truth_in=True, excl_2_10=[], excl_2_50=[13, 18, 46], excl_2_10_ratios=[], min_2_50=0.9419, max_2_50=1.0482, max_dev_2_10=0.0336
Poisson, seed + 1000: one_back=0.8019, one_low=0.7705, one_high=0.8346, truth_in=True, excl_2_10=[], excl_2_50=[40], excl_2_10_ratios=[], min_2_50=0.9582, max_2_50=1.0481, max_dev_2_10=0.0277
Poisson, seed + 2000: one_back=0.8062, one_low=0.7665, one_high=0.848, truth_in=True, excl_2_10=[8, 9], excl_2_50=[8, 9, 12, 20, 21, 29, 32, 33], excl_2_10_ratios=[0.9578, 0.9563], min_2_50=0.9502, max_2_50=1.0804, max_dev_2_10=0.048
Poisson, seed + 3000: one_back=0.8324, one_low=0.7929, one_high=0.874, truth_in=True, excl_2_10=[], excl_2_50=[40], excl_2_10_ratios=[], min_2_50=0.9429, max_2_50=1.0508, max_dev_2_10=0.0251
Poisson, seed + 4000: one_back=0.8166, one_low=0.78, one_high=0.8549, truth_in=True, excl_2_10=[], excl_2_50=[14, 21, 32], excl_2_10_ratios=[], min_2_50=0.9419, max_2_50=1.0387, max_dev_2_10=0.0351
no noise: one_back=0.8212, one_low=0.8212, one_high=0.8212, truth_in=True, excl_2_10=[2, 6], excl_2_50=[2, 6, 42], excl_2_10_ratios=[0.9963, 1.003], min_2_50=0.9949, max_2_50=1.0034, max_dev_2_10=0.0037 static: ground truth 0.8968, rate 9.04 Hz
Poisson, seed + 0: one_back=0.8961, one_low=0.884, one_high=0.9084, truth_in=True, excl_2_10=[5, 6], excl_2_50=[5, 6], excl_2_10_ratios=[0.9858, 0.987], min_2_50=0.9858, max_2_50=1.009, max_dev_2_10=0.0142
Poisson, seed + 1000: one_back=0.8997, one_low=0.8896, one_high=0.9098, truth_in=True, excl_2_10=[], excl_2_50=[33, 37, 38], excl_2_10_ratios=[], min_2_50=0.988, max_2_50=1.0129, max_dev_2_10=0.0096
Poisson, seed + 2000: one_back=0.8984, one_low=0.8909, one_high=0.9059, truth_in=True, excl_2_10=[], excl_2_50=[25, 29, 32], excl_2_10_ratios=[], min_2_50=0.9901, max_2_50=1.0148, max_dev_2_10=0.0113
Poisson, seed + 3000: one_back=0.8895, one_low=0.8797, one_high=0.8994, truth_in=True, excl_2_10=[6], excl_2_50=[6, 22, 26, 27, 40], excl_2_10_ratios=[1.0108], min_2_50=0.9837, max_2_50=1.0126, max_dev_2_10=0.0108
Poisson, seed + 4000: one_back=0.9014, one_low=0.8927, one_high=0.9102, truth_in=True, excl_2_10=[2], excl_2_50=[2, 18], excl_2_10_ratios=[1.0084], min_2_50=0.9786, max_2_50=1.0085, max_dev_2_10=0.0085
no noise: one_back=0.8968, one_low=0.8968, one_high=0.8968, truth_in=True, excl_2_10=[], excl_2_50=[32], excl_2_10_ratios=[], min_2_50=0.9994, max_2_50=1.0008, max_dev_2_10=0.0007 reading (a, c): criterion met under seed +k: 0: False, 1000: True, 2000: False, 3000: False, 4000: False reading (a, d): criterion met under seed +k: 0: False, 1000: False, 2000: False, 3000: False, 4000: False reading (b, c): criterion met under seed +k: 0: False reading (b, d): criterion met under seed +k: 0: False partial rule (no more than one n in 2-10 excluding 1, within 0.01 of 1), Poisson: False partial rule (no more than one n in 2-10 excluding 1, within 0.01 of 1), no noise: False
# Seed dependence of reading (a): 200 further Poisson seeds, each simulated exactly as above, and
# the number of excluding n expected by chance (5% of the n per stimulus set if the CIs are exact).
def sim_weights(stim):
"""Per session, the 1-back repeat flags and, for n = 1 to 50, the positions of repeat and
orthogonal pairs, so that the pooled ratio of `simulate` is a ratio of two weighted sums."""
W = []
for s in S:
ori, blk, order = A.sequence(s[stim], None, "hold", "within")
rep1 = np.zeros(len(ori), bool); rep1[1:] = A.pair_masks(ori, blk, 1)[0]
wr = np.zeros((len(ori), 50)); wo = np.zeros((len(ori), 50))
for n in range(1, 51):
r_, o_, _ = A.pair_masks(ori, blk, n)
wr[n:, n - 1] = r_ / r_.sum(); wo[n:, n - 1] = o_ / o_.sum()
W.append((rep1, wr, wo))
return W
def simulate_fast(W, truth, rate, win, rng):
out = []
for rep1, wr, wo in W:
c = rng.poisson(rate * win * np.where(rep1, truth, 1.0)).astype(float)
with np.errstate(divide="ignore", invalid="ignore"):
out.append(np.log((c @ wr) / (c @ wo)))
return np.array(out)
P8 = {}
for stim, ar, d, win in [("dg", ar_dg, DG, A.DG_WIN), ("sg", ar_sg, SG, A.SG_WIN)]:
truth = A.region_value(ar[d["area"] == "V1", 0], "geo")
v1 = d["area"] == "V1"
rate = float(np.median(d["nb"]["os"][v1, 0].sum(1) / d["nb"]["on"][v1, 0].sum(1) / win))
W = sim_weights(stim)
chk = sim_eval(simulate_fast(W, truth, rate, win, np.random.default_rng(s8 + (0 if stim == "dg" else 1))), truth)
assert chk["excl_2_50"] == SIM[(stim, True, 0)]["excl_2_50"] # the same as `simulate`
P8[stim] = [sim_eval(simulate_fast(W, truth, rate, win, np.random.default_rng(s8 + 10_000 + 2 * j + (0 if stim == "dg" else 1))), truth)
for j in range(200)]
def meets(r_, rng_n, partial=False):
ex = r_["excl_2_10"] if rng_n == "c" else r_["excl_2_50"]
if partial:
return r_["truth_in"] and len(r_["excl_2_10"]) <= 1 and all(abs(x - 1) <= 0.01 for x in r_["excl_2_10_ratios"])
return r_["truth_in"] and not ex
for rng_n in ["c", "d"]:
both = np.mean([meets(a, rng_n) and meets(b, rng_n) for a, b in zip(P8["dg"], P8["sg"])])
print(f"reading (a, {rng_n}): criterion met in {100 * both:.1f}% of 200 seeds "
f"(drifting alone {100 * np.mean([meets(a, rng_n) for a in P8['dg']]):.1f}%, static alone {100 * np.mean([meets(b, rng_n) for b in P8['sg']]):.1f}%)")
part = np.mean([meets(a, "c", True) and meets(b, "c", True) for a, b in zip(P8["dg"], P8["sg"])])
print(f"partial rule met in {100 * part:.1f}% of 200 seeds")
for stim in ["dg", "sg"]:
e10 = [len(r_["excl_2_10"]) for r_ in P8[stim]]; e50 = [len(r_["excl_2_50"]) for r_ in P8[stim]]
dev = [abs(x - 1) for r_ in P8[stim] for x in r_["excl_2_10_ratios"]]
print(f"{'drifting' if stim == 'dg' else 'static'}: excluding n per seed, 2 to 10 mean {np.mean(e10):.2f} (chance 0.45), "
f"2 to 50 mean {np.mean(e50):.2f} (chance 2.45); truth inside the 1-back CI in {sum(r_['truth_in'] for r_ in P8[stim])} of 200; "
f"excluding ratios within {max(dev) if dev else 0:.4f} of 1")
print("chance that no n of 9 (49) excludes 1 in both sets, if independent: "
f"{0.95 ** 18:.3f} ({0.95 ** 98:.4f})")
for k in [1000, 2000, 3000, 4000]:
print(f"partial rule under seed + {k}:", all(len(SIM[(st, True, k)]["excl_2_10"]) <= 1 and
all(abs(x - 1) <= 0.01 for x in SIM[(st, True, k)]["excl_2_10_ratios"]) for st in ["dg", "sg"]))
reading (a, c): criterion met in 38.0% of 200 seeds (drifting alone 64.5%, static alone 58.5%) reading (a, d): criterion met in 0.0% of 200 seeds (drifting alone 5.0%, static alone 7.0%) partial rule met in 41.5% of 200 seeds drifting: excluding n per seed, 2 to 10 mean 0.36 (chance 0.45), 2 to 50 mean 2.57 (chance 2.45); truth inside the 1-back CI in 192 of 200; excluding ratios within 0.0852 of 1 static: excluding n per seed, 2 to 10 mean 0.47 (chance 0.45), 2 to 50 mean 2.46 (chance 2.45); truth inside the 1-back CI in 189 of 200; excluding ratios within 0.0176 of 1 chance that no n of 9 (49) excludes 1 in both sets, if independent: 0.397 (0.0066) partial rule under seed + 1000: True partial rule under seed + 2000: False partial rule under seed + 3000: False partial rule under seed + 4000: True
Result: not reproduced. The simulated neuron's 1-back interval contains the ground truth in each of the six runs above; over the 200 further Poisson seeds it does in 192 (drifting) and 189 (static). Under the claim's seed with Poisson noise (a), no drifting n from 2 to 10 excludes 1, but static 5- and 6-back do (0.986, 0.987); with no noise (b), static passes and drifting 2- and 6-back exclude 1 (0.996, 1.003). No reading meets the criterion or its partial rule under the claim's seed; reading (a, c) meets it under one of the four other seeds. The spurious ratios are small: within 0.0037 of 1 for drifting and 0.0007 for static over n = 2 to 10 without noise, against V1 drifting ratios of 0.918 to 0.984 at 2- to 8-back. Over 200 further Poisson seeds, reading (a, c) meets the criterion in 38.0% and the partial rule in 41.5%, reading (a, d) in none; the n whose interval excludes 1 number 0.36 (drifting) and 0.47 (static) per seed over 2 to 10, and 2.57 and 2.46 over 2 to 50, close to the 0.45 and 2.45 expected by chance from 95% intervals, and if exclusions were independent no n of 9 would exclude 1 in both sets in 39.7% of seeds. The failures under reading (a) are thus those of a criterion that asks every interval to contain 1, which noise alone breaks about as often as the data show (a question to a reader, questions/fritsche-2022.yaml). Under the four other seeds the partial rule holds at +1000 and +4000. Without noise the exclusions (drifting 0.996 at 2-back and 1.003 at 6-back) come from the sequences themselves, not from noise.
robust-threshold-preferred-window¶
The results are qualitatively similar with a responsiveness threshold of 2.5 or 10 Hz, when only trials at the neuron's preferred orientation are used (drifting gratings), and with a 0 to 100 ms window for static gratings.
Each variant: V1 adaptation significant beyond 1-back (FDR as in the main analysis: n = 1 to 10 for drifting, 1 to 20 for static, reading (a) of fig7a), V1 better fit by the double exponential (F test on the mean, p < 0.05), and for drifting gratings no LGN n beyond 2 significant. The preferred-orientation variant uses trials whose current orientation is the unit's preferred and whose n-back is the preferred (repeat) or its orthogonal (Methods).
def variant_eval(ar, area, stim, label):
n_fam = 10 if stim == "dg" else 20
_, sig = nback_tests(ar, area, "V1", range(1, n_fam + 1))
lr = np.log(ar[area == "V1"]); lr = np.where(np.isfinite(lr), lr, np.nan)
m = np.nanmean(lr, 0)
dd, ss = A.fit_models(m, -1)
F, p = A.ftest(ss[1], dd[1], len(m))
row = dict(variant=label, V1_units=int((area == "V1").sum()),
V1_nonfinite=int(np.sum(~np.isfinite(np.log(ar[area == "V1"])))),
V1_sig=sig, V1_beyond_1=any(n > 1 for n in sig), V1_tau_slow=dd[0][3], F_p=p,
double_better=p < 0.05)
if stim == "dg":
_, sl = nback_tests(ar, area, "LGN", range(1, 11))
row.update(LGN_units=int((area == "LGN").sum()), LGN_sig=sl, LGN_ok=all(n <= 2 for n in sl))
row["meets"] = row["V1_beyond_1"] and row["double_better"] and row.get("LGN_ok", True)
return row
rows = []
for thr in [2.5, 10.0]:
kw = dict(MAIN, thr=thr)
d = build("dg", sel_kw=kw); rows.append(variant_eval(A.ratios(d["nb"], "pooled"), d["area"], "dg", f"drifting {thr} Hz"))
d = build("sg", sel_kw=kw); rows.append(variant_eval(A.ratios(d["nb"], "pooled"), d["area"], "sg", f"static {thr} Hz"))
# Preferred orientation only (drifting).
pi = np.array([int(np.flatnonzero(DG["oris"] == p)[0]) for p in DG["pref"]])
u = np.arange(len(pi))
nbp = {k: v[u, :, pi][:, :, None] for k, v in DG["nb"].items()}
nbp = {k: v.reshape(len(pi), -1, 1) for k, v in nbp.items()}
with np.errstate(divide="ignore", invalid="ignore"):
ar_pref = A.ratios(nbp, "pooled")
rows.append(variant_eval(ar_pref, DG["area"], "dg", "drifting, preferred orientation only"))
d = build("sg", short_counts=True)
rows.append(variant_eval(A.ratios(d["nb"], "pooled"), d["area"], "sg", "static 0-100 ms, units selected on 0-250 ms"))
d = build("sg", win=A.SG_WIN_SHORT)
rows.append(variant_eval(A.ratios(d["nb"], "pooled"), d["area"], "sg", "static 0-100 ms, units selected on 0-100 ms"))
rob = pd.DataFrame(rows)
print(rob.round(4).to_string())
print(f"variants meeting the reading: {int(rob.meets.sum())} of {len(rob)}")
variant V1_units V1_nonfinite V1_sig V1_beyond_1 V1_tau_slow F_p double_better LGN_units LGN_sig LGN_ok meets 0 drifting 2.5 Hz 656 0 [1, 2, 3, 4, 5, 6, 7] True 7.7140 0.0105 True 146.0 [1] True True 1 static 2.5 Hz 649 0 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 17, 18, 20] True 9.3506 0.0000 True NaN NaN NaN True 2 drifting 10.0 Hz 430 0 [1, 2, 3, 4, 5, 7, 8] True 5.3669 0.0069 True 138.0 [1] True True 3 static 10.0 Hz 381 0 [1, 2, 3, 4, 5, 6, 7, 9, 10, 15, 18, 20] True 11.7758 0.0000 True NaN NaN NaN True 4 drifting, preferred orientation only 580 0 [1, 2, 4, 5, 6, 8] True 10.1676 0.0065 True 142.0 [1] True True 5 static 0-100 ms, units selected on 0-250 ms 545 0 [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 17, 18, 20] True 7.8479 0.0000 True NaN NaN NaN True 6 static 0-100 ms, units selected on 0-100 ms 97 0 [1, 2, 3, 13, 20] True 5.7475 0.0016 True NaN NaN NaN True variants meeting the reading: 7 of 7
Result: reproduced. All seven variants meet the reading: V1 adaptation is significant beyond 1-back, V1 favours the double exponential (F test p <= 0.0105), and for drifting gratings LGN is significant only at 1-back. This holds at 2.5 and 10 Hz for both stimulus sets, for the preferred-orientation trials, and for static 0 to 100 ms rates with units selected on 0 to 250 ms (545 V1 units) or on 0 to 100 ms (97 V1 units).
Summary¶
| Claim | Outcome |
|---|---|
| units-responsive-count | reproduced |
| fig1d-v1-1back | reproduced |
| fig1d-extrastriate-1back | reproduced |
| fig1d-thalamus-1back | reproduced |
| fig1e-consistent-across-mice | partially reproduced |
| fig2-v1-tuning-main-effect | reproduced |
| fig2-v1-tuning-interaction | reproduced |
| fig2-v1-adaptation-at-all-orientations | reproduced |
| fig2-thalamus-no-tuning-dependence | reproduced |
| fig3a-v1-long-term | reproduced |
| fig3a-v1-double-exponential | reproduced |
| fig3a-v1-half-life | reproduced |
| fig4-cumulative-adaptation | reproduced |
| fig4b-linear-accumulation | reproduced |
| fig3b-thalamus-short-term | reproduced (rests on an assumption) |
| v1-vs-thalamus-welch | reproduced |
| fig3c-mice-long-term | reproduced |
| decay-cortex-double-better | reproduced |
| table1-extrastriate-tau-slow | reproduced |
| decay-thalamus-single | reproduced (rests on an assumption) |
| fig5-repeat-suppression | not reproduced |
| fig6c-static-v1-1back | reproduced |
| fig6c-static-other-areas-1back | reproduced |
| fig6d-static-consistent-across-mice | partially reproduced |
| fig7a-static-v1-long-term | reproduced |
| fig7b-static-cortex-decay | reproduced |
| fig7-static-lgn-single | reproduced |
| fig7b-static-areas-long-term | reproduced |
| fig7c-static-long-term-across-mice | partially reproduced |
| fig8-no-spurious-long-term | not reproduced (seed sensitive) |
| robust-threshold-preferred-window | reproduced |
A failure to reproduce here may be a failure of this attempt, not of the paper: see the reasoning and the differences from the paper's method.
How the analysis differs from the paper's. The paper's code is restricted and was not read. The open details of the claims file were each run; the adopted main reading (pooled per-unit ratio, geometric region value, blank trials holding positions, pairs within blocks, gray mean
- 1 SD of the blank trials, preferred orientation pooled,
noiseunits left out) is the one the unit counts single out, and it gives the paper's 1-back values to within 0.01 for drifting gratings and for static gratings in cortex; for static gratings in the thalamus it gives LGN 0.957 against 0.93 and LP 0.900 against 0.85. Two outcomes marked above rest on assumptions. Leaving out thenoiseunits is one: with them kept, LGN gains a significant 7-back and its single-exponential tau falls to 0.000, outside the interval of decay-thalamus-single, and no reading of fig3b-thalamus-short-term meets its criterion (RL stops at 5-back). fig3b also rests on a second assumption, that significant adaptation counts only ratios below 1; read two-sided, it would be partially reproduced. The invalid intervals listed in the files are not applied; leaving out the presentations inside them leaves the unit counts and 1-back ratios within tolerance, keeps fig3b's across-blocks reading passing, and adds a significant LGN 7-back under the main reading. The simulated neuron of Figure 8 needs a rate and a noise model the paper does not give; the V1 median rate with Poisson counts, and no noise, were run. Its criterion asks every interval to contain 1, which Poisson noise breaks at about the rate expected by chance (38% of 200 seeds pass); this is asked of a reader.
What was found about the dataset. The files hold the 32 mice and both stimulus sets the paper
describes. The units table holds every sorted unit, with a quality column marking 20182 of
74658 as noise and quality metric columns, none of them described in the file; the paper's
counts are matched when the noise units are left out, as the AllenSDK does. Three sessions
hold 598 drifting gratings in place of 600. Thirteen sessions list probe-tagged invalid
intervals, some inside the grating epochs. Units on channels labelled grey or VIS have no
area.