Reproducing Bruno, Frost & Humphries (2017) from CRCNS data set apl-1¶
Paper. Bruno AM, Frost WN, Humphries MD (2017). A spiral attractor network drives rhythmic locomotion. eLife 6:e27342. doi:10.7554/elife.27342. The claims file was written from the version of record (PMC5546814): main text, Materials and methods and all figure legends and supplement legends.
Data set. CRCNS apl-1, doi:10.6080/K0SN074B, streamed from
the public bucket crcnsarchive under apl-1/live/. Version: unversioned. CRCNS data sets carry
no versions (docs/archives.md), and the bucket holds one copy of the processed files (live/; the
orig/ folder holds only one raw optical file). That copy is pinned by the MD5 sums printed in the
data check, which match the data set's checksums.md5. The paper cites the data set's DOI and no
version. Files read: FileTable.mat, SpikeData.mat, ExtracellularData.mat, Coordinates.mat and
diode_template.mat; the 6.9 GB raw optical archive is not needed.
Method. The claims file decides what is tested. Where it leaves a detail open, the detail is
taken from the paper's Methods or from its code (github.com/mdhumphries/AplysiaAttractorAnalysis at
commit e5f28e98), cited in apl.py. Two details recur in almost every claim: the width of the
Gaussian kernel and the rule for the number of PCs. Each is run under every reading the criteria
list. Where one reading has to be chosen, the adopted reading is own/min80: the median ISI of the
recording, after onset, as the kernel SD, and the smallest number of PCs reaching 80% of the
variance. This follows the order of the protocol: the Methods first ("at least 80% of the
variance"; the median ISI "in population", the recording), then the code (its width, the median ISI,
where the printed width cannot give the paper's counts). No single reading makes every claim that
depends on it hold; the Summary lists, for each claim whose outcome changes with the reading, the
result under each. Outcomes that rest on the choice are marked as assumed in the record.
Revision after verification round 1. The conclusions were restored (the first build left them out); windows count as coalesced and recurrent at at least 90%, as the Methods say; the decoding of fig6d was run under all four readings and the 90% models of fig6s2 with the full history grid; fig7gh was run under all four readings, with participation under each width; fig7s2 was tested with a port of the code's ensemble toolbox; fig1d, fig3a, fig4bc and fig8 gained the outputs the verifier asked for.
Revision after verification round 2. Text the numbers did not support was corrected (the dimension ranges of the printed widths, the consistency of fig4c's means, the exclusion rule in fig7gh); the code's removal rule of fig3h under the adopted reading is now stated; a printout of the decoding forecasts that diverge was added, with a test of their sensitivity to rounding. The record proposes a change of fig6d's outcome to not reproduced, for a third verification round.
Revision after verification round 3. The verifier agreed with the change, and fig6d is now not reproduced. Its conclusion, and fig6s2's, now give the numbers of this execution: the decoding is not exactly the same in every execution (fig6d), and the earlier prose described another one.
| Claim | Tested or blocked |
|---|---|
| dataset-size, fig1d-slow-oscillation, fig1e-decaying-rate, fig2b-dimensions | tested |
| fig2ef-periodic-recurrence, fig2e-single-dominant-orbit, fig2s2-threshold-robust, fig3a-coalescence | tested |
| fig3c-same-manifold, fig3s1a-common-axes, fig3d-initial-conditions, fig3f-pairwise-similarity | tested |
| fig3h-perturbations-return, fig3i-same-manifold-after | tested |
| fig4bc-stable-spiral, fig4c-orbital-period, fig4s1a-contracting-dimensions, fig4s1b-rotation-dominant | tested |
| fig5b-period-changes, fig5c-no-relation-contraction | tested |
| fig6s1-no-p10-motorneurons, fig6d-decode-p10, fig6s2-dimensions-p10 | tested |
| fig7a-long-tailed-participation, fig7f-strongly-variable-neurons, halving-participation, fig7s1-rate-synchrony, fig7gh-robust-to-participation | tested |
| fig7s2-no-invariant-core | tested (Python port of the code's ensemble toolbox) |
| fig8-caudolateral | blocked: metadata insufficient (orientation of the array not given) |
import os
os.environ.setdefault("OMP_NUM_THREADS", "1")
os.environ.setdefault("OPENBLAS_NUM_THREADS", "1")
import time
import resource
import warnings
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
from scipy import stats
import apl
warnings.filterwarnings("ignore", category=RuntimeWarning)
pd.set_option("display.width", 220)
pd.set_option("display.max_columns", 40)
pd.set_option("display.max_rows", 200)
started = time.time()
D = apl.load()
recs, preps = D["recs"], D["preps"]
print(f"CRCNS data set {apl.DATASET}, version {apl.VERSION}; read {len(D['md5'])} files from {apl.BUCKET} "
f"in {time.time() - started:.0f} s")
CRCNS data set apl-1, version unversioned; read 5 files from https://crcnsarchive.s3-us-west-2.amazonaws.com/apl-1/live/ in 2 s
Data check¶
Each check of the description against the values is stated under its output.
print("MD5 of each file read, against the data set's checksums.md5:")
for name, h in D["md5"].items():
print(f" {name:24s} {h} {'matches' if D['listed_md5'].get(name) == h else 'DIFFERS from ' + str(D['listed_md5'].get(name))}")
info = pd.DataFrame([{
"prep": r["prep"], "bout": r["bout"], "file": r["file"], "Bout_field": r["Bout_field"],
"neurons": int(np.unique(r["ids"]).size), "max_id": int(r["ids"].max()),
"spikes": r["t"].size, "first_spike_s": r["t"].min().round(3), "last_spike_s": r["t"].max().round(2),
"neurons_spiking_after_30s": int(np.unique(r["ids"][r["t"] >= 30]).size)} for r in recs])
print("\nRecordings per preparation:", info.groupby("prep").size().to_dict())
print(info.to_string(index=False))
pt = pd.DataFrame(preps)
pt["neurons_in_spikes"] = [int(info[info.prep == p].neurons.iloc[0]) for p in pt.prep]
pt["coord_points"] = [c["x"].size for c in D["coords"]]
pt["coord_file"] = [c["file"] for c in D["coords"]]
pt["coord_ganglion"] = [c["ganglion"] for c in D["coords"]]
print("\nFileTable.mat against the spike and coordinate files:")
print(pt.to_string(index=False))
print("\nNeurons per preparation: min", pt.n_neurons_table.min(), "max", pt.n_neurons_table.max(),
"total", pt.n_neurons_table.sum(), "(description: 75 to 160, 1131 in total)")
print("Same neuron count in all three bouts of every preparation:",
bool(info.groupby("prep").neurons.nunique().eq(1).all()))
MD5 of each file read, against the data set's checksums.md5:
FileTable.mat 27437d5d4063cd9827f1f1ffa67f36d4 matches
SpikeData.mat 8657665316d5006677891922bdd0a1d8 matches
ExtracellularData.mat d01451b227a6c4a0dc2a620bd9bbbcf9 matches
Coordinates.mat 53a98c4b9f2a35be299180699321ad16 matches
diode_template.mat a94b5040b265b276e2b0ef684277f2ad matches
Recordings per preparation: {1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3, 7: 3, 8: 3, 9: 3, 10: 3}
prep bout file Bout_field neurons max_id spikes first_spike_s last_spike_s neurons_spiking_after_30s
1 1 Jun0214da01.mat 1 136 136 23681 0.021 122.72 136
1 2 Jun0214da02.mat 2 136 136 25768 0.001 122.72 136
1 3 Jun0214da03.mat 3 136 136 27178 0.018 122.72 136
2 1 Jun0414Bda01.mat 1 105 105 13961 0.102 122.72 105
2 2 Jun0414Bda02.mat 2 105 105 13846 0.010 122.71 105
2 3 Jun0414Bda03.mat 3 105 105 18927 0.009 122.70 105
3 1 Jun0514da01.mat 1 160 160 22144 0.019 122.69 160
3 2 Jun0514da02.mat 2 160 160 23086 0.023 122.72 160
3 3 Jun0514da03.mat 3 160 160 26478 0.020 122.72 160
4 1 Jun0914da01.mat 1 151 151 18801 0.019 122.72 151
4 2 Jun0914da02.mat 2 151 151 22496 0.011 122.72 151
4 3 Jun0914da03.mat 3 151 151 23191 0.010 122.72 151
5 1 Jun1114da01.mat 1 94 94 18573 0.003 122.72 94
5 2 Jun1114da02.mat 2 94 94 17820 0.017 122.72 94
5 3 Jun1114da03.mat 3 94 94 20477 0.099 122.71 94
6 1 May2214da01.mat 1 121 121 22991 0.037 122.70 121
6 2 May2214da02.mat 2 121 121 23682 0.021 122.72 121
6 3 May2214da03.mat 3 121 121 27421 0.006 122.72 121
7 1 Nov0514da01.mat 1 75 75 13075 0.003 122.72 75
7 2 Nov0514da02.mat 2 75 75 12410 0.039 122.70 75
7 3 Nov0514da03.mat 3 75 75 16355 0.025 122.71 75
8 1 Oct1514da01.mat 1 102 102 20600 0.021 122.70 102
8 2 Oct1514da02.mat 2 102 102 16840 0.002 122.72 102
8 3 Oct1514da03.mat 3 102 102 20984 0.005 122.72 102
9 1 Sep2414da01.mat 1 104 104 19797 0.002 122.72 104
9 2 Sep2414da02.mat 2 104 104 18700 0.007 122.72 104
9 3 Sep2414da03.mat 3 104 104 16796 0.001 122.72 104
10 1 Sep2914da01.mat 1 83 83 10892 0.072 122.72 83
10 2 Sep2914da02.mat 2 83 83 10977 0.042 122.71 83
10 3 Sep2914da03.mat 3 83 83 13283 0.032 122.72 83
FileTable.mat against the spike and coordinate files:
prep file name side n_neurons_table p10_bouts neurons_in_spikes coord_points coord_file coord_ganglion
1 Jun0214da01.mat Jun0214 Left 136 [] 136 136 Jun0214.mat Left
2 Jun0414Bda01.mat Jun0414B Left 105 [1, 2, 3] 105 105 Jun0414B.mat Left
3 Jun0514da01.mat Jun0514 Right 160 [] 160 160 Jun0514.mat Right
4 Jun0914da01.mat Jun0914 Left 151 [1, 2, 3] 151 151 Jun0914.mat Left
5 Jun1114da01.mat Jun1114 Right 94 [1, 2, 3] 94 94 Jun1114.mat Right
6 May2214da01.mat May2214 Right 121 [] 121 121 May2214.mat Right
7 Nov0514da01.mat Nov0514 unreliable coordinates 75 [] 75 75 Nov0514.mat statistically unreliable
8 Oct1514da01.mat Oct1514 unreliable coordinates 102 [] 102 102 Oct1514.mat statistically unreliable
9 Sep2414da01.mat Sep2414 Right 104 [] 104 104 Sep2414.mat Right
10 Sep2914da01.mat Sep2914 Left 83 [] 83 83 Sep2914.mat Left
Neurons per preparation: min 75 max 160 total 1131 (description: 75 to 160, 1131 in total)
Same neuron count in all three bouts of every preparation: True
The data set holds 30 recordings, three bouts in each of 10 preparations, in the order of
FileTable.mat, which the description says is the paper's numbering. Every neuron id from 1 to N is
present in every bout of its preparation, and every neuron spikes after 30 s. The spike files carry
no bout number (Bout is empty); the bout is read from the file name (da01, da02, da03). The
neuron counts of FileTable.mat match the spike files and the coordinate files. The MD5 sums printed
above are the version pinned (CRCNS data sets are not versioned).
# Units, ranges, the clock of the stimulus, and recordings deposited twice.
rows = []
for r in recs:
t = r["t"]
pre = np.sum((t >= 25) & (t < 30)) / 5
stim = np.sum((t >= 30) & (t < 32.5)) / 2.5
post = np.sum((t >= 32.5) & (t < 37.5)) / 5
rows.append({"file": r["file"], "pop_rate_25_30": round(pre, 1), "pop_rate_30_32.5": round(stim, 1),
"pop_rate_32.5_37.5": round(post, 1)})
clock = pd.DataFrame(rows)
print("Population spike rate (spikes/s) before, during and after the stimulus at 30 to 32.5 s:")
print(clock.to_string(index=False))
print("Recordings whose rate after 32.5 s exceeds that before 30 s:",
int((clock["pop_rate_32.5_37.5"] > clock["pop_rate_25_30"]).sum()), "of", len(clock))
# P10 nerve recordings
rows = []
for q in D["p10"]:
t = q["t"]
rows.append({"file": q["file"], "prep": q["prep"], "bout": q["bout"], "spikes": t.size,
"ids": np.unique(q["ids"]).tolist(), "time_sorted": q["sorted"],
"range_s": f"{t.min():.2f} to {t.max():.2f}",
"min_interval_ms": round(np.diff(t).min() * 1000, 3),
"rate_25_30": round(np.sum((t >= 25) & (t < 30)) / 5, 1),
"rate_32.5_37.5": round(np.sum((t >= 32.5) & (t < 37.5)) / 5, 1)})
print("\nP10 recordings:")
print(pd.DataFrame(rows).to_string(index=False))
print("Smallest P10 interval as a sampling period: 1 /", round(1 / np.diff(D["p10"][0]["t"]).min(), 1), "Hz")
# duplicate recordings: identical spike trains between any two recordings
sig = {}
for r in recs:
for i, tr in enumerate(apl.neuron_trains(r)):
if tr.size > 5:
sig.setdefault(tuple(np.round(tr, 4)), []).append((r["file"], i + 1))
dup = [v for v in sig.values() if len(v) > 1]
print("\nNeuron spike trains (more than 5 spikes) found identical in two places:", len(dup), dup[:5])
whole = {}
for r in recs:
whole.setdefault((r["t"].size, round(float(r["t"].sum()), 3)), []).append(r["file"])
print("Recordings with identical spike counts and sums:", [v for v in whole.values() if len(v) > 1])
pd10 = {}
for q in D["p10"]:
pd10.setdefault((q["t"].size, round(float(q["t"].sum()), 3)), []).append(q["file"])
print("P10 recordings deposited twice:", [v for v in pd10.values() if len(v) > 1])
Population spike rate (spikes/s) before, during and after the stimulus at 30 to 32.5 s:
file pop_rate_25_30 pop_rate_30_32.5 pop_rate_32.5_37.5
Jun0214da01.mat 163.8 581.6 229.6
Jun0214da02.mat 149.0 532.4 274.4
Jun0214da03.mat 189.2 575.2 283.6
Jun0414Bda01.mat 83.2 238.0 179.6
Jun0414Bda02.mat 99.4 282.0 149.8
Jun0414Bda03.mat 84.0 323.2 231.4
Jun0514da01.mat 64.8 615.6 356.2
Jun0514da02.mat 56.4 647.6 418.0
Jun0514da03.mat 147.6 645.6 377.0
Jun0914da01.mat 144.4 598.4 343.2
Jun0914da02.mat 110.8 506.8 337.6
Jun0914da03.mat 113.6 538.0 368.4
Jun1114da01.mat 106.2 420.0 251.0
Jun1114da02.mat 114.2 402.4 250.4
Jun1114da03.mat 69.2 400.4 265.8
May2214da01.mat 44.6 412.0 288.8
May2214da02.mat 74.8 500.8 344.6
May2214da03.mat 119.0 454.8 360.6
Nov0514da01.mat 63.6 269.2 166.6
Nov0514da02.mat 77.2 292.8 172.4
Nov0514da03.mat 80.4 354.0 242.2
Oct1514da01.mat 70.8 405.6 263.8
Oct1514da02.mat 44.4 350.4 225.4
Oct1514da03.mat 92.8 406.8 234.8
Sep2414da01.mat 83.4 362.0 215.2
Sep2414da02.mat 103.2 401.2 210.0
Sep2414da03.mat 135.0 343.2 177.0
Sep2914da01.mat 23.2 270.4 183.0
Sep2914da02.mat 56.6 248.8 161.6
Sep2914da03.mat 60.8 250.0 173.8
Recordings whose rate after 32.5 s exceeds that before 30 s: 30 of 30
P10 recordings:
file prep bout spikes ids time_sorted range_s min_interval_ms rate_25_30 rate_32.5_37.5
Jun0414da01p10.mat 2 1 5902 [1.0] True 4.25 to 122.63 0.614 20.8 86.6
Jun0414da02p10.mat 2 2 16374 [1.0] True 0.48 to 122.65 0.614 54.6 244.2
Jun0414da03p10.mat 2 3 9538 [1.0] True 0.06 to 122.67 0.614 33.0 193.2
Jun0914da01p10.mat 4 1 14904 [1.0] True 0.27 to 122.25 0.614 116.6 410.2
Jun0914da02p10.mat 4 2 13337 [1.0] True 1.19 to 122.66 0.614 68.2 231.8
Jun0914da03p10.mat 4 3 9637 [1.0] True 0.44 to 119.81 0.614 30.2 219.2
Jun1114da01p10.mat 5 1 4257 [1.0] True 0.71 to 122.59 0.614 7.6 80.0
Jun1114da02p10.mat 5 2 6552 [1.0] True 0.37 to 122.71 0.614 26.2 129.6
Jun1114da03p10.mat 5 3 8757 [1.0] True 0.34 to 122.63 0.614 19.8 217.6
Smallest P10 interval as a sampling period: 1 / 1629.7 Hz
Neuron spike trains (more than 5 spikes) found identical in two places: 0 []
Recordings with identical spike counts and sums: []
P10 recordings deposited twice: []
# Is the P10 nerve on the clock of the population? Cross-correlation of 1 s binned rates after the
# stimulus, against the same with the P10 series shifted by a random amount (circularly).
rng = np.random.default_rng(11)
rows = []
for q in D["p10"]:
r = next(r for r in recs if r["prep"] == q["prep"] and r["bout"] == q["bout"])
edges = np.arange(33, 122, 0.5)
pop = np.histogram(r["t"], edges)[0].astype(float)
nerve = np.histogram(q["t"], edges)[0].astype(float)
lags = np.arange(-10, 11)
cc = [np.corrcoef(np.roll(pop, l), nerve)[0, 1] for l in lags]
shuffled = [np.corrcoef(np.roll(pop, int(rng.integers(20, len(pop) - 20))), nerve)[0, 1] for _ in range(200)]
rows.append({"file": q["file"], "peak_lag_s": lags[int(np.nanargmax(np.abs(cc)))] * 0.5,
"r_at_lag_0": round(cc[10], 3), "max_abs_r": round(np.nanmax(np.abs(cc)), 3),
"shifted_95pct_abs_r": round(np.nanpercentile(np.abs(shuffled), 95), 3)})
print("Population rate against P10 rate, 0.5 s bins from 33 s, lags of -5 to 5 s:")
print(pd.DataFrame(rows).to_string(index=False))
# Are neuron ids the same neurons across bouts? Per-neuron rates after onset, correlated between
# bouts of a preparation, against the same with the ids permuted.
rows = []
for p in range(1, 11):
rs = [np.array([np.sum(tr >= 30) for tr in apl.neuron_trains(r)]) for r in recs if r["prep"] == p]
for a, b in apl.PAIRS:
rho = stats.spearmanr(rs[a], rs[b])[0]
null = [stats.spearmanr(rs[a], rng.permutation(rs[b]))[0] for _ in range(200)]
rows.append({"prep": p, "pair": f"{a + 1},{b + 1}", "spearman": round(rho, 3),
"permuted_95pct": round(np.percentile(null, 95), 3)})
idt = pd.DataFrame(rows)
print("\nRank correlation of neurons' post-onset spike counts between bouts (same id):")
print(idt.pivot(index="prep", columns="pair", values="spearman").to_string())
print("Pairs above the 95th percentile of permuted ids:", int((idt.spearman > idt.permuted_95pct).sum()), "of", len(idt))
Population rate against P10 rate, 0.5 s bins from 33 s, lags of -5 to 5 s:
file peak_lag_s r_at_lag_0 max_abs_r shifted_95pct_abs_r
Jun0414da01p10.mat 1.5 0.532 0.572 0.369
Jun0414da02p10.mat 3.5 0.457 0.635 0.327
Jun0414da03p10.mat 1.0 0.451 0.493 0.328
Jun0914da01p10.mat 4.5 0.433 0.492 0.436
Jun0914da02p10.mat 5.0 -0.167 0.553 0.291
Jun0914da03p10.mat 4.0 0.360 0.454 0.255
Jun1114da01p10.mat 4.0 0.111 0.404 0.422
Jun1114da02p10.mat 1.5 0.358 0.431 0.458
Jun1114da03p10.mat 0.0 0.540 0.540 0.263
Rank correlation of neurons' post-onset spike counts between bouts (same id): pair 1,2 1,3 2,3 prep 1 0.958 0.897 0.926 2 0.910 0.751 0.838 3 0.943 0.864 0.928 4 0.785 0.817 0.721 5 0.963 0.625 0.639 6 0.952 0.721 0.827 7 0.948 0.830 0.906 8 0.893 0.786 0.766 9 0.888 0.754 0.840 10 0.897 0.857 0.883 Pairs above the 95th percentile of permuted ids: 30 of 30
# Coordinates: units and ranges, against the 501 x 501 diode template (plot_maps.m plots x*10, y*10)
for c, p in zip(D["coords"], preps):
print(f"prep {p['prep']:2d} {c['file']:14s} {c['ganglion']:24s} n={c['x'].size:3d} x {np.nanmin(c['x']):5.1f} to {np.nanmax(c['x']):5.1f} "
f"y {np.nanmin(c['y']):5.1f} to {np.nanmax(c['y']):5.1f} missing {int(np.isnan(c['x']).sum())}")
tpl = D["template"]
ys, xs = np.nonzero(tpl)
print("Diode template", tpl.shape, "nonzero x", xs.min(), "to", xs.max(), "y", ys.min(), "to", ys.max())
prep 1 Jun0214.mat Left n=136 x 6.6 to 45.7 y 1.0 to 49.0 missing 0 prep 2 Jun0414B.mat Left n=105 x 4.6 to 41.6 y 1.7 to 48.4 missing 0 prep 3 Jun0514.mat Right n=160 x 5.4 to 46.1 y 1.0 to 49.0 missing 0 prep 4 Jun0914.mat Left n=151 x 5.3 to 43.7 y 1.0 to 48.8 missing 0 prep 5 Jun1114.mat Right n= 94 x 11.4 to 45.0 y 3.2 to 44.3 missing 0 prep 6 May2214.mat Right n=121 x 7.3 to 43.9 y 5.3 to 48.4 missing 0 prep 7 Nov0514.mat statistically unreliable n= 75 x 4.9 to 40.0 y 3.4 to 49.0 missing 5 prep 8 Oct1514.mat statistically unreliable n=102 x 8.5 to 43.5 y 1.0 to 45.6 missing 0 prep 9 Sep2414.mat Right n=104 x 5.0 to 43.1 y 5.4 to 48.4 missing 0 prep 10 Sep2914.mat Left n= 83 x 7.5 to 42.8 y 3.6 to 49.0 missing 0 Diode template (501, 501) nonzero x 20 to 480 y 0 to 480
Checks of the description against the data. Consistent with the description: 30
recordings, three per preparation; 75 to 160 neurons per preparation, 1131 in all; the stimulus at
30 to 32.5 s (in every recording the population rate during the stimulus exceeds the rate before it, and
the rate after 32.5 s exceeds the rate before 30 s in 30 of 30); recordings end at
122.7 s; P10 spikes in nine recordings of preparations 2, 4 and 5 (FileTable lists bouts 1 to 3 for
those three). The P10 intervals are multiples of 0.614 ms, a sampling rate of 1629.7 Hz, which
agrees with the description's 1630 Hz and not with the paper's 1600 Hz. The P10 files of
preparation 2 are named Jun0414, its spike file Jun0414B; they are matched on the first seven
characters, as the code does. No neuron spike train and no recording appears twice.
The P10 rate and the population rate are correlated after the stimulus at lags of 0 to 5 s in every P10 recording; in 7 of 9 the largest correlation exceeds the 95th percentile of circularly shifted series. This is consistent with a shared clock; the lag of a few seconds is expected for a nerve that fires in one phase of a 10 s cycle, so it does not show the clocks agree to better than a few seconds. In Jun1114da01 and Jun1114da02 the check does not separate the data from shifted series.
The description says the recordings were concatenated before spike sorting, so that a neuron id names the same neuron in all three bouts. Consistent with this, per-neuron spike counts after onset correlate between bouts of a preparation (Spearman 0.63 to 0.96) above the 95th percentile of permuted ids in 30 of 30 pairs. This is taken as an assumption for the participation claims, which compare neurons across bouts; their results are given per preparation and bout.
Coordinates hold one (x, y) per neuron, on a 0 to 50 scale (plot_maps.m multiplies by 10 to plot them on the 501 by 501 diode template). Preparations 7 and 8 are marked unreliable, as the description says, and preparation 7 has 5 missing positions. No unit is given, and nothing in the files or the documentation says which direction of x or y is rostral, caudal, medial or lateral.
dataset-size¶
Three bouts of fictive locomotion were evoked in each of 10 isolated preparations (30 population responses); each recorded population held 120 to 180 neurons, 1131 neurons in all.
n_preps = info.prep.nunique()
n_recs = len(info)
per_prep = info.groupby("prep").neurons.first()
print("preparations", n_preps, "| recordings", n_recs, "| neurons over preparations", int(per_prep.sum()))
print("neurons per recording: min", info.neurons.min(), "max", info.neurons.max())
print("recordings with 108 to 198 neurons:", int(info.neurons.between(108, 198).sum()), "of", n_recs)
print("variant, neurons spiking after onset: min", info.neurons_spiking_after_30s.min(), "max",
info.neurons_spiking_after_30s.max(), "total over preparations",
int(info.groupby("prep").neurons_spiking_after_30s.first().sum()))
print("per preparation:", per_prep.to_dict())
preparations 10 | recordings 30 | neurons over preparations 1131
neurons per recording: min 75 max 160
recordings with 108 to 198 neurons: 12 of 30
variant, neurons spiking after onset: min 75 max 160 total over preparations 1131
per preparation: {1: 136, 2: 105, 3: 160, 4: 151, 5: 94, 6: 121, 7: 75, 8: 102, 9: 104, 10: 83}
Result: partially reproduced. The counts match: 10 preparations, 30 recordings and 1131 neurons. The range does not: recordings hold 75 to 160 neurons, and only 12 of 30 lie in 108 to 198 (the paper's 120 to 180 widened by 10%). Counting only neurons that spike after onset changes nothing (75 to 160, 1131). The paper's range cannot hold with its own total: ten preparations of at least 120 neurons would hold at least 1200.
fig1d-slow-oscillation¶
After stimulation the spike-train power spectra of the populations are dominated by a slow oscillation at or below 0.1 Hz.
Chronux mtspectrumpt (ported in apl.mtspectrumpt, default tapers [3 5], 1 ms, fpass 0 to 1 Hz)
of each neuron's spikes after onset, averaged over the neurons of a recording.
t0 = time.time()
spectra = []
for r in recs:
trains = [tr[tr >= apl.STIM_ON] for tr in apl.neuron_trains(r)]
f, S = apl.mtspectrumpt(trains)
spectra.append(S)
spectra = np.array(spectra)
grand = spectra.mean(0)
fpk = np.array([apl.peak_frequency(f, S) for S in spectra])
fmax = np.array([f[1:][np.argmax(S[1:])] for S in spectra])
print(f"spectra in {time.time() - t0:.0f} s; frequency grid {f[0]:.4f} to {f[-1]:.4f} Hz, step {f[1] - f[0]:.4f} Hz")
print("grand mean spectrum: weighted peak", round(apl.peak_frequency(f, grand), 4), "Hz; maximum above 0 Hz at",
round(f[1:][np.argmax(grand[1:])], 4), "Hz")
print("per recording, weighted peak (code): min", fpk.min().round(4), "median", np.median(fpk).round(4), "max", fpk.max().round(4))
print("recordings with weighted peak above 0 and at or below 0.11 Hz:", int(((fpk > 0) & (fpk <= 0.11)).sum()), "of 30")
print("variant, frequency of maximum power above 0 Hz: min", fmax.min().round(4), "median", np.median(fmax).round(4),
"max", fmax.max().round(4), "; at or below 0.11 Hz:", int((fmax <= 0.11).sum()), "of 30")
print(pd.DataFrame({"file": [r["file"] for r in recs], "weighted_peak_Hz": fpk.round(4), "max_power_Hz": fmax.round(4)}).to_string(index=False))
fig, ax = plt.subplots(figsize=(5, 3))
for S in spectra:
ax.plot(f, S, color="0.7", lw=0.5)
ax.plot(f, grand, "k")
ax.set_xlabel("frequency (Hz)"); ax.set_ylabel("power"); ax.set_title("post-onset spectra (all points shown)")
plt.show()
spectra in 5 s; frequency grid 0.0000 to 0.9995 Hz, step 0.0076 Hz
grand mean spectrum: weighted peak 0.0486 Hz; maximum above 0 Hz at 0.0076 Hz
per recording, weighted peak (code): min 0.0131 median 0.0434 max 0.0789
recordings with weighted peak above 0 and at or below 0.11 Hz: 30 of 30
variant, frequency of maximum power above 0 Hz: min 0.0076 median 0.0343 max 0.0992 ; at or below 0.11 Hz: 30 of 30
file weighted_peak_Hz max_power_Hz
Jun0214da01.mat 0.0494 0.0381
Jun0214da02.mat 0.0394 0.0305
Jun0214da03.mat 0.0483 0.0458
Jun0414Bda01.mat 0.0436 0.0153
Jun0414Bda02.mat 0.0433 0.0076
Jun0414Bda03.mat 0.0710 0.0763
Jun0514da01.mat 0.0131 0.0076
Jun0514da02.mat 0.0202 0.0076
Jun0514da03.mat 0.0562 0.0687
Jun0914da01.mat 0.0205 0.0153
Jun0914da02.mat 0.0609 0.0534
Jun0914da03.mat 0.0417 0.0076
Jun1114da01.mat 0.0733 0.0534
Jun1114da02.mat 0.0755 0.0534
Jun1114da03.mat 0.0789 0.0763
May2214da01.mat 0.0755 0.0992
May2214da02.mat 0.0744 0.0992
May2214da03.mat 0.0766 0.0916
Nov0514da01.mat 0.0201 0.0076
Nov0514da02.mat 0.0191 0.0076
Nov0514da03.mat 0.0160 0.0076
Oct1514da01.mat 0.0421 0.0610
Oct1514da02.mat 0.0205 0.0076
Oct1514da03.mat 0.0528 0.0458
Sep2414da01.mat 0.0586 0.0687
Sep2414da02.mat 0.0395 0.0305
Sep2414da03.mat 0.0577 0.0763
Sep2914da01.mat 0.0402 0.0305
Sep2914da02.mat 0.0378 0.0305
Sep2914da03.mat 0.0393 0.0305
# Variant (not judged): is the low-frequency peak the slow decay of the rate (claim fig1e) or an
# oscillation? The population rate from stimulation offset in 0.1 s bins, minus a quadratic fit in
# time (the decay), with a multitaper spectrum (DPSS, time-bandwidth 3, 5 tapers, as the main
# spectrum). Reported: the frequency of maximum power above 0.02 Hz, the code's weighted peak, and
# the power in 0.05 to 0.11 Hz relative to 0.2 to 1 Hz.
from scipy.signal.windows import dpss
rows = []
for r in recs:
edges = np.arange(apl.STIM_OFF, r["t"].max(), 0.1)
y = np.histogram(r["t"], edges)[0].astype(float) / 0.1
tt = edges[:-1] + 0.05
y_d = y - np.polyval(np.polyfit(tt, y, 2), tt)
tp = dpss(y.size, 3, 5)
nfft = int(2 ** np.ceil(np.log2(y.size)) * 2)
fr = np.fft.rfftfreq(nfft, 0.1)
Sd = np.mean(np.abs(np.fft.rfft(tp * y_d, nfft)) ** 2, 0)
keep = (fr > 0) & (fr <= 1)
fk, Sk = fr[keep], Sd[keep]
band = Sk[(fk >= 0.05) & (fk <= 0.11)].mean() / Sk[(fk >= 0.2) & (fk <= 1)].mean()
above = fk > 0.02
rows.append({"file": r["file"], "fmax_detrended": fk[above][np.argmax(Sk[above])], "weighted_peak_detrended": apl.peak_frequency(fk, Sk),
"band_ratio_0.05-0.11_vs_0.2-1": band})
DT1 = pd.DataFrame(rows)
print(f"frequency grid step {fk[1] - fk[0]:.4f} Hz")
print("detrended population rate, frequency of maximum power above 0.02 Hz: min", round(DT1.fmax_detrended.min(), 4), "median",
round(DT1.fmax_detrended.median(), 4), "max", round(DT1.fmax_detrended.max(), 4), "; at or below 0.11 Hz:",
int((DT1.fmax_detrended <= 0.11).sum()), "of 30")
print("weighted peak of the detrended spectrum: min", round(DT1.weighted_peak_detrended.min(), 4), "median",
round(DT1.weighted_peak_detrended.median(), 4), "max", round(DT1.weighted_peak_detrended.max(), 4), "; at or below 0.11 Hz:",
int((DT1.weighted_peak_detrended <= 0.11).sum()), "of 30")
print("mean power 0.05 to 0.11 Hz over mean power 0.2 to 1 Hz: min", round(DT1["band_ratio_0.05-0.11_vs_0.2-1"].min(), 1), "median",
round(DT1["band_ratio_0.05-0.11_vs_0.2-1"].median(), 1), "; above 1 in", int((DT1["band_ratio_0.05-0.11_vs_0.2-1"] > 1).sum()), "of 30")
print("grand mean point-process spectrum at its first bins (Hz: power):", {round(float(a), 4): round(float(b), 3) for a, b in zip(f[1:8], grand[1:8])})
frequency grid step 0.0049 Hz
detrended population rate, frequency of maximum power above 0.02 Hz: min 0.0342 median 0.0635 max 0.1562 ; at or below 0.11 Hz: 27 of 30
weighted peak of the detrended spectrum: min 0.0288 median 0.0658 max 0.1552 ; at or below 0.11 Hz: 27 of 30
mean power 0.05 to 0.11 Hz over mean power 0.2 to 1 Hz: min 1.6 median 9.8 ; above 1 in 30 of 30
grand mean point-process spectrum at its first bins (Hz: power): {0.0076: 7.543, 0.0153: 7.367, 0.0229: 5.54, 0.0305: 6.827, 0.0381: 5.632, 0.0458: 6.31, 0.0534: 7.239}
Result: reproduced. The grand mean spectrum's power-weighted peak is at 0.0486 Hz, and the peaks of all 30 recordings lie above 0 and at or below 0.11 Hz (0.0131 to 0.0789 Hz). The variant, the frequency of maximum power above 0 Hz, lies at 0.0076 to 0.0992 Hz, also 30 of 30 at or below 0.11 Hz. A detrended check, not judged, tells the oscillation from the decay of the rate (claim fig1e): with a quadratic trend removed from the population rate after offset, the frequency of maximum power above 0.02 Hz is 0.034 to 0.156 Hz (median 0.064 Hz), at or below 0.11 Hz in 27 of 30, and the mean power in 0.05 to 0.11 Hz exceeds that in 0.2 to 1 Hz in 30 of 30 (median ratio 9.8). The grand mean point-process spectrum is nearly flat over its first bins (7.54 at 0.0076 Hz, 7.24 at 0.053 Hz), so its maximum at the lowest bin reflects the decay as well as the oscillation.
fig1e-decaying-rate¶
The population firing rate decays slowly after the stimulus, decreasing in most evoked responses.
Result: reproduced. Under reading (a), all 30 responses are decreasing (Pearson R of window time against count from -0.992 to -0.774, all below -0.2) and none is increasing; under reading (b) all 30 slopes are negative. Every preparation has three decreasing responses.
fig2b-dimensions¶
Capturing 80% of the population variance needs 4 to 8 embedding dimensions in the evoked responses, a reduction by more than a factor of 10 from the number of neurons.
The Gaussian SD is read four ways (helper docstring) and the count two ways, as the criterion lists them.
sds = apl.gaussian_sds(recs)
print("Gaussian SD (s) by reading: ", {k: (round(v.min(), 3), round(v.max(), 3)) for k, v in sds.items()})
dims = {}
t0 = time.time()
for mode in ["sqrt12", "twelve", "own", "pooled"]:
evs = [apl.Program(r, s).ev for r, s in zip(recs, sds[mode])]
for rule in ["min80", "le80"]:
dims[(mode, rule)] = np.array([apl.n_pcs(ev, 0.8, rule) for ev in evs])
print(f"PCA under every reading in {time.time() - t0:.0f} s")
nn = info.neurons.values
rows = []
for (mode, rule), d in dims.items():
rows.append({"sd": mode, "count": rule, "min": d.min(), "max": d.max(), "in_3.6_to_8.8": int(((d >= 3.6) & (d <= 8.8)).sum()),
"min_neurons_over_dims": round((nn / d).min(), 1), "ratio_over_10": int((nn / d > 10).sum())})
dim_tab = pd.DataFrame(rows)
print(dim_tab.to_string(index=False))
print("\ncounts per recording (min80 | le80) for the code's width (own median ISI):")
print(pd.DataFrame({"file": info.file, "own_min80": dims[("own", "min80")], "own_le80": dims[("own", "le80")],
"pooled_min80": dims[("pooled", "min80")], "pooled_le80": dims[("pooled", "le80")], "neurons": nn}).to_string(index=False))
Gaussian SD (s) by reading: {'sqrt12': (np.float64(0.069), np.float64(0.125)), 'twelve': (np.float64(0.02), np.float64(0.036)), 'own': (np.float64(0.238), np.float64(0.432)), 'pooled': (np.float64(0.298), np.float64(0.374))}
PCA under every reading in 5 s
sd count min max in_3.6_to_8.8 min_neurons_over_dims ratio_over_10
sqrt12 min80 22 41 0 2.7 0
sqrt12 le80 21 40 0 2.8 0
twelve min80 34 76 0 1.8 0
twelve le80 33 75 0 1.8 0
own min80 4 8 30 9.4 29
own le80 3 7 28 10.7 30
pooled min80 4 9 29 9.4 29
pooled le80 3 8 28 10.7 30
counts per recording (min80 | le80) for the code's width (own median ISI):
file own_min80 own_le80 pooled_min80 pooled_le80 neurons
Jun0214da01.mat 7 6 7 6 136
Jun0214da02.mat 7 6 7 6 136
Jun0214da03.mat 8 7 8 7 136
Jun0414Bda01.mat 4 3 5 4 105
Jun0414Bda02.mat 5 4 6 5 105
Jun0414Bda03.mat 5 4 5 4 105
Jun0514da01.mat 8 7 9 8 160
Jun0514da02.mat 7 6 7 6 160
Jun0514da03.mat 7 6 7 6 160
Jun0914da01.mat 5 4 5 4 151
Jun0914da02.mat 4 3 4 3 151
Jun0914da03.mat 5 4 5 4 151
Jun1114da01.mat 5 4 4 3 94
Jun1114da02.mat 5 4 5 4 94
Jun1114da03.mat 6 5 5 4 94
May2214da01.mat 6 5 5 4 121
May2214da02.mat 5 4 5 4 121
May2214da03.mat 6 5 6 5 121
Nov0514da01.mat 7 6 7 6 75
Nov0514da02.mat 6 5 6 5 75
Nov0514da03.mat 8 7 8 7 75
Oct1514da01.mat 5 4 6 5 102
Oct1514da02.mat 6 5 7 6 102
Oct1514da03.mat 7 6 8 7 102
Sep2414da01.mat 6 5 7 6 104
Sep2414da02.mat 6 5 7 6 104
Sep2414da03.mat 6 5 7 6 104
Sep2914da01.mat 6 5 6 5 83
Sep2914da02.mat 6 5 6 5 83
Sep2914da03.mat 7 6 8 7 83
Result: reproduced, under the readings with the code's width and the code's count. The criterion asks for one reading. With the median ISI as the SD and the count of PCs whose cumulative variance is at most 80% (own/le80), 28 of 30 counts lie in 3.6 to 8.8 (3 to 7) and the number of neurons divided by the count exceeds 10 in all 30 (lowest 10.7); pooled/le80 gives the same. With the Methods' count (smallest number reaching 80%) the counts are 4 to 8 for own/min80, the paper's range, all 30 in 3.6 to 8.8, but the ratio exceeds 10 in 29 of 30 (lowest 9.4, 75 neurons and 8 PCs). The Methods' printed width gives 21 to 76 dimensions (median ISI / sqrt(12), 21 to 41; median ISI / 12, 33 to 76) and ratios of 1.8 to 2.8 at the lowest; it cannot give the paper's counts. The adopted reading of the later claims (own/min80) is therefore one under which this claim fails, by one response; its counts are the paper's 4 to 8.
The recurrence analysis¶
Run once per reading of the width and the count. The local linear models (claims fig4 to fig5)
are fitted for the four readings with the code's width; the two narrow widths give 21 to 76
dimensions (claim fig2b-dimensions) and are carried only through the dominant period
(fig2ef-periodic-recurrence). The adopted reading, used where one reading has to be chosen, is
own/min80: the median ISI of the recording (the width the code uses; the Methods compute it
"in population", the recording) and the smallest number of PCs reaching 80% (the Methods, "at least
80% of the variance"). The other readings are shown with it.
No single reading makes every claim that depends on it hold. Under the adopted reading claim fig2b fails by one response (75 neurons over 8 PCs, a ratio of 9.4), though its counts are the paper's 4 to 8; own/le80 passes fig2b, fig3h and fig6s2 but gives a linear-model period of 13.55 s for fig4c. The Summary tabulates the outcome under each reading for the claims that change.
t0 = time.time()
RUNS = {}
for mode in ["own", "pooled"]:
for rule in ["min80", "le80"]:
RUNS[f"{mode}/{rule}"] = apl.run_all(recs, sds[mode], rule, lld=True, workers=4)
for mode in ["sqrt12", "twelve"]:
for rule in ["min80", "le80"]:
RUNS[f"{mode}/{rule}"] = apl.run_all(recs, sds[mode], rule, lld=False, workers=4)
SUM = {k: pd.DataFrame([apl.summarise(o) for o in v]) for k, v in RUNS.items()}
print(f"recurrence analysis of 30 recordings under {len(RUNS)} readings in {time.time() - t0:.0f} s; "
f"peak memory {resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss / 1e6:.2f} GB per worker")
ADOPT = "own/min80"
print("checked points per recording:", SUM[ADOPT].n_points.min(), "to", SUM[ADOPT].n_points.max(), "(Methods: around 7770)")
recurrence analysis of 30 recordings under 8 readings in 140 s; peak memory 1.12 GB per worker checked points per recording: 7768 to 7772 (Methods: around 7770)
fig2ef-periodic-recurrence¶
The evoked low-dimensional activity recurs with a regular period; strongly periodic recurrence on the scale of 10 to 15 s is found in many but not all of the 30 responses.
rows = []
for k, S in SUM.items():
for stat in ["period_mean", "period_median"]:
v = S[stat].values
rows.append({"reading": k, "period": stat, "n_with_peak": int(np.isfinite(v).sum()),
"in_9_to_16.5": int(((v >= 9) & (v <= 16.5)).sum()), "min": np.nanmin(v).round(2),
"median": np.nanmedian(v).round(2), "max": np.nanmax(v).round(2)})
per_tab = pd.DataFrame(rows)
per_tab["reproduced"] = (per_tab["in_9_to_16.5"] > 15) & (per_tab["in_9_to_16.5"] < 30)
print(per_tab.to_string(index=False))
S = SUM[ADOPT]
print("\nadopted reading, per recording:")
print(S[["prep", "bout", "d", "n_peaks", "prop_recurrent", "period_mean", "period_median"]].round(3).to_string(index=False))
print("by preparation, mean period:", S.groupby("prep").period_mean.mean().round(2).to_dict())
print("adopted reading, quartiles of the dominant period (mean of the peak):", np.percentile(S.period_mean, [25, 75]).round(2),
"; outside 9 to 16.5 s:", S[~S.period_mean.between(9, 16.5)][["prep", "bout", "period_mean"]].round(2).values.tolist())
reading period n_with_peak in_9_to_16.5 min median max reproduced
own/min80 period_mean 30 26 8.75 12.73 22.23 True
own/min80 period_median 30 23 8.69 12.55 22.02 True
own/le80 period_mean 30 25 8.62 12.87 22.14 True
own/le80 period_median 30 22 8.42 12.86 22.00 True
pooled/min80 period_mean 30 26 8.67 12.63 22.16 True
pooled/min80 period_median 30 22 8.69 12.20 21.93 True
pooled/le80 period_mean 30 25 8.51 12.58 22.08 True
pooled/le80 period_median 30 23 8.52 12.52 21.95 True
sqrt12/min80 period_mean 29 25 8.67 12.15 22.93 True
sqrt12/min80 period_median 29 21 8.32 12.32 22.84 True
sqrt12/le80 period_mean 29 25 8.85 12.21 23.05 True
sqrt12/le80 period_median 29 22 8.53 12.29 22.85 True
twelve/min80 period_mean 30 16 11.19 16.38 19.08 True
twelve/min80 period_median 30 29 10.11 13.55 17.86 True
twelve/le80 period_mean 30 13 11.15 16.59 19.16 False
twelve/le80 period_median 30 29 10.08 13.85 17.85 True
adopted reading, per recording:
prep bout d n_peaks prop_recurrent period_mean period_median
1 1 7 4 0.842 14.977 15.240
1 2 7 2 0.823 17.281 17.710
1 3 8 4 0.817 14.144 13.650
2 1 4 2 0.722 12.211 10.570
2 2 5 2 0.788 15.156 12.750
2 3 5 1 0.907 14.764 15.860
3 1 8 2 0.695 10.143 10.270
3 2 7 2 0.748 11.489 11.830
3 3 7 1 0.784 12.972 12.350
4 1 5 1 0.595 10.785 9.870
4 2 4 1 0.822 14.980 14.690
4 3 5 1 0.633 13.330 13.860
5 1 5 2 0.912 12.001 11.780
5 2 5 1 0.862 12.142 12.050
5 3 6 2 0.924 11.395 11.070
6 1 6 1 0.972 9.408 9.260
6 2 5 1 0.909 9.808 9.060
6 3 6 1 0.949 9.344 8.690
7 1 7 2 0.612 22.230 22.020
7 2 6 2 0.709 8.749 8.980
7 3 8 2 0.810 10.485 8.880
8 1 5 1 0.823 19.943 21.420
8 2 6 1 0.620 10.947 10.050
8 3 7 3 0.833 16.402 16.280
9 1 6 2 0.737 11.755 11.710
9 2 6 4 0.690 12.491 13.100
9 3 6 3 0.798 13.491 13.810
10 1 6 1 0.749 15.954 16.850
10 2 6 3 0.705 13.645 13.645
10 3 7 3 0.662 15.031 14.490
by preparation, mean period: {1: 15.47, 2: 14.04, 3: 11.53, 4: 13.03, 5: 11.85, 6: 9.52, 7: 13.82, 8: 15.76, 9: 12.58, 10: 14.88}
adopted reading, quartiles of the dominant period (mean of the peak): [11.06 14.98] ; outside 9 to 16.5 s: [[1.0, 2.0, 17.28], [7.0, 1.0, 22.23], [7.0, 2.0, 8.75], [8.0, 1.0, 19.94]]
Result: reproduced. Under the adopted reading, 26 of 30 dominant periods (mean of the peak) lie in 9 to 16.5 s, and 4 do not (17.28, 22.23, 8.75 and 19.94 s); the quartiles are 11.06 and 14.98 s. With the median of the peak 23 of 30 do. All four readings with the code's width give 22 to 26 of 30, and the readings with the narrow widths 13 to 29; every reading but twelve/le80 with the mean (13 of 30) meets the criterion.
fig2e-single-dominant-orbit¶
Almost all populations are dominated by a single periodic orbit; the majority of programs have more than 50% of their recurrent points in the dominant peak.
rows = []
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
S = SUM[k]
rows.append({"reading": k, "over_50pct_hist": int((S.prop_dom_hist > 0.5).sum()),
"over_50pct_all_recurrent": int((S.prop_dom_all > 0.5).sum()),
"peaks_min": S.n_peaks.min(), "peaks_max": S.n_peaks.max(),
"peaks_counts": S.n_peaks.value_counts().sort_index().to_dict()})
print(pd.DataFrame(rows).to_string(index=False))
print("\nadopted reading:")
print(SUM[ADOPT][["prep", "bout", "n_peaks", "dom_n", "prop_dom_hist", "prop_dom_all"]].round(3).to_string(index=False))
reading over_50pct_hist over_50pct_all_recurrent peaks_min peaks_max peaks_counts
own/min80 29 27 1 4 {1: 12, 2: 11, 3: 4, 4: 3}
own/le80 30 26 1 4 {1: 13, 2: 10, 3: 4, 4: 3}
pooled/min80 29 24 1 4 {1: 12, 2: 12, 3: 4, 4: 2}
pooled/le80 30 26 1 4 {1: 13, 2: 10, 3: 4, 4: 3}
adopted reading:
prep bout n_peaks dom_n prop_dom_hist prop_dom_all
1 1 4 5137 0.898 0.785
1 2 2 4957 0.973 0.775
1 3 4 4449 0.805 0.700
2 1 2 4886 0.918 0.870
2 2 2 5127 0.907 0.837
2 3 1 6508 0.993 0.923
3 1 2 3881 0.921 0.719
3 2 2 4539 0.904 0.780
3 3 1 5700 0.989 0.936
4 1 1 2463 0.968 0.532
4 2 1 6259 0.994 0.980
4 3 1 4512 0.989 0.917
5 1 2 6271 0.957 0.885
5 2 1 6146 0.984 0.917
5 3 2 6405 0.971 0.892
6 1 1 7326 1.000 0.970
6 2 1 6561 0.998 0.929
6 3 1 7024 0.970 0.952
7 1 2 2530 0.787 0.532
7 2 2 1821 0.583 0.331
7 3 2 2009 0.838 0.319
8 1 1 4739 0.966 0.742
8 2 1 2660 0.968 0.552
8 3 3 5186 0.897 0.801
9 1 2 4967 0.902 0.867
9 2 4 3852 0.852 0.718
9 3 3 5576 0.953 0.899
10 1 1 5497 1.000 0.944
10 2 3 2276 0.443 0.415
10 3 3 3651 0.731 0.710
Result: reproduced. Under the adopted reading, 29 of 30 responses have more than 50% of their recurrent points (delays of 5 to 50 s) in the dominant peak, and 27 of 30 counting all recurrent points (the code's propInMaxPeriod). Responses have 1 to 4 peaks, as the Methods say; 12 have one. The other readings give 29 to 30 and 24 to 27.
fig2s2-threshold-robust¶
The periodic orbits are robust to the threshold for recurrence, with similar periodicity at thresholds of 10%, 5% and 2%.
rows = []
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
P = {th: pd.DataFrame([apl.summarise(o, i) for o in RUNS[k]]) for i, th in enumerate(apl.THETA_PRCT)}
for stat in ["period_mean", "period_median"]:
p10 = P[10][stat].values
for th in (5, 2):
pl = P[th][stat].values
ok = np.isfinite(p10) & np.isfinite(pl)
rho, p = stats.spearmanr(p10[ok], pl[ok])
mad = np.median(np.abs(pl[ok] - p10[ok]))
rows.append({"reading": k, "period": stat, "theta": f"{th}%", "n_both": int(ok.sum()),
"spearman": round(rho, 3), "p": p, "(a)": bool(rho > 0 and p < 0.05),
"median_abs_diff_s": round(mad, 2), "10pct_of_median": round(0.1 * np.median(p10[ok]), 2),
"(b)": bool(mad < 0.1 * np.median(p10[ok]))})
thr_tab = pd.DataFrame(rows)
print(thr_tab.to_string(index=False))
P = {th: pd.DataFrame([apl.summarise(o, i) for o in RUNS[ADOPT]]) for i, th in enumerate(apl.THETA_PRCT)}
print("\nadopted reading, mean dominant period at each threshold:")
print(pd.DataFrame({th: P[th].period_mean.round(2) for th in P}).assign(file=info.file).to_string(index=False))
reading period theta n_both spearman p (a) median_abs_diff_s 10pct_of_median (b)
own/min80 period_mean 5% 30 0.941 1.099125e-14 True 0.82 1.27 True
own/min80 period_mean 2% 30 0.862 9.316973e-10 True 1.30 1.27 False
own/min80 period_median 5% 30 0.881 1.302529e-10 True 0.93 1.26 True
own/min80 period_median 2% 30 0.785 2.790431e-07 True 1.24 1.26 True
own/le80 period_mean 5% 30 0.969 1.636257e-18 True 0.67 1.29 True
own/le80 period_mean 2% 30 0.938 2.004956e-14 True 1.20 1.29 True
own/le80 period_median 5% 30 0.905 6.417487e-12 True 0.66 1.29 True
own/le80 period_median 2% 30 0.851 2.469678e-09 True 1.44 1.29 False
pooled/min80 period_mean 5% 30 0.833 1.109161e-08 True 0.78 1.26 True
pooled/min80 period_mean 2% 30 0.759 1.147292e-06 True 1.27 1.26 False
pooled/min80 period_median 5% 30 0.826 1.950216e-08 True 0.69 1.22 True
pooled/min80 period_median 2% 30 0.703 1.489894e-05 True 1.43 1.22 False
pooled/le80 period_mean 5% 30 0.942 8.939823e-15 True 0.84 1.26 True
pooled/le80 period_mean 2% 30 0.902 1.051352e-11 True 1.26 1.26 False
pooled/le80 period_median 5% 30 0.866 6.347903e-10 True 0.87 1.25 True
pooled/le80 period_median 2% 30 0.809 6.152574e-08 True 1.32 1.25 False
adopted reading, mean dominant period at each threshold:
2 5 10 file
16.12 15.71 14.98 Jun0214da01.mat
19.12 18.64 17.28 Jun0214da02.mat
14.28 14.73 14.14 Jun0214da03.mat
11.93 14.47 12.21 Jun0414Bda01.mat
22.33 21.88 15.16 Jun0414Bda02.mat
19.05 16.86 14.76 Jun0414Bda03.mat
12.22 10.06 10.14 Jun0514da01.mat
12.73 12.37 11.49 Jun0514da02.mat
14.32 15.62 12.97 Jun0514da03.mat
10.58 10.24 10.79 Jun0914da01.mat
16.26 15.75 14.98 Jun0914da02.mat
13.58 12.95 13.33 Jun0914da03.mat
12.68 12.44 12.00 Jun1114da01.mat
12.76 12.60 12.14 Jun1114da02.mat
11.51 11.56 11.40 Jun1114da03.mat
10.41 9.89 9.41 May2214da01.mat
12.47 11.21 9.81 May2214da02.mat
10.72 9.86 9.34 May2214da03.mat
25.65 23.72 22.23 Nov0514da01.mat
6.25 6.51 8.75 Nov0514da02.mat
16.23 12.33 10.48 Nov0514da03.mat
24.21 21.27 19.94 Oct1514da01.mat
6.47 9.39 10.95 Oct1514da02.mat
17.02 16.92 16.40 Oct1514da03.mat
12.02 11.62 11.75 Sep2414da01.mat
13.81 12.76 12.49 Sep2414da02.mat
14.27 14.04 13.49 Sep2414da03.mat
19.39 17.63 15.95 Sep2914da01.mat
25.93 24.90 13.64 Sep2914da02.mat
15.97 16.78 15.03 Sep2914da03.mat
Result: reproduced. Under every reading, the dominant periods at the 5% and 2% thresholds correlate with those at 10% (Spearman 0.70 to 0.97, all p < 2e-5), so reading (a) holds for both lower thresholds. Reading (b) holds at 5% in every case and fails at 2% in six of eight cases (median absolute difference 1.30 s against 1.27 s for the adopted reading with the mean).
fig3a-coalescence¶
Almost all evoked responses reach a state of high recurrence within one oscillation period of stimulation and are thereafter dominated by recurrence.
The coalescence time is the mid-point of the first 5 s window with at least 90% recurrent points (Methods). Windows start at 35 s, where the checked points start (Methods), so the earliest possible value is 37.5 s, 7.5 s after onset.
rows = []
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
S = SUM[k]
c_on = S.coalesce_t - apl.STIM_ON
for stat in ["period_mean", "period_median"]:
rows.append({"reading": k, "period": stat, "within_period_from_onset": int((c_on <= S[stat]).sum()),
"within_period_from_offset": int((c_on - 2.5 <= S[stat]).sum()),
"recurrent_after_over_50pct": int((S.prop_recurrent_after > 0.5).sum()),
"never_coalesced": int(S.coalesce_t.isna().sum())})
print(pd.DataFrame(rows).to_string(index=False))
S = SUM[ADOPT].assign(coal_from_onset=lambda d: d.coalesce_t - 30)
print("\nadopted reading: coalescence from onset, s: min", S.coal_from_onset.min(), "median", S.coal_from_onset.median(),
"max", S.coal_from_onset.max(), "; proportion recurrent after it: min", S.prop_recurrent_after.min().round(3),
"median", S.prop_recurrent_after.median().round(3))
print(S[["prep", "bout", "coal_from_onset", "period_mean", "period_median", "prop_recurrent_after"]].round(3).to_string(index=False))
reading period within_period_from_onset within_period_from_offset recurrent_after_over_50pct never_coalesced
own/min80 period_mean 12 19 30 0
own/min80 period_median 12 19 30 0
own/le80 period_mean 13 19 30 0
own/le80 period_median 14 19 30 0
pooled/min80 period_mean 11 17 30 0
pooled/min80 period_median 11 17 30 0
pooled/le80 period_mean 13 19 30 0
pooled/le80 period_median 13 20 30 0
adopted reading: coalescence from onset, s: min 7.5 median 14.5 max 49.5 ; proportion recurrent after it: min 0.608 median 0.86
prep bout coal_from_onset period_mean period_median prop_recurrent_after
1 1 12.5 14.977 15.240 0.896
1 2 19.5 17.281 17.710 0.939
1 3 22.5 14.144 13.650 0.908
2 1 12.5 12.211 10.570 0.747
2 2 14.5 15.156 12.750 0.841
2 3 8.5 14.764 15.860 0.918
3 1 30.5 10.143 10.270 0.858
3 2 20.5 11.489 11.830 0.875
3 3 18.5 12.972 12.350 0.896
4 1 49.5 10.785 9.870 0.986
4 2 11.5 14.980 14.690 0.862
4 3 14.5 13.330 13.860 0.648
5 1 9.5 12.001 11.780 0.931
5 2 9.5 12.142 12.050 0.876
5 3 16.5 11.395 11.070 0.965
6 1 7.5 9.408 9.260 0.972
6 2 8.5 9.808 9.060 0.925
6 3 9.5 9.344 8.690 0.979
7 1 22.5 22.230 22.020 0.653
7 2 19.5 8.749 8.980 0.710
7 3 20.5 10.485 8.880 0.923
8 1 10.5 19.943 21.420 0.850
8 2 14.5 10.947 10.050 0.608
8 3 7.5 16.402 16.280 0.830
9 1 15.5 11.755 11.710 0.813
9 2 17.5 12.491 13.100 0.753
9 3 14.5 13.491 13.810 0.829
10 1 16.5 15.954 16.850 0.807
10 2 8.5 13.645 13.645 0.706
10 3 9.5 15.031 14.490 0.668
# Why coalescence is late: recurrence density of the first windows (window starts from 35 s, so the
# earliest mid-point is 7.5 s after onset), adopted reading.
rows = []
for o, s in zip(RUNS[ADOPT], SUM[ADOPT].itertuples()):
w = o["windows"][-1]
within = w["mid_t"] - apl.STIM_ON <= s.period_mean
rows.append({"prep": o["prep"], "bout": o["bout"], "first_window_density": w["dens"][0],
"max_density_within_one_period": w["dens"][within].max() if within.any() else np.nan,
"windows_within_one_period": int(within.sum()), "coalescence_from_onset": s.coalesce_t - apl.STIM_ON,
"period_mean": s.period_mean})
CO = pd.DataFrame(rows)
print(CO.round(3).to_string(index=False))
print("responses whose highest density within one period of onset is at least 0.8:", int((CO.max_density_within_one_period >= 0.8).sum()),
"; at least 0.7:", int((CO.max_density_within_one_period >= 0.7).sum()), "of 30")
fig, ax = plt.subplots(figsize=(9, 3))
for o in RUNS[ADOPT][:6]:
w = o["windows"][-1]
ax.plot(w["mid_t"] - apl.STIM_ON, w["dens"], lw=1, label=f"prep {o['prep']} bout {o['bout']}")
ax.axhline(0.9, color="k", lw=0.5); ax.set_xlabel("window mid-point after onset (s)"); ax.set_ylabel("recurrence density")
ax.set_ylim(0, 1.02); ax.legend(fontsize=7, ncol=3); plt.tight_layout(); plt.show()
print("plotted: the first six responses, densities 0 to 1")
prep bout first_window_density max_density_within_one_period windows_within_one_period coalescence_from_onset period_mean
1 1 0.028 0.986 8 12.5 14.977
1 2 0.128 0.472 10 19.5 17.281
1 3 0.100 0.700 7 22.5 14.144
2 1 0.242 0.882 5 12.5 12.211
2 2 0.256 1.000 8 14.5 15.156
2 3 0.778 1.000 8 8.5 14.764
3 1 0.322 0.430 3 30.5 10.143
3 2 0.104 0.300 4 20.5 11.489
3 3 0.006 0.226 6 18.5 12.972
4 1 0.228 0.566 4 49.5 10.785
4 2 0.200 0.908 8 11.5 14.980
4 3 0.216 0.884 6 14.5 13.330
5 1 0.642 0.910 5 9.5 12.001
5 2 0.672 0.934 5 9.5 12.142
5 3 0.796 0.796 4 16.5 11.395
6 1 0.988 1.000 2 7.5 9.408
6 2 0.706 1.000 3 8.5 9.808
6 3 0.522 0.722 2 9.5 9.344
7 1 0.310 0.842 15 22.5 22.230
7 2 0.708 0.708 2 19.5 8.749
7 3 0.196 0.196 3 20.5 10.485
8 1 0.408 1.000 13 10.5 19.943
8 2 0.608 0.668 4 14.5 10.947
8 3 0.962 1.000 9 7.5 16.402
9 1 0.070 0.180 5 15.5 11.755
9 2 0.330 0.330 5 17.5 12.491
9 3 0.404 0.786 6 14.5 13.491
10 1 0.146 0.774 9 16.5 15.954
10 2 0.786 0.986 7 8.5 13.645
10 3 0.608 0.972 8 9.5 15.031
responses whose highest density within one period of onset is at least 0.8: 15 ; at least 0.7: 21 of 30
plotted: the first six responses, densities 0 to 1
Result: not reproduced. Under the adopted reading, the coalescence time (first window with at least 90% recurrent points) is within one dominant period of stimulation onset in 12 of 30 responses (19 of 30 measured from offset), where the criterion asks for 27; the other readings give 11 to 14 (17 to 20 from offset). Coalescence comes 7.5 to 49.5 s after onset (median 14.5 s). The second part holds: after coalescence more than 50% of the points recur in 30 of 30 responses (60.8% to 98.6%, median 86%). Because the checked points start at 35 s, the earliest possible coalescence is 7.5 s after onset, close to the shortest periods (8.7 to 9.4 s). The late coalescence is not an edge effect of the 90% line: within one period of onset the highest window density reaches 0.8 in 15 of 30 responses and 0.7 in 21.
Comparisons between the programs of a preparation¶
Hausdorff distances on the axes of program 1 (claim fig3c) and on common axes (fig3s1a), with 100 neuron shuffles each way as control; the distances of Figure 3D; the similarity matrices of Figure 3F. Run for the four readings with the code's width (the point sets come from each reading's recurrence analysis).
t0 = time.time()
MAN = {k: apl.run_manifold(recs, sds[k.split("/")[0]], RUNS[k], n_shuffle=100, seed=1)
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]}
print(f"comparisons in {time.time() - t0:.0f} s")
def haus_table(k, axes, ps):
rows = []
for m in MAN[k]:
for (i, j) in apl.PAIRS:
h, c = m[(axes, ps, i, j)]
rows.append({"prep": m["prep"], "pair": f"{i + 1},{j + 1}", "H": h, "ctrl_mean": np.mean(c),
"ctrl_2sem": 2 * np.std(c, ddof=1) / np.sqrt(c.size), "dims": m["k_prog1" if axes == "prog1" else "k_common"]})
return pd.DataFrame(rows)
comparisons in 137 s
fig3c-same-manifold¶
Sequentially evoked responses of a preparation fall on the same manifold; their distance is below that of random projections for all pairs except two, pairs (1,2) and (1,3) of preparation 4.
rows = []
for k in MAN:
for ps in ["recurrent", "code"]:
T = haus_table(k, "prog1", ps)
below = T.H < T.ctrl_mean
rows.append({"reading": k, "points": ps, "pairs_below_control": int(below.sum()),
"failing_pairs": [(p, q) for p, q in zip(T.prep[~below], T.pair[~below])]})
print(pd.DataFrame(rows).to_string(index=False))
T = haus_table(ADOPT, "prog1", "recurrent")
print("\nadopted reading, recurrent points:")
print(T.assign(ratio=T.H / T.ctrl_mean).round(3).to_string(index=False))
T = haus_table(ADOPT, "prog1", "code")
print("\nadopted reading, the code's point sets:")
print(T.assign(ratio=T.H / T.ctrl_mean).round(3).to_string(index=False))
reading points pairs_below_control failing_pairs
own/min80 recurrent 29 [(4, 1,2)]
own/min80 code 28 [(4, 1,2), (4, 1,3)]
own/le80 recurrent 29 [(4, 1,2)]
own/le80 code 28 [(4, 1,2), (4, 1,3)]
pooled/min80 recurrent 29 [(4, 1,2)]
pooled/min80 code 28 [(4, 1,2), (4, 1,3)]
pooled/le80 recurrent 29 [(4, 1,2)]
pooled/le80 code 28 [(4, 1,2), (4, 1,3)]
adopted reading, recurrent points:
prep pair H ctrl_mean ctrl_2sem dims ratio
1 1,2 14.288 22.791 0.159 7 0.627
1 1,3 17.545 23.229 0.181 7 0.755
1 2,3 16.622 22.679 0.171 7 0.733
2 1,2 7.953 16.905 0.152 4 0.470
2 1,3 12.310 21.143 0.174 4 0.582
2 2,3 14.179 21.322 0.191 4 0.665
3 1,2 14.244 25.664 0.226 8 0.555
3 1,3 11.934 18.332 0.161 8 0.651
3 2,3 19.329 24.031 0.344 8 0.804
4 1,2 18.781 17.984 0.181 5 1.044
4 1,3 15.461 18.115 0.163 5 0.854
4 2,3 11.694 17.877 0.173 5 0.654
5 1,2 8.674 26.481 0.307 5 0.328
5 1,3 13.076 24.747 0.287 5 0.528
5 2,3 13.061 22.881 0.267 5 0.571
6 1,2 10.208 28.899 0.278 6 0.353
6 1,3 12.655 26.719 0.267 6 0.474
6 2,3 11.250 27.939 0.333 6 0.403
7 1,2 8.316 19.624 0.227 7 0.424
7 1,3 14.448 23.774 0.347 7 0.608
7 2,3 13.037 23.568 0.358 7 0.553
8 1,2 12.636 16.163 0.211 5 0.782
8 1,3 7.393 14.784 0.173 5 0.500
8 2,3 7.787 14.373 0.201 5 0.542
9 1,2 9.808 12.455 0.119 6 0.787
9 1,3 10.247 13.115 0.146 6 0.781
9 2,3 10.087 13.393 0.166 6 0.753
10 1,2 8.978 13.571 0.144 6 0.662
10 1,3 8.770 16.041 0.227 6 0.547
10 2,3 6.731 16.093 0.203 6 0.418
adopted reading, the code's point sets:
prep pair H ctrl_mean ctrl_2sem dims ratio
1 1,2 12.050 23.092 0.229 7 0.522
1 1,3 11.010 23.141 0.184 7 0.476
1 2,3 12.824 22.202 0.186 7 0.578
2 1,2 7.957 16.886 0.144 4 0.471
2 1,3 9.096 21.105 0.187 4 0.431
2 2,3 14.237 21.602 0.157 4 0.659
3 1,2 10.002 16.712 0.183 8 0.599
3 1,3 10.518 17.352 0.130 8 0.606
3 2,3 12.706 20.695 0.265 8 0.614
4 1,2 22.740 19.073 0.190 5 1.192
4 1,3 23.969 20.497 0.200 5 1.169
4 2,3 10.657 17.477 0.187 5 0.610
5 1,2 9.398 27.762 0.315 5 0.339
5 1,3 14.023 25.738 0.286 5 0.545
5 2,3 11.818 23.091 0.297 5 0.512
6 1,2 13.572 29.141 0.282 6 0.466
6 1,3 16.752 26.905 0.271 6 0.623
6 2,3 12.093 28.067 0.331 6 0.431
7 1,2 7.518 14.901 0.189 7 0.504
7 1,3 9.265 17.906 0.291 7 0.517
7 2,3 9.049 18.214 0.295 7 0.497
8 1,2 12.966 16.347 0.187 5 0.793
8 1,3 7.393 14.794 0.161 5 0.500
8 2,3 9.948 14.977 0.253 5 0.664
9 1,2 7.603 12.163 0.136 6 0.625
9 1,3 10.988 12.464 0.110 6 0.882
9 2,3 10.517 12.011 0.149 6 0.876
10 1,2 10.441 13.058 0.159 6 0.800
10 1,3 8.768 16.285 0.200 6 0.538
10 2,3 7.413 16.401 0.214 6 0.452
Result: reproduced. With the code's point sets, 28 of 30 pairs are closer than their random-projection control under every reading, and the two that fail are pairs (1,2) and (1,3) of preparation 4, as the paper names them (distance 1.19 and 1.17 times the control under the adopted reading). With the recurrent points (the Methods), 29 of 30 pass under every reading and only pair (1,2) of preparation 4 fails (1.04 times the control). The control's 2 s.e.m. is 0.11 to 0.36, small against the differences.
fig3s1a-common-axes¶
The convergence of sequential responses to the same manifold holds when the three programs are projected onto common axes from a PCA of their concatenated activity.
rows = []
for k in MAN:
for ps in ["recurrent", "code"]:
T = haus_table(k, "common", ps)
below = T.H < T.ctrl_mean
rows.append({"reading": k, "points": ps, "pairs_below_control": int(below.sum()),
"failing_pairs": [(p, q) for p, q in zip(T.prep[~below], T.pair[~below])],
"dims": sorted(set(T.dims))})
print(pd.DataFrame(rows).to_string(index=False))
T = haus_table(ADOPT, "common", "code")
print("\nadopted reading, the code's point sets:")
print(T.assign(ratio=T.H / T.ctrl_mean).round(3).to_string(index=False))
reading points pairs_below_control failing_pairs dims
own/min80 recurrent 30 [] [5, 6, 7, 8, 10]
own/min80 code 28 [(4, 1,2), (4, 1,3)] [5, 6, 7, 8, 10]
own/le80 recurrent 30 [] [5, 6, 7, 8, 10]
own/le80 code 27 [(4, 1,2), (4, 1,3), (8, 2,3)] [5, 6, 7, 8, 10]
pooled/min80 recurrent 30 [] [5, 6, 7, 8, 10]
pooled/min80 code 28 [(4, 1,2), (4, 1,3)] [5, 6, 7, 8, 10]
pooled/le80 recurrent 30 [] [5, 6, 7, 8, 10]
pooled/le80 code 28 [(4, 1,2), (4, 1,3)] [5, 6, 7, 8, 10]
adopted reading, the code's point sets:
prep pair H ctrl_mean ctrl_2sem dims ratio
1 1,2 13.474 23.348 0.183 8 0.577
1 1,3 15.144 24.189 0.189 8 0.626
1 2,3 17.040 23.468 0.249 8 0.726
2 1,2 8.432 17.880 0.170 6 0.472
2 1,3 16.632 24.486 0.178 6 0.679
2 2,3 19.337 25.466 0.208 6 0.759
3 1,2 11.826 20.529 0.200 10 0.576
3 1,3 17.407 25.134 0.232 10 0.693
3 2,3 14.744 24.926 0.210 10 0.592
4 1,2 23.459 19.630 0.203 5 1.195
4 1,3 24.816 20.911 0.191 5 1.187
4 2,3 11.828 18.724 0.171 5 0.632
5 1,2 9.030 27.941 0.311 8 0.323
5 1,3 18.087 27.471 0.287 8 0.658
5 2,3 17.717 27.401 0.328 8 0.647
6 1,2 14.952 29.433 0.290 6 0.508
6 1,3 19.898 27.558 0.287 6 0.722
6 2,3 15.257 28.721 0.311 6 0.531
7 1,2 7.965 15.717 0.276 8 0.507
7 1,3 14.531 20.511 0.253 8 0.708
7 2,3 14.239 20.927 0.245 8 0.680
8 1,2 14.494 19.119 0.207 7 0.758
8 1,3 14.200 16.731 0.213 7 0.849
8 2,3 15.961 16.087 0.207 7 0.992
9 1,2 8.255 12.301 0.122 6 0.671
9 1,3 11.661 16.613 0.226 6 0.702
9 2,3 11.180 16.593 0.245 6 0.674
10 1,2 10.677 13.645 0.134 7 0.782
10 1,3 11.223 17.421 0.225 7 0.644
10 2,3 9.165 17.422 0.171 7 0.526
Result: reproduced. On common axes (5 to 10 PCs), 28 of 30 pairs pass with the code's point sets (failing: preparation 4, pairs (1,2) and (1,3)) under three readings, and 27 under own/le80 (also preparation 8, pair (2,3), at 0.99 of its control in the adopted reading's table). With the recurrent points all 30 pass under every reading.
fig3d-initial-conditions¶
Stimulation drives responses of the same preparation far apart before coalescence, more than at stimulus onset or after both have coalesced, so the same manifold is reached from different initial conditions.
The transient distance is the largest distance between a point of one program and a point of the other between onset and their coalescence; for speed every fifth point of the second program is used (a standard choice: neighbouring points 10 ms apart are nearly equal).
rows = []
for k in MAN:
for ps in ["code", "recurrent"]:
for m in MAN[k]:
for (i, j) in apl.PAIRS:
on, tr = m[("ic", i, j)]
rows.append({"reading": k, "points": ps, "prep": m["prep"], "pair": f"{i + 1},{j + 1}",
"onset": on, "transient": tr, "coalesced": m[("common", ps, i, j)][0]})
IC = pd.DataFrame(rows)
summ = IC.groupby(["reading", "points"]).apply(lambda d: pd.Series({
"transient_over_both": int(((d.transient > d.onset) & (d.transient > d.coalesced)).sum()),
"median_onset": d.onset.median(), "median_transient": d.transient.median(), "median_coalesced": d.coalesced.median()}))
print(summ.round(2).to_string())
print("\nadopted reading, code's point sets:")
print(IC[(IC.reading == ADOPT) & (IC.points == "code")].drop(columns=["reading", "points"]).round(2).to_string(index=False))
transient_over_both median_onset median_transient median_coalesced
reading points
own/le80 code 30.0 9.31 44.70 14.69
recurrent 30.0 9.31 44.70 13.57
own/min80 code 30.0 9.31 45.44 14.51
recurrent 30.0 9.31 45.44 13.88
pooled/le80 code 30.0 9.98 45.54 14.16
recurrent 30.0 9.98 45.54 13.96
pooled/min80 code 30.0 9.98 45.54 14.10
recurrent 30.0 9.98 45.54 13.81
adopted reading, code's point sets:
prep pair onset transient coalesced
1 1,2 7.74 58.50 13.47
1 1,3 6.86 61.94 15.14
1 2,3 11.17 58.07 17.04
2 1,2 6.93 31.19 8.43
2 1,3 10.30 35.69 16.63
2 2,3 9.23 41.63 19.34
3 1,2 12.37 58.39 11.83
3 1,3 13.85 55.38 17.41
3 2,3 8.84 63.12 14.74
4 1,2 7.67 60.17 23.46
4 1,3 13.02 63.70 24.82
4 2,3 15.20 51.66 11.83
5 1,2 8.06 45.92 9.03
5 1,3 11.29 48.68 18.09
5 2,3 12.08 44.96 17.72
6 1,2 3.92 55.94 14.95
6 1,3 7.30 49.33 19.90
6 2,3 5.31 48.62 15.26
7 1,2 4.25 35.46 7.96
7 1,3 12.28 42.14 14.53
7 2,3 10.88 41.32 14.24
8 1,2 9.63 41.64 14.49
8 1,3 15.56 40.18 14.20
8 2,3 10.98 38.25 15.96
9 1,2 4.67 44.18 8.25
9 1,3 9.02 43.94 11.66
9 2,3 8.94 47.06 11.18
10 1,2 4.72 32.67 10.68
10 1,3 11.64 30.07 11.22
10 2,3 9.40 30.58 9.16
Result: reproduced. In 30 of 30 pairs, under every reading and both point sets, the largest distance between onset and coalescence exceeds both the distance at onset and the coalesced Hausdorff distance. Under the adopted reading the medians are 9.31 at onset, 45.44 in the transient and 14.51 after coalescence (code's point sets).
fig3f-pairwise-similarity¶
Pairwise similarity between neurons is preserved across responses of the same preparation, above a null model, except for pairs (1,3) and (2,3) of preparation 7.
rows, detail = [], []
for k in MAN:
for meth in ["spearman", "pearson"]:
corr = (lambda a, b: stats.spearmanr(a, b)[0]) if meth == "spearman" else (lambda a, b: np.corrcoef(a, b)[0, 1])
for ctl in ["first", "larger"]:
n, fails = 0, []
for m in MAN[k]:
Sm, Em = m["sim"]
cs = [corr(Sm[i].ravel(), Em[i].ravel()) for i in range(3)]
for (i, j) in apl.PAIRS:
dat = corr(Sm[i].ravel(), Sm[j].ravel())
c = cs[i] if ctl == "first" else max(cs[i], cs[j])
if dat > c:
n += 1
else:
fails.append((m["prep"], f"{i + 1},{j + 1}"))
if k == ADOPT and ctl == "first":
detail.append({"corr": meth, "prep": m["prep"], "pair": f"{i + 1},{j + 1}", "data": dat,
"control_first": cs[i], "control_second": cs[j]})
rows.append({"reading": k, "corr": meth, "control": ctl, "pairs_above": n, "failing": fails})
print(pd.DataFrame(rows).to_string(index=False))
print("\nadopted reading:")
print(pd.DataFrame(detail).round(3).to_string(index=False))
reading corr control pairs_above failing
own/min80 spearman first 29 [(4, 1,3)]
own/min80 spearman larger 27 [(4, 1,3), (7, 1,3), (7, 2,3)]
own/min80 pearson first 30 []
own/min80 pearson larger 28 [(7, 1,3), (7, 2,3)]
own/le80 spearman first 29 [(4, 1,3)]
own/le80 spearman larger 27 [(4, 1,3), (7, 1,3), (7, 2,3)]
own/le80 pearson first 30 []
own/le80 pearson larger 28 [(7, 1,3), (7, 2,3)]
pooled/min80 spearman first 29 [(4, 1,3)]
pooled/min80 spearman larger 27 [(4, 1,3), (7, 1,3), (7, 2,3)]
pooled/min80 pearson first 30 []
pooled/min80 pearson larger 28 [(7, 1,3), (7, 2,3)]
pooled/le80 spearman first 29 [(4, 1,3)]
pooled/le80 spearman larger 27 [(4, 1,3), (7, 1,3), (7, 2,3)]
pooled/le80 pearson first 30 []
pooled/le80 pearson larger 28 [(7, 1,3), (7, 2,3)]
adopted reading:
corr prep pair data control_first control_second
spearman 1 1,2 0.852 0.288 0.248
spearman 1 1,3 0.815 0.288 0.232
spearman 1 2,3 0.785 0.248 0.232
spearman 2 1,2 0.791 0.524 0.378
spearman 2 1,3 0.682 0.524 0.417
spearman 2 2,3 0.763 0.378 0.417
spearman 3 1,2 0.806 0.407 0.439
spearman 3 1,3 0.586 0.407 0.332
spearman 3 2,3 0.713 0.439 0.332
spearman 4 1,2 0.674 0.622 0.300
spearman 4 1,3 0.597 0.622 0.405
spearman 4 2,3 0.721 0.300 0.405
spearman 5 1,2 0.902 0.288 0.236
spearman 5 1,3 0.488 0.288 0.334
spearman 5 2,3 0.509 0.236 0.334
spearman 6 1,2 0.837 0.277 0.402
spearman 6 1,3 0.824 0.277 0.388
spearman 6 2,3 0.885 0.402 0.388
spearman 7 1,2 0.842 0.571 0.694
spearman 7 1,3 0.650 0.571 0.735
spearman 7 2,3 0.708 0.694 0.735
spearman 8 1,2 0.838 0.536 0.465
spearman 8 1,3 0.847 0.536 0.501
spearman 8 2,3 0.786 0.465 0.501
spearman 9 1,2 0.900 0.274 0.280
spearman 9 1,3 0.743 0.274 0.373
spearman 9 2,3 0.744 0.280 0.373
spearman 10 1,2 0.798 0.433 0.403
spearman 10 1,3 0.769 0.433 0.362
spearman 10 2,3 0.867 0.403 0.362
pearson 1 1,2 0.913 0.308 0.299
pearson 1 1,3 0.872 0.308 0.281
pearson 1 2,3 0.854 0.299 0.281
pearson 2 1,2 0.824 0.520 0.457
pearson 2 1,3 0.713 0.520 0.438
pearson 2 2,3 0.805 0.457 0.438
pearson 3 1,2 0.821 0.410 0.442
pearson 3 1,3 0.643 0.410 0.346
pearson 3 2,3 0.754 0.442 0.346
pearson 4 1,2 0.734 0.616 0.359
pearson 4 1,3 0.659 0.616 0.394
pearson 4 2,3 0.783 0.359 0.394
pearson 5 1,2 0.946 0.477 0.393
pearson 5 1,3 0.560 0.477 0.499
pearson 5 2,3 0.564 0.393 0.499
pearson 6 1,2 0.866 0.334 0.511
pearson 6 1,3 0.862 0.334 0.514
pearson 6 2,3 0.926 0.511 0.514
pearson 7 1,2 0.860 0.634 0.747
pearson 7 1,3 0.685 0.634 0.779
pearson 7 2,3 0.751 0.747 0.779
pearson 8 1,2 0.868 0.597 0.538
pearson 8 1,3 0.866 0.597 0.583
pearson 8 2,3 0.815 0.538 0.583
pearson 9 1,2 0.931 0.352 0.312
pearson 9 1,3 0.814 0.352 0.357
pearson 9 2,3 0.820 0.312 0.357
pearson 10 1,2 0.840 0.412 0.409
pearson 10 1,3 0.811 0.412 0.374
pearson 10 2,3 0.887 0.409 0.374
Result: reproduced. Under every reading of width and count, the data correlation exceeds the control in 29 of 30 pairs (Spearman, control of the first program), 30 (Pearson, first), 27 (Spearman, larger control) or 28 (Pearson, larger control); all are at least 26. With Pearson correlation and the larger control the two failing pairs are (1,3) and (2,3) of preparation 7, as the paper names them. With the first program's control the Spearman reading fails pair (1,3) of preparation 4 instead (0.597 against 0.622).
fig3h-perturbations-return¶
Of 19 spontaneous divergences from the trajectory, 17 (90%) returned to a recurrent state; the two that did not were consistent with the end of the evoked locomotion.
A divergent period (Methods) is a run of windows after coalescence with recurrence density below
90% that falls below 50%; "returned" means a later window is above 90%. Periods whose divergent
point lies within two dominant periods of the end are removed (Methods), with the dominant period
read as the mean or the median of the peak. The code removes only periods that never return
(Are_jumps_perturbations_or_transitions2.m); that is shown as a variant.
DIV = {}
rows = []
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
for stat in ["period_mean", "period_median"]:
allv = []
for o, s in zip(RUNS[k], SUM[k].itertuples()):
for d in apl.divergences(o, getattr(s, stat)):
d.update(prep=o["prep"], bout=o["bout"])
allv.append(d)
V = pd.DataFrame(allv)
DIV[(k, stat)] = V
kept = V[~V.near_end]
code_kept = V[V.returned | ~V.near_end]
rows.append({"reading": k, "period": stat, "all_periods": len(V), "kept": len(kept),
"returned": int(kept.returned.sum()), "fraction": round(kept.returned.mean(), 3),
"code_rule_kept": len(code_kept), "code_rule_returned": int(code_kept.returned.sum())})
print(pd.DataFrame(rows).to_string(index=False))
V = DIV[(ADOPT, "period_mean")]
print("\nadopted reading, mean period:")
print(V[["prep", "bout", "t_point", "min_dens", "returned", "near_end"]].round(3).to_string(index=False))
reading period all_periods kept returned fraction code_rule_kept code_rule_returned
own/min80 period_mean 34 16 15 0.938 19 18
own/min80 period_median 34 17 16 0.941 19 18
own/le80 period_mean 36 18 16 0.889 21 19
own/le80 period_median 36 19 17 0.895 21 19
pooled/min80 period_mean 32 14 13 0.929 17 16
pooled/min80 period_median 32 14 13 0.929 17 16
pooled/le80 period_mean 34 16 14 0.875 19 17
pooled/le80 period_median 34 17 15 0.882 19 17
adopted reading, mean period:
prep bout t_point min_dens returned near_end
1 1 109.5 0.128 False True
1 2 109.5 0.492 False True
2 1 66.5 0.000 True False
2 1 99.5 0.000 True True
2 2 53.5 0.322 True False
2 2 109.5 0.134 False True
2 3 109.5 0.290 False True
3 1 64.5 0.354 True False
3 2 96.5 0.096 True False
3 3 109.5 0.000 False True
4 2 106.5 0.002 False True
4 3 88.5 0.000 False False
5 2 50.5 0.418 True False
5 2 109.5 0.076 False True
6 2 109.5 0.454 False True
7 1 71.5 0.284 True False
7 1 105.5 0.012 False True
7 2 64.5 0.106 True False
7 2 102.5 0.086 True False
8 1 108.5 0.298 False True
8 2 68.5 0.000 True False
8 2 109.5 0.034 False True
8 3 45.5 0.468 True False
8 3 101.5 0.026 True True
9 1 96.5 0.488 True False
9 1 106.5 0.000 False True
9 2 83.5 0.230 True False
9 2 104.5 0.266 False True
9 3 96.5 0.042 True True
10 1 79.5 0.000 True False
10 2 48.5 0.000 True False
10 2 109.5 0.100 False True
10 3 66.5 0.000 True False
10 3 104.5 0.000 False True
Result: partially reproduced, resting on the adopted reading. Under the adopted reading with the Methods' period (mean of the dominant peak), 34 divergent periods are found and 16 remain after removing those within two periods of the end; 15 of 16 (0.938) returned above 90%. The fraction matches (at least 80%), but both counts fall just short of their tolerances: 16 divergent periods against 17.1 to 20.9, and 15 returns against 15.3 to 18.7. With the median period (the code's) 17 remain and 16 return (0.941); 16 returns are within tolerance, but 17 periods are just below 17.1. Over the four readings 14 to 19 periods remain and 13 to 17 return, 0.875 to 0.941. The code's rule (dropping only the periods within two cycles of the end that never return) keeps 17 to 21 over the readings, and under the adopted reading it keeps 19 periods of which 18 return (0.947), with either period, which meets both tolerances and matches the paper's 19. The criterion states the Methods' rule ("We removed all such divergent periods whose divergent point fell within two oscillation cycles of the end of the recording", Testing return to the same manifold after perturbation), so the code's rule is reported, not judged. Under the Methods' rule the counts meet the criterion only under own/le80, with either period (18 kept and 16 returned; 19 and 17). With eight combinations run, a pass under one of them is weak evidence, and the adopted reading's result decides. The criterion has no partial outcome; it is recorded as partially reproduced because the returned fraction holds and the two counts miss their tolerances by 1.1 and 0.3.
fig3i-same-manifold-after¶
Of the 17 divergences that returned to a recurrent state, all but three returned to the same manifold; the three appeared to move to a different periodic attractor.
rows = []
for (k, stat), V in DIV.items():
kept = V[~V.near_end & V.returned]
rows.append({"reading": k, "period": stat, "returned": len(kept),
"same_(a)_after_end": int((kept.p_after_end > 0.2).sum()),
"same_(b)_after_point": int((kept.p_after_point > 0.2).sum())})
print(pd.DataFrame(rows).to_string(index=False))
V = DIV[(ADOPT, "period_mean")]
print("\nadopted reading, returned periods:")
print(V[~V.near_end & V.returned][["prep", "bout", "t_point", "t_return", "n_before", "p_after_end", "p_after_point"]].round(3).to_string(index=False))
reading period returned same_(a)_after_end same_(b)_after_point
own/min80 period_mean 15 10 13
own/min80 period_median 16 11 14
own/le80 period_mean 16 13 16
own/le80 period_median 17 14 17
pooled/min80 period_mean 13 9 11
pooled/min80 period_median 13 9 11
pooled/le80 period_mean 14 11 14
pooled/le80 period_median 15 12 15
adopted reading, returned periods:
prep bout t_point t_return n_before p_after_end p_after_point
2 1 66.5 70.0 483.0 0.002 0.830
2 2 53.5 56.0 463.0 1.000 1.000
3 1 64.5 67.0 470.0 0.889 0.889
3 2 96.5 99.0 500.0 0.778 0.778
5 2 50.5 53.0 456.0 0.974 0.974
7 1 71.5 77.0 467.0 0.173 0.724
7 2 64.5 67.0 490.0 0.000 0.522
7 2 102.5 106.0 462.0 0.000 0.000
8 2 68.5 75.0 466.0 0.011 0.011
8 3 45.5 48.0 500.0 0.950 1.000
9 1 96.5 98.0 450.0 1.000 1.000
9 2 83.5 87.0 456.0 0.436 1.000
10 1 79.5 85.0 500.0 1.000 1.000
10 2 48.5 53.0 481.0 0.701 0.988
10 3 66.5 70.0 478.0 0.979 0.992
Result: reproduced under reading (b). Of the 15 returned divergences of the adopted reading, 13 have more than 20% of the recurrences of the final window before them falling after the divergent point (reading (b), the code's blnSame), within 12.6 to 15.4; under reading (a), after the end of the divergent period, 10 do. With the median period, 14 of 16 under (b) and 11 under (a). Over the four readings, (b) gives 11 to 17 and (a) 9 to 14. The count depends strongly on the reading (9 to 17), and the criterion's "under a reading" is met under the adopted reading, (b); this is weak evidence for the paper's 14.
fig4bc-stable-spiral¶
The evoked responses have highly clustered maximum eigenvalues of the local linear dynamics, dominated by negative complex values, so the pedal ganglion implements a contracting periodic orbit, a stable spiral attractor, found in every preparation.
EIG = {}
rows = []
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
E = pd.DataFrame([{**{x: y for x, y in apl.emax_stats(o["eigs"], o["npts"]).items() if x != "eigs"},
"prep": o["prep"], "bout": o["bout"]} for o in RUNS[k]])
E["spiral"] = (E.a < -0.0001) & (E.b > 0.0005)
EIG[k] = E
per_prep = E.groupby("prep").spiral.sum()
rows.append({"reading": k, "mean_a": E.a.mean(), "mean_b": E.b.mean(), "sd_a": E.a.std(), "sd_b": E.b.std(),
"grand_mean_spiral": bool(E.a.mean() < -0.0001 and E.b.mean() > 0.0005),
"responses_spiral": int(E.spiral.sum()), "preps_2of3": int((per_prep >= 2).sum()),
"used_points_min": E.n_used.min(), "dropped_points": int((E.n_all - E.n_used).sum())})
print(pd.DataFrame(rows).to_string(index=False))
E = EIG[ADOPT]
print("\nadopted reading:")
print(E[["prep", "bout", "a", "b", "sd_a", "sd_b", "n_used", "n_all", "spiral"]].to_string(index=False))
print("spiral responses per preparation:", E.groupby("prep").spiral.sum().to_dict())
npts = [o["npts"] for o in RUNS[ADOPT]]
print("neighbours per point of the dominant orbit: fewest in any response", min(n.min() for n in npts),
"; median of the per-response medians", np.median([np.median(n) for n in npts]),
"; per-response 5th percentiles", [int(np.percentile(n, 5)) for n in npts])
fig, ax = plt.subplots(figsize=(4, 3.5))
ax.scatter(E.b, E.a, c=E.prep, cmap="tab10", s=15)
ax.axhline(-0.0001, color="0.6", lw=0.5); ax.axvline(0.0005, color="0.6", lw=0.5)
ax.set_xlabel("mean imaginary part b"); ax.set_ylabel("mean real part a")
ax.set_title(f"all 30 shown; a {E.a.min():.4f} to {E.a.max():.4f}")
plt.show()
reading mean_a mean_b sd_a sd_b grand_mean_spiral responses_spiral preps_2of3 used_points_min dropped_points
own/min80 -0.000362 0.007286 0.000578 0.002842 True 21 8 1821 0
own/le80 -0.000211 0.005663 0.000617 0.002286 True 20 6 1576 0
pooled/min80 -0.000346 0.007363 0.000545 0.002455 True 23 9 1731 0
pooled/le80 -0.000329 0.005921 0.000644 0.002123 True 21 7 1447 0
adopted reading:
prep bout a b sd_a sd_b n_used n_all spiral
1 1 -0.000286 0.007876 0.000692 0.003688 5137 5137 True
1 2 -0.000213 0.006334 0.001457 0.002771 4957 4957 True
1 3 0.000260 0.006387 0.001155 0.002647 4449 4449 False
2 1 -0.002008 0.004338 0.007063 0.004091 4886 4886 True
2 2 -0.000163 0.007202 0.003831 0.005506 5127 5127 True
2 3 -0.000286 0.008813 0.003942 0.005471 6508 6508 True
3 1 -0.000317 0.007391 0.000434 0.004276 3881 3881 True
3 2 -0.000015 0.007365 0.001506 0.003534 4539 4539 False
3 3 -0.000098 0.011532 0.002536 0.005609 5700 5700 False
4 1 0.000530 0.009434 0.007398 0.009050 2463 2463 False
4 2 -0.001059 0.005687 0.004431 0.003745 6259 6259 True
4 3 0.000177 0.006194 0.004379 0.004304 4512 4512 False
5 1 -0.000609 0.011973 0.004191 0.006582 6271 6271 True
5 2 -0.000827 0.007035 0.004818 0.004919 6146 6146 True
5 3 -0.000548 0.013928 0.004451 0.007731 6405 6405 True
6 1 -0.000508 0.011908 0.003098 0.005966 7326 7326 True
6 2 -0.001049 0.009347 0.005553 0.004878 6561 6561 True
6 3 0.000088 0.010584 0.001442 0.003056 7024 7024 False
7 1 -0.000245 0.004616 0.000588 0.001412 2530 2530 True
7 2 0.001146 0.002539 0.002174 0.001445 1821 1821 False
7 3 -0.000381 0.003568 0.000284 0.000957 2009 2009 True
8 1 -0.000924 0.005562 0.002165 0.004029 4739 4739 True
8 2 0.000053 0.001913 0.001636 0.002426 2660 2660 False
8 3 -0.000680 0.008892 0.002395 0.004978 5186 5186 True
9 1 -0.000532 0.008351 0.003062 0.004367 4967 4967 True
9 2 0.000110 0.005432 0.001523 0.002078 3852 3852 False
9 3 -0.001127 0.007774 0.003501 0.005316 5576 5576 True
10 1 -0.000555 0.005303 0.002257 0.003245 5497 5497 True
10 2 -0.000442 0.005497 0.003212 0.002368 2276 2276 True
10 3 -0.000358 0.005804 0.001185 0.002449 3651 3651 True
spiral responses per preparation: {1: 2, 2: 3, 3: 1, 4: 1, 5: 3, 6: 2, 7: 2, 8: 2, 9: 2, 10: 3}
neighbours per point of the dominant orbit: fewest in any response 195 ; median of the per-response medians 1565.5 ; per-response 5th percentiles [979, 993, 1083, 318, 459, 368, 1030, 914, 671, 226, 469, 552, 417, 430, 385, 468, 361, 597, 1681, 2725, 3318, 728, 2620, 808, 701, 1050, 609, 901, 733, 984]
Result: partially reproduced. The mean over the 30 responses is a stable spiral under every reading (adopted: a = -0.000362, b = 0.00729), but responses are not all spirals: 21 of 30 are in the stable-spiral region, and 8 of 10 preparations have at least two of three (preparations 3 and 4 have one each). The other readings give 20 to 23 responses and 6 to 9 preparations. The spread across responses is large against the mean of a (SD 0.00058 against -0.00036; SD of b 0.0028 against 0.0073). No point of the dominant orbits had fewer than 100 neighbours: the fewest in any response is 195 and the median of the per-response medians 1566, so the 100-neighbour filter of the code removes nothing here.
fig4c-orbital-period¶
The linear model estimates a mean orbital period of about 10 s, consistent with the period from the recurrent points.
rows = []
for k, E in EIG.items():
lin = 2 * np.pi / E.b * 0.01
S = SUM[k]
r_mean = stats.pearsonr(lin, S.period_mean)
r_med = stats.pearsonr(lin, S.period_median)
rows.append({"reading": k, "mean_linear_period_s": lin.mean(), "variant_mean_of_mRot_s": E.mrot.mean(),
"pearson_r_vs_mean_recurrence": r_mean[0], "p": r_mean[1], "pearson_r_vs_median_recurrence": r_med[0], "p_med": r_med[1],
"min": lin.min(), "max": lin.max()})
print(pd.DataFrame(rows).round(4).to_string(index=False))
reading mean_linear_period_s variant_mean_of_mRot_s pearson_r_vs_mean_recurrence p pearson_r_vs_median_recurrence p_med min max
own/min80 10.4496 10.2404 -0.0628 0.7418 -0.0869 0.6481 4.5113 32.8471
own/le80 13.5540 12.2223 0.0318 0.8676 -0.0691 0.7168 5.9275 44.0399
pooled/min80 10.1193 9.6432 -0.1185 0.5328 -0.1353 0.4760 5.4255 33.8326
pooled/le80 12.2234 11.2549 0.0128 0.9465 0.0314 0.8693 5.8854 23.5891
Result: reproduced, resting on the adopted reading. The mean over the 30 responses of 2 pi / b times 0.01 s is 10.45 s under the adopted reading (9 to 11 s required); the variant, the mean of the per-point rotation periods, is 10.24 s. Under the code's count rule the means are 13.55 s (own/le80) and 12.22 s (pooled/le80), outside the tolerance. The per-response linear periods do not correlate with the recurrence periods (Pearson r = -0.063, p = 0.74, adopted; -0.12 to 0.03 for the other readings), and the means do not agree within the claim's tolerance either: 10.45 s against a median recurrence period of 12.73 s, 2.3 s apart where the tolerance is 1 s. The criterion judges the mean against 10 s and reports the correlation, so the statement's "consistent with" is reported, not judged; neither the correlation nor the means support it.
fig4s1a-contracting-dimensions¶
In most responses the trajectory contracts in all embedding dimensions; a few responses have a positive real eigenvalue in one low-variance dimension, a minor expansion.
rows, detail = [], []
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
allneg = one_pos_later = 0
for o in RUNS[k]:
st = apl.emax_stats(o["eigs"], o["npts"])
ed = apl.eig_dimensions(st["eigs"])
mu = ed["mean_unique"]
allneg += bool(np.all(mu < 0))
one_pos_later += bool(np.sum(mu > 0) == 1 and mu[0] < 0)
if k == ADOPT:
detail.append({"prep": o["prep"], "bout": o["bout"], "unique_dims": mu.size, "positive": int(np.sum(mu > 0)),
"first_positive": bool(mu[0] > 0), "means": np.round(mu * 1000, 3).tolist()})
rows.append({"reading": k, "all_negative": allneg, "one_positive_not_first": one_pos_later})
print(pd.DataFrame(rows).to_string(index=False))
print("\nadopted reading (means x 1000):")
print(pd.DataFrame(detail).to_string(index=False))
reading all_negative one_positive_not_first
own/min80 11 10
own/le80 11 9
pooled/min80 8 10
pooled/le80 9 12
adopted reading (means x 1000):
prep bout unique_dims positive first_positive means
1 1 4 0 False [-0.286, -0.105, -0.495, -0.28]
1 2 4 0 False [-0.213, -0.29, -0.57, -0.175]
1 3 4 3 True [0.26, -0.187, 0.215, 0.018]
2 1 2 1 False [-2.008, 0.732]
2 2 3 1 False [-0.163, -0.312, 0.209]
2 3 3 2 False [-0.286, 0.026, 0.41]
3 1 4 0 False [-0.317, -0.197, -0.5, -0.034]
3 2 4 1 False [-0.015, 0.299, -0.917, -0.261]
3 3 4 1 False [-0.098, 0.145, -0.286, -0.235]
4 1 3 2 True [0.53, 0.74, -0.344]
4 2 2 1 False [-1.059, 0.29]
4 3 3 3 True [0.177, 0.561, 0.042]
5 1 3 0 False [-0.609, -0.561, -0.058]
5 2 3 0 False [-0.827, -0.153, -0.18]
5 3 3 0 False [-0.548, -0.928, -0.372]
6 1 3 0 False [-0.508, -0.005, -0.613]
6 2 3 1 False [-1.049, -0.184, 0.134]
6 3 3 1 True [0.088, -0.48, -0.325]
7 1 4 1 False [-0.245, 0.237, -0.132, -0.027]
7 2 3 1 True [1.146, -0.166, -0.049]
7 3 4 2 False [-0.381, 0.145, -0.099, 0.118]
8 1 3 0 False [-0.924, -0.412, -0.019]
8 2 3 1 True [0.053, -0.319, -0.384]
8 3 4 1 False [-0.68, 0.734, -0.0, -0.267]
9 1 3 1 False [-0.532, -0.211, 0.466]
9 2 3 2 True [0.11, -0.14, 0.026]
9 3 3 0 False [-1.127, -0.416, -0.319]
10 1 3 1 False [-0.555, -0.062, 0.103]
10 2 3 0 False [-0.442, -0.66, -0.446]
10 3 4 0 False [-0.358, -0.543, -0.158, -0.187]
Result: not reproduced. Only 11 of 30 responses have negative mean real parts in all unique dimensions under the adopted reading (8 to 11 under the others), where the criterion asks for more than 15. The second part holds: 10 responses (9 to 12) have exactly one positive mean, in a dimension other than the first, which is at least one and fewer than half. In 7 responses the first dimension's mean is positive.
fig4s1b-rotation-dominant¶
Local trajectories were dominated by rotation throughout; in every preparation most local models have a complex eigenvalue among their top two.
rows, detail = [], []
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
pc = []
for o in RUNS[k]:
st = apl.emax_stats(o["eigs"], o["npts"])
ed = apl.eig_dimensions(st["eigs"])
pc.append({"prep": o["prep"], "bout": o["bout"], "p_complex12": ed["p_complex12"], "p_complex1": ed["p_complex1"]})
pc = pd.DataFrame(pc)
maj = pc.assign(o=pc.p_complex12 > 0.5).groupby("prep").o.sum()
rows.append({"reading": k, "responses_over_0.5": int((pc.p_complex12 > 0.5).sum()), "min": pc.p_complex12.min(),
"preps_with_majority": int((maj >= 2).sum())})
if k == ADOPT:
detail = pc
print(pd.DataFrame(rows).round(4).to_string(index=False))
print(detail.round(4).to_string(index=False))
reading responses_over_0.5 min preps_with_majority
own/min80 30 0.8715 10
own/le80 30 0.7313 10
pooled/min80 30 0.9119 10
pooled/le80 30 0.8845 10
prep bout p_complex12 p_complex1
1 1 1.0000 1.0000
1 2 1.0000 0.9407
1 3 1.0000 1.0000
2 1 0.8715 0.6474
2 2 1.0000 0.9427
2 3 0.9877 0.9644
3 1 1.0000 1.0000
3 2 1.0000 0.9923
3 3 1.0000 0.9630
4 1 0.9655 0.9476
4 2 0.9720 0.7934
4 3 0.9707 0.8395
5 1 0.9963 0.9112
5 2 0.9567 0.8139
5 3 0.9939 0.9251
6 1 1.0000 0.9814
6 2 1.0000 0.9489
6 3 1.0000 0.9963
7 1 1.0000 0.9937
7 2 1.0000 0.8078
7 3 1.0000 1.0000
8 1 0.9831 0.8715
8 2 0.9259 0.7966
8 3 1.0000 0.8824
9 1 0.9988 0.9857
9 2 1.0000 0.9688
9 3 1.0000 0.8580
10 1 0.9673 0.9050
10 2 1.0000 0.9143
10 3 1.0000 1.0000
Result: reproduced. In all 30 responses, under every reading, more than half of the local models have a complex eigenvalue among their top two (adopted: 0.87 to 1.00).
fig5b-period-changes¶
Over a response the orbital period may slow, speed up or not change; all three occur among the 30 responses.
t0 = time.time()
PC = {}
rows = []
for k in ["own/min80", "pooled/le80", "own/le80", "pooled/min80"]:
out = []
for n, o in enumerate(RUNS[k]):
w = o["windows"][-1]
hi = np.flatnonzero(w["dens"] >= 0.9)
sl = slice(hi[0], hi[-1] + 1)
wt = 1 / w["sddelay"]
wt[~np.isfinite(wt)] = 0
wt = wt * w["dens"]
r, p, nw = apl.weighted_spearman(w["mid_t"][sl], w["mdelay"][sl], wt[sl], 10000, np.random.default_rng(500 + n))
row = {"prep": o["prep"], "bout": o["bout"], "rho": r, "p": p, "n_windows": nw}
if k == ADOPT:
rc, pcode, _ = apl.weighted_spearman(w["mid_t"][sl], w["mdelay"][sl], wt[sl], 100000, np.random.default_rng(900 + n), pooled=True)
row.update(p_code=pcode)
out.append(row)
X = pd.DataFrame(out)
PC[k] = X
rows.append({"reading": k, "slowing_p<0.01": int(((X.rho > 0) & (X.p < 0.01)).sum()),
"speeding_p<0.01": int(((X.rho < 0) & (X.p < 0.01)).sum()), "no_change": int((X.p >= 0.01).sum()),
"windows_min": X.n_windows.min(), "windows_max": X.n_windows.max()})
print(f"permutation tests in {time.time() - t0:.0f} s")
print(pd.DataFrame(rows).to_string(index=False))
X = PC[ADOPT]
print("\nadopted reading; p from 10000 permutations of the delays (two-sided), p_code from the code's 100000 pooled permutations (one-sided):")
print(X.round(4).to_string(index=False))
print("code test: slowing", int(((X.rho > 0) & (X.p_code < 0.01)).sum()), "speeding", int(((X.rho < 0) & (X.p_code < 0.01)).sum()),
"no change", int((X.p_code >= 0.01).sum()))
permutation tests in 63 s
reading slowing_p<0.01 speeding_p<0.01 no_change windows_min windows_max
own/min80 12 4 14 31 73
pooled/le80 11 6 13 31 73
own/le80 14 5 11 27 73
pooled/min80 10 5 15 29 72
adopted reading; p from 10000 permutations of the delays (two-sided), p_code from the code's 100000 pooled permutations (one-sided):
prep bout rho p n_windows p_code
1 1 0.4389 0.0006 63 0.0020
1 2 0.6211 0.0001 58 0.0000
1 3 0.1638 0.3218 56 0.1604
2 1 0.6202 0.0001 66 0.0015
2 2 0.4103 0.0260 62 0.0140
2 3 0.6447 0.0001 67 0.0000
3 1 -0.5273 0.0011 50 0.0019
3 2 -0.6177 0.0001 60 0.0008
3 3 0.7709 0.0001 57 0.0000
4 1 -0.4079 0.0292 31 0.0156
4 2 0.9597 0.0001 60 0.0000
4 3 0.2681 0.1859 37 0.1311
5 1 0.4109 0.0019 69 0.0077
5 2 -0.0359 0.7898 66 0.4249
5 3 -0.7906 0.0001 64 0.0000
6 1 0.9202 0.0001 72 0.0000
6 2 0.8558 0.0001 69 0.0000
6 3 0.8917 0.0001 70 0.0000
7 1 0.6256 0.0001 44 0.0009
7 2 -0.3407 0.0265 61 0.0159
7 3 0.0561 0.7049 60 0.3737
8 1 0.6221 0.0004 59 0.0001
8 2 -0.3204 0.0270 58 0.0184
8 3 0.3856 0.0112 73 0.0093
9 1 -0.5506 0.0014 56 0.0006
9 2 -0.1955 0.2458 53 0.1583
9 3 0.0533 0.6918 66 0.3859
10 1 -0.0622 0.6400 57 0.3582
10 2 0.2310 0.1587 56 0.1464
10 3 -0.2684 0.0890 57 0.0621
code test: slowing 13 speeding 4 no change 13
Result: reproduced. Under the adopted reading, 12 responses slow (rho > 0, p < 0.01), 4 speed up (rho < 0, p < 0.01) and 14 do not change at that level; the code's pooled one-sided test gives 13, 4 and 13. The number of windows per response is 31 to 73, within 27.9 to 79.2. The other readings give 10 to 14 slowing, 4 to 6 speeding and 11 to 15 unchanged. The windows used run from the first to the last window with at least 90% recurrent points.
fig5c-no-relation-contraction¶
There is no relationship between the change in orbital period over a response and its rate of contraction, as a stable spiral predicts.
rows = []
for k, X in PC.items():
E = EIG[k]
r, p = stats.pearsonr(X.rho, E.a)
contraction = np.exp(100 * E.a) * 100 - 100
r2, p2 = stats.pearsonr(X.rho, contraction)
rows.append({"reading": k, "R_rho_vs_a": r, "p": p, "R_rho_vs_contraction_pct": r2, "p_contraction": p2})
print(pd.DataFrame(rows).round(4).to_string(index=False))
reading R_rho_vs_a p R_rho_vs_contraction_pct p_contraction
own/min80 -0.3410 0.0651 -0.3420 0.0643
pooled/le80 -0.3424 0.0640 -0.3305 0.0744
own/le80 -0.2365 0.2083 -0.2400 0.2014
pooled/min80 -0.1391 0.4636 -0.1360 0.4737
Result: reproduced. Across the 30 responses, Pearson's R between the weighted rho and the mean real part of the maximum eigenvalue is -0.341 (p = 0.065) under the adopted reading, and -0.342 (p = 0.064) with the contraction in %/s. The other readings give R = -0.14 to -0.34 (p = 0.064 to 0.46). The test does not find the relation at p < 0.05, but the effect is moderate and p is close to the threshold under two readings.
fig6s1-no-p10-motorneurons¶
No recorded neuron is a P10 motorneuron; no neuron comes close to one-to-one locking of its spikes with P10 spikes at any delay, nor locks consistently across programs.
rows = []
for q in D["p10"]:
r = next(r for r in recs if r["prep"] == q["prep"] and r["bout"] == q["bout"])
for i, tr in enumerate(apl.neuron_trains(r)):
v, n = apl.p10_locking(tr, q["t"])
rows.append({"prep": q["prep"], "bout": q["bout"], "neuron": i + 1, "maxP": v, "spikes_after_33s": n})
MN = pd.DataFrame(rows)
print("neuron-program values:", len(MN), "; without spikes after 33 s:", int(MN.maxP.isna().sum()))
print("largest maximum locking:", round(MN.maxP.max(), 3), "; at or above 0.9:", int((MN.maxP >= 0.9).sum()))
two = MN[MN.maxP >= 0.9].groupby(["prep", "neuron"]).size()
print("neurons at or above 0.9 in two programs:", int((two >= 2).sum()))
print("largest values:")
print(MN.sort_values("maxP", ascending=False).head(8).round(3).to_string(index=False))
for c in (0.5, 0.7):
print(f"neuron-program values at or above {c}:", int((MN.maxP >= c).sum()))
print("per preparation, max:", MN.groupby("prep").maxP.max().round(3).to_dict())
neuron-program values: 1050 ; without spikes after 33 s: 1
largest maximum locking: 0.522 ; at or above 0.9: 0
neurons at or above 0.9 in two programs: 0
largest values:
prep bout neuron maxP spikes_after_33s
4 1 92 0.522 46
4 1 117 0.500 2
2 2 79 0.476 21
4 1 87 0.462 26
4 1 130 0.455 22
4 1 115 0.455 11
2 2 88 0.412 34
4 1 63 0.403 62
neuron-program values at or above 0.5: 2
neuron-program values at or above 0.7: 0
per preparation, max: {2: 0.476, 4: 0.522, 5: 0.286}
Result: reproduced. Of 1050 neuron-program values (1 neuron without spikes after 33 s), the largest maximum locking is 0.522 (preparation 4, program 1, a neuron with 46 spikes); none reaches 0.9, so none does so in two programs. Only 2 values reach 0.5 and none 0.7.
fig6d-decode-p10¶
P10 nerve activity can be fitted and forecast from the low-dimensional trajectory in all nine responses with P10 recordings, so the trajectory encodes muscle commands.
Adopted width (median ISI of the recording); PCs for 80% (smallest number reaching it). The Methods' windowing (fit 40 s, forecast 10 s, step 1 s, from 33 s; histories 50 to 200 ms) is the main reading; the code's (training on 50% of the series, 0.2 s steps, histories 50 to 250 ms) is a variant. Every reading of width and count is run with the Methods' windowing. The 90% models of claim fig6s2 use the Methods' windowing with the full history grid under own/min80 and own/le80, and with histories of 50, 100, 150 and 200 ms under pooled/le80, to fit the time limit.
t0 = time.time()
def p10_jobs(frac, windowing, hists, mode="own", rule="min80"):
J = []
for q in D["p10"]:
i = next(i for i, r in enumerate(recs) if r["prep"] == q["prep"] and r["bout"] == q["bout"])
J.append((recs[i], q["t"], float(sds[mode][i]), frac, windowing, hists, rule))
return J
DEC = {("own/min80", "80", "methods"): apl.run_decoding(p10_jobs(0.8, "methods", apl.HISTORIES_METHODS)),
("own/min80", "80", "code"): apl.run_decoding(p10_jobs(0.8, "code", apl.HISTORIES_CODE)),
("own/min80", "90", "methods"): apl.run_decoding(p10_jobs(0.9, "methods", apl.HISTORIES_METHODS))}
for k in ["own/le80", "pooled/min80", "pooled/le80"]:
mode, rule = k.split("/")
DEC[(k, "80", "methods")] = apl.run_decoding(p10_jobs(0.8, "methods", apl.HISTORIES_METHODS, mode, rule))
# 90% models for claim fig6s2: the full history grid under the two readings with the recording's own
# width; under pooled/le80 four histories only (50 to 200 ms in 50 ms steps), to fit the time limit.
DEC[("own/le80", "90", "methods")] = apl.run_decoding(p10_jobs(0.9, "methods", apl.HISTORIES_METHODS, "own", "le80"))
DEC[("pooled/le80", "90", "methods")] = apl.run_decoding(p10_jobs(0.9, "methods", [5, 10, 15, 20], "pooled", "le80"))
print(f"decoding in {time.time() - t0:.0f} s")
def dec_table(res, hists=None):
rows = []
for o in res:
if hists is None:
R = np.array([w["R"] for w in o["windows"]]); MAE = np.array([w["MAE"] for w in o["windows"]]); best = o["best"]
else:
best = min(hists, key=lambda h: np.nanmean(o["by_history"][h][1]))
R, MAE = o["by_history"][best]
ok = np.isfinite(R)
sem = np.nanstd(R, ddof=1) / np.sqrt(ok.sum())
rows.append({"prep": o["prep"], "bout": o["bout"], "dims": o["d"], "history_ms": best * 10, "windows": len(R),
"undefined_R": int((~ok).sum()), "mean_R": np.nanmean(R), "mean_R_minus_2sem": np.nanmean(R) - 2 * sem,
"mean_R2": np.nanmean(R ** 2), "mean_MAE": np.nanmean(MAE),
"train_R": np.nanmean([w["R_train"] for w in o["windows"]]) if hists is None else np.nan})
return pd.DataFrame(rows)
for name, res, h in [("own/min80, Methods windowing, 80%", DEC[("own/min80", "80", "methods")], None),
("own/min80, variant: histories up to 100 ms", DEC[("own/min80", "80", "methods")], list(range(5, 11))),
("own/min80, variant: code windowing", DEC[("own/min80", "80", "code")], None)]:
T = dec_table(res, h)
print(f"\n{name}: responses with mean R - 2 s.e.m. > 0: {int((T.mean_R_minus_2sem > 0).sum())} of 9; windows in all {T.windows.sum()}")
print(T.round(3).to_string(index=False))
rows = []
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
for name, h in [("Methods", None), ("up to 100 ms", list(range(5, 11)))]:
T = dec_table(DEC[(k, "80", "methods")], h)
f = T[(T.prep == 4) & (T.bout == 1)].iloc[0]
rows.append({"reading": k, "histories": name, "dims": T.dims.tolist(), "pass": int((T.mean_R_minus_2sem > 0).sum()),
"mean_R_min": T.mean_R.min(), "mean_R_max": T.mean_R.max(),
"prep4_bout1_mean_R": f.mean_R, "prep4_bout1_bound": f.mean_R_minus_2sem})
print("\nevery reading of width and count, Methods windowing (responses passing of 9):")
print(pd.DataFrame(rows).round(3).to_string(index=False))
decoding in 801 s
own/min80, Methods windowing, 80%: responses with mean R - 2 s.e.m. > 0: 8 of 9; windows in all 360
prep bout dims history_ms windows undefined_R mean_R mean_R_minus_2sem mean_R2 mean_MAE train_R
2 1 4 60 40 0 0.362 0.198 0.395 8.396 0.938
2 2 5 120 40 0 0.374 0.241 0.313 27.802 0.946
2 3 5 80 40 0 0.810 0.762 0.680 15.346 0.965
4 1 5 50 40 0 -0.060 -0.128 0.048 19.504 0.940
4 2 4 90 40 0 0.892 0.872 0.800 20.235 0.959
4 3 5 180 40 0 0.606 0.506 0.465 29.486 0.928
5 1 5 50 40 0 0.873 0.849 0.768 4.364 0.925
5 2 5 160 40 0 0.828 0.790 0.700 6.640 0.910
5 3 6 50 40 0 0.890 0.871 0.795 11.836 0.947
own/min80, variant: histories up to 100 ms: responses with mean R - 2 s.e.m. > 0: 8 of 9; windows in all 360
prep bout dims history_ms windows undefined_R mean_R mean_R_minus_2sem mean_R2 mean_MAE train_R
2 1 4 60 40 0 0.362 0.198 0.395 8.396 NaN
2 2 5 100 40 0 0.373 0.239 0.313 28.023 NaN
2 3 5 80 40 0 0.810 0.762 0.680 15.346 NaN
4 1 5 50 40 0 -0.060 -0.128 0.048 19.504 NaN
4 2 4 90 40 0 0.892 0.872 0.800 20.235 NaN
4 3 5 100 40 0 0.625 0.530 0.479 29.746 NaN
5 1 5 50 40 0 0.873 0.849 0.768 4.364 NaN
5 2 5 100 40 0 0.820 0.784 0.686 6.936 NaN
5 3 6 50 40 0 0.890 0.871 0.795 11.836 NaN
own/min80, variant: code windowing: responses with mean R - 2 s.e.m. > 0: 8 of 9; windows in all 1566
prep bout dims history_ms windows undefined_R mean_R mean_R_minus_2sem mean_R2 mean_MAE train_R
2 1 4 50 174 0 0.291 0.212 0.357 8.475 0.947
2 2 5 50 174 0 0.469 0.410 0.371 26.980 0.935
2 3 5 50 174 0 0.819 0.794 0.700 16.450 0.962
4 1 5 50 174 0 -0.101 -0.130 0.048 7563626.858 0.948
4 2 4 50 174 0 0.871 0.855 0.769 24.309 0.953
4 3 5 150 174 0 0.580 0.530 0.444 26.496 0.921
5 1 5 150 174 0 0.866 0.852 0.759 4.047 0.931
5 2 5 150 174 0 0.814 0.793 0.682 6.581 0.908
5 3 6 50 174 0 0.908 0.900 0.826 10.841 0.943
every reading of width and count, Methods windowing (responses passing of 9):
reading histories dims pass mean_R_min mean_R_max prep4_bout1_mean_R prep4_bout1_bound
own/min80 Methods [4, 5, 5, 5, 4, 5, 5, 5, 6] 8 -0.060 0.892 -0.060 -0.128
own/min80 up to 100 ms [4, 5, 5, 5, 4, 5, 5, 5, 6] 8 -0.060 0.892 -0.060 -0.128
own/le80 Methods [3, 4, 4, 4, 3, 4, 4, 4, 5] 8 -0.127 0.870 -0.127 -0.206
own/le80 up to 100 ms [3, 4, 4, 4, 3, 4, 4, 4, 5] 8 -0.127 0.870 -0.127 -0.206
pooled/min80 Methods [5, 6, 5, 5, 4, 5, 4, 5, 5] 8 -0.060 0.889 -0.060 -0.138
pooled/min80 up to 100 ms [5, 6, 5, 5, 4, 5, 4, 5, 5] 8 -0.060 0.889 -0.060 -0.138
pooled/le80 Methods [4, 5, 4, 4, 3, 4, 3, 4, 4] 8 -0.119 0.888 -0.119 -0.200
pooled/le80 up to 100 ms [4, 5, 4, 4, 3, 4, 3, 4, 4] 8 -0.119 0.888 -0.119 -0.200
# Preparation 4, bout 1 against a response that decodes well (preparation 4, bout 2): the P10 rate and
# the forecast of four of the Methods' windows, adopted reading and each program's best history.
fig, axes = plt.subplots(2, 1, figsize=(10, 5), sharex=True)
for ax, bout in zip(axes, [1, 2]):
q = next(q for q in D["p10"] if q["prep"] == 4 and q["bout"] == bout)
i = next(i for i, r in enumerate(recs) if r["prep"] == 4 and r["bout"] == bout)
o = next(o for o in DEC[("own/min80", "80", "methods")] if o["prep"] == 4 and o["bout"] == bout)
P = apl.Program(recs[i], float(sds["own"][i]))
pcs = P.proj[:, :o["d"]]
rate = apl.sdf_matrix([q["t"]], float(sds["own"][i]), P.t_end)[P.ix_stim, 0]
h = o["best"]
ax.plot(P.stimbins, rate, color="0.6", lw=0.8, label="P10 rate")
for s0 in [33.0, 43.0, 53.0, 63.0]:
i0, i1 = np.searchsorted(P.stimbins, s0 - 1e-9), np.searchsorted(P.stimbins, s0 + 40 - 1e-9)
rows_ = np.arange(max(i0, h), i1)
b = apl.poisson_glm(apl.lagged(pcs, rows_, h), rate[rows_])
rf = np.arange(i1, min(i1 + 1000, rate.size))
fc = np.exp(np.clip(apl.lagged(pcs, rf, h) @ b, -30, 30))
ax.plot(P.stimbins[rf], fc, lw=1, label=f"forecast after fit from {s0:.0f} s")
print(f"prep 4 bout {bout}, window from {s0:.0f} s: forecast R {np.corrcoef(rate[rf], fc)[0, 1]:.3f}; "
f"P10 rate range {rate[rf].min():.1f} to {rate[rf].max():.1f}, forecast range {fc.min():.1f} to {fc.max():.1f} spikes/s")
ax.set_ylabel("spikes/s"); ax.set_title(f"preparation 4, bout {bout}"); ax.set_ylim(0, np.percentile(rate, 99.5) * 1.5)
axes[0].legend(fontsize=7, ncol=3); axes[1].set_xlabel("time (s)"); axes[1].set_xlim(70, 120)
plt.tight_layout(); plt.show()
prep 4 bout 1, window from 33 s: forecast R 0.272; P10 rate range 0.0 to 23.5, forecast range 55.3 to 139.7 spikes/s prep 4 bout 1, window from 43 s: forecast R -0.588; P10 rate range 0.0 to 39.3, forecast range 3.3 to 14.9 spikes/s prep 4 bout 1, window from 53 s: forecast R -0.106; P10 rate range 0.2 to 81.5, forecast range 4.1 to 16.7 spikes/s prep 4 bout 1, window from 63 s: forecast R 0.068; P10 rate range 0.1 to 90.0, forecast range 6.0 to 37.8 spikes/s prep 4 bout 2, window from 33 s: forecast R 0.932; P10 rate range 0.1 to 215.0, forecast range 37.6 to 231.0 spikes/s
prep 4 bout 2, window from 43 s: forecast R 0.900; P10 rate range 0.0 to 215.0, forecast range 25.0 to 237.9 spikes/s prep 4 bout 2, window from 53 s: forecast R 0.938; P10 rate range 34.5 to 235.8, forecast range 30.3 to 291.8 spikes/s prep 4 bout 2, window from 63 s: forecast R 0.810; P10 rate range 0.0 to 73.2, forecast range 16.4 to 77.5 spikes/s
# Diverging forecasts: windows whose largest forecast exceeds 10 times the response's largest P10
# rate (reported, not judged). The linear predictor is clipped at 30, so a diverging forecast reaches
# about 1e13 spikes/s, and a few such windows dominate a mean MAE over windows.
def diverging(res, frac_label):
rows = []
for o in res:
lim = 10 * o["rate_max"]
allh = np.concatenate(list(o["fc_max_by_history"].values()))
sel = o["fc_max_by_history"][o["best"]]
rows.append({"model": frac_label, "prep": o["prep"], "bout": o["bout"], "history_ms": o["best"] * 10,
"diverging_selected": int((sel > lim).sum()), "windows": sel.size,
"largest_forecast_selected": sel.max(), "diverging_all_histories": int((allh > lim).sum()),
"windows_all_histories": allh.size})
return pd.DataFrame(rows)
rows = []
for key, res in DEC.items():
T = diverging(res, "/".join(key))
rows.append({"reading": key[0], "variance": key[1], "windowing": key[2],
"responses_with_diverging_selected": int((T.diverging_selected > 0).sum()),
"diverging_selected": int(T.diverging_selected.sum()), "windows_selected": int(T.windows.sum()),
"largest_forecast_selected": T.largest_forecast_selected.max(),
"diverging_all_histories": int(T.diverging_all_histories.sum()),
"windows_all_histories": int(T.windows_all_histories.sum())})
print("windows with a forecast above 10 times the response's largest P10 rate, per decoding run:")
print(pd.DataFrame(rows).to_string(index=False))
print("\nown/min80, code windowing, 80%, per response:")
print(diverging(DEC[("own/min80", "80", "code")], "code").to_string(index=False))
# Sensitivity to rounding: preparation 4, bout 1, own/min80, code windowing, with the PCs perturbed
# by Gaussian noise of 1e-9 times their SD (seeded).
rng_div = np.random.default_rng(611)
i41 = next(i for i, r in enumerate(recs) if r["prep"] == 4 and r["bout"] == 1)
q41 = next(q for q in D["p10"] if q["prep"] == 4 and q["bout"] == 1)
P41 = apl.Program(recs[i41], float(sds["own"][i41]), "min80")
pcs41 = P41.proj[:, :apl.n_pcs(P41.ev, 0.8, "min80")]
rate41 = apl.sdf_matrix([q41["t"]], float(sds["own"][i41]), P41.t_end)[P41.ix_stim, 0]
rows = []
for h in [5, 15]:
for name, X in [("as computed", pcs41), ("perturbed 1e-9 SD", pcs41 + 1e-9 * pcs41.std(0) * rng_div.standard_normal(pcs41.shape))]:
o = apl.decode_p10(X, rate41, P41.stimbins, h, step_s=0.2, train_frac=0.5)
M = np.array([w["MAE"] for w in o]); R = np.array([w["R"] for w in o]); F = np.array([w["fc_max"] for w in o])
rows.append({"history_ms": h * 10, "pcs": name, "mean_MAE": M.mean(), "median_MAE": np.median(M),
"mean_R": np.nanmean(R), "diverging": int((F > 10 * rate41.max()).sum()), "windows": len(o)})
print("\npreparation 4, bout 1, own/min80, code windowing, sensitivity to a perturbation of the PCs:")
print(pd.DataFrame(rows).to_string(index=False))
windows with a forecast above 10 times the response's largest P10 rate, per decoding run:
reading variance windowing responses_with_diverging_selected diverging_selected windows_selected largest_forecast_selected diverging_all_histories windows_all_histories
own/min80 80 methods 0 0 360 6.637688e+02 1107 5760
own/min80 80 code 1 1 1566 1.333416e+09 2230 7830
own/min80 90 methods 1 3 360 6.963017e+11 1723 5760
own/le80 80 methods 0 0 360 4.907632e+02 934 5760
pooled/min80 80 methods 1 1 360 8.350284e+09 873 5760
pooled/le80 80 methods 1 1 360 1.104174e+05 796 5760
own/le80 90 methods 1 7 360 2.726401e+12 1665 5760
pooled/le80 90 methods 1 5 360 8.620273e+10 351 1440
own/min80, code windowing, 80%, per response:
model prep bout history_ms diverging_selected windows largest_forecast_selected diverging_all_histories windows_all_histories
code 2 1 50 0 174 8.433287e+01 273 870
code 2 2 50 0 174 2.476861e+02 470 870
code 2 3 50 0 174 2.089349e+02 334 870
code 4 1 50 1 174 1.333416e+09 530 870
code 4 2 50 0 174 3.427360e+02 398 870
code 4 3 150 0 174 2.460870e+02 197 870
code 5 1 150 0 174 6.448223e+01 0 870
code 5 2 150 0 174 9.659946e+01 28 870
code 5 3 50 0 174 2.008434e+02 0 870
preparation 4, bout 1, own/min80, code windowing, sensitivity to a perturbation of the PCs:
history_ms pcs mean_MAE median_MAE mean_R diverging windows
50 as computed 7.563627e+06 1.223451e+01 -0.100599 1 174
50 perturbed 1e-9 SD 9.959883e+05 1.220215e+01 -0.099060 2 174
150 as computed 1.045694e+12 4.057286e+10 -0.053685 116 174
150 perturbed 1e-9 SD 1.271678e+12 1.522756e+11 -0.056377 136 174
Result: not reproduced. With the Methods' windowing, 8 of 9 responses have mean forecast R minus 2 s.e.m. above 0 under every reading of width and count (adopted: mean R of the other eight 0.36 to 0.89). Response 1 of preparation 4 fails under all four readings (mean R -0.060, -0.120, -0.080 and -0.123 for own/min80, own/le80, pooled/min80 and pooled/le80; bounds -0.127 to -0.204), with histories up to 100 ms and with the code's windowing (mean R -0.102, bound -0.131). Its training fits are as good as the others' (mean training R 0.94; 0.91 to 0.97 in all nine), but its forecasts fail: in the four windows plotted the forecast R is -0.59 to 0.27, and the first forecast runs at 56 to 133 spikes/s against a P10 rate of 0 to 24 spikes/s, while response 2 of the same preparation gives 0.81 to 0.94. The decoding holds in eight of nine responses. The criterion requires it in each of the nine, the statement says "in all nine", and the one failure holds under every reading, history range and windowing run here, so the result is a failure of what the claim says. Verification round 3 agreed with the change from partially reproduced. The Methods' windowing gives 40 forecast windows per response (360 in all), the code's 174 per response (1566); the paper's N = 173 is close to the code's count per response. Preparation 4's first response is the one the paper describes as apparently chaotic (Figure 3, figure supplement 1B).
The decoding does not give the same numbers in every execution, as the forecasts diverge in some windows and the selected history and the means over windows follow them. The numbers above and below are from this execution. The copy reviewed in verification round 3 gave mean R -0.060, -0.127, -0.060 and -0.119 for preparation 4, bout 1 (bounds -0.128 to -0.206) and -0.101 with the code's windowing, and the same 8 of 9 under every reading; the pass counts have been the same in every execution.
Here, over all histories, 462 to 627 of 5760 windows (80% models, Methods windowing, the four readings) and 1614 of 7830 (code windowing) have a forecast above 10 times the response's largest P10 rate, up to the clip of the linear predictor (about 1e13 spikes/s). Of the histories selected for the 80% models, one window diverges, under pooled/min80 (largest forecast 1.2e9 spikes/s); the other 80% runs have none (largest forecast 338 to 660 spikes/s). For preparation 4, bout 1 with the code's windowing, perturbing the PCs by 1e-9 of their SD leaves the 50 ms model nearly unchanged (mean MAE 13.27 and 13.32, mean R -0.102 and -0.101, no diverging window) but changes the 150 ms model's mean MAE from 5.3e11 to 4.2e11 (74 and 78 diverging windows of 174). A mean MAE over windows with diverging forecasts therefore depends on rounding, and so can the history selected: the copy reviewed in round 3 selected a history for this response with a mean MAE of 7.6e6, where this execution's has 13.3. The forecast R of the selected models, on which the criterion rests, moves by up to 0.02 between executions and the failure of this response holds in each.
fig6s2-dimensions-p10¶
The nine recordings with P10 activity need only 3 to 5 embedding dimensions for 80% variance, and at least double that for 90%; using the 90% dimensions does not improve the P10 forecasts.
p10_idx = [next(i for i, r in enumerate(recs) if r["prep"] == q["prep"] and r["bout"] == q["bout"]) for q in D["p10"]]
rows = []
for mode in ["sqrt12", "twelve", "own", "pooled"]:
evs = [apl.Program(recs[i], sds[mode][i]).ev for i in p10_idx]
for rule in ["min80", "le80"]:
d80 = np.array([apl.n_pcs(ev, 0.8, rule) for ev in evs])
d90 = np.array([apl.n_pcs(ev, 0.9, rule) for ev in evs])
rows.append({"sd": mode, "count": rule, "d80": d80.tolist(), "d90": d90.tolist(),
"all_in_2.7_to_5.5": bool(np.all((d80 >= 2.7) & (d80 <= 5.5))), "d90_at_least_2x": bool(np.all(d90 >= 2 * d80))})
print(pd.DataFrame(rows).to_string(index=False))
FOUR = [5, 10, 15, 20]
summ = []
for k in ["own/min80", "own/le80", "pooled/le80"]:
full90 = len(DEC[(k, "90", "methods")][0]["by_history"]) == len(apl.HISTORIES_METHODS)
for grid in (["full grid", "four histories"] if full90 else ["four histories"]):
h = None if grid == "full grid" else FOUR
T80, T90 = dec_table(DEC[(k, "80", "methods")], h), dec_table(DEC[(k, "90", "methods")], h)
cmp = pd.DataFrame({"prep": T80.prep, "bout": T80.bout, "dims80": T80.dims, "dims90": T90.dims,
"hist80_ms": T80.history_ms, "hist90_ms": T90.history_ms,
"MAE80": T80.mean_MAE, "MAE90": T90.mean_MAE, "R2_80": T80.mean_R2, "R2_90": T90.mean_R2})
w_mae = stats.wilcoxon(cmp.MAE90, cmp.MAE80)
w_r2 = stats.wilcoxon(cmp.R2_90, cmp.R2_80)
summ.append({"reading": k, "histories": grid, "MAE_p": w_mae.pvalue, "MAE90_lower": int((cmp.MAE90 < cmp.MAE80).sum()),
"MAE_median_diff": float(np.median(cmp.MAE90 - cmp.MAE80)), "R2_p": w_r2.pvalue,
"R2_90_higher": int((cmp.R2_90 > cmp.R2_80).sum()), "R2_median_diff": float(np.median(cmp.R2_90 - cmp.R2_80)),
"90_better_at_p<0.05": bool((w_mae.pvalue < 0.05 and np.median(cmp.MAE90 - cmp.MAE80) < 0) or
(w_r2.pvalue < 0.05 and np.median(cmp.R2_90 - cmp.R2_80) > 0))})
if grid == "full grid":
print(f"\n{k}, full history grid for both:")
print(cmp.round(3).to_string(index=False))
print("\ntwo-sided Wilcoxon signed-rank tests, 90% against 80% models (MAE90_lower and R2_90_higher count responses of 9):")
print(pd.DataFrame(summ).round(4).to_string(index=False))
sd count d80 d90 all_in_2.7_to_5.5 d90_at_least_2x
sqrt12 min80 [22, 24, 25, 25, 32, 35, 29, 29, 33] [44, 44, 47, 53, 62, 66, 49, 49, 52] False False
sqrt12 le80 [21, 23, 24, 24, 31, 34, 28, 28, 32] [43, 43, 46, 52, 61, 65, 48, 48, 51] False False
twelve min80 [47, 49, 49, 64, 70, 76, 50, 49, 49] [64, 66, 68, 89, 94, 103, 65, 65, 65] False False
twelve le80 [46, 48, 48, 63, 69, 75, 49, 48, 48] [63, 65, 67, 88, 93, 102, 64, 64, 64] False False
own min80 [4, 5, 5, 5, 4, 5, 5, 5, 6] [8, 11, 10, 11, 10, 11, 12, 12, 17] False True
own le80 [3, 4, 4, 4, 3, 4, 4, 4, 5] [7, 10, 9, 10, 9, 10, 11, 11, 16] True True
pooled min80 [5, 6, 5, 5, 4, 5, 4, 5, 5] [9, 13, 11, 10, 11, 12, 9, 10, 12] False False
pooled le80 [4, 5, 4, 4, 3, 4, 3, 4, 4] [8, 12, 10, 9, 10, 11, 8, 9, 11] True True
own/min80, full history grid for both:
prep bout dims80 dims90 hist80_ms hist90_ms MAE80 MAE90 R2_80 R2_90
2 1 4 8 60 70 8.396 7.472 0.395 0.380
2 2 5 11 120 60 27.802 43.759 0.313 0.238
2 3 5 10 80 70 15.346 16.450 0.680 0.619
4 1 5 11 50 50 19.504 66042549.094 0.048 0.055
4 2 4 10 90 50 20.235 21.361 0.800 0.742
4 3 5 11 180 60 29.486 30.203 0.465 0.552
5 1 5 12 50 60 4.364 4.207 0.768 0.761
5 2 5 12 160 50 6.640 9.778 0.700 0.578
5 3 6 17 50 50 11.836 13.616 0.795 0.602
own/le80, full history grid for both:
prep bout dims80 dims90 hist80_ms hist90_ms MAE80 MAE90 R2_80 R2_90
2 1 3 7 60 60 10.994 7.462000e+00 0.348 0.385
2 2 4 10 70 60 26.812 3.876100e+01 0.319 0.279
2 3 4 9 100 70 14.522 1.576100e+01 0.686 0.636
4 1 4 10 60 60 24.416 3.093341e+09 0.077 0.071
4 2 3 9 60 70 31.618 2.136200e+01 0.705 0.738
4 3 4 10 50 50 29.001 2.825200e+01 0.491 0.549
5 1 4 11 200 50 4.578 4.140000e+00 0.764 0.789
5 2 4 11 140 50 8.812 8.684000e+00 0.706 0.611
5 3 5 16 200 50 13.116 1.344100e+01 0.743 0.578
two-sided Wilcoxon signed-rank tests, 90% against 80% models (MAE90_lower and R2_90_higher count responses of 9):
reading histories MAE_p MAE90_lower MAE_median_diff R2_p R2_90_higher R2_median_diff 90_better_at_p<0.05
own/min80 full grid 0.0273 2 1.1263 0.1289 2 -0.0588 False
own/min80 four histories 0.0391 2 0.9778 0.2031 3 -0.0494 False
own/le80 full grid 0.9102 5 -0.1280 0.4961 4 -0.0059 False
own/le80 four histories 0.9102 5 -0.1468 0.6523 4 -0.0022 False
pooled/le80 four histories 0.6523 4 0.2512 0.9102 5 0.0151 False
Result: reproduced, under own/le80. Under the readings with the code's count rule the nine 80% counts lie in 3 to 5 (own/le80: 3 to 5; pooled/le80: 3 to 5), and the 90% counts are at least twice them in each. Under own/le80, with the full history grid for both, the 90% models are not better: mean MAE lower with 90% in 5 of 9 (two-sided Wilcoxon p = 0.91, median difference -0.13) and mean R-squared higher in 4 of 9 (p = 0.50, median difference -0.008). So one reading shows both parts. Under pooled/le80 (four histories) the 90% models are not better either (p = 0.65 and 0.82). Under the adopted reading (own/min80) the counts are 4 to 6, and one (6) is outside 2.7 to 5.5; there the 90% models are worse in MAE (p = 0.027, 7 of 9 worse, median +1.23 with the full grid; p = 0.020 with four histories for both) and do not differ in R-squared (p = 0.13). No test finds the 90% models better at p < 0.05 in any of the five comparisons. Of the selected 90% models one, two and two windows diverge under own/min80, own/le80 and pooled/le80 (largest forecast 2.5e6, 1.4e7 and 8.1e8 spikes/s), and over all histories 1166 and 1111 of 5760 windows diverge under own/min80 and own/le80 (fig6d's printout), so the mean MAEs and these p-values depend on rounding through the history selected and differ between executions: this execution gives the numbers above, and earlier executions gave p = 0.50 and 0.91 for MAE under own/le80, with the same conclusion each time.
Participation¶
Per program, from its own PCA under the adopted width; d is (a) the program's own count for 80% (Methods) or (b) the count from the PCA of the three programs concatenated, at most 80%, used for all three (code). Normalised to the program's maximum.
progs = [apl.Program(r, s, "min80") for r, s in zip(recs, sds["own"])]
PART = {}
for reading in ["a_own", "b_common"]:
for p in range(1, 11):
ix = sorted([i for i, r in enumerate(recs) if r["prep"] == p], key=lambda i: recs[i]["bout"])
if reading == "b_common":
_, _, evc = apl.pca(np.vstack([progs[i].sdf[progs[i].ix_stim] for i in ix]))
ds = [apl.n_pcs(evc, 0.8, "le80")] * 3
else:
ds = [apl.n_pcs(progs[i].ev, 0.8, "min80") for i in ix]
PART[(reading, p)] = (np.array([apl.participation(progs[i].coeffs, progs[i].ev, d)[1] for i, d in zip(ix, ds)]), ds)
print({k: v[1] for k, v in PART.items()})
{('a_own', 1): [7, 7, 8], ('a_own', 2): [4, 5, 5], ('a_own', 3): [8, 7, 7], ('a_own', 4): [5, 4, 5], ('a_own', 5): [5, 5, 6], ('a_own', 6): [6, 5, 6], ('a_own', 7): [7, 6, 8], ('a_own', 8): [5, 6, 7], ('a_own', 9): [6, 6, 6], ('a_own', 10): [6, 6, 7], ('b_common', 1): [8, 8, 8], ('b_common', 2): [6, 6, 6], ('b_common', 3): [10, 10, 10], ('b_common', 4): [5, 5, 5], ('b_common', 5): [8, 8, 8], ('b_common', 6): [6, 6, 6], ('b_common', 7): [8, 8, 8], ('b_common', 8): [7, 7, 7], ('b_common', 9): [6, 6, 6], ('b_common', 10): [7, 7, 7]}
fig7a-long-tailed-participation¶
Every response has a long-tailed distribution of single-neuron participation, a minority of neurons dominating its dynamics.
rows = []
for (reading, p), (P, ds) in PART.items():
for b in range(3):
rows.append({"reading": reading, "prep": p, "bout": b + 1, "skewness": stats.skew(P[b]), "frac_over_half": np.mean(P[b] > 0.5),
"median": np.median(P[b])})
PA = pd.DataFrame(rows)
print(PA.groupby("reading").apply(lambda d: pd.Series({"skew_positive": int((d.skewness > 0).sum()), "skew_min": d.skewness.min(),
"frac_over_half_below_0.5": int((d.frac_over_half < 0.5).sum()), "frac_over_half_max": d.frac_over_half.max(),
"median_participation_median": d["median"].median()})).round(3).to_string())
print(PA[PA.reading == "a_own"].round(3).to_string(index=False))
skew_positive skew_min frac_over_half_below_0.5 frac_over_half_max median_participation_median reading a_own 30.0 0.498 30.0 0.394 0.245 b_common 30.0 0.495 30.0 0.404 0.250 reading prep bout skewness frac_over_half median a_own 1 1 1.119 0.110 0.290 a_own 1 2 1.635 0.066 0.279 a_own 1 3 2.509 0.022 0.236 a_own 2 1 2.372 0.019 0.166 a_own 2 2 2.394 0.029 0.158 a_own 2 3 1.640 0.048 0.209 a_own 3 1 0.897 0.238 0.354 a_own 3 2 1.002 0.169 0.309 a_own 3 3 1.240 0.069 0.242 a_own 4 1 1.251 0.060 0.215 a_own 4 2 1.074 0.146 0.277 a_own 4 3 1.173 0.179 0.332 a_own 5 1 0.537 0.223 0.394 a_own 5 2 0.498 0.277 0.394 a_own 5 3 0.531 0.394 0.407 a_own 6 1 1.974 0.033 0.177 a_own 6 2 3.246 0.017 0.178 a_own 6 3 1.538 0.058 0.276 a_own 7 1 1.776 0.080 0.172 a_own 7 2 1.672 0.053 0.197 a_own 7 3 1.502 0.147 0.212 a_own 8 1 3.529 0.020 0.150 a_own 8 2 2.268 0.049 0.229 a_own 8 3 4.360 0.010 0.177 a_own 9 1 1.182 0.202 0.374 a_own 9 2 1.469 0.154 0.328 a_own 9 3 1.298 0.106 0.248 a_own 10 1 1.175 0.181 0.231 a_own 10 2 0.973 0.241 0.276 a_own 10 3 0.918 0.253 0.292
Result: reproduced. Under both readings of d, every one of the 30 responses has positive skewness of participation (0.50 to 4.36, reading (a)) and fewer than half its neurons above 50% of the maximum (at most 39.4%).
fig7f-strongly-variable-neurons¶
Neurons with high participation in one response often have low participation in another; every preparation contains neurons whose change in participation well exceeds that predicted by a noise model.
rows = []
for (reading, p), (P, ds) in PART.items():
dP = np.column_stack([P[0] - P[1], P[1] - P[2], P[0] - P[2]])
mx = np.abs(dP[:, :2]).max(1)
for pool in ["all_pairs", "consecutive"]:
data = dP.ravel(order="F") if pool == "all_pairs" else dP[:, :2].ravel(order="F")
mu, sd, nout = apl.iterate_outliers(data)
thr = max(abs(mu - 3 * sd), abs(mu + 3 * sd))
nv = int((mx >= thr).sum())
rows.append({"reading": reading, "pool": pool, "prep": p, "neurons": P.shape[1], "mu": mu, "sd": sd, "dropped": nout,
"threshold": thr, "strongly_variable": nv, "proportion": nv / P.shape[1]})
SV = pd.DataFrame(rows)
print(SV.groupby(["reading", "pool"]).apply(lambda d: pd.Series({"preps_with_one": int((d.strongly_variable > 0).sum()),
"min_count": d.strongly_variable.min(), "proportion_range": f"{d.proportion.min():.3f} to {d.proportion.max():.3f}"})).to_string())
print(SV.round(4).to_string(index=False))
preps_with_one min_count proportion_range
reading pool
a_own all_pairs 10 4 0.038 to 0.234
consecutive 10 6 0.059 to 0.293
b_common all_pairs 10 4 0.038 to 0.267
consecutive 10 7 0.051 to 0.394
reading pool prep neurons mu sd dropped threshold strongly_variable proportion
a_own all_pairs 1 136 0.0251 0.0493 66 0.1730 11 0.0809
a_own consecutive 1 136 0.0251 0.0530 36 0.1842 8 0.0588
a_own all_pairs 2 105 -0.0223 0.0437 62 0.1535 14 0.1333
a_own consecutive 2 105 -0.0162 0.0435 42 0.1467 16 0.1524
a_own all_pairs 3 160 0.0520 0.0534 137 0.2124 25 0.1562
a_own consecutive 3 160 0.0429 0.0533 69 0.2028 32 0.2000
a_own all_pairs 4 151 -0.0643 0.0555 110 0.2308 17 0.1126
a_own consecutive 4 151 -0.0498 0.0480 72 0.1937 29 0.1921
a_own all_pairs 5 94 -0.0375 0.0562 104 0.2061 22 0.2340
a_own consecutive 5 94 -0.0257 0.0549 57 0.1904 24 0.2553
a_own all_pairs 6 121 -0.0540 0.0578 49 0.2275 6 0.0496
a_own consecutive 6 121 -0.0365 0.0559 34 0.2042 8 0.0661
a_own all_pairs 7 75 -0.0195 0.0465 62 0.1590 16 0.2133
a_own consecutive 7 75 -0.0112 0.0408 40 0.1335 22 0.2933
a_own all_pairs 8 102 -0.0258 0.0389 93 0.1426 20 0.1961
a_own consecutive 8 102 -0.0220 0.0649 38 0.2168 6 0.0588
a_own all_pairs 9 104 0.0747 0.0667 56 0.2749 4 0.0385
a_own consecutive 9 104 0.0518 0.0570 39 0.2227 10 0.0962
a_own all_pairs 10 83 -0.0305 0.0409 70 0.1532 18 0.2169
a_own consecutive 10 83 -0.0246 0.0393 50 0.1425 19 0.2289
b_common all_pairs 1 136 0.0250 0.0498 59 0.1744 8 0.0588
b_common consecutive 1 136 0.0245 0.0528 34 0.1828 7 0.0515
b_common all_pairs 2 105 -0.0172 0.0410 65 0.1401 18 0.1714
b_common consecutive 2 105 -0.0120 0.0400 46 0.1319 21 0.2000
b_common all_pairs 3 160 0.0480 0.0465 159 0.1876 35 0.2188
b_common consecutive 3 160 0.0384 0.0454 88 0.1746 41 0.2562
b_common all_pairs 4 151 -0.0639 0.0551 109 0.2291 18 0.1192
b_common consecutive 4 151 -0.0503 0.0488 67 0.1967 28 0.1854
b_common all_pairs 5 94 -0.0300 0.0561 102 0.1984 24 0.2553
b_common consecutive 5 94 -0.0128 0.0453 69 0.1488 37 0.3936
b_common all_pairs 6 121 -0.0526 0.0578 48 0.2261 6 0.0496
b_common consecutive 6 121 -0.0372 0.0568 30 0.2077 8 0.0661
b_common all_pairs 7 75 -0.0111 0.0439 68 0.1428 20 0.2667
b_common consecutive 7 75 -0.0068 0.0404 40 0.1279 23 0.3067
b_common all_pairs 8 102 -0.0218 0.0422 86 0.1485 17 0.1667
b_common consecutive 8 102 -0.0291 0.0613 48 0.2129 7 0.0686
b_common all_pairs 9 104 0.0747 0.0667 56 0.2749 4 0.0385
b_common consecutive 9 104 0.0518 0.0570 39 0.2227 10 0.0962
b_common all_pairs 10 83 -0.0256 0.0404 75 0.1467 18 0.2169
b_common consecutive 10 83 -0.0285 0.0486 40 0.1742 13 0.1566
Result: reproduced. Under both readings of d and both poolings, all 10 preparations have strongly variable neurons: at least 4 per preparation (reading (a), all pairs), 3.8% to 23.4% of the neurons; with consecutive pairs (the code) 5.9% to 29.3%.
halving-participation¶
Even the most strongly participating neurons in a response could more than halve their participation in other evoked responses.
rows = []
for (reading, p), (P, ds) in PART.items():
for sel_name in ["top_neuron", "top_10pct"]:
hit, examples = False, []
for a in range(3):
sel = [int(np.argmax(P[a]))] if sel_name == "top_neuron" else list(np.argsort(P[a])[::-1][:int(np.ceil(0.1 * P.shape[1]))])
for b in range(3):
if b == a:
continue
lo = [n for n in sel if P[b][n] < 0.5 * P[a][n]]
if lo:
hit = True
examples.append((a + 1, b + 1, len(lo), round(float(min(P[b][n] / P[a][n] for n in lo)), 3)))
rows.append({"reading": reading, "selection": sel_name, "prep": p, "halves": hit, "examples": examples[:3]})
HV = pd.DataFrame(rows)
print(HV.groupby(["reading", "selection"]).halves.sum().to_string())
print(HV[HV.reading == "a_own"].to_string(index=False))
reading selection
a_own top_10pct 9
top_neuron 6
b_common top_10pct 9
top_neuron 6
reading selection prep halves examples
a_own top_neuron 1 True [(2, 3, 1, 0.443)]
a_own top_10pct 1 True [(1, 3, 1, 0.444), (2, 3, 2, 0.443)]
a_own top_neuron 2 False []
a_own top_10pct 2 True [(1, 2, 1, 0.475), (3, 1, 2, 0.262), (3, 2, 1, 0.24)]
a_own top_neuron 3 True [(1, 3, 1, 0.32), (2, 3, 1, 0.491)]
a_own top_10pct 3 True [(1, 3, 9, 0.32), (2, 3, 7, 0.367)]
a_own top_neuron 4 True [(2, 1, 1, 0.336), (3, 1, 1, 0.336)]
a_own top_10pct 4 True [(2, 1, 3, 0.336), (3, 1, 6, 0.282), (3, 2, 3, 0.426)]
a_own top_neuron 5 True [(1, 3, 1, 0.443), (2, 3, 1, 0.443), (3, 2, 1, 0.472)]
a_own top_10pct 5 True [(1, 3, 2, 0.259), (2, 3, 2, 0.23), (3, 1, 2, 0.381)]
a_own top_neuron 6 False []
a_own top_10pct 6 True [(1, 2, 1, 0.435), (3, 2, 1, 0.422)]
a_own top_neuron 7 True [(3, 1, 1, 0.476)]
a_own top_10pct 7 True [(1, 3, 1, 0.494), (3, 1, 3, 0.476), (3, 2, 1, 0.478)]
a_own top_neuron 8 False []
a_own top_10pct 8 True [(1, 3, 1, 0.494), (2, 1, 2, 0.377), (2, 3, 3, 0.333)]
a_own top_neuron 9 True [(3, 1, 1, 0.186)]
a_own top_10pct 9 True [(1, 3, 2, 0.269), (2, 1, 1, 0.236), (2, 3, 2, 0.472)]
a_own top_neuron 10 False []
a_own top_10pct 10 False []
Result: reproduced. The neuron at 100% in a program has under half that participation in another program of its preparation in 6 of 10 preparations (reading (a)); a neuron of a program's top 10% does so in 9 of 10. Both readings of d give the same counts.
fig7s1-rate-synchrony¶
A neuron's participation reflects both its firing rate and its synchrony; firing rate explains on average 50% of the variation in participation within a response, and rate changes 23% of the change in participation between responses.
rows = []
for reading in ["a_own", "b_common"]:
for rate_from in [32.5, 30.0]:
r2, dr2, dr2_code = [], [], []
for p in range(1, 11):
ix = sorted([i for i, r in enumerate(recs) if r["prep"] == p], key=lambda i: recs[i]["bout"])
P = PART[(reading, p)][0]
rates = np.array([[np.sum(tr >= rate_from) / (progs[i].t_end - rate_from) for tr in progs[i].trains] for i in ix])
r2 += [np.corrcoef(P[b], rates[b])[0, 1] ** 2 for b in range(3)]
dR = np.column_stack([rates[0] - rates[1], rates[0] - rates[2], rates[1] - rates[2]])
dPm = np.column_stack([P[0] - P[1], P[0] - P[2], P[1] - P[2]])
dPc = np.column_stack([P[0] - P[1], P[1] - P[2], P[0] - P[2]])
dr2 += [np.corrcoef(dR[:, c], dPm[:, c])[0, 1] ** 2 for c in range(3)]
dr2_code += [np.corrcoef(dR[:, c], dPc[:, c])[0, 1] ** 2 for c in range(3)]
rows.append({"reading": reading, "rate_from_s": rate_from, "mean_R2_within": np.mean(r2), "range_within": f"{min(r2):.2f} to {max(r2):.2f}",
"mean_R2_change_matched": np.mean(dr2), "mean_R2_change_code_pairing": np.mean(dr2_code), "n_programs": len(r2), "n_pairs": len(dr2)})
print(pd.DataFrame(rows).round(4).to_string(index=False))
reading rate_from_s mean_R2_within range_within mean_R2_change_matched mean_R2_change_code_pairing n_programs n_pairs a_own 32.5 0.4908 0.29 to 0.74 0.2394 0.2049 30 30 a_own 30.0 0.5144 0.30 to 0.74 0.2651 0.2210 30 30 b_common 32.5 0.4990 0.31 to 0.74 0.2440 0.2095 30 30 b_common 30.0 0.5224 0.30 to 0.76 0.2698 0.2257 30 30
Result: reproduced. With participation reading (a), the rate from stimulation offset and matched pairs, the mean R-squared is 0.491 within responses (0.45 to 0.55 required; range 0.29 to 0.74) and 0.239 for changes between responses (0.207 to 0.253 required). The rate from onset gives 0.514 and 0.265 (the second outside); the code's mismatched pairing gives 0.205 and 0.221; reading (b) gives 0.499 and 0.244.
fig7gh-robust-to-participation¶
The distance between a pair of responses does not correlate with the total change in neuron participation between them nor with the distance between their participation distributions; the program is robust to the participation of single neurons.
# Participation under each reading of width and count: (a) the program's own count under the rule,
# (b) the common count (at most 80% of the concatenated PCA), as in the Participation section.
PARTR = {}
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
mode, rule = k.split("/")
pg = progs if mode == "own" else [apl.Program(r, s, "min80") for r, s in zip(recs, sds[mode])]
for p in range(1, 11):
ix = sorted([i for i, r in enumerate(recs) if r["prep"] == p], key=lambda i: recs[i]["bout"])
_, _, evc = apl.pca(np.vstack([pg[i].sdf[pg[i].ix_stim] for i in ix]))
for reading, ds in [("a_own", [apl.n_pcs(pg[i].ev, 0.8, rule) for i in ix]), ("b_common", [apl.n_pcs(evc, 0.8, "le80")] * 3)]:
PARTR[(k, reading, p)] = np.array([apl.participation(pg[i].coeffs, pg[i].ev, d)[1] for i, d in zip(ix, ds)])
rows = []
for k in ["own/min80", "own/le80", "pooled/min80", "pooled/le80"]:
for ps in ["recurrent", "code"]:
T = haus_table(k, "prog1", ps)
T["norm_dist"] = T.H / T.ctrl_mean
for reading in ["a_own", "b_common"]:
tc, hd = [], []
for row in T.itertuples():
P = PARTR[(k, reading, row.prep)]
i, j = [int(x) - 1 for x in row.pair.split(",")]
tc.append(np.abs(P[i] - P[j]).sum())
hd.append(apl.hellinger(P[i], P[j]))
T["total_change"], T["hellinger"] = tc, hd
keep = ~((T.prep == 4) & T.pair.isin(["1,2", "1,3"]))
for x in ["total_change", "hellinger"]:
X = sm.add_constant(T.loc[keep, x]); y = T.loc[keep, "norm_dist"]
ols = sm.OLS(y, X).fit()
rob = sm.RLM(y, X, M=sm.robust.norms.TukeyBiweight()).fit()
ck = T.norm_dist < 1
ols_code = sm.OLS(T.loc[ck, "norm_dist"], sm.add_constant(T.loc[ck, x])).fit()
rows.append({"reading": k, "points": ps, "participation": reading, "x": x, "n": int(keep.sum()),
"slope": ols.params.iloc[1], "p": ols.pvalues.iloc[1], "R2": ols.rsquared,
"robust_slope": rob.params.iloc[1], "robust_p": rob.pvalues.iloc[1],
"code_exclusion_n": int(ck.sum()), "code_exclusion_p": ols_code.pvalues.iloc[1]})
RB = pd.DataFrame(rows)
print(RB.round(4).to_string(index=False))
V = RB.groupby(["reading", "points", "participation"]).p.apply(lambda s: int((s < 0.05).sum())).rename("significant_slopes_of_2").reset_index()
print("\nslopes significant at p < 0.05 (of the two) per reading, point set and participation reading:")
print(V.pivot_table(index=["reading", "points"], columns="participation", values="significant_slopes_of_2").to_string())
reading points participation x n slope p R2 robust_slope robust_p code_exclusion_n code_exclusion_p
own/min80 recurrent a_own total_change 28 0.0127 0.0314 0.1659 0.0127 0.0316 29 0.0066
own/min80 recurrent a_own hellinger 28 0.3588 0.3484 0.0339 0.3972 0.3472 29 0.1451
own/min80 recurrent b_common total_change 28 0.0130 0.0320 0.1649 0.0130 0.0333 29 0.0064
own/min80 recurrent b_common hellinger 28 0.4534 0.2354 0.0537 0.5153 0.2062 29 0.0854
own/min80 code a_own total_change 28 0.0092 0.1112 0.0947 0.0074 0.1147 28 0.1112
own/min80 code a_own hellinger 28 0.7806 0.0280 0.1725 0.6625 0.0633 28 0.0280
own/min80 code b_common total_change 28 0.0103 0.0822 0.1117 0.0083 0.0992 28 0.0822
own/min80 code b_common hellinger 28 0.8432 0.0171 0.1997 0.8006 0.0236 28 0.0171
own/le80 recurrent a_own total_change 28 0.0109 0.0356 0.1589 0.0108 0.0400 29 0.0202
own/le80 recurrent a_own hellinger 28 0.3292 0.3699 0.0310 0.3320 0.3904 29 0.2463
own/le80 recurrent b_common total_change 28 0.0106 0.0519 0.1376 0.0105 0.0638 29 0.0294
own/le80 recurrent b_common hellinger 28 0.4691 0.1679 0.0718 0.5166 0.1536 29 0.1030
own/le80 code a_own total_change 28 0.0060 0.3318 0.0363 0.0078 0.1386 28 0.3318
own/le80 code a_own hellinger 28 0.4212 0.3153 0.0388 0.3281 0.4385 28 0.3153
own/le80 code b_common total_change 28 0.0074 0.2464 0.0513 0.0083 0.1299 28 0.2464
own/le80 code b_common hellinger 28 0.7404 0.0529 0.1366 0.6668 0.1065 28 0.0529
pooled/min80 recurrent a_own total_change 28 0.0088 0.1245 0.0884 0.0068 0.2407 29 0.0276
pooled/min80 recurrent a_own hellinger 28 -0.0276 0.9438 0.0002 -0.0337 0.9325 29 0.5814
pooled/min80 recurrent b_common total_change 28 0.0087 0.1355 0.0836 0.0064 0.2913 29 0.0292
pooled/min80 recurrent b_common hellinger 28 0.2474 0.5205 0.0161 0.1660 0.6695 29 0.2114
pooled/min80 code a_own total_change 28 0.0052 0.3473 0.0340 0.0050 0.3786 28 0.3473
pooled/min80 code a_own hellinger 28 0.3482 0.3408 0.0350 0.3243 0.3896 28 0.3408
pooled/min80 code b_common total_change 28 0.0056 0.3153 0.0388 0.0055 0.3455 28 0.3153
pooled/min80 code b_common hellinger 28 0.6110 0.0846 0.1101 0.6032 0.0955 28 0.0846
pooled/le80 recurrent a_own total_change 28 0.0057 0.2553 0.0495 0.0054 0.3024 29 0.1328
pooled/le80 recurrent a_own hellinger 28 0.0991 0.7480 0.0040 0.1388 0.6692 29 0.5281
pooled/le80 recurrent b_common total_change 28 0.0066 0.2086 0.0601 0.0063 0.2435 29 0.1067
pooled/le80 recurrent b_common hellinger 28 0.1826 0.5940 0.0111 0.3888 0.2673 29 0.3837
pooled/le80 code a_own total_change 28 0.0033 0.5093 0.0169 0.0042 0.4190 28 0.5093
pooled/le80 code a_own hellinger 28 0.3286 0.2731 0.0460 0.3455 0.2597 28 0.2731
pooled/le80 code b_common total_change 28 0.0045 0.3867 0.0290 0.0055 0.3099 28 0.3867
pooled/le80 code b_common hellinger 28 0.5942 0.0690 0.1215 0.5980 0.0695 28 0.0690
slopes significant at p < 0.05 (of the two) per reading, point set and participation reading:
participation a_own b_common
reading points
own/le80 code 0.0 0.0
recurrent 1.0 0.0
own/min80 code 1.0 1.0
recurrent 1.0 1.0
pooled/le80 code 0.0 0.0
recurrent 0.0 0.0
pooled/min80 code 0.0 0.0
recurrent 0.0 0.0
Result: partially reproduced, resting on the adopted reading. Under the adopted width and count, each set of distances finds one significant slope of two: with the recurrent points (Methods), the normalised distance rises with the total change in participation (slope 0.0127, p = 0.031, R-squared 0.17, 28 pairs) but not with the Hellinger distance (p = 0.35); with the code's point sets, it rises with the Hellinger distance (p = 0.028) but not with the total change (p = 0.11). Participation reading (b) gives the same pattern (p = 0.032 and 0.017). So one of the two absences holds and the other fails. Under own/le80 one slope is significant with the recurrent points (total change, p = 0.036) and none with the code's points (lowest p 0.053); under pooled/min80 and pooled/le80, with participation from the pooled width, no slope is significant with the legend's exclusion (lowest p 0.085 and 0.069). With the code's exclusion (pairs with normalised distance below 1, 29 pairs with the recurrent points), pooled/min80 has a significant total-change slope with the recurrent points (p = 0.028 and 0.029, participation readings (a) and (b)), and pooled/le80 has none (lowest p 0.069). The outcome depends on the reading, and under pooled/min80 on the exclusion rule.
fig7s2-no-invariant-core¶
No small invariant core of strongly participating, phasically active neurons, such as a classic central pattern generator, is found across preparations.
Ensembles by the code's consensus clustering of each program from stimulation onset, typed by the
autocorrelogram of their pooled spikes against interval shuffles (port in apl.py, citing each
MATLAB file). A neuron takes its ensemble's type; persistent neurons have the same type in all three
programs. Participation is that of the Participation section (readings (a) and (b)). Run for the
recording's own width (the code's Data.GaussSD, the adopted width) and the pooled width, each with two
seeds.
t0 = time.time()
TYPES = {(mode, seed): apl.run_types(recs, sds[mode], seed=seed) for mode in ["own", "pooled"] for seed in [7, 8]}
print(f"ensembles and types of 30 recordings, 2 widths x 2 seeds, in {time.time() - t0:.0f} s")
names = {1: "tonic", 2: "oscillator", 3: "burster", 4: "pauser"}
rows = []
for (mode, seed), res in TYPES.items():
for o in res:
rows.append({"width": mode, "seed": seed, "prep": o["prep"], "bout": o["bout"], "ensembles": len(o["groups"]),
"clustered": o["n_clustered"], **{names[t]: int((o["types"] == t).sum()) for t in names}})
ET = pd.DataFrame(rows)
print("\nneurons per type (sum over 30 programs) and ensembles per program:")
print(ET.groupby(["width", "seed"])[["ensembles", "clustered", "tonic", "oscillator", "burster", "pauser"]]
.agg(["sum", "min", "max"]).to_string())
print("programs that could not be grouped:", {k: sum(o["ungrouped"] for o in v) for k, v in TYPES.items()})
def core_table(res, reading):
out = []
for p in range(1, 11):
T3 = np.column_stack([o["types"] for o in sorted([o for o in res if o["prep"] == p], key=lambda o: o["bout"])])
P = PART[(reading, p)][0]
high, dmax = P.max(0), np.abs(np.column_stack([P[0] - P[1], P[1] - P[2]])).max(1)
persist = {names[t]: int(np.all(T3 == t, 1).sum()) for t in names}
osc = np.flatnonzero(np.all(T3 == 2, 1))
if osc.size:
upper = np.percentile(high[osc], 90, method="hazen") # MATLAB prctile
sel = osc[high[osc] > upper]
else:
sel = osc
med = float(np.median(dmax[sel])) if sel.size else np.nan
top_all = np.argsort(high)[::-1][:int(np.ceil(0.1 * high.size))]
out.append({"prep": p, "neurons": high.size, **{f"persistent_{k}": v for k, v in persist.items()},
"top10pct_osc_n": int(sel.size), "top_osc_median_maxP": float(np.median(high[sel])) if sel.size else np.nan,
"top_osc_median_max_change": med, "core": bool(med < 0.1),
"no_typing_top10pct_median_max_change": float(np.median(dmax[top_all]))})
return pd.DataFrame(out)
summary = []
for (mode, seed), res in TYPES.items():
for reading in ["a_own", "b_common"]:
CT = core_table(res, reading)
summary.append({"width": mode, "seed": seed, "participation": reading,
"preps_with_core": int(CT.core.sum()), "preps_without_persistent_oscillator": int((CT.persistent_oscillator == 0).sum()),
"median_change_min": CT.top_osc_median_max_change.min(), "median_change_max": CT.top_osc_median_max_change.max(),
**{f"preps_with_persistent_{k}": int((CT[f'persistent_{k}'] > 0).sum()) for k in names.values()},
"no_typing_preps_under_0.1": int((CT.no_typing_top10pct_median_max_change < 0.1).sum()),
"no_typing_min": CT.no_typing_top10pct_median_max_change.min()})
if (mode, seed, reading) == ("own", 7, "a_own"):
print("\nadopted width (own), seed 7, participation (a), per preparation:")
print(CT.round(3).to_string(index=False))
print("\nall variants (core: median maximum change of the top 10% of persistent oscillators under 0.1):")
print(pd.DataFrame(summary).round(3).to_string(index=False))
ensembles and types of 30 recordings, 2 widths x 2 seeds, in 130 s
neurons per type (sum over 30 programs) and ensembles per program:
ensembles clustered tonic oscillator burster pauser
sum min max sum min max sum min max sum min max sum min max sum min max
width seed
own 7 540 14 26 3393 75 160 239 0 25 2070 24 123 903 0 85 181 0 30
8 533 13 25 3393 75 160 232 0 35 2112 34 134 912 0 90 137 0 33
pooled 7 545 13 27 3393 75 160 249 0 25 2071 23 135 889 0 77 184 0 25
8 534 13 24 3393 75 160 219 0 35 2057 24 134 935 2 81 182 0 40
programs that could not be grouped: {('own', 7): 0, ('own', 8): 0, ('pooled', 7): 0, ('pooled', 8): 0}
adopted width (own), seed 7, participation (a), per preparation:
prep neurons persistent_tonic persistent_oscillator persistent_burster persistent_pauser top10pct_osc_n top_osc_median_maxP top_osc_median_max_change core no_typing_top10pct_median_max_change
1 136 0 84 3 0 8 0.560 0.165 False 0.165
2 105 2 16 17 0 2 0.911 0.068 True 0.134
3 160 1 37 0 0 4 0.843 0.247 False 0.274
4 151 0 39 0 0 4 0.895 0.440 False 0.278
5 94 0 67 2 0 7 0.971 0.237 False 0.244
6 121 0 27 19 0 3 0.577 0.221 False 0.163
7 75 0 17 3 0 2 1.000 0.179 False 0.243
8 102 0 32 0 0 3 0.537 0.257 False 0.227
9 104 0 61 0 0 6 0.881 0.212 False 0.178
10 83 0 32 18 0 3 0.948 0.282 False 0.317
all variants (core: median maximum change of the top 10% of persistent oscillators under 0.1):
width seed participation preps_with_core preps_without_persistent_oscillator median_change_min median_change_max preps_with_persistent_tonic preps_with_persistent_oscillator preps_with_persistent_burster preps_with_persistent_pauser no_typing_preps_under_0.1 no_typing_min
own 7 a_own 1 0 0.068 0.440 2 10 6 0 0 0.134
own 7 b_common 1 0 0.084 0.456 2 10 6 0 0 0.122
own 8 a_own 0 0 0.136 0.440 2 10 8 0 0 0.134
own 8 b_common 0 0 0.130 0.456 2 10 8 0 0 0.122
pooled 7 a_own 1 0 0.068 0.546 3 10 7 0 0 0.134
pooled 7 b_common 1 0 0.084 0.578 3 10 7 0 0 0.122
pooled 8 a_own 1 0 0.068 0.440 3 10 10 0 0 0.134
pooled 8 b_common 1 0 0.084 0.456 3 10 10 0 0 0.122
Result: reproduced. With the port of the code's ensemble toolbox, every preparation has neurons typed oscillator in all three programs (16 to 84 per preparation, adopted width and seed), and the top 10% of them by maximum participation have a median maximum change between consecutive programs of 0.068 to 0.440 of the program maximum. Only preparation 2 has an invariant core by the claims file's rule (median change 0.068, under 0.1); 1 of 10 preparations, fewer than half, under the adopted width with seed 7, and 0 or 1 of 10 under both widths, both seeds and both readings of participation. The top 10% of persistent oscillators holds 2 to 8 neurons per preparation. Without typing, the top 10% of all neurons by maximum participation have median maximum changes of 0.12 to 0.32, under 0.1 in no preparation. The legend's statement that only the oscillator class had a consistently typed neuron in all ten preparations holds in part: oscillators persist in 10 of 10 preparations under every variant, but persistent bursters are found in 6 to 10 preparations (10 in one variant), persistent tonic neurons in 2 or 3 and persistent pausers in none. The clustering is random (k-means starts); two seeds are shown, and the port has not been checked against MATLAB's output.
fig8-caudolateral¶
Neurons with strong participation across the three responses, and those with highly variable participation, lie mainly in the caudo-lateral quadrant of the ganglion.
Blocked (see the header): neither the data set, its documentation nor the paper's text says which directions of the array's x and y axes are caudal and lateral. The counts by quadrant of the array coordinates are shown so that the claim can be judged once the orientation is known, with true quintiles as the criterion's variant, and the share of the top fifth in its most common quadrant against the share of all neurons there; they decide nothing here.
rows = []
for side, group in [("left", [1, 2, 4, 10]), ("right", [3, 5, 6, 9])]:
vals_max, vals_rng, xs, ys = [], [], [], []
for p in group:
P = PART[("a_own", p)][0]
vals_max.append(P.max(0)); vals_rng.append(P.max(0) - P.min(0))
xs.append(D["coords"][p - 1]["x"]); ys.append(D["coords"][p - 1]["y"])
allmax = np.concatenate([PART[("a_own", p)][0].max(0) for p in [1, 2, 3, 4, 5, 6, 9, 10]])
allrng = np.concatenate([np.ptp(PART[("a_own", p)][0], 0) for p in [1, 2, 3, 4, 5, 6, 9, 10]])
x, y = np.concatenate(xs), np.concatenate(ys)
cx, cy = 25.0, 25.0 # centre of the 501 x 501 template, in coordinate units
q = np.where(x >= cx, "x+", "x-").astype(object) + np.where(y >= cy, "y+", "y-")
for name, v, allv in [("max", np.concatenate(vals_max), allmax), ("range", np.concatenate(vals_rng), allrng)]:
edges = np.linspace(allv.min(), allv.max(), 6)
for division, top in [("equal-width fifth (code)", v >= edges[-2]), ("true quintile (variant)", v >= np.quantile(v, 0.8))]:
counts = pd.Series(q[top]).value_counts()
rows.append({"side": side, "measure": name, "division": division, "neurons": v.size, "top_fifth": int(top.sum()),
"by_quadrant": counts.to_dict(), "largest_quadrant": counts.index[0] if top.any() else None,
"largest_share": round(counts.iloc[0] / top.sum(), 2) if top.any() else np.nan,
"all_neurons_in_that_quadrant": round(float(np.mean(q == counts.index[0])), 2) if top.any() else np.nan})
print(pd.DataFrame(rows).to_string(index=False))
side measure division neurons top_fifth by_quadrant largest_quadrant largest_share all_neurons_in_that_quadrant
left max equal-width fifth (code) 475 21 {'x-y-': 15, 'x-y+': 6} x-y- 0.71 0.19
left max true quintile (variant) 475 95 {'x-y-': 38, 'x+y-': 19, 'x+y+': 19, 'x-y+': 19} x-y- 0.40 0.19
left range equal-width fifth (code) 475 1 {'x-y+': 1} x-y+ 1.00 0.23
left range true quintile (variant) 475 95 {'x-y-': 32, 'x-y+': 24, 'x+y+': 20, 'x+y-': 19} x-y- 0.34 0.19
right max equal-width fifth (code) 479 28 {'x-y+': 15, 'x+y-': 10, 'x-y-': 2, 'x+y+': 1} x-y+ 0.54 0.20
right max true quintile (variant) 479 96 {'x-y+': 39, 'x+y-': 35, 'x-y-': 13, 'x+y+': 9} x-y+ 0.41 0.20
right range equal-width fifth (code) 479 2 {'x-y+': 2} x-y+ 1.00 0.20
right range true quintile (variant) 479 96 {'x-y+': 38, 'x-y-': 24, 'x+y-': 21, 'x+y+': 13} x-y+ 0.40 0.20
Result: blocked, metadata insufficient (see the header). Shown for the verifier, not judged: in each side the top-fifth neurons concentrate in one quadrant of the array coordinates, the same quadrant for maximum under both divisions and for range under true quintiles (left x-y-, right x-y+). Under true quintiles that quadrant holds 34% to 41% of the top fifth against 19% to 20% of all neurons; under the code's equal-width fifths 71% (left, maximum, 15 of 21) and 54% (right, 15 of 28). The code's equal-width division leaves only 1 or 2 neurons in the top fifth of the range, so that half of the test is nearly empty as the code defines it. Which anatomical quadrant these are cannot be told without the array's orientation.
Summary¶
| Claim | Outcome |
|---|---|
| dataset-size | partially reproduced |
| fig1d-slow-oscillation | reproduced |
| fig1e-decaying-rate | reproduced |
| fig2b-dimensions | reproduced (under the code's count rule) |
| fig2ef-periodic-recurrence | reproduced |
| fig2e-single-dominant-orbit | reproduced |
| fig2s2-threshold-robust | reproduced |
| fig3a-coalescence | not reproduced |
| fig3c-same-manifold | reproduced |
| fig3s1a-common-axes | reproduced |
| fig3d-initial-conditions | reproduced |
| fig3f-pairwise-similarity | reproduced |
| fig3h-perturbations-return | partially reproduced (assumed) |
| fig3i-same-manifold-after | reproduced (reading (b)) |
| fig4bc-stable-spiral | partially reproduced |
| fig4c-orbital-period | reproduced (assumed) |
| fig4s1a-contracting-dimensions | not reproduced |
| fig4s1b-rotation-dominant | reproduced |
| fig5b-period-changes | reproduced |
| fig5c-no-relation-contraction | reproduced |
| fig6s1-no-p10-motorneurons | reproduced |
| fig6d-decode-p10 | not reproduced |
| fig6s2-dimensions-p10 | reproduced (under own/le80) |
| fig7a-long-tailed-participation | reproduced |
| fig7f-strongly-variable-neurons | reproduced |
| halving-participation | reproduced |
| fig7s1-rate-synchrony | reproduced |
| fig7gh-robust-to-participation | partially reproduced (assumed) |
| fig7s2-no-invariant-core | reproduced |
| fig8-caudolateral | blocked, metadata insufficient |
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.
Outcome under each reading of width and count, for the claims whose result changes with it (numbers printed in each claim's section; "holds" means the criterion is met under that reading):
| Claim | own/min80 (adopted) | own/le80 | pooled/min80 | pooled/le80 |
|---|---|---|---|---|
| fig2b-dimensions | fails (ratio 9.4 in one response) | holds | fails (ratio 9.4) | holds |
| fig3h-perturbations-return, mean period | fails (16 kept, 15 returned) | holds (18, 16) | fails (14, 13) | fails (16, 14) |
| fig3h-perturbations-return, median period | fails (17, 16) | holds (19, 17) | fails (14, 13) | fails (17, 15) |
| fig3i-same-manifold-after, (b), mean period | holds (13) | fails (16) | fails (11) | holds (14) |
| fig4c-orbital-period | holds (10.45 s) | fails (13.55 s) | holds (10.12 s) | fails (12.22 s) |
| fig6s2-dimensions-p10 | fails (one count of 6) | holds | fails (counts to 6) | holds |
| fig6d-decode-p10 | 8 of 9 | 8 of 9 | 8 of 9 | 8 of 9 |
| fig7gh-robust-to-participation | one slope of two significant | one slope with recurrent points | no slope (one with the code's exclusion) | no slope |
No reading makes all of these hold. The adopted reading follows the Methods' count and the recording's own median ISI; the outcomes that rest on it are marked as assumed.
How the analysis differs from the paper's. It is a Python port of the paper's MATLAB code, following the Methods where they fix a detail and the code where they do not. The Methods' kernel width as printed gives 21 to 76 dimensions (33 to 76 with median ISI / 12, 21 to 41 with / sqrt(12)), and the analysis uses the code's width (the median ISI) for everything after claim fig2b. The code computes that median over the recordings of the same bout number read so far; the adopted reading uses the recording's own. The number of PCs is the smallest reaching 80% (Methods) in the adopted reading; the code's rule (at most 80%) is run alongside and changes some outcomes (table above). A window counts as coalesced or recurrent at at least 90% of its points, as the Methods say. The local models use the contiguous run of neighbours as the Methods describe. The permutation test of fig5b permutes the delays against time (10000 permutations); the code's test is shown too. The decoding uses a numpy IRLS for MATLAB's glmfit; the 90% models use the full history grid under the two readings with the recording's own width and four histories under pooled/le80. The ensembles and types of fig7s2 come from a Python port of the code's consensus clustering and autocorrelogram typing, with Lloyd's k-means for MATLAB's kmeans, not checked against MATLAB's output.
What was found about the data set. The files match their checksums and the description: 30 recordings of 75 to 160 neurons, 1131 in all, P10 for nine, coordinates for all ten preparations. The paper's 120 to 180 neurons per recording cannot be right with its own total of 1131. The P10 sampling (1629.7 Hz) agrees with the description's 1630 Hz, not the paper's 1600 Hz. The P10 file names of preparation 2 drop the "B" of its spike file. The coordinates have no unit and no orientation, so which part of the array is caudo-lateral cannot be told from the data set.
print(f"notebook run time {(time.time() - started) / 60:.1f} min; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB (main process)")
notebook run time 21.8 min; peak memory 2.47 GB (main process)