Najafi et al. (2020) on DANDI:000016, part 3: decoder time course and learning¶

Paper doi:10.1016/j.neuron.2019.09.045; dataset DANDI:000016 version 0.260915.2309, the only published version (the paper cites none). Claims file claims/najafi-2020.yaml.

Decoders as in 02_decoders.ipynb (coarser C grid, a deviation). For the time courses a decoder is trained and tested at every 97 ms bin with the C chosen at bin -1 (0-97 ms before the choice); the paper chooses C at every bin, which was too slow here (a deviation); 04_time_course_per_bin_C.ipynb repeats fig3b for mice 2 and 3 with C chosen at every bin. The per-bin weights of fig3df are taken from these time-course decoders. Learning mice are mice 1, 2 and 4 (fni16, fni17, fni19; claims file). Excitatory populations are 3 random subsamples of as many excitatory neurons as the session has inhibitory neurons (the paper 50), and the time courses use 25 random splits per bin (the paper 50).

Claim Here
fig3b-decoding-time-course tested
fig3df-weights-similar per-bin part tested
fig8ab-learning-accuracy tested
fig8ce-choice-signal-onset tested
fig8de-learning-parallel tested
figs13c-equal-trials tested
figs13ab-pseudo-learning tested
In [1]:
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,))
for s in S:
    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 788 s, peak memory 5.8 GB
In [2]:
L = pd.DataFrame([{"i": i, "mouse": s["mouse"], "session": s["session_id"], "date": s["start"][:10],
                   "perf": nj.easy_performance(s["trials"])[0], "n_easy": nj.easy_performance(s["trials"])[1],
                   "correct": int(nj.trial_mask(s, (1,)).sum()), "incorrect": int(nj.trial_mask(s, (0,)).sum())} for i, s in enumerate(S)])
L["day"] = L.groupby("mouse").date.rank(method="first").astype(int)
for m, g in L[L.mouse.isin(nj.LEARNING_MICE)].groupby("mouse"):
    el = nj.early_late(g.perf.to_numpy(), g.day.to_numpy())
    for rd in ("a", "b"):
        L.loc[g.index, "early_" + rd] = el[rd][0]; L.loc[g.index, "late_" + rd] = el[rd][1]
    print(f"mouse {m}: {len(g)} days {g.date.min()} to {g.date.max()}; easy-trial performance {g.perf.min():.2f} to {g.perf.max():.2f} "
          f"(r with day {stats.pearsonr(g.day, g.perf)[0]:.2f}); early (a) days {sorted(g.day[el['a'][0]])}, late (a) days {sorted(g.day[el['a'][1]])}; "
          f"early (b) {int(el['b'][0].sum())}, late (b) {int(el['b'][1].sum())} days")
print(L.groupby("mouse")[["correct", "incorrect", "n_easy"]].median())
# fig S13C: the same number of correct trials of each choice in every session of a mouse, the minimum over its sessions
neq = {}
for m in nj.LEARNING_MICE:
    v = [min(np.sum(s["trials"].choice.to_numpy()[nj.trial_mask(s, (1,))] == c) for c in (0, 1)) for s in S if s["mouse"] == m]
    v = [x for x in v if x >= nj.MIN_TRIALS]
    neq[m] = int(min(v))
print("correct trials per choice in every session (fig S13C), minimum over sessions with at least 10:", neq)
mouse 1: 45 days 2015-08-17 to 2015-10-29; easy-trial performance 0.44 to 0.88 (r with day 0.53); early (a) days [1, 3, 5, 6, 7, 8, 10, 11, 16], late (a) days [23, 24, 25, 26, 27, 28, 31, 34, 35]; early (b) 1, late (b) 0 days
mouse 2: 48 days 2015-08-14 to 2015-11-02; easy-trial performance 0.45 to 0.89 (r with day 0.59); early (a) days [1, 2, 3, 4, 5, 6, 7, 8, 19, 23], late (a) days [13, 15, 16, 30, 32, 35, 36, 37, 45, 48]; early (b) 8, late (b) 1 days
mouse 4: 35 days 2015-09-03 to 2015-11-01; easy-trial performance 0.51 to 0.85 (r with day 0.24); early (a) days [2, 3, 5, 7, 8, 32, 33], late (a) days [12, 13, 14, 15, 16, 17, 20]; early (b) 0, late (b) 0 days
       correct  incorrect  n_easy
mouse                            
1         98.0       48.0   159.0
2        142.0       41.5   162.5
3        120.0       31.0   110.0
4        129.0       44.0   171.0
correct trials per choice in every session (fig S13C), minimum over sessions with at least 10: {1: 12, 2: 14, 4: 15}
In [3]:
os.environ.setdefault("OMP_NUM_THREADS", "1")
t1 = time.time()
OUT = Parallel(n_jobs=4)(delayed(nj.learn_session)(s, 5000 + i, n_equal=neq.get(s["mouse"]), learning=s["mouse"] in nj.LEARNING_MICE) for i, s in enumerate(S))
print("decoders: %.1f min" % ((time.time() - t1) / 60))
rows = []
for o, (_, l) in zip(OUT, L.iterrows()):
    for rd in ("a", "b"):
        if rd in o:
            for p, r in o[rd].items():
                pop = "exc" if p.startswith("exc") else p
                rows.append({"mouse": o["mouse"], "session": o["session"], "rd": rd, "pop": pop, "sub": p, **{k: r.get(k, np.nan) for k in ("acc", "acc_sh", "on05", "on001", "pseudo")}})
R = pd.DataFrame(rows).groupby(["mouse", "session", "rd", "pop"])[["acc", "acc_sh", "on05", "on001", "pseudo"]].mean().reset_index()
R = R.merge(L[["session", "perf", "day", "early_a", "late_a", "early_b", "late_b"]], on="session")
print("learning sessions decoded, reading (a):", R[(R.rd == "a") & (R["pop"] == "all")].groupby("mouse").size().to_dict(),
      "reading (b):", R[(R.rd == "b") & (R["pop"] == "all")].groupby("mouse").size().to_dict())
/home/runner/work/encore/encore/executed/najafi-2020/.venv/lib/python3.13/site-packages/scipy/stats/_axis_nan_policy.py:644: 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, axis=axis, **kwds)
/home/runner/work/encore/encore/executed/najafi-2020/.venv/lib/python3.13/site-packages/scipy/stats/_axis_nan_policy.py:644: 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, axis=axis, **kwds)
/home/runner/work/encore/encore/executed/najafi-2020/.venv/lib/python3.13/site-packages/scipy/stats/_axis_nan_policy.py:644: 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, axis=axis, **kwds)
decoders: 42.4 min
learning sessions decoded, reading (a): {1: 43, 2: 46, 4: 35} reading (b): {1: 41, 2: 41, 4: 31}

fig3b-decoding-time-course¶

Accuracy of the all-neuron choice decoder grows after stimulus onset and peaks at the time of the choice.

In [4]:
TC = pd.DataFrame([{"mouse": o["mouse"], "k": k, "acc": a, "sh": b} for o in OUT if "tc_corr" in o for k, a, b in zip(o["k"], *o["tc_corr"])])
for m, g in TC.groupby("mouse"):
    n = g.groupby("k").size(); nmax = n.max()
    v = g.groupby("k").acc.mean()[n >= 0.5 * nmax]; vs = g.groupby("k").sh.mean()[n >= 0.5 * nmax]
    kp = int(v.idxmax()); first = int(v.index.min())
    print(f"mouse {m} ({nmax} sessions): bins {first} to {int(v.index.max())}; earliest {v.loc[first]:.1f}, bin -1 {v.loc[-1]:.1f}, bin 0 {v.loc[0]:.1f}, "
          f"peak {v.max():.1f} at bin {kp}; (a) peak in bins -1 or 0: {kp in (-1, 0)}; (b) peak within 300 ms (bins -3 to 2): {-3 <= kp <= 2}; "
          f"earliest below bin -1: {v.loc[first] < v.loc[-1]}; shuffle {vs.min():.1f} to {vs.max():.1f}")
    print("   accuracy by bin:", v.round(1).to_dict())
mouse 1 (41 sessions): bins -17 to 10; earliest 70.2, bin -1 81.1, bin 0 85.4, peak 87.5 at bin 2; (a) peak in bins -1 or 0: False; (b) peak within 300 ms (bins -3 to 2): True; earliest below bin -1: True; shuffle 51.1 to 57.7
   accuracy by bin: {-17: 70.2, -16: 66.5, -15: 66.1, -14: 64.9, -13: 65.0, -12: 65.5, -11: 64.6, -10: 64.9, -9: 67.2, -8: 64.8, -7: 68.6, -6: 69.2, -5: 70.6, -4: 69.7, -3: 73.5, -2: 76.2, -1: 81.1, 0: 85.4, 1: 85.8, 2: 87.5, 3: 87.1, 4: 87.1, 5: 85.6, 6: 82.8, 7: 77.8, 8: 83.1, 9: 82.3, 10: 81.3}
mouse 2 (45 sessions): bins -17 to 7; earliest 59.4, bin -1 81.9, bin 0 84.9, peak 86.6 at bin 3; (a) peak in bins -1 or 0: False; (b) peak within 300 ms (bins -3 to 2): False; earliest below bin -1: True; shuffle 51.2 to 53.6
   accuracy by bin: {-17: 59.4, -16: 59.4, -15: 59.3, -14: 59.9, -13: 62.0, -12: 61.8, -11: 61.0, -10: 60.5, -9: 60.0, -8: 60.0, -7: 61.2, -6: 63.6, -5: 65.4, -4: 67.7, -3: 72.9, -2: 76.8, -1: 81.9, 0: 84.9, 1: 86.3, 2: 86.6, 3: 86.6, 4: 86.0, 5: 85.4, 6: 83.5, 7: 77.7}
mouse 3 (7 sessions): bins -11 to 6; earliest 65.3, bin -1 72.4, bin 0 74.2, peak 83.1 at bin 6; (a) peak in bins -1 or 0: False; (b) peak within 300 ms (bins -3 to 2): False; earliest below bin -1: True; shuffle 49.3 to 52.8
   accuracy by bin: {-11: 65.3, -10: 63.0, -9: 62.0, -8: 61.4, -7: 58.2, -6: 56.1, -5: 55.3, -4: 63.1, -3: 67.6, -2: 67.4, -1: 72.4, 0: 74.2, 1: 75.9, 2: 79.4, 3: 78.6, 4: 78.0, 5: 76.7, 6: 83.1}
mouse 4 (34 sessions): bins -17 to 7; earliest 69.3, bin -1 86.4, bin 0 85.7, peak 87.6 at bin 2; (a) peak in bins -1 or 0: False; (b) peak within 300 ms (bins -3 to 2): True; earliest below bin -1: True; shuffle 51.7 to 55.6
   accuracy by bin: {-17: 69.3, -16: 71.1, -15: 73.2, -14: 74.5, -13: 74.7, -12: 73.6, -11: 75.7, -10: 74.3, -9: 76.3, -8: 77.2, -7: 76.0, -6: 78.5, -5: 79.9, -4: 80.9, -3: 82.3, -2: 83.7, -1: 86.4, 0: 85.7, 1: 87.0, 2: 87.6, 3: 86.1, 4: 85.8, 5: 85.9, 6: 85.0, 7: 81.0}

Result: not reproduced. With C chosen at bin -1 and 25 splits (03), all-neuron accuracy on correct trials rises from the earliest bin (59.4 to 70.2 percent) to the bin before the choice (72.4 to 86.4) in every mouse; the peak falls at bin 2 in mice 1 and 4, bin 3 in mouse 2 (86.6) and bin 6 in mouse 3. With C chosen at every bin and 50 splits (04, mice 1, 2 and 3), mouse 1 peaks at bin 3 (89.5, next 88.5), mouse 2 at bin 2 (88.4, next 88.2) and mouse 3 at bin 6 (83.6). The peak is never in bins -1 or 0, reading (a), and in mouse 3 it lies outside 300 ms, reading (b), under both C rules, so the claim fails under both readings; the criterion has no partial band.

fig3df-weights-similar, per bin¶

In the decoder trained on all neurons, excitatory and inhibitory neurons receive weights of matched magnitude throughout the trial and with very similar distributions.

The criterion asks for the mean |w| per cell type at 0-97 ms before the choice (in 02_decoders.ipynb) and per bin. Here the per-bin part: the all-neuron time-course decoders of fig3b (correct trials, C chosen at bin -1, 25 splits), weights averaged over the splits and normalised to unit length at each bin, mean |w| per cell type per session, and the unpaired t-test across sessions per mouse at each bin.

In [5]:
WB = pd.DataFrame([{"mouse": o["mouse"], "k": k, "E": e, "I": i} for o in OUT if "w_bins" in o for k, e, i in zip(o["k"], *o["w_bins"])])
for m, g in WB.groupby("mouse"):
    n = g.groupby("k").size(); keep = n.index[n >= 0.5 * n.max()]
    res = []
    for k in keep:
        x = g[g.k == k]
        res.append((int(k), x.E.mean(), x.I.mean(), stats.ttest_ind(x.E, x.I).pvalue))
    ps = np.array([r[3] for r in res])
    print(f"mouse {m} ({n.max()} sessions): {len(res)} bins; bins with p < 0.05: {[r[0] for r in res if r[3] < 0.05]}; smallest p {ps.min():.3g}; "
          f"I - E from {min(r[2]-r[1] for r in res):+.4f} to {max(r[2]-r[1] for r in res):+.4f}")
    print("   mean |w| E/I by bin:", {r[0]: f"{r[1]:.4f}/{r[2]:.4f}" for r in res})
print("range of the per-session mean |w|: %.4f to %.4f" % (WB[["E", "I"]].min().min(), WB[["E", "I"]].max().max()))
mouse 1 (41 sessions): 28 bins; bins with p < 0.05: []; smallest p 0.101; I - E from -0.0011 to +0.0022
   mean |w| E/I by bin: {-17: '0.0406/0.0409', -16: '0.0413/0.0434', -15: '0.0410/0.0418', -14: '0.0407/0.0412', -13: '0.0402/0.0407', -12: '0.0397/0.0411', -11: '0.0397/0.0401', -10: '0.0390/0.0392', -9: '0.0389/0.0398', -8: '0.0389/0.0399', -7: '0.0388/0.0390', -6: '0.0389/0.0403', -5: '0.0387/0.0389', -4: '0.0386/0.0394', -3: '0.0388/0.0378', -2: '0.0387/0.0383', -1: '0.0384/0.0395', 0: '0.0388/0.0383', 1: '0.0381/0.0392', 2: '0.0383/0.0397', 3: '0.0384/0.0398', 4: '0.0379/0.0400', 5: '0.0379/0.0382', 6: '0.0371/0.0368', 7: '0.0352/0.0349', 8: '0.0345/0.0349', 9: '0.0343/0.0365', 10: '0.0337/0.0344'}
mouse 2 (45 sessions): 25 bins; bins with p < 0.05: [-14, -13, -12, -10, -9, -7, -4, 1, 2, 4, 5, 6]; smallest p 0.00406; I - E from -0.0001 to +0.0034
   mean |w| E/I by bin: {-17: '0.0353/0.0356', -16: '0.0347/0.0362', -15: '0.0341/0.0357', -14: '0.0340/0.0374', -13: '0.0344/0.0367', -12: '0.0341/0.0370', -11: '0.0342/0.0360', -10: '0.0339/0.0367', -9: '0.0340/0.0364', -8: '0.0343/0.0357', -7: '0.0338/0.0362', -6: '0.0341/0.0358', -5: '0.0340/0.0358', -4: '0.0338/0.0367', -3: '0.0342/0.0353', -2: '0.0339/0.0357', -1: '0.0339/0.0363', 0: '0.0339/0.0357', 1: '0.0337/0.0369', 2: '0.0336/0.0366', 3: '0.0338/0.0355', 4: '0.0335/0.0367', 5: '0.0333/0.0361', 6: '0.0326/0.0346', 7: '0.0313/0.0313'}
mouse 3 (7 sessions): 18 bins; bins with p < 0.05: []; smallest p 0.142; I - E from -0.0046 to +0.0048
   mean |w| E/I by bin: {-11: '0.0394/0.0363', -10: '0.0396/0.0376', -9: '0.0392/0.0420', -8: '0.0399/0.0392', -7: '0.0386/0.0376', -6: '0.0397/0.0352', -5: '0.0382/0.0381', -4: '0.0380/0.0367', -3: '0.0380/0.0421', -2: '0.0369/0.0379', -1: '0.0373/0.0394', 0: '0.0380/0.0396', 1: '0.0380/0.0416', 2: '0.0386/0.0400', 3: '0.0385/0.0409', 4: '0.0378/0.0422', 5: '0.0387/0.0403', 6: '0.0366/0.0415'}
mouse 4 (34 sessions): 25 bins; bins with p < 0.05: [-5]; smallest p 0.0115; I - E from -0.0005 to +0.0041
   mean |w| E/I by bin: {-17: '0.0381/0.0407', -16: '0.0377/0.0393', -15: '0.0367/0.0375', -14: '0.0360/0.0388', -13: '0.0355/0.0378', -12: '0.0351/0.0362', -11: '0.0349/0.0356', -10: '0.0348/0.0344', -9: '0.0345/0.0366', -8: '0.0344/0.0361', -7: '0.0344/0.0371', -6: '0.0346/0.0376', -5: '0.0347/0.0388', -4: '0.0348/0.0380', -3: '0.0352/0.0375', -2: '0.0354/0.0380', -1: '0.0354/0.0378', 0: '0.0353/0.0371', 1: '0.0353/0.0373', 2: '0.0355/0.0367', 3: '0.0355/0.0376', 4: '0.0355/0.0383', 5: '0.0350/0.0377', 6: '0.0345/0.0359', 7: '0.0326/0.0329'}
range of the per-session mean |w|: 0.0104 to 0.0729

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.

fig8ab-learning-accuracy¶

During learning, choice decoding accuracy increases and correlates with behavioural performance across sessions, for all, excitatory and inhibitory populations (r = 0.55, 0.35, 0.32 in mouse 2 and 0.57, 0.63, 0.32 in mouse 3).

In [6]:
exp_r = {"legend mouse 2": (0.55, 0.35, 0.32), "legend mouse 3": (0.57, 0.63, 0.32)}
for rd in ("a", "b"):
    print("trials, reading", rd)
    for m in nj.LEARNING_MICE:
        out = []
        for pop in ("all", "exc", "inh"):
            g = R[(R.rd == rd) & (R.mouse == m) & (R["pop"] == pop)].dropna(subset=["acc", "perf"])
            r, p = stats.pearsonr(g.perf, g.acc)
            out.append(f"{pop} r = {r:.2f} (p = {p:.2g}, {len(g)} days)")
        print(f"  mouse {m}: " + "; ".join(out))
print("expected: legend 'mouse 2' r = 0.55, 0.35, 0.32; legend 'mouse 3' r = 0.57, 0.63, 0.32 (tolerance 10%);"
      " reading (a) of the names is the paper's mice 2 and 4, reading (b) the paper's mice 2 and 3 (mouse 3 was not imaged through learning and is not decoded here)")
trials, reading a
  mouse 1: all r = 0.66 (p = 1.9e-06, 43 days); exc r = 0.57 (p = 6.8e-05, 43 days); inh r = 0.51 (p = 0.00053, 43 days)
  mouse 2: all r = 0.39 (p = 0.0067, 46 days); exc r = 0.22 (p = 0.14, 46 days); inh r = 0.21 (p = 0.16, 46 days)
  mouse 4: all r = 0.57 (p = 0.00035, 35 days); exc r = 0.56 (p = 0.00051, 35 days); inh r = 0.31 (p = 0.067, 35 days)
trials, reading b
  mouse 1: all r = 0.57 (p = 9.2e-05, 41 days); exc r = 0.44 (p = 0.0037, 41 days); inh r = 0.50 (p = 0.00082, 41 days)
  mouse 2: all r = 0.36 (p = 0.019, 41 days); exc r = 0.07 (p = 0.67, 41 days); inh r = 0.20 (p = 0.21, 41 days)
  mouse 4: all r = 0.29 (p = 0.12, 31 days); exc r = 0.27 (p = 0.15, 31 days); inh r = 0.12 (p = 0.54, 31 days)
expected: legend 'mouse 2' r = 0.55, 0.35, 0.32; legend 'mouse 3' r = 0.57, 0.63, 0.32 (tolerance 10%); reading (a) of the names is the paper's mice 2 and 4, reading (b) the paper's mice 2 and 3 (mouse 3 was not imaged through learning and is not decoded here)

Result: not reproduced. Decoder accuracy correlates positively with easy-trial performance in every learning mouse and population. With all trials, reading (a), mouse 1 has r = 0.66, 0.57, 0.52 (all p < 0.001), mouse 2 0.39, 0.22, 0.21 (p = 0.0067, 0.14, 0.16) and mouse 4 0.57, 0.55, 0.32 (p = 0.00035, 0.0007, 0.063). Reading (b) gives mouse 2 0.36, 0.07, 0.21 and mouse 4 0.29, 0.26, 0.12. Under the reading of the legend's mice as the paper's mice 2 and 4, mouse 2 matches none of the reported values and mouse 4 matches 0.57 and 0.32 but not 0.63 (0.55). Not all p < 0.05, so neither the reproduced nor the partial band holds.

fig8ce-choice-signal-onset¶

The choice signal emerges progressively earlier in the trial as mice become experts, so the onset of above-chance decoding correlates negatively with performance (r = -0.60, -0.34, -0.38 in mouse 2 and -0.60, -0.27, -0.28 in mouse 3 for all, excitatory and inhibitory).

In [7]:
for col, lab in (("on05", "p < 0.05 (Methods)"), ("on001", "variant p < 0.001 (code)")):
    for rd in ("a", "b"):
        print(lab, "trials reading", rd)
        for m in nj.LEARNING_MICE:
            out = []
            for pop in ("all", "exc", "inh"):
                g = R[(R.rd == rd) & (R.mouse == m) & (R["pop"] == pop)].dropna(subset=[col, "perf"])
                if len(g) > 2:
                    r, p = stats.pearsonr(g.perf, g[col])
                    out.append(f"{pop} r = {r:.2f} (p = {p:.2g}, {len(g)} days with onset, median onset {g[col].median():.0f} ms)")
            print(f"  mouse {m}: " + "; ".join(out))
p < 0.05 (Methods) trials reading a
  mouse 1: all r = -0.49 (p = 0.0013, 40 days with onset, median onset -1067 ms); exc r = -0.38 (p = 0.026, 35 days with onset, median onset -388 ms); inh r = -0.06 (p = 0.76, 27 days with onset, median onset -291 ms)
  mouse 2: all r = -0.07 (p = 0.65, 44 days with onset, median onset -1018 ms); exc r = -0.06 (p = 0.7, 40 days with onset, median onset -307 ms); inh r = -0.24 (p = 0.15, 37 days with onset, median onset -291 ms)
  mouse 4: all r = -0.11 (p = 0.57, 29 days with onset, median onset -1164 ms); exc r = -0.12 (p = 0.58, 24 days with onset, median onset -388 ms); inh r = 0.13 (p = 0.62, 17 days with onset, median onset -873 ms)
p < 0.05 (Methods) trials reading b
  mouse 1: all r = -0.41 (p = 0.021, 32 days with onset, median onset -485 ms); exc r = -0.24 (p = 0.28, 22 days with onset, median onset -194 ms); inh r = 0.30 (p = 0.29, 15 days with onset, median onset -97 ms)
  mouse 2: all r = -0.18 (p = 0.34, 32 days with onset, median onset -291 ms); exc r = -0.03 (p = 0.91, 18 days with onset, median onset -146 ms); inh r = 0.21 (p = 0.57, 10 days with onset, median onset -194 ms)
  mouse 4: all r = -0.28 (p = 0.24, 19 days with onset, median onset -388 ms); exc r = -0.16 (p = 0.65, 10 days with onset, median onset -291 ms); inh r = 0.17 (p = 0.75, 6 days with onset, median onset -436 ms)
variant p < 0.001 (code) trials reading a
  mouse 1: all r = -0.39 (p = 0.024, 34 days with onset, median onset -1067 ms); exc r = -0.13 (p = 0.51, 28 days with onset, median onset -194 ms); inh r = 0.08 (p = 0.71, 21 days with onset, median onset -194 ms)
  mouse 2: all r = -0.10 (p = 0.52, 43 days with onset, median onset -582 ms); exc r = -0.13 (p = 0.45, 34 days with onset, median onset -170 ms); inh r = 0.07 (p = 0.73, 26 days with onset, median onset -242 ms)
  mouse 4: all r = 0.17 (p = 0.41, 26 days with onset, median onset -873 ms); exc r = -0.17 (p = 0.51, 17 days with onset, median onset -291 ms); inh r = -0.16 (p = 0.71, 8 days with onset, median onset -679 ms)
variant p < 0.001 (code) trials reading b
  mouse 1: all r = -0.16 (p = 0.44, 25 days with onset, median onset -194 ms); exc r = -0.31 (p = 0.41, 9 days with onset, median onset -97 ms); inh r = -0.28 (p = 0.65, 5 days with onset, median onset 0 ms)
  mouse 2: all r = -0.30 (p = 0.16, 23 days with onset, median onset -291 ms); exc r = 0.13 (p = 0.79, 7 days with onset, median onset 0 ms); inh r = 0.81 (p = 0.093, 5 days with onset, median onset 0 ms)
  mouse 4: all r = -0.27 (p = 0.39, 12 days with onset, median onset -291 ms); exc r = -0.11 (p = 0.89, 4 days with onset, median onset -97 ms)

Result: not reproduced. The onset of the first 500 ms run of above-shuffle accuracy correlates negatively with performance in mouse 1 for the all-neuron and excitatory decoders (r = -0.49, -0.42; p = 0.0013, 0.01), not for inhibitory (r = -0.06). In mice 2 and 4 it does not (r -0.24 to -0.04, p >= 0.16), under trial reading (a) and the Methods alpha 0.05. Reading (b) and the code's alpha 0.001 give no more. None of the six reported values is matched. Per-bin C was not run for these decoders (estimated over 6 hours of CPU), so the onsets rest on C chosen at bin -1 with 25 splits.

fig8de-learning-parallel¶

The choice signal emerges at the same time in excitatory and inhibitory populations, and its magnitude and timing are matched for the two cell types throughout learning.

In [8]:
def tt(a, b):
    a, b = np.asarray(a, float), np.asarray(b, float); a, b = a[~np.isnan(a)], b[~np.isnan(b)]
    return stats.ttest_ind(a, b).pvalue if len(a) > 1 and len(b) > 1 else np.nan
for rd in ("a", "b"):
    for el in ("a", "b"):
        print(f"trials reading {rd}, early/late reading {el}")
        for m in nj.LEARNING_MICE:
            g = R[(R.rd == rd) & (R.mouse == m)]
            out = []
            for per in ("early", "late"):
                gg = g[g[per + "_" + el].astype(bool)]
                e, i = gg[gg["pop"] == "exc"], gg[gg["pop"] == "inh"]
                out.append(f"{per} ({len(i)} days): acc exc {e.acc.mean():.1f} inh {i.acc.mean():.1f} p = {tt(e.acc, i.acc):.2g}; "
                           f"onset exc {e.on05.mean():.0f} inh {i.on05.mean():.0f} ms p = {tt(e.on05, i.on05):.2g}")
            le = []
            for pop in ("exc", "inh"):
                x = g[g["pop"] == pop]
                lt, er = x[x["late_" + el].astype(bool)].acc, x[x["early_" + el].astype(bool)].acc
                le.append(f"{pop} late {lt.mean():.1f} vs early {er.mean():.1f} p = {tt(lt, er):.2g}")
            print(f"  mouse {m}: " + " | ".join(out) + " | " + "; ".join(le))
trials reading a, early/late reading a
  mouse 1: early (8 days): acc exc 58.4 inh 56.2 p = 0.64; onset exc 129 inh nan ms p = nan | late (9 days): acc exc 72.0 inh 69.4 p = 0.42; onset exc -774 inh -754 ms p = 0.95 | exc late 72.0 vs early 58.4 p = 0.0018; inh late 69.4 vs early 56.2 p = 0.004
  mouse 2: early (8 days): acc exc 62.1 inh 61.3 p = 0.81; onset exc -334 inh 0 ms p = 0.22 | late (10 days): acc exc 67.1 inh 65.7 p = 0.63; onset exc -500 inh -764 ms p = 0.38 | exc late 67.1 vs early 62.1 p = 0.085; inh late 65.7 vs early 61.3 p = 0.23
  mouse 4: early (7 days): acc exc 58.8 inh 58.3 p = 0.84; onset exc -129 inh -194 ms p = nan | late (7 days): acc exc 68.1 inh 65.1 p = 0.23; onset exc -474 inh -146 ms p = 0.26 | exc late 68.1 vs early 58.8 p = 0.0013; inh late 65.1 vs early 58.3 p = 0.031
trials reading a, early/late reading b
  mouse 1: early (1 days): acc exc 46.2 inh 35.0 p = nan; onset exc nan inh nan ms p = nan | late (0 days): acc exc nan inh nan p = nan; onset exc nan inh nan ms p = nan | exc late nan vs early 46.2 p = nan; inh late nan vs early 35.0 p = nan
  mouse 2: early (6 days): acc exc 62.4 inh 60.5 p = 0.69; onset exc -776 inh 97 ms p = nan | late (1 days): acc exc 58.8 inh 63.1 p = nan; onset exc -194 inh nan ms p = nan | exc late 58.8 vs early 62.4 p = nan; inh late 63.1 vs early 60.5 p = nan
  mouse 4: early (0 days): acc exc nan inh nan p = nan; onset exc nan inh nan ms p = nan | late (0 days): acc exc nan inh nan p = nan; onset exc nan inh nan ms p = nan | exc late nan vs early nan p = nan; inh late nan vs early nan p = nan
trials reading b, early/late reading a
  mouse 1: early (8 days): acc exc 58.3 inh 56.9 p = 0.79; onset exc -582 inh -97 ms p = nan | late (7 days): acc exc 69.7 inh 69.4 p = 0.96; onset exc -679 inh -48 ms p = 0.042 | exc late 69.7 vs early 58.3 p = 0.016; inh late 69.4 vs early 56.9 p = 0.036
  mouse 2: early (5 days): acc exc 62.0 inh 58.0 p = 0.29; onset exc 24 inh -97 ms p = nan | late (10 days): acc exc 60.8 inh 67.8 p = 0.023; onset exc -205 inh -194 ms p = nan | exc late 60.8 vs early 62.0 p = 0.7; inh late 67.8 vs early 58.0 p = 0.013
  mouse 4: early (6 days): acc exc 57.9 inh 57.9 p = 0.99; onset exc -97 inh nan ms p = nan | late (4 days): acc exc 59.7 inh 64.6 p = 0.067; onset exc nan inh -291 ms p = nan | exc late 59.7 vs early 57.9 p = 0.59; inh late 64.6 vs early 57.9 p = 0.16
trials reading b, early/late reading b
  mouse 1: early (1 days): acc exc 54.0 inh 48.7 p = nan; onset exc nan inh nan ms p = nan | late (0 days): acc exc nan inh nan p = nan; onset exc nan inh nan ms p = nan | exc late nan vs early 54.0 p = nan; inh late nan vs early 48.7 p = nan
  mouse 2: early (3 days): acc exc 59.3 inh 58.2 p = 0.85; onset exc nan inh nan ms p = nan | late (1 days): acc exc 64.9 inh 70.7 p = nan; onset exc nan inh nan ms p = nan | exc late 64.9 vs early 59.3 p = nan; inh late 70.7 vs early 58.2 p = nan
  mouse 4: early (0 days): acc exc nan inh nan p = nan; onset exc nan inh nan ms p = nan | late (0 days): acc exc nan inh nan p = nan; onset exc nan inh nan ms p = nan | exc late nan vs early nan p = nan; inh late nan vs early nan p = nan

Result: not reproduced. With all trials, reading (a), and early and late days by reading (a), the subsampled excitatory and inhibitory decoders do not differ in accuracy or onset in early or late days in any learning mouse (p 0.2 to 0.81 where testable). Late accuracy exceeds early for both types in mice 1 and 4 (p 0.0013 to 0.03), but not in mouse 2 (p = 0.084, 0.24). Under trial reading (b), late-day accuracy differs between types in mouse 2 (I 67.9 against E 60.6, p = 0.016), and late exceeds early for excitatory neurons in neither mouse 2 nor mouse 4. Early and late days by reading (b) give 0 or 1 day in most mice and cannot be tested, so the outcome rests on early and late days by reading (a), an assumption. The claim fails under both trial readings, so it is not reproduced.

figs13c-equal-trials¶

The learning-related increase in decoding accuracy remains when the number of trials is equal in every session.

In [9]:
EQ = pd.DataFrame([{"session": o["session"], "mouse": o["mouse"], **o["equal"]} for o in OUT if "equal" in o]).merge(L[["session", "early_a", "late_a", "early_b", "late_b"]], on="session")
for el in ("a", "b"):
    for m, g in EQ.groupby("mouse"):
        e, l = g[g["early_" + el].astype(bool)].acc, g[g["late_" + el].astype(bool)].acc
        print(f"early/late reading {el}, mouse {m}: {g.n.iloc[0]} trials per choice, {len(g)} sessions; early {e.mean():.1f} ({len(e)}), late {l.mean():.1f} ({len(l)}), "
              f"late - early {l.mean()-e.mean():+.1f}, p = {tt(l, e):.2g}")
early/late reading a, mouse 1: 12 trials per choice, 41 sessions; early 79.8 (6), late 87.2 (9), late - early +7.4, p = 0.073
early/late reading a, mouse 2: 14 trials per choice, 45 sessions; early 78.3 (7), late 82.7 (10), late - early +4.4, p = 0.32
early/late reading a, mouse 4: 15 trials per choice, 34 sessions; early 80.1 (6), late 96.8 (7), late - early +16.7, p = 0.0046
early/late reading b, mouse 1: 12 trials per choice, 41 sessions; early nan (0), late nan (0), late - early +nan, p = nan
early/late reading b, mouse 2: 14 trials per choice, 45 sessions; early 77.6 (5), late 78.0 (1), late - early +0.4, p = nan
early/late reading b, mouse 4: 15 trials per choice, 34 sessions; early nan (0), late nan (0), late - early +nan, p = nan

Result: not reproduced. With 12, 14 and 15 correct trials of each choice in every session, all-neuron accuracy is higher late than early in every learning mouse (+7.4, +4.4 and +16.7 points), significantly only in mouse 4 (p = 0.0046), not in mice 1 and 2 (p = 0.073, 0.32).

figs13ab-pseudo-learning¶

Decoding accuracy of pseudo populations, which lack noise correlations, also increases significantly with training, so reduced noise correlations do not alone explain the improved accuracy.

In [10]:
for el in ("a", "b"):
    for m in nj.LEARNING_MICE:
        g = R[(R.rd == "a") & (R.mouse == m)]
        out = []
        for pop in ("all", "exc", "inh"):
            x = g[g["pop"] == pop]
            e, l = x[x["early_" + el].astype(bool)].pseudo, x[x["late_" + el].astype(bool)].pseudo
            out.append(f"{pop} early {e.mean():.1f} late {l.mean():.1f} p = {tt(l, e):.2g}")
        print(f"early/late reading {el}, mouse {m}: " + "; ".join(out))
early/late reading a, mouse 1: all early 75.5 late 95.5 p = 0.00025; exc early 58.2 late 70.9 p = 0.0027; inh early 56.8 late 71.1 p = 0.00033
early/late reading a, mouse 2: all early 80.5 late 88.3 p = 0.18; exc early 61.0 late 66.0 p = 0.16; inh early 63.7 late 66.3 p = 0.58
early/late reading a, mouse 4: all early 73.3 late 92.9 p = 0.0011; exc early 55.7 late 68.5 p = 0.00046; inh early 58.7 late 65.1 p = 0.11
early/late reading b, mouse 1: all early 63.0 late nan p = nan; exc early 51.5 late nan p = nan; inh early 48.0 late nan p = nan
early/late reading b, mouse 2: all early 78.9 late 85.2 p = nan; exc early 60.8 late 56.6 p = nan; inh early 62.6 late 63.8 p = nan
early/late reading b, mouse 4: all early nan late nan p = nan; exc early nan late nan p = nan; inh early nan late nan p = nan

Result: not reproduced. Pseudo-population accuracy of the all-neuron decoder rises from early to late days in every learning mouse (75.5 to 95.5, 80.5 to 88.3, 73.3 to 92.9). The rise is significant in mice 1 and 4 (p = 0.00025, 0.0011) and not in mouse 2 (p = 0.18). Excitatory and inhibitory pseudo populations rise in the same direction in every mouse.

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.

In [11]:
print("runtime %.1f min, peak memory %.1f GB" % ((time.time() - T0) / 60, resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6))
runtime 55.6 min, peak memory 5.8 GB