Najafi et al. (2020) on DANDI:000016, part 2: choice decoders in expert sessions¶
Paper doi:10.1016/j.neuron.2019.09.045; dataset DANDI:000016 version 0.260915.2309, the only
published version (the paper cites none; see 01_single_neurons_correlations.ipynb for the
data checks). Claims file claims/najafi-2020.yaml.
Decoders as in the claims file's opening comment (linear SVM per 97 ms bin, z-scored neurons, choices matched, 50 random 90/10 splits, C by minimum mean test error, shuffled-label control), at the bin 0-97 ms before the choice, on correct trials, every session with at least 10 correct trials of each choice. Two departures for runtime, recorded as deviations: C is chosen from 10^-6 to 10^6 in steps of 1 (the paper's grid has steps of 0.2), and the excitatory, mixed and 2n-excitatory populations use 5 random subsamples (the paper 50). A check of the full grid on a few sessions is at the end.
| Claim | Here |
|---|---|
| fig3bc-decoding-similar | tested |
| fig3hi-mixed-no-advantage | tested |
| fig3df-weights-similar | tested (bin -1 only) |
| figs6de-incorrect-trials | tested |
| fig4bd-stability-similar | tested |
| fig7-noise-correlations-limit-decoding | tested |
| figs12-licking-running | blocked (lick spout not identified); the running part is shown |
| learning decoders | 03_learning_decoders.ipynb |
import time, resource, os
import numpy as np
import pandas as pd
from scipy import stats
from joblib import Parallel, delayed
import najafi as nj
T0 = time.time()
A = nj.assets()
S = nj.load_all(A, workers=6, alignments=(nj.CHOICE,), behaviour=True)
for s in S: # keep only what the decoders use
s["al"][nj.CHOICE].pop("frames", None)
print("loaded", len(S), "sessions in %.0f s, peak memory %.1f GB" % (time.time() - T0, resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6))
loaded 135 sessions in 843 s, peak memory 5.7 GB
D = pd.DataFrame([{"mouse": s["mouse"], "session": s["session_id"], "correct": int(nj.trial_mask(s, (1,)).sum()),
"incorrect": int(nj.trial_mask(s, (0,)).sum()), "exc": int((s["type"] == "excitatory").sum()),
"inh": int((s["type"] == "inhibitory").sum()), "all": len(s["type"]),
"minchoice_corr": int(min(np.sum(s["trials"].choice.to_numpy()[nj.trial_mask(s, (1,))] == v) for v in (0, 1)))} for s in S])
print(D.groupby("mouse")[["correct", "incorrect", "exc", "inh", "all", "minchoice_corr"]].median())
print("sessions with fewer than 10 correct trials of a choice:", int((D.minchoice_corr < 10).sum()))
print("sessions with fewer than twice as many excitatory as inhibitory neurons:", int((D.exc < 2 * D.inh).sum()))
wh = np.concatenate([s["wheel"].ravel() for s in S]); wh = wh[~np.isnan(wh)]
print("wheel (revolutions, cumulative, in the 200 ms before the choice): %.3f to %.3f; samples every %.3f s" % (wh.min(), wh.max(), np.diff(S[0]["wheel_t"]).mean()))
print("lick trace values:", np.unique(np.concatenate([np.unique(s["lick"][~np.isnan(s["lick"])]) for s in S])), "time range of the lick trace, s:", S[0]["lick_range"])
correct incorrect exc inh all minchoice_corr mouse 1 98.0 48.0 309.0 40.0 458.0 44.0 2 142.0 41.5 393.5 49.5 576.5 64.5 3 120.0 31.0 270.0 27.0 393.0 53.0 4 129.0 44.0 347.0 37.0 478.0 52.0 sessions with fewer than 10 correct trials of a choice: 8 sessions with fewer than twice as many excitatory as inhibitory neurons: 0 wheel (revolutions, cumulative, in the 200 ms before the choice): -3.876 to 0.066; samples every 0.010 s lick trace values: [0. 1.] time range of the lick trace, s: (-4.045, 1.008)
# one generator per session, seeded from its index, so a session's numbers do not depend on the others
os.environ.setdefault("OMP_NUM_THREADS", "1")
t1 = time.time()
OUT = Parallel(n_jobs=4)(delayed(nj.decode_session)(s, 1000 + i) for i, s in enumerate(S))
print("decoders: %.1f min" % ((time.time() - t1) / 60))
OUT = [o for o in OUT if "all" in o]
print("sessions decoded:", len(OUT), pd.Series([o["mouse"] for o in OUT]).value_counts().sort_index().to_dict())
Q = pd.DataFrame([{"mouse": o["mouse"], "session": o["session"], "nI": o["nI"], "ntr": o["ntr"],
"all": o["all"]["acc"], "all_sh": o["all"]["acc_sh"], "inh": o["inh"]["acc"], "inh_sh": o["inh"]["acc_sh"],
"exc": np.mean([x["acc"] for x in o["exc_subs"]]), "exc_sh": np.mean([x["acc_sh"] for x in o["exc_subs"]]),
"all_inc": o["all"]["acc_inc"], "inh_inc": o["inh"]["acc_inc"], "exc_inc": np.mean([x["acc_inc"] for x in o["exc_subs"]]),
"all_inc_sh": o["all"]["acc_inc_sh"], "inh_inc_sh": o["inh"]["acc_inc_sh"], "exc_inc_sh": np.mean([x["acc_inc_sh"] for x in o["exc_subs"]]),
"n_inc": o["n_incorr"], "mixed": np.mean(o["mixed"]) if "mixed" in o else np.nan, "exc2n": np.mean(o["exc2n"]) if "exc2n" in o else np.nan,
"pseudo": o["pseudo"]["acc"], "all_alltr": o.get("all_alltr", {}).get("acc", np.nan), "pseudo_alltr": o.get("pseudo_alltr", {}).get("acc", np.nan)} for o in OUT])
print("accuracy range over sessions (percent): all %.1f to %.1f, inh %.1f to %.1f, exc %.1f to %.1f" % (Q["all"].min(), Q["all"].max(), Q.inh.min(), Q.inh.max(), Q.exc.min(), Q.exc.max()))
def ttest(a, b):
a, b = np.asarray(a, float), np.asarray(b, float)
return stats.ttest_ind(a[~np.isnan(a)], b[~np.isnan(b)])
decoders: 37.1 min
sessions decoded: 127 {1: 41, 2: 45, 3: 7, 4: 34}
accuracy range over sessions (percent): all 62.3 to 99.2, inh 48.0 to 88.3, exc 51.5 to 80.3
fig3bc-decoding-similar¶
Choice can be decoded from population activity well above chance, and inhibitory populations decode it as accurately as excitatory populations of the same size, in every mouse.
for m, g in Q.groupby("mouse"):
pe, pi, pa = ttest(g.exc, g.exc_sh).pvalue, ttest(g.inh, g.inh_sh).pvalue, ttest(g["all"], g.all_sh).pvalue
d = ttest(g.inh, g.exc)
print(f"mouse {m} ({len(g)} sessions): all {g['all'].mean():.1f} (shuffle {g.all_sh.mean():.1f}, p = {pa:.2g}); "
f"exc {g.exc.mean():.1f} (shuffle {g.exc_sh.mean():.1f}, p = {pe:.2g}); inh {g.inh.mean():.1f} (shuffle {g.inh_sh.mean():.1f}, p = {pi:.2g}); "
f"inh - exc {g.inh.mean()-g.exc.mean():+.2f}, t = {d.statistic:.2f}, p = {d.pvalue:.3g}")
mouse 1 (41 sessions): all 82.2 (shuffle 55.6, p = 7.2e-26); exc 65.3 (shuffle 51.2, p = 3.3e-22); inh 64.6 (shuffle 51.3, p = 5.6e-17); inh - exc -0.68, t = -0.44, p = 0.66 mouse 2 (45 sessions): all 82.7 (shuffle 53.2, p = 1.1e-36); exc 64.3 (shuffle 50.6, p = 8.8e-26); inh 66.0 (shuffle 50.2, p = 3.3e-25); inh - exc +1.70, t = 1.24, p = 0.217 mouse 3 (7 sessions): all 73.3 (shuffle 51.9, p = 9e-05); exc 60.3 (shuffle 50.7, p = 0.0015); inh 59.0 (shuffle 50.8, p = 0.00028); inh - exc -1.27, t = -0.46, p = 0.651 mouse 4 (34 sessions): all 87.2 (shuffle 54.2, p = 9.2e-32); exc 67.2 (shuffle 51.3, p = 1e-22); inh 69.5 (shuffle 51.3, p = 2.4e-20); inh - exc +2.32, t = 1.42, p = 0.161
Result: reproduced. In every mouse the inhibitory and subsampled excitatory decoders are above their shuffles (p below 0.003), and they do not differ. Mean accuracies are E 65.3, 64.3, 60.2, 67.2 and I 64.6, 66.1, 58.9, 69.6 percent (p = 0.671, 0.185, 0.64, 0.153). The all-neuron decoder reaches 73.3 to 87.2 percent.
fig3hi-mixed-no-advantage¶
A population of half excitatory and half inhibitory neurons decodes choice with accuracy similar to that of an excitatory population of the same size, so a mixed population offers no major advantage.
print("sessions without 2n excitatory neurons (left out):", int(Q.mixed.isna().sum()))
for m, g in Q.dropna(subset=["mixed"]).groupby("mouse"):
d = ttest(g.mixed, g.exc2n)
print(f"mouse {m} ({len(g)} sessions): mixed {g.mixed.mean():.1f}, 2n excitatory {g.exc2n.mean():.1f}, difference {g.mixed.mean()-g.exc2n.mean():+.2f}, t = {d.statistic:.2f}, p = {d.pvalue:.3g}")
sessions without 2n excitatory neurons (left out): 0 mouse 1 (41 sessions): mixed 68.9, 2n excitatory 68.6, difference +0.22, t = 0.14, p = 0.891 mouse 2 (45 sessions): mixed 69.8, 2n excitatory 69.2, difference +0.66, t = 0.41, p = 0.684 mouse 3 (7 sessions): mixed 63.7, 2n excitatory 63.7, difference -0.06, t = -0.02, p = 0.988 mouse 4 (34 sessions): mixed 74.1, 2n excitatory 73.4, difference +0.67, t = 0.36, p = 0.718
Result: reproduced. Mixed populations (n inhibitory plus n excitatory) and 2n-excitatory populations decode the choice equally in every mouse (differences -0.02 to +0.66 points, p 0.689 to 0.996).
fig3df-weights-similar¶
In the decoder trained on all neurons, excitatory and inhibitory neurons receive weights of matched magnitude throughout the trial and with very similar distributions.
nE = sum(len(o["w_E"]) for o in OUT); nI = sum(len(o["w_I"]) for o in OUT)
print(f"neurons pooled over decoded sessions: excitatory {nE} (expected 42019 +/- 4202), inhibitory {nI} (expected 5172 +/- 517)")
W = pd.DataFrame([{"mouse": o["mouse"], "E": o["w_E"].mean(), "I": o["w_I"].mean()} for o in OUT])
nsig = 0
for m, g in W.groupby("mouse"):
d = ttest(g.E, g.I); nsig += d.pvalue < 0.05
pool = stats.ttest_ind(np.concatenate([o["w_E"] for o in OUT if o["mouse"] == m]), np.concatenate([o["w_I"] for o in OUT if o["mouse"] == m]))
print(f"mouse {m}: mean |w| E {g.E.mean():.4f}, I {g.I.mean():.4f}, I - E {g.I.mean()-g.E.mean():+.4f}, across sessions p = {d.pvalue:.3g}; [neurons pooled p = {pool.pvalue:.3g}]")
print("mice with a significant difference across sessions:", nsig)
allw = np.concatenate([np.concatenate([o["w_E"], o["w_I"]]) for o in OUT])
print("range of |w| (unit-length weight vectors): %.2g to %.3f" % (allw.min(), allw.max()))
neurons pooled over decoded sessions: excitatory 42019 (expected 42019 +/- 4202), inhibitory 5172 (expected 5172 +/- 517) mouse 1: mean |w| E 0.0383, I 0.0388, I - E +0.0005, across sessions p = 0.748; [neurons pooled p = 0.517] mouse 2: mean |w| E 0.0339, I 0.0360, I - E +0.0021, across sessions p = 0.0514; [neurons pooled p = 0.00466] mouse 3: mean |w| E 0.0377, I 0.0414, I - E +0.0037, across sessions p = 0.318; [neurons pooled p = 0.129] mouse 4: mean |w| E 0.0353, I 0.0377, I - E +0.0024, across sessions p = 0.125; [neurons pooled p = 0.0227] mice with a significant difference across sessions: 0 range of |w| (unit-length weight vectors): 1.5e-11 to 0.259
Result: partially reproduced. At 0-97 ms before the choice (02), the mean |w| of unit-length weight vectors of the all-neuron decoder does not differ between types in any mouse across sessions (p = 0.75, 0.051, 0.32, 0.13). Per bin (03, the time-course decoders with C chosen at bin -1), inhibitory weights are larger in 12 of 25 bins of mouse 2 (smallest p 0.0041) and in 1 of 25 bins of mouse 4 (p = 0.012), and no bin differs in mice 1 and 3 (smallest p 0.10 and 0.14). So two mice differ in part of the trial, the criterion's partial band. With C chosen at every bin and 50 splits (04, mice 1, 2 and 3, the earliest bin and bins -3 to the last), no bin differs in mice 1 and 3 (smallest p 0.171 and 0.0851) and inhibitory weights are larger in 3 of 12 bins of mouse 2 (bins 2, 4, 5; smallest p 0.0222), so the band is the same under that C rule. The pooled counts, 42019 excitatory and 5172 inhibitory neurons, equal the expected values. The per-bin part is in 03_learning_decoders.ipynb.
figs6de-incorrect-trials¶
Decoders trained on correct trials predict the choice on incorrect trials with high accuracy, slightly lower than on correct trials, and the reduction is similar for excitatory and inhibitory populations in every mouse.
for minn, lab in ((1, "sessions with at least one incorrect trial of each choice"), (10, "variant, at least 10 incorrect trials of each choice")):
G = Q[[min(n) >= minn for n in Q.n_inc]]
print(lab, ":", len(G), "sessions", G.groupby("mouse").size().to_dict())
red = {}
for m, g in G.groupby("mouse"):
out = []
for pop in ("all", "exc", "inh"):
p = ttest(g[pop + "_inc"], g[pop + "_inc_sh"]).pvalue
out.append(f"{pop} incorrect {g[pop+'_inc'].mean():.1f} (shuffle {g[pop+'_inc_sh'].mean():.1f}, p = {p:.2g}), correct {g[pop].mean():.1f}")
rE, rI = g.exc - g.exc_inc, g.inh - g.inh_inc
d = ttest(rI, rE); red[m] = (g["all"] - g.all_inc).mean()
print(f" mouse {m}: " + "; ".join(out) + f"; reduction exc {rE.mean():.1f}, inh {rI.mean():.1f}, p = {d.pvalue:.3g}")
print(" reduction of the all-neuron decoder by mouse:", {k: round(v, 1) for k, v in red.items()}, "largest in mouse", max(red, key=red.get))
sessions with at least one incorrect trial of each choice : 127 sessions {1: 41, 2: 45, 3: 7, 4: 34}
mouse 1: all incorrect 73.6 (shuffle 54.9, p = 2.2e-11), correct 82.2; exc incorrect 61.8 (shuffle 53.1, p = 5.3e-08), correct 65.3; inh incorrect 61.7 (shuffle 52.9, p = 1.3e-06), correct 64.6; reduction exc 3.5, inh 2.9, p = 0.743
mouse 2: all incorrect 75.3 (shuffle 55.4, p = 1.5e-16), correct 82.7; exc incorrect 61.7 (shuffle 52.3, p = 1.8e-08), correct 64.3; inh incorrect 62.6 (shuffle 52.4, p = 1.1e-06), correct 66.0; reduction exc 2.6, inh 3.4, p = 0.669
mouse 3: all incorrect 64.8 (shuffle 53.5, p = 0.12), correct 73.3; exc incorrect 51.9 (shuffle 48.6, p = 0.12), correct 60.3; inh incorrect 50.0 (shuffle 48.4, p = 0.72), correct 59.0; reduction exc 8.4, inh 9.0, p = 0.879
mouse 4: all incorrect 44.0 (shuffle 48.2, p = 0.13), correct 87.2; exc incorrect 47.4 (shuffle 50.2, p = 0.18), correct 67.2; inh incorrect 45.9 (shuffle 49.0, p = 0.23), correct 69.5; reduction exc 19.8, inh 23.7, p = 0.255
reduction of the all-neuron decoder by mouse: {1: np.float64(8.6), 2: np.float64(7.4), 3: np.float64(8.5), 4: np.float64(43.2)} largest in mouse 4
variant, at least 10 incorrect trials of each choice : 94 sessions {1: 34, 2: 31, 3: 3, 4: 26}
mouse 1: all incorrect 73.7 (shuffle 53.7, p = 2.2e-11), correct 81.9; exc incorrect 61.5 (shuffle 52.0, p = 3.8e-08), correct 65.2; inh incorrect 61.9 (shuffle 52.4, p = 5.2e-06), correct 64.2; reduction exc 3.7, inh 2.3, p = 0.469
mouse 2: all incorrect 78.9 (shuffle 54.1, p = 2.1e-20), correct 84.8; exc incorrect 63.6 (shuffle 51.7, p = 1.2e-11), correct 66.0; inh incorrect 64.3 (shuffle 52.0, p = 6.4e-09), correct 67.1; reduction exc 2.4, inh 2.8, p = 0.836
mouse 3: all incorrect 63.4 (shuffle 49.8, p = 0.031), correct 69.9; exc incorrect 52.9 (shuffle 48.6, p = 0.21), correct 57.4; inh incorrect 48.9 (shuffle 48.9, p = 0.98), correct 56.4; reduction exc 4.6, inh 7.6, p = 0.64
mouse 4: all incorrect 47.6 (shuffle 49.4, p = 0.55), correct 86.1; exc incorrect 50.0 (shuffle 51.2, p = 0.58), correct 66.8; inh incorrect 48.6 (shuffle 50.5, p = 0.43), correct 68.5; reduction exc 16.8, inh 19.9, p = 0.361
reduction of the all-neuron decoder by mouse: {1: np.float64(8.2), 2: np.float64(5.9), 3: np.float64(6.5), 4: np.float64(38.6)} largest in mouse 4
Result: not reproduced. Decoders trained on correct trials predict the choice on incorrect trials above the shuffle in mice 1 and 2 for all three populations (p below 6e-6). In mice 3 and 4 they do not (mouse 3 p 0.086 to 0.7; mouse 4 accuracy 44.0 to 47.8 percent, below the shuffle). The reduction from correct to incorrect trials does not differ between inhibitory and excitatory decoders in any mouse (p 0.278 to 0.993), and it is largest in mouse 4 for the all-neuron decoder (43.2 points, others 7.4 to 8.6). The variant with at least 10 incorrect trials of each choice gives the same pattern for the cell-type decoders. The criterion has no partial band. Whether the criterion's above-shuffle rule in every mouse reads the paper correctly is asked of a reader (questions/najafi-2020.yaml).
fig4bd-stability-similar¶
Choice decoders lose accuracy at a similar rate away from their training time for excitatory and inhibitory populations, and their stability duration is indistinguishable.
rows = []
for o in OUT:
for pop, recs in (("inh", [o["inh"]]), ("exc", o["exc_subs"])):
for rule in ("sd", "se"):
for cont, ci in (("any", 0), ("contig", 1)):
v = [r["stab"][rule][ci] * 97 for r in recs]
pt = [r["stab"]["p_train"] for r in recs]
rows.append({"mouse": o["mouse"], "session": o["session"], "pop": pop, "rule": rule, "cont": cont, "dur": np.mean(v),
"p_train": np.max(pt) if pop == "inh" else np.median(pt), "nbins": len(o["k"])})
ST = pd.DataFrame(rows)
for alpha in (0.001, 0.05):
for rule in ("sd", "se"):
for cont in ("any", "contig"):
g = ST[(ST.rule == rule) & (ST.cont == cont)]
ok = g.pivot_table(index="session", columns="pop", values="p_train").max(1) < alpha
g = g[g.session.isin(ok[ok].index)]
mm = g.groupby(["mouse", "pop"]).dur.mean().unstack()
d = stats.ttest_ind(mm.exc, mm.inh)
per = {m: round(stats.ttest_ind(x[x["pop"] == "exc"].dur, x[x["pop"] == "inh"].dur).pvalue, 3) for m, x in g.groupby("mouse")}
print(f"alpha {alpha}, {rule.upper()} rule, {cont} bins: {ok.sum()} sessions; mouse means exc {mm.exc.round(0).to_dict()} inh {mm.inh.round(0).to_dict()} ms; "
f"across mice t = {d.statistic:.2f}, p = {d.pvalue:.3g}; per mouse across sessions p {per}")
sa = pd.DataFrame([{"mouse": o["mouse"], "k": k, "inh": a, "exc": e} for o in OUT for k, a, e in zip(o["k"], o["inh"]["stab_acc"], np.mean([x["stab_acc"] for x in o["exc_subs"]], 0))])
print("accuracy of the decoder trained at bin -1, tested at bins -10, -5, -1, 0, 3 (mean over sessions):")
print(sa[sa.k.isin([-10, -5, -1, 0, 3])].groupby(["mouse", "k"])[["exc", "inh"]].mean().round(1).unstack().to_string())
alpha 0.001, SD rule, any bins: 78 sessions; mouse means exc {1: 2226.0, 2: 2058.0, 3: 1765.0, 4: 2357.0} inh {1: 2168.0, 2: 2034.0, 3: 1843.0, 4: 2270.0} ms; across mice t = 0.15, p = 0.889; per mouse across sessions p {1: np.float64(0.777), 2: np.float64(0.87), 3: np.float64(nan), 4: np.float64(0.449)}
alpha 0.001, SD rule, contig bins: 78 sessions; mouse means exc {1: 2076.0, 2: 1931.0, 3: 1727.0, 4: 2227.0} inh {1: 1984.0, 2: 1816.0, 3: 1843.0, 4: 2181.0} ms; across mice t = 0.25, p = 0.808; per mouse across sessions p {1: np.float64(0.666), 2: np.float64(0.423), 3: np.float64(nan), 4: np.float64(0.71)}
alpha 0.001, SE rule, any bins: 78 sessions; mouse means exc {1: 573.0, 2: 549.0, 3: 272.0, 4: 704.0} inh {1: 543.0, 2: 461.0, 3: 291.0, 4: 547.0} ms; across mice t = 0.59, p = 0.578; per mouse across sessions p {1: np.float64(0.737), 2: np.float64(0.213), 3: np.float64(nan), 4: np.float64(0.075)}
alpha 0.001, SE rule, contig bins: 78 sessions; mouse means exc {1: 430.0, 2: 395.0, 3: 175.0, 4: 457.0} inh {1: 417.0, 2: 355.0, 3: 194.0, 4: 369.0} ms; across mice t = 0.38, p = 0.718; per mouse across sessions p {1: np.float64(0.864), 2: np.float64(0.467), 3: np.float64(nan), 4: np.float64(0.276)}
alpha 0.05, SD rule, any bins: 104 sessions; mouse means exc {1: 2289.0, 2: 2148.0, 3: 1727.0, 4: 2387.0} inh {1: 2257.0, 2: 2134.0, 3: 1843.0, 4: 2325.0} ms; across mice t = -0.01, p = 0.992; per mouse across sessions p {1: np.float64(0.821), 2: np.float64(0.916), 3: np.float64(0.223), 4: np.float64(0.524)}
alpha 0.05, SD rule, contig bins: 104 sessions; mouse means exc {1: 2176.0, 2: 2035.0, 3: 1643.0, 4: 2276.0} inh {1: 2115.0, 2: 1940.0, 3: 1843.0, 4: 2255.0} ms; across mice t = -0.03, p = 0.973; per mouse across sessions p {1: np.float64(0.692), 2: np.float64(0.486), 3: np.float64(0.242), 4: np.float64(0.843)}
alpha 0.05, SE rule, any bins: 104 sessions; mouse means exc {1: 624.0, 2: 645.0, 3: 627.0, 4: 774.0} inh {1: 679.0, 2: 520.0, 3: 679.0, 4: 594.0} ms; across mice t = 0.94, p = 0.382; per mouse across sessions p {1: np.float64(0.607), 2: np.float64(0.115), 3: np.float64(0.893), 4: np.float64(0.032)}
alpha 0.05, SE rule, contig bins: 104 sessions; mouse means exc {1: 431.0, 2: 452.0, 3: 382.0, 4: 469.0} inh {1: 472.0, 2: 378.0, 3: 485.0, 4: 397.0} ms; across mice t = 0.01, p = 0.994; per mouse across sessions p {1: np.float64(0.601), 2: np.float64(0.25), 3: np.float64(0.717), 4: np.float64(0.321)}
accuracy of the decoder trained at bin -1, tested at bins -10, -5, -1, 0, 3 (mean over sessions):
exc inh k -10 -5 -1 0 3 -10 -5 -1 0 3 mouse 1 49.4 54.8 65.3 62.8 59.5 49.0 54.9 64.6 62.5 60.3 2 49.5 54.7 64.3 62.8 58.7 49.8 54.8 66.0 63.5 60.6 3 47.6 52.3 60.3 56.3 56.8 48.0 50.0 59.0 56.1 56.6 4 51.3 59.0 67.2 64.3 61.2 50.0 58.7 69.5 66.1 63.4
/tmp/ipykernel_3165/1782141124.py:15: Pandas4Warning: Starting with pandas version 4.0 all arguments of max will be keyword-only. ok = g.pivot_table(index="session", columns="pop", values="p_train").max(1) < alpha /home/runner/work/encore/encore/executed/najafi-2020/.venv/lib/python3.13/site-packages/scipy/stats/_stats_py.py:6395: RuntimeWarning: invalid value encountered in scalar divide svar = ((n1 - 1) * v1 + (n2 - 1) * v2) / df /tmp/ipykernel_3165/1782141124.py:15: Pandas4Warning: Starting with pandas version 4.0 all arguments of max will be keyword-only. ok = g.pivot_table(index="session", columns="pop", values="p_train").max(1) < alpha /home/runner/work/encore/encore/executed/najafi-2020/.venv/lib/python3.13/site-packages/scipy/stats/_stats_py.py:6395: RuntimeWarning: invalid value encountered in scalar divide svar = ((n1 - 1) * v1 + (n2 - 1) * v2) / df /tmp/ipykernel_3165/1782141124.py:15: Pandas4Warning: Starting with pandas version 4.0 all arguments of max will be keyword-only. ok = g.pivot_table(index="session", columns="pop", values="p_train").max(1) < alpha /home/runner/work/encore/encore/executed/najafi-2020/.venv/lib/python3.13/site-packages/scipy/stats/_stats_py.py:6395: RuntimeWarning: invalid value encountered in scalar divide svar = ((n1 - 1) * v1 + (n2 - 1) * v2) / df /tmp/ipykernel_3165/1782141124.py:15: Pandas4Warning: Starting with pandas version 4.0 all arguments of max will be keyword-only. ok = g.pivot_table(index="session", columns="pop", values="p_train").max(1) < alpha /home/runner/work/encore/encore/executed/najafi-2020/.venv/lib/python3.13/site-packages/scipy/stats/_stats_py.py:6395: RuntimeWarning: invalid value encountered in scalar divide svar = ((n1 - 1) * v1 + (n2 - 1) * v2) / df /tmp/ipykernel_3165/1782141124.py:15: Pandas4Warning: Starting with pandas version 4.0 all arguments of max will be keyword-only. ok = g.pivot_table(index="session", columns="pop", values="p_train").max(1) < alpha /home/runner/work/encore/encore/executed/najafi-2020/.venv/lib/python3.13/site-packages/scipy/stats/_axis_nan_policy.py:601: RuntimeWarning: Precision loss occurred in moment calculation due to catastrophic cancellation. This occurs when the data are nearly identical. Results may be unreliable. res = hypotest_fun_out(*samples, **kwds) /tmp/ipykernel_3165/1782141124.py:15: Pandas4Warning: Starting with pandas version 4.0 all arguments of max will be keyword-only. ok = g.pivot_table(index="session", columns="pop", values="p_train").max(1) < alpha /home/runner/work/encore/encore/executed/najafi-2020/.venv/lib/python3.13/site-packages/scipy/stats/_axis_nan_policy.py:601: RuntimeWarning: Precision loss occurred in moment calculation due to catastrophic cancellation. This occurs when the data are nearly identical. Results may be unreliable. res = hypotest_fun_out(*samples, **kwds) /tmp/ipykernel_3165/1782141124.py:15: Pandas4Warning: Starting with pandas version 4.0 all arguments of max will be keyword-only. ok = g.pivot_table(index="session", columns="pop", values="p_train").max(1) < alpha /tmp/ipykernel_3165/1782141124.py:15: Pandas4Warning: Starting with pandas version 4.0 all arguments of max will be keyword-only. ok = g.pivot_table(index="session", columns="pop", values="p_train").max(1) < alpha
Result: reproduced. The stability duration of decoders trained at 0-97 ms before the choice does not differ between excitatory and inhibitory populations by the t-test of the mouse means under every reading (SD or SE rule, any or contiguous bins, alpha 0.001 or 0.05; p 0.524 to 0.991). Per mouse across sessions, a variant, 1 of 28 tests is below 0.05 (mouse 4, alpha 0.05, SE rule, any bins, p = 0.037); the others have p 0.064 or more.
fig7-noise-correlations-limit-decoding¶
Removing noise correlations by building pseudo populations increases choice decoding accuracy of the full population in every mouse.
for real, ps, lab in (("all", "pseudo", "correct trials"), ("all_alltr", "pseudo_alltr", "all trials with a choice")):
print(lab)
for m, g in Q.dropna(subset=[real, ps]).groupby("mouse"):
ch = g[ps] - g[real]
p1 = stats.ttest_1samp(ch, 0).pvalue; p2 = ttest(g[ps], g[real]).pvalue
print(f" mouse {m} ({len(g)} sessions): real {g[real].mean():.1f}, pseudo {g[ps].mean():.1f}, change {ch.mean():+.2f} (range {ch.min():+.1f} to {ch.max():+.1f}); "
f"(a) one-sample p = {p1:.2g}; (b) unpaired p = {p2:.2g}")
correct trials mouse 1 (41 sessions): real 82.2, pseudo 87.5, change +5.38 (range -5.1 to +12.7); (a) one-sample p = 4e-10; (b) unpaired p = 0.0078 mouse 2 (45 sessions): real 82.7, pseudo 88.1, change +5.45 (range -5.2 to +12.7); (a) one-sample p = 9.9e-12; (b) unpaired p = 0.0055 mouse 3 (7 sessions): real 73.3, pseudo 77.6, change +4.32 (range -1.0 to +9.5); (a) one-sample p = 0.011; (b) unpaired p = 0.32 mouse 4 (34 sessions): real 87.2, pseudo 92.4, change +5.27 (range -3.7 to +16.3); (a) one-sample p = 6.2e-10; (b) unpaired p = 0.0088 all trials with a choice mouse 1 (41 sessions): real 80.7, pseudo 87.5, change +6.79 (range -1.2 to +15.6); (a) one-sample p = 1.8e-14; (b) unpaired p = 0.0019 mouse 2 (45 sessions): real 82.8, pseudo 88.0, change +5.21 (range -6.7 to +12.8); (a) one-sample p = 2e-10; (b) unpaired p = 0.0068 mouse 3 (7 sessions): real 71.1, pseudo 76.0, change +4.88 (range -1.8 to +16.3); (a) one-sample p = 0.08; (b) unpaired p = 0.25 mouse 4 (34 sessions): real 75.6, pseudo 81.7, change +6.11 (range -9.0 to +17.7); (a) one-sample p = 2.7e-07; (b) unpaired p = 0.037
Result: blocked, methods underspecified. Pseudo populations raise the all-neuron accuracy in every mouse under both trial sets, on correct trials by +5.38, +5.45, +4.32 and +5.27 points and on all trials with a choice by +6.79, +5.21, +4.88 and +6.11. On correct trials with the one-sample test, reading (a), the change is significant in every mouse (p = 4e-10, 9.9e-12, 0.011, 6.2e-10), so that reading gives reproduced. Each of the other three readings fails in mouse 3 (correct trials unpaired p = 0.32; all trials one-sample p = 0.08 and unpaired p = 0.25), so they give not reproduced. The readings differ, so the claim is blocked.
figs12-licking-running (running part only)¶
Licking and running do not explain the learning-related changes; centre-spout licks before left and right choices are similar early and late in training, and decoding remains accurate in sessions where running did not differ between choices.
The lick trace in the files (firstSideTryAl_lick, 0 or 1 per ms) does not say which spout was
licked, so the centre-spout licks of the criterion cannot be separated; the claim is blocked.
The running part is shown.
rr = []
for o in OUT:
if "run" in o and o["mouse"] in nj.LEARNING_MICE:
d, c = o["run"]
p = stats.ttest_ind(d[c == 0], d[c == 1]).pvalue if min((c == 0).sum(), (c == 1).sum()) > 1 else np.nan
rr.append({"mouse": o["mouse"], "p_run": p, "all": o["all"]["acc"], "all_sh": o["all"]["acc_sh"]})
RR = pd.DataFrame(rr)
for m, g in RR.groupby("mouse"):
g2 = g[g.p_run > 0.05]
print(f"mouse {m}: {len(g2)} of {len(g)} sessions with running not different (p > 0.05); all-neuron accuracy there {g2['all'].mean():.1f} against shuffle {g2.all_sh.mean():.1f}, p = {ttest(g2['all'], g2.all_sh).pvalue:.2g}")
mouse 1: 2 of 41 sessions with running not different (p > 0.05); all-neuron accuracy there 69.2 against shuffle 63.2, p = 0.47 mouse 2: 10 of 45 sessions with running not different (p > 0.05); all-neuron accuracy there 75.9 against shuffle 55.0, p = 1.3e-06 mouse 4: 16 of 34 sessions with running not different (p > 0.05); all-neuron accuracy there 84.0 against shuffle 54.4, p = 7.7e-13
Check of the coarser C grid¶
On four sessions (one per mouse), the all-neuron and inhibitory decoders with the paper's grid (steps of 0.2) against the grid used here (steps of 1).
chk = []
for m in range(1, 5):
i = [j for j, s in enumerate(S) if s["mouse"] == m][0]
s = S[i]
rng = np.random.default_rng(7)
X, y, _ = nj._xy(s, (1,), rng=rng)
X = nj.zscore_bins(X)[:, nj.bin_index(s, -1)]
I = s["type"] == "inhibitory"
for pop, cols in (("all", slice(None)), ("inh", I)):
a = nj.svm_cv(X[:, cols], y, np.random.default_rng(8), cgrid=nj.CGRID)["acc"]
b = nj.svm_cv(X[:, cols], y, np.random.default_rng(8), cgrid=nj.CGRID_RUN)["acc"]
chk.append({"mouse": m, "pop": pop, "full grid": a, "coarse grid": b, "difference": b - a})
print(pd.DataFrame(chk).round(2).to_string())
mouse pop full grid coarse grid difference 0 1 all 92.00 92.00 0.00 1 1 inh 73.40 73.40 0.00 2 2 all 85.67 85.50 -0.17 3 2 inh 64.17 64.17 -0.00 4 3 all 67.78 67.33 -0.44 5 3 inh 58.22 57.78 -0.44 6 4 all 96.00 96.00 0.00 7 4 inh 64.00 64.00 0.00
Summary¶
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.
| Claim | Outcome |
|---|---|
| data-composition | reproduced |
| fig1b-psychometric | reproduced |
| figs1b-trial-history | blocked, data missing |
| fig1gi-inferred-spiking-differs | not reproduced |
| fig2a-example-session | not reproduced |
| fig2bc-fraction-selective-similar | not reproduced |
| fig2bd-selectivity-time-course | blocked, methods underspecified |
| fig2de-selectivity-magnitude-similar | partially reproduced |
| figs3d-same-spiking-selectivity | reproduced |
| figs3c-wider-window | not reproduced |
| figs3e-correct-error-correlation | not reproduced |
| fig3bc-decoding-similar | reproduced |
| fig3b-decoding-time-course | not reproduced |
| fig3df-weights-similar | partially reproduced |
| fig3hi-mixed-no-advantage | reproduced |
| figs5-fluorescence-decoding | blocked, data missing |
| figs6ab-previous-choice-stimulus | blocked, other |
| figs6c-outcome-decoding | blocked, other |
| figs6de-incorrect-trials | not reproduced |
| fig4bd-stability-similar | reproduced |
| figs7c-angle-stability | blocked, too large |
| fig5a-nonselective-model, fig5bc-selective-models-match, figs9-signal-selective-best | blocked, not reached in the run's time (simulations) |
| fig6a-same-selectivity-correlations | reproduced |
| fig6bc-inhibitory-correlations-higher | blocked, methods underspecified |
| fig7-noise-correlations-limit-decoding | blocked, methods underspecified |
| fig8ab-learning-accuracy | not reproduced |
| fig8ce-choice-signal-onset | not reproduced |
| fig8de-learning-parallel | not reproduced |
| figs13c-equal-trials | not reproduced |
| figs12-licking-running | not reproduced |
| fig8f-correlations-decrease | partially reproduced |
| figs13ab-pseudo-learning | not reproduced |
| fig8g-fraction-selective-triples | not reproduced |
| figs2-temporal-dynamics-similar | blocked, other |
| figs14-neuropil, figs15-labeling-specificity | blocked, data missing (raw movies, histology) |
How the analysis differs from the paper's: the SVM regularisation is chosen from a grid with steps
of 1 in log10 (the paper 0.2; the check in 02_decoders.ipynb shows differences of at most 0.44
points); excitatory, mixed and 2n-excitatory populations use 5 subsamples (3 in the learning
analysis) where the paper uses 50; the time courses use 25 splits per bin and one C per session
chosen at the bin before the choice; choices are matched once per session; and side labels are
"high-rate" and "low-rate" choices, as the files do not name the side. 16 Hz trials are left out everywhere, as their choice side is unknown; the trial table has no flag for helped trials or the first trials of a session, so those exclusions of the code are not applied; notebook 04 repeats the fig3b time course and the per-bin fig3df weights for mice 1, 2 and 3 with C chosen at every bin and 50 splits.
What was found about the dataset: the session counts, trials per session and neuron counts match
the paper; the traces named dFoF_* hold the normalised inferred spiking activity, not Delta F/F,
and no fluorescence trace is in the files; the attribute named rate of each trial series holds the
frame interval; trial times are relative to each trial, so inter-trial intervals cannot be
computed; the lick trace does not say which spout was licked; some files store non-integer pulse
rates; and the NWB session identifiers are the CNMF run timestamps, while the recording date is in
session_start_time and session_description. The trial table has no helped-trial or first-trial flag (trial_is_good equals a correct or incorrect response), and the side licked on 16 Hz trials cannot be recovered.
print("runtime %.1f min, peak memory %.1f GB" % ((time.time() - T0) / 60, resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6))
runtime 52.3 min, peak memory 5.7 GB