Reproducing McGuire, Telian, Laboy-Juarez et al. (2016) from CRCNS ssc-4: decoders (Figure 9)¶

Paper: doi:10.1371/journal.pbio.1002549. Dataset: CRCNS ssc-4 (doi:10.6080/K06D5QXN), ssc-4/live/AllRats.mat, version unversioned, pinned by its MD5 sum a929b803ca0feab5270e807f571d13eb from the data set's checksums.md5 (the only version in the bucket; see the header of reproduce_mcguire_2016.ipynb for the reasons and the data checks). The claims file was written from the version of record with the Methods and supporting legends.

The unit classes are those of reproduce_mcguire_2016.ipynb: the data set's temporally modulated units (its stored p-values, which the descriptor names as the units of the paper's analyses), classed by the regression (reading a, 55 ms Medium), which gives the data set's own labels. The set recomputed with the Methods' test (reading a, same seed) is a variant. The first run used the recomputed set; it was changed after the verifier's first report.

claim here
fig9b-stimulus-decoder-fast-medium tested
fig9c-best-units-short-windows tested
fig9b-stimulus-decoder-slow-chance tested
fig9d-single-bin-decoder tested
fig9e-temporal-pattern-decoding tested
fig9f-choice-decoder tested
fig9g-l5b-slow-positive-best-choice tested

Decoder details (helper docstring): logistic regression per unit, L2 with C = 1 (claim reading a) fit by a batched Newton solver checked against scikit-learn below; reading b (C chosen by 5-fold cross-validation on the 70%) is run with fewer repeats, as it costs about 30 times more. The number of repeats of each run is printed with it.

In [1]:
import collections, time, os
os.environ.setdefault("OMP_NUM_THREADS", "1")
import numpy as np, pandas as pd
from scipy import stats
from sklearn.linear_model import LogisticRegression
import ssc4
pd.set_option("display.width", 200)
t_start = time.time()
D = ssc4.Data(ssc4.load_mat())
U = D.units
pmod = ssc4.temporal_pvals(D, "np", seed=1)
R2, P, B = ssc4.regress_all(D)
R2 = np.nan_to_num(R2, nan=0.0); P = np.nan_to_num(P, nan=1.0); B = np.nan_to_num(B)
U["mod"] = U.dep_temp_p.values < 0.05    # the data set's modulated units (see reproduce_mcguire_2016.ipynb)
U["mod_a"] = pmod < 0.05                  # recomputed with the Methods' test (reading a), a variant
U["cls"], U["best"], _, _ = ssc4.unit_classes(R2, P, B, U["mod"].values, "all", True)
U["cls_a"] = ssc4.unit_classes(R2, P, B, U["mod_a"].values, "all", True)[0]
U["cls_dep"] = ssc4.deposited_classes(D)
In [2]:
print("sessions", len(D.A), "units", len(U), "completed trials", int(D.trials.complete.sum()))
print("completed trials by sequence", D.trials[D.trials.complete].stim.value_counts().to_dict())
print("classes (main: deposited modulated set, reading a, 55 ms Medium)", U.cls.value_counts().to_dict())
print("main classes equal the deposited labels for every unit:", bool((U.cls == U.cls_dep).all()))
print("classes (variant: recomputed modulated set)", U.cls_a.value_counts().to_dict())
FM = U.uid[U.cls.isin(["Fast", "Medium"])].values
SL = U.uid[U.cls.isin(["SlowPos", "SlowNeg"])].values
FMa = U.uid[U.cls_a.isin(["Fast", "Medium"])].values
SLa = U.uid[U.cls_a.isin(["SlowPos", "SlowNeg"])].values
print("Fast/Medium units %d, Slow units %d (variant, recomputed set: %d, %d)" % (len(FM), len(SL), len(FMa), len(SLa)))
ntr = pd.Series({u: len(D.unit_trials(u)[1]) for u in U.uid})
print("completed trials per unit: min %d, median %d, max %d" % (ntr.min(), ntr.median(), ntr.max()))
X, t = ssc4.unit_features(D, FM[0], "10ms")
print("10-ms features of one unit: shape", X.shape, "count range", X.min(), X.max())
withdraw = D.trials[D.trials.complete].withdraw_t
print("withdrawal after onset (ms), completed trials: min %.0f, mean %.0f, max %.0f" % (withdraw.min(), withdraw.mean(), withdraw.max()))
# the batched solver against scikit-learn on one unit
y = (t.stim == "FFF").values.astype(float)
b = ssc4.fit_logistic(X[None], y[None], np.ones((1, len(y))))
sk = LogisticRegression(C=1.0, tol=1e-10, max_iter=10000).fit(X, y)
print("batched Newton vs scikit-learn lbfgs: max coefficient difference %.2e, intercepts %.5f %.5f"
      % (np.abs(b[0, :-1] - sk.coef_[0]).max(), b[0, -1], sk.intercept_[0]))
sessions 80 units 506 completed trials 14186
completed trials by sequence {'SMF': 3599, 'SSS': 3558, 'FMS': 3547, 'FFF': 3482}
classes (main: deposited modulated set, reading a, 55 ms Medium) {'none': 196, 'Fast': 160, 'Medium': 53, 'SlowPos': 51, 'SlowNeg': 46}
main classes equal the deposited labels for every unit: True
classes (variant: recomputed modulated set) {'none': 196, 'Fast': 160, 'SlowNeg': 50, 'Medium': 50, 'SlowPos': 50}
Fast/Medium units 213, Slow units 97 (variant, recomputed set: 210, 100)
completed trials per unit: min 43, median 168, max 332
10-ms features of one unit: shape (124, 15) count range 0.0 4.0
withdrawal after onset (ms), completed trials: min 153, mean 194, max 362
batched Newton vs scikit-learn lbfgs: max coefficient difference 6.43e-08, intercepts -1.04419 -1.04419
In [3]:
ORDER = ["FFF", "FMS", "SMF", "SSS"]
def show(conf, accs, label):
    cm = pd.DataFrame(conf, index=ORDER, columns=ORDER)
    diag = np.diag(conf)
    fs = [ORDER.index("FMS"), ORDER.index("SMF")]
    A = diag[fs].mean()
    sub = conf[np.ix_(fs, fs)]
    Bv = np.mean(np.diag(sub) / sub.sum(1))
    print("%s: %d repeats, overall %.1f%% (SD over repeats %.1f); per sequence %s; FMS/SMF reading A %.1f%%, reading B %.1f%%"
          % (label, len(accs), 100 * accs.mean(), 100 * accs.std(), dict(zip(ORDER, (100 * diag).round(1))), 100 * A, 100 * Bv))
    print(cm.round(3))
    return dict(overall=100 * accs.mean(), **{s: 100 * d for s, d in zip(ORDER, diag)}, A=100 * A, B=100 * Bv)
RES = {}
def run(name, units, kind, how=None, reps=300, cv=False, seed=0):
    t0 = time.time()
    conf, accs, ua = ssc4.stim_decoder(D, units, kind, how, repeats=reps, seed=seed, cv=cv)
    RES[name] = dict(conf=conf, accs=accs, ua=ua, units=units, summary=show(conf, accs, name))
    print("   (%.0f s)" % (time.time() - t0))

fig9b-stimulus-decoder-fast-medium¶

A decoder built from all Fast and Medium units with 10-ms bins identified the sequence with 83% accuracy (74% for FMS to 88% for FFF; chance 25%), and identified FMS and SMF with 78% accuracy.

In [4]:
run("FM 10ms", FM, "10ms", seed=11)
run("FM 10ms, C by CV (reading b)", FM, "10ms", reps=5, cv=True, seed=12)
run("variant: FM 10ms, recomputed set (a)", FMa, "10ms", reps=100, seed=13)
FM 10ms: 300 repeats, overall 86.9% (SD over repeats 3.2); per sequence {'FFF': np.float64(91.7), 'FMS': np.float64(78.5), 'SMF': np.float64(84.0), 'SSS': np.float64(93.4)}; FMS/SMF reading A 81.2%, reading B 98.8%
       FFF    FMS    SMF    SSS
FFF  0.917  0.077  0.004  0.002
FMS  0.161  0.785  0.019  0.035
SMF  0.000  0.000  0.840  0.160
SSS  0.000  0.000  0.066  0.934
   (125 s)
FM 10ms, C by CV (reading b): 5 repeats, overall 72.0% (SD over repeats 3.0); per sequence {'FFF': np.float64(78.8), 'FMS': np.float64(42.4), 'SMF': np.float64(75.2), 'SSS': np.float64(91.8)}; FMS/SMF reading A 58.8%, reading B 88.0%
       FFF    FMS    SMF    SSS
FFF  0.788  0.136  0.038  0.038
FMS  0.216  0.424  0.134  0.226
SMF  0.000  0.000  0.752  0.248
SSS  0.000  0.000  0.082  0.918
   (52 s)
variant: FM 10ms, recomputed set (a): 100 repeats, overall 83.8% (SD over repeats 4.1); per sequence {'FFF': np.float64(85.3), 'FMS': np.float64(74.1), 'SMF': np.float64(88.8), 'SSS': np.float64(86.9)}; FMS/SMF reading A 81.4%, reading B 97.4%
       FFF    FMS    SMF    SSS
FFF  0.853  0.138  0.007  0.001
FMS  0.195  0.741  0.040  0.025
SMF  0.000  0.001  0.888  0.111
SSS  0.000  0.001  0.130  0.869
   (42 s)

Result: reproduced. With C = 1 (reading a, 300 repeats) the decoder of 213 Fast and Medium units is 86.9% correct overall, 78.5% for FMS and 91.7% for FFF, and 81.2% on FMS and SMF (reading A; 98.8% under reading B), all within tolerance. With C chosen by cross-validation (5 repeats) it is 72.0% overall and 42.4% for FMS, outside tolerance. The recomputed set gives 83.8% (100 repeats).

fig9c-best-units-short-windows¶

The individual units with the best stimulus prediction in the Fast/Medium decoder were those with 5 to 10 ms best integration windows.

In [5]:
r = RES["FM 10ms"]
ua = pd.DataFrame(dict(acc=100 * r["ua"], best=U.best[r["units"]].values, cls=U.cls[r["units"]].values))
g = ua.groupby("best").acc.agg(["mean", "size"]).round(1)
print(g.T.to_string())
top = ua.nlargest(int(np.ceil(0.1 * len(ua))), "acc")
print("top 10%% (%d units): best windows %s; from 5 or 10 ms: %d" % (len(top), top.best.value_counts().to_dict(), top.best.isin([5, 10]).sum()))
print("group with the highest mean:", g["mean"].idxmax(), "ms; groups with at least 3 units:", g[g["size"] >= 3]["mean"].idxmax(), "ms")
print("chance 25%; units above 25%:", int((ua.acc > 25).sum()), "of", len(ua))
best    5     10    15    20    25    30    35    40    45    50    55
mean  33.5  31.7  32.5  27.3  29.4  30.6  27.9  29.8  28.8  29.0  31.9
size  65.0  70.0  15.0  10.0  15.0   9.0   4.0  13.0   5.0   6.0   1.0
top 10% (22 units): best windows {5: 11, 10: 6, 15: 1, 40: 1, 25: 1, 30: 1, 20: 1}; from 5 or 10 ms: 17
group with the highest mean: 5 ms; groups with at least 3 units: 5 ms
chance 25%; units above 25%: 191 of 213

Result: reproduced. Units with a 5-ms best window have the highest mean single-unit accuracy (33.5%; 10 ms 31.7%, 15 ms 32.5%, longer windows 27.3 to 31.9%, the 31.9% being one 55-ms unit), and 17 of the 22 top-ranked units have 5 or 10 ms windows.

fig9b-stimulus-decoder-slow-chance¶

A decoder built from all Slow units with 10-ms bins predicted sequence identity near chance (32%, not different from chance).

In [6]:
run("Slow 10ms", SL, "10ms", seed=21)
run("Slow 10ms, C by CV (reading b)", SL, "10ms", reps=5, cv=True, seed=22)
run("variant: Slow 10ms, recomputed set (a)", SLa, "10ms", reps=100, seed=23)
def chance_tests(name, npseudo=100):
    a = RES[name]["accs"]
    pa = min(1.0, 2 * min(np.mean(a <= 0.25), np.mean(a >= 0.25)))
    n = len(a) * 4 * npseudo
    k = int(round(a.mean() * n))
    pb = stats.binomtest(k, n, 0.25).pvalue
    print("%s: accuracy %.1f%%; (a) two-sided fraction of repeats on the other side of 25%%: p = %.3f; (b) binomial test of %d pooled pseudo-trials: p = %.2g"
          % (name, 100 * a.mean(), pa, n, pb))
for nm in ["Slow 10ms", "Slow 10ms, C by CV (reading b)", "variant: Slow 10ms, recomputed set (a)"]:
    chance_tests(nm)
Slow 10ms: 300 repeats, overall 33.9% (SD over repeats 3.8); per sequence {'FFF': np.float64(49.1), 'FMS': np.float64(11.0), 'SMF': np.float64(62.6), 'SSS': np.float64(12.7)}; FMS/SMF reading A 36.8%, reading B 51.9%
       FFF    FMS    SMF    SSS
FFF  0.491  0.129  0.301  0.078
FMS  0.345  0.110  0.475  0.070
SMF  0.158  0.111  0.626  0.105
SSS  0.234  0.072  0.567  0.127
   (57 s)
Slow 10ms, C by CV (reading b): 5 repeats, overall 28.4% (SD over repeats 2.8); per sequence {'FFF': np.float64(31.4), 'FMS': np.float64(2.4), 'SMF': np.float64(78.8), 'SSS': np.float64(0.8)}; FMS/SMF reading A 40.6%, reading B 50.8%
       FFF    FMS    SMF    SSS
FFF  0.314  0.028  0.622  0.036
FMS  0.272  0.024  0.684  0.020
SMF  0.178  0.014  0.788  0.020
SSS  0.212  0.008  0.772  0.008
   (25 s)
variant: Slow 10ms, recomputed set (a): 100 repeats, overall 29.2% (SD over repeats 4.2); per sequence {'FFF': np.float64(22.9), 'FMS': np.float64(16.6), 'SMF': np.float64(53.3), 'SSS': np.float64(23.9)}; FMS/SMF reading A 34.9%, reading B 49.1%
       FFF    FMS    SMF    SSS
FFF  0.229  0.287  0.310  0.174
FMS  0.208  0.166  0.463  0.163
SMF  0.082  0.209  0.533  0.176
SSS  0.122  0.180  0.458  0.239
   (20 s)
Slow 10ms: accuracy 33.9%; (a) two-sided fraction of repeats on the other side of 25%: p = 0.027; (b) binomial test of 120000 pooled pseudo-trials: p = 0
Slow 10ms, C by CV (reading b): accuracy 28.4%; (a) two-sided fraction of repeats on the other side of 25%: p = 0.400; (b) binomial test of 2000 pooled pseudo-trials: p = 0.00065
variant: Slow 10ms, recomputed set (a): accuracy 29.2%; (a) two-sided fraction of repeats on the other side of 25%: p = 0.360; (b) binomial test of 40000 pooled pseudo-trials: p = 5.1e-80

Result: partially reproduced. The decoder of 97 Slow units is 33.9% correct (C = 1, 300 repeats), within tolerance of 32%, but above chance by both tests: the fraction of repeats at or below 25% (p = 0.027, reading a) and the binomial test (p near 0, reading b). With C by cross-validation it is 28.4%, below the tolerance (28.8 to 35.2%), though not above chance by reading (a) (p = 0.400). No reading has the accuracy within tolerance and the test not significant. The recomputed set gives 29.2%, p = 0.360 by reading (a), which would meet the criterion, so the outcome rests on the unit set. Test (a) measures the spread of repeats around 25%, not a null distribution, as the verifier noted.

fig9d-single-bin-decoder¶

Decoding from mean firing rate in a single 150-ms bin reduced Fast/Medium decoder accuracy to 43% and did not improve Slow decoder accuracy.

In [7]:
run("FM 1bin", FM, "1bin", seed=31)
run("Slow 1bin", SL, "1bin", seed=32)
run("FM 1bin, C by CV (reading b)", FM, "1bin", reps=5, cv=True, seed=33)
run("Slow 1bin, C by CV (reading b)", SL, "1bin", reps=5, cv=True, seed=34)
run("variant: FM 1bin, recomputed set (a)", FMa, "1bin", seed=35)
for a, b in [("Slow 1bin", "Slow 10ms"), ("Slow 1bin, C by CV (reading b)", "Slow 10ms, C by CV (reading b)")]:
    d = RES[a]["summary"]["overall"] - RES[b]["summary"]["overall"]
    print("%s minus %s: %.1f points (limit 3.2)" % (a, b, d))
FM 1bin: 300 repeats, overall 38.2% (SD over repeats 3.8); per sequence {'FFF': np.float64(17.3), 'FMS': np.float64(0.1), 'SMF': np.float64(44.3), 'SSS': np.float64(91.3)}; FMS/SMF reading A 22.2%, reading B 49.7%
       FFF    FMS    SMF    SSS
FFF  0.173  0.005  0.663  0.159
FMS  0.011  0.001  0.439  0.549
SMF  0.011  0.003  0.443  0.543
SSS  0.000  0.000  0.087  0.913
   (27 s)
Slow 1bin: 300 repeats, overall 26.6% (SD over repeats 3.1); per sequence {'FFF': np.float64(29.1), 'FMS': np.float64(1.3), 'SMF': np.float64(75.3), 'SSS': np.float64(0.6)}; FMS/SMF reading A 38.3%, reading B 50.3%
       FFF    FMS    SMF    SSS
FFF  0.291  0.013  0.694  0.002
FMS  0.267  0.013  0.712  0.008
SMF  0.225  0.009  0.753  0.013
SSS  0.124  0.012  0.858  0.006
   (13 s)
FM 1bin, C by CV (reading b): 5 repeats, overall 33.5% (SD over repeats 1.0); per sequence {'FFF': np.float64(0.2), 'FMS': np.float64(0.0), 'SMF': np.float64(39.8), 'SSS': np.float64(94.2)}; FMS/SMF reading A 19.9%, reading B 50.0%
       FFF  FMS    SMF    SSS
FFF  0.002  0.0  0.672  0.326
FMS  0.000  0.0  0.344  0.656
SMF  0.000  0.0  0.398  0.602
SSS  0.000  0.0  0.058  0.942
   (10 s)
Slow 1bin, C by CV (reading b): 5 repeats, overall 24.5% (SD over repeats 0.9); per sequence {'FFF': np.float64(0.6), 'FMS': np.float64(0.0), 'SMF': np.float64(97.4), 'SSS': np.float64(0.0)}; FMS/SMF reading A 48.7%, reading B 50.0%
       FFF  FMS    SMF  SSS
FFF  0.006  0.0  0.994  0.0
FMS  0.008  0.0  0.992  0.0
SMF  0.026  0.0  0.974  0.0
SSS  0.014  0.0  0.986  0.0
   (5 s)
variant: FM 1bin, recomputed set (a): 300 repeats, overall 40.0% (SD over repeats 3.6); per sequence {'FFF': np.float64(11.1), 'FMS': np.float64(0.4), 'SMF': np.float64(77.0), 'SSS': np.float64(71.5)}; FMS/SMF reading A 38.7%, reading B 49.5%
       FFF    FMS    SMF    SSS
FFF  0.111  0.014  0.824  0.052
FMS  0.012  0.004  0.747  0.238
SMF  0.012  0.012  0.770  0.206
SSS  0.000  0.002  0.283  0.715
   (27 s)
Slow 1bin minus Slow 10ms: -7.3 points (limit 3.2)
Slow 1bin, C by CV (reading b) minus Slow 10ms, C by CV (reading b): -3.9 points (limit 3.2)

Result: partially reproduced. With one 150-ms bin the Fast/Medium decoder falls to 38.2%, just below the tolerance of 43% (38.7 to 47.3%), and the Slow decoder to 26.6%, 7.3 points below its 10-ms value, not above it. With C by cross-validation the values are 33.5% and 24.5%. The fall in Fast/Medium accuracy and the absence of a Slow gain hold; the Fast/Medium value is 0.5 points outside tolerance. On the recomputed modulated set (a variant) the Fast/Medium single-bin decoder is 40.0%, within tolerance, so the outcome rests on the unit set.

fig9e-temporal-pattern-decoding¶

Fast/Medium decoders trained on rate-normalized spike trains performed well (80%), while time-scrambling spikes within trials abolished performance.

In [8]:
run("FM 10ms rate-normalized", FM, "10ms", "norm", seed=41)
run("FM 10ms time-scrambled", FM, "10ms", "scramble", seed=42)
run("FM 10ms rate-normalized, C by CV (reading b)", FM, "10ms", "norm", reps=5, cv=True, seed=43)
run("FM 10ms time-scrambled, C by CV (reading b)", FM, "10ms", "scramble", reps=5, cv=True, seed=44)
for nm in ["FM 10ms time-scrambled", "FM 10ms time-scrambled, C by CV (reading b)"]:
    chance_tests(nm)
    print("   below 32%%: %s" % (RES[nm]["summary"]["overall"] < 32))
FM 10ms rate-normalized: 300 repeats, overall 84.5% (SD over repeats 3.4); per sequence {'FFF': np.float64(87.1), 'FMS': np.float64(76.6), 'SMF': np.float64(81.9), 'SSS': np.float64(92.5)}; FMS/SMF reading A 79.3%, reading B 97.6%
       FFF    FMS    SMF    SSS
FFF  0.871  0.107  0.012  0.010
FMS  0.140  0.766  0.038  0.055
SMF  0.000  0.000  0.819  0.181
SSS  0.000  0.000  0.075  0.925
   (111 s)
FM 10ms time-scrambled: 300 repeats, overall 32.7% (SD over repeats 4.2); per sequence {'FFF': np.float64(17.3), 'FMS': np.float64(8.6), 'SMF': np.float64(40.5), 'SSS': np.float64(64.3)}; FMS/SMF reading A 24.5%, reading B 52.9%
       FFF    FMS    SMF    SSS
FFF  0.173  0.110  0.480  0.237
FMS  0.085  0.086  0.314  0.516
SMF  0.107  0.075  0.405  0.413
SSS  0.015  0.072  0.270  0.643
   (119 s)
FM 10ms rate-normalized, C by CV (reading b): 5 repeats, overall 69.0% (SD over repeats 4.5); per sequence {'FFF': np.float64(65.6), 'FMS': np.float64(45.0), 'SMF': np.float64(75.2), 'SSS': np.float64(90.4)}; FMS/SMF reading A 60.1%, reading B 81.0%
       FFF    FMS    SMF    SSS
FFF  0.656  0.126  0.114  0.104
FMS  0.056  0.450  0.276  0.218
SMF  0.000  0.000  0.752  0.248
SSS  0.000  0.000  0.096  0.904
   (47 s)
FM 10ms time-scrambled, C by CV (reading b): 5 repeats, overall 22.7% (SD over repeats 2.6); per sequence {'FFF': np.float64(1.0), 'FMS': np.float64(0.0), 'SMF': np.float64(24.2), 'SSS': np.float64(65.4)}; FMS/SMF reading A 12.1%, reading B 50.0%
       FFF  FMS    SMF    SSS
FFF  0.010  0.0  0.466  0.524
FMS  0.006  0.0  0.308  0.686
SMF  0.010  0.0  0.242  0.748
SSS  0.002  0.0  0.344  0.654
   (51 s)
FM 10ms time-scrambled: accuracy 32.7%; (a) two-sided fraction of repeats on the other side of 25%: p = 0.060; (b) binomial test of 120000 pooled pseudo-trials: p = 0
   below 32%: False
FM 10ms time-scrambled, C by CV (reading b): accuracy 22.7%; (a) two-sided fraction of repeats on the other side of 25%: p = 0.400; (b) binomial test of 2000 pooled pseudo-trials: p = 0.015
   below 32%: True

Result: reproduced. Rate-normalized trains give 84.5% (within tolerance of 80%). Time-scrambled trains give 32.7%, not above chance by the fraction of repeats (p = 0.060, reading a), so the scrambled decoder meets reading (a) of "abolished" under that test; it is not below 32% (reading b), and the binomial test finds it above chance. With C by cross-validation, 69.0% (outside tolerance) and 22.7%.

fig9f-choice-decoder¶

A choice decoder from Slow units predicted drink port choice at 65% (chance 50%) from a single 150-ms bin or from the last 100 ms before nose poke withdrawal, while one from Fast and Medium units could not predict choice.

Training weights each choice equally (an assumption: the Methods sum the probabilities and give chance as 50%, which an unweighted fit on a side-biased rat does not give); the unweighted fit is shown as a variant.

In [9]:
CH = {}
def runc(name, units, kind, reps=300, seed=0, balanced=True, cv=False):
    t0 = time.time()
    res, ua = ssc4.choice_decoder(D, units, kind, repeats=reps, seed=seed, balanced=balanced, cv=cv)
    tab = pd.DataFrame(res, index=["i equal draws", "ii data proportions"]).T.loc[ORDER] * 100
    a_i, a_ii = tab.iloc[:, 0].mean(), tab.iloc[:, 1].mean()
    allt = D.trials[D.trials.complete & D.trials.session.isin(U.session[units].unique())]
    w = allt.groupby("stim").size()
    p_i = (tab.iloc[:, 0] * w.loc[ORDER]).sum() / w.sum()
    p_ii = (tab.iloc[:, 1] * w.loc[ORDER]).sum() / w.sum()
    CH[name] = dict(tab=tab, ua=ua, units=units, a_i=a_i, a_ii=a_ii, pooled_i=p_i, pooled_ii=p_ii)
    print("%s: %d repeats; mean over sequences (a): draws i %.1f%%, ii %.1f%%; pooled over trials (b): i %.1f%%, ii %.1f%%  (%.0f s)"
          % (name, reps, a_i, a_ii, p_i, p_ii, time.time() - t0))
    print(tab.round(1).T.to_string())
runc("Slow 1bin", SL, "1bin", seed=51)
runc("Slow pre100", SL, "pre100", seed=52)
runc("FM 1bin", FM, "1bin", seed=53)
runc("FM pre100", FM, "pre100", seed=54)
runc("Slow 1bin, C by CV (reading b)", SL, "1bin", reps=10, seed=55, cv=True)
runc("Slow pre100, C by CV (reading b)", SL, "pre100", reps=10, seed=56, cv=True)
runc("FM 1bin, C by CV (reading b)", FM, "1bin", reps=10, seed=57, cv=True)
runc("FM pre100, C by CV (reading b)", FM, "pre100", reps=10, seed=58, cv=True)
runc("variant: Slow pre100, unweighted training", SL, "pre100", reps=50, seed=59, balanced=False)
runc("variant: FM pre100, unweighted training", FM, "pre100", reps=50, seed=60, balanced=False)
runc("variant: Slow pre100, recomputed set (a)", SLa, "pre100", reps=100, seed=61)
runc("variant: FM pre100, recomputed set (a)", FMa, "pre100", reps=100, seed=62)
print("\nchance: 50% under draws i; under draws ii, the majority choice of each sequence gives",
      {s: round(100 * max(p, 1 - p), 1) for s, p in D.trials[D.trials.complete].groupby("stim").chosen.mean().items()})
print("\nAccuracy against the number of units (asked by the verifier): random subsets of the units, 5 subsets of each size, 20 repeats each, equal draws (i), mean over sequences")
rng_n = np.random.default_rng(63)
rows = []
for nm, units, kind in [("Slow pre100", SL, "pre100"), ("Slow 1bin", SL, "1bin"), ("FM pre100", FM, "pre100"), ("FM 1bin", FM, "1bin")]:
    for n in [1, 2, 5, 10, 20, 50, len(units)]:
        accs = []
        for k in range(5 if n < len(units) else 1):
            sub = rng_n.choice(units, n, replace=False)
            res, _ = ssc4.choice_decoder(D, sub, kind, repeats=20, seed=int(rng_n.integers(1 << 30)))
            accs.append(100 * np.mean([v[0] for v in res.values()]))
        rows.append(dict(decoder=nm, n_units=n, mean_acc=np.mean(accs), min_acc=np.min(accs), max_acc=np.max(accs)))
print(pd.DataFrame(rows).round(1).to_string(index=False))
print("\nSingle-unit balanced choice accuracy (each unit's own classifier on its test trials, 300 repeats), percent:")
for nm in ["Slow pre100", "FM pre100", "Slow 1bin", "FM 1bin"]:
    a = 100 * CH[nm]["ua"]
    print("%-12s n = %d, mean %.1f, median %.1f, 90th percentile %.1f, max %.1f; units above 55%%: %d" % (nm, len(a), a.mean(), np.median(a), np.percentile(a, 90), a.max(), (a > 55).sum()))
Slow 1bin: 300 repeats; mean over sequences (a): draws i 80.8%, ii 81.3%; pooled over trials (b): i 80.7%, ii 81.2%  (22 s)
                      FFF   FMS   SMF   SSS
i equal draws        86.4  79.4  71.1  86.4
ii data proportions  85.7  79.0  72.3  88.1
Slow pre100: 300 repeats; mean over sequences (a): draws i 92.9%, ii 93.3%; pooled over trials (b): i 92.9%, ii 93.3%  (23 s)
                      FFF   FMS   SMF   SSS
i equal draws        94.0  91.9  92.6  93.0
ii data proportions  93.8  91.9  92.7  94.6
FM 1bin: 300 repeats; mean over sequences (a): draws i 71.3%, ii 74.4%; pooled over trials (b): i 71.2%, ii 74.4%  (47 s)
                      FFF   FMS   SMF   SSS
i equal draws        72.4  80.2  56.6  75.8
ii data proportions  75.9  80.3  59.1  82.2
FM pre100: 300 repeats; mean over sequences (a): draws i 81.9%, ii 82.5%; pooled over trials (b): i 81.9%, ii 82.5%  (47 s)
                      FFF   FMS   SMF   SSS
i equal draws        79.7  86.3  74.4  87.4
ii data proportions  80.4  87.4  73.7  88.6
Slow 1bin, C by CV (reading b): 10 repeats; mean over sequences (a): draws i 72.8%, ii 72.6%; pooled over trials (b): i 72.8%, ii 72.6%  (5 s)
                      FFF   FMS   SMF   SSS
i equal draws        81.8  73.5  71.3  64.6
ii data proportions  80.1  73.1  71.7  65.6
Slow pre100, C by CV (reading b): 10 repeats; mean over sequences (a): draws i 75.8%, ii 76.3%; pooled over trials (b): i 75.8%, ii 76.3%  (5 s)
                      FFF   FMS   SMF   SSS
i equal draws        83.9  69.7  76.5  73.0
ii data proportions  81.1  69.8  77.1  77.2
FM 1bin, C by CV (reading b): 10 repeats; mean over sequences (a): draws i 65.3%, ii 68.4%; pooled over trials (b): i 65.3%, ii 68.4%  (10 s)
                      FFF   FMS   SMF   SSS
i equal draws        64.6  73.9  54.9  67.8
ii data proportions  68.0  74.4  57.6  73.6
FM pre100, C by CV (reading b): 10 repeats; mean over sequences (a): draws i 76.2%, ii 76.4%; pooled over trials (b): i 76.2%, ii 76.4%  (10 s)
                      FFF   FMS   SMF   SSS
i equal draws        69.2  77.6  72.0  85.9
ii data proportions  70.9  78.9  70.6  85.3
variant: Slow pre100, unweighted training: 50 repeats; mean over sequences (a): draws i 53.6%, ii 56.0%; pooled over trials (b): i 53.6%, ii 56.0%  (4 s)
                      FFF   FMS   SMF   SSS
i equal draws        55.1  55.0  52.4  52.0
ii data proportions  41.2  57.2  57.0  68.6
variant: FM pre100, unweighted training: 50 repeats; mean over sequences (a): draws i 50.0%, ii 54.1%; pooled over trials (b): i 50.0%, ii 54.2%  (8 s)
                      FFF   FMS   SMF   SSS
i equal draws        50.0  50.0  50.0  50.0
ii data proportions  36.7  55.1  56.8  67.6
variant: Slow pre100, recomputed set (a): 100 repeats; mean over sequences (a): draws i 92.0%, ii 92.2%; pooled over trials (b): i 92.0%, ii 92.2%  (8 s)
                      FFF   FMS   SMF   SSS
i equal draws        91.9  90.0  93.0  93.1
ii data proportions  91.5  89.8  93.1  94.3
variant: FM pre100, recomputed set (a): 100 repeats; mean over sequences (a): draws i 78.3%, ii 79.4%; pooled over trials (b): i 78.3%, ii 79.3%  (16 s)
                      FFF   FMS   SMF   SSS
i equal draws        75.4  89.3  70.0  78.6
ii data proportions  75.9  89.9  69.2  82.5

chance: 50% under draws i; under draws ii, the majority choice of each sequence gives {'FFF': 63.0, 'FMS': 54.4, 'SMF': 55.4, 'SSS': 67.1}

Accuracy against the number of units (asked by the verifier): random subsets of the units, 5 subsets of each size, 20 repeats each, equal draws (i), mean over sequences
    decoder  n_units  mean_acc  min_acc  max_acc
Slow pre100        1      52.1     43.4     59.1
Slow pre100        2      53.3     45.3     60.1
Slow pre100        5      61.6     53.0     77.6
Slow pre100       10      60.4     53.5     68.2
Slow pre100       20      74.2     71.5     78.6
Slow pre100       50      86.4     82.1     91.0
Slow pre100       97      93.2     93.2     93.2
  Slow 1bin        1      49.7     46.0     52.5
  Slow 1bin        2      57.1     45.8     74.5
  Slow 1bin        5      55.0     48.0     62.3
  Slow 1bin       10      59.1     52.9     64.6
  Slow 1bin       20      65.5     57.3     72.5
  Slow 1bin       50      72.0     70.4     74.4
  Slow 1bin       97      82.1     82.1     82.1
  FM pre100        1      54.4     45.9     61.5
  FM pre100        2      51.9     49.4     56.5
  FM pre100        5      53.9     49.4     61.2
  FM pre100       10      54.3     45.5     61.2
  FM pre100       20      60.9     53.9     69.6
  FM pre100       50      65.0     57.8     69.2
  FM pre100      213      81.0     81.0     81.0
    FM 1bin        1      53.3     44.1     61.0
    FM 1bin        2      49.9     43.8     55.4
    FM 1bin        5      57.0     45.4     64.1
    FM 1bin       10      54.4     52.2     56.9
    FM 1bin       20      55.7     48.1     63.5
    FM 1bin       50      60.9     56.8     64.6
    FM 1bin      213      72.6     72.6     72.6

Single-unit balanced choice accuracy (each unit's own classifier on its test trials, 300 repeats), percent:
Slow pre100  n = 97, mean 54.9, median 54.0, 90th percentile 62.5, max 81.0; units above 55%: 43
FM pre100    n = 213, mean 52.1, median 51.3, 90th percentile 59.0, max 71.4; units above 55%: 60
Slow 1bin    n = 97, mean 52.2, median 50.8, 90th percentile 59.3, max 75.1; units above 55%: 26
FM 1bin      n = 213, mean 51.3, median 49.8, 90th percentile 57.6, max 71.0; units above 55%: 47

Result: not reproduced. The Slow choice decoder predicts choice far better than 65%: 80.8% from the 150-ms bin and 92.9% from the 100 ms before withdrawal (equal draws, mean over sequences; about 73% and 76% with C by cross-validation), and the Fast/Medium decoder is not unable (71.3% and 81.9%; about 65% and 76% with cross-validation). Trained without balancing the two choices, both decoders fall to 50 to 56%, Slow included. None of the readings gives Slow at 65% with Fast/Medium near 50%. The cross-validated values change by 0.1 point between runs with the same seeds, so they are given rounded. Accuracy grows with the number of units summed: random sets of 20 Slow units give 74.2% (pre-withdrawal) and 65.5% (150-ms bin), and of 20 Fast/Medium units 60.9% and 55.7%, while single units average 54.9% (Slow) and 52.1% (Fast/Medium) alone. So the gap from the paper may come from how many units entered each prediction, which the Methods do not say.

fig9g-l5b-slow-positive-best-choice¶

The units with the best choice prediction were Slow Positive units located primarily in L5b.

Each Slow unit's own classifier on its test trials, one 100-ms bin before withdrawal, scored as balanced accuracy (mean of right and left hit rates) so that chance is 50%, a standard choice.

In [10]:
r = CH["Slow pre100"]
ua = pd.DataFrame(dict(acc=100 * r["ua"], layer=U.layer[r["units"]].values, cls=U.cls[r["units"]].values))
g = ua.groupby(["layer", "cls"]).acc.agg(["mean", "size"]).round(1)
print(g.to_string())
print("group with the highest mean:", g["mean"].idxmax(), "| among groups with at least 3 units:", g[g["size"] >= 3]["mean"].idxmax())
top = ua.nlargest(int(np.ceil(0.1 * len(ua))), "acc")
print("top 10%% (%d units): %s; L5b Slow Positive: %d" % (len(top), collections.Counter(zip(top.layer, top.cls)).most_common(),
      int(((top.layer == "L5b") & (top.cls == "SlowPos")).sum())))
print("total run time of this notebook so far: %.1f min" % ((time.time() - t_start) / 60))
               mean  size
layer cls                
L2/3  SlowNeg  51.6     4
      SlowPos  48.8     1
L4    SlowNeg  50.1     3
      SlowPos  52.6     5
L5a   SlowNeg  49.8    12
      SlowPos  57.1     7
L5b   SlowNeg  56.5    12
      SlowPos  60.3    14
L6    SlowNeg  54.2    15
      SlowPos  54.9    24
group with the highest mean: ('L5b', 'SlowPos') | among groups with at least 3 units: ('L5b', 'SlowPos')
top 10% (10 units): [(('L5b', 'SlowPos'), 4), (('L6', 'SlowPos'), 2), (('L5a', 'SlowPos'), 2), (('L5b', 'SlowNeg'), 1), (('L6', 'SlowNeg'), 1)]; L5b Slow Positive: 4
total run time of this notebook so far: 16.8 min

Result: reproduced. L5b Slow Positive units have the highest mean single-unit choice accuracy (60.3%, 14 units; next L5a Slow Positive 57.1%, L5b Slow Negative 56.5%), and 4 of the 10 top-ranked units are L5b Slow Positive, the largest group but not more than half.

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
fig9b-stimulus-decoder-fast-medium reproduced
fig9c-best-units-short-windows reproduced
fig9b-stimulus-decoder-slow-chance partially reproduced (33.9%, but above chance)
fig9d-single-bin-decoder partially reproduced (38.2%, 0.5 points below tolerance)
fig9e-temporal-pattern-decoding reproduced
fig9f-choice-decoder not reproduced
fig9g-l5b-slow-positive-best-choice reproduced

How the analysis differs from the paper's: the units are the data set's modulated units and its classes (213 Fast/Medium, 97 Slow) from all 506 deposited units, not the paper's 473; the population decoder draws 100 pseudo-trials per class per repeat; the cross-validated penalty (reading b) is run with 5 to 10 repeats; the choice decoder weights the two choices equally in training (an assumption), as the unweighted fit predicts one side for every trial.