Lakshminarasimhan et al. (2024) on dandiset 000009¶

Paper. Lakshminarasimhan KJ, Xie M, Cohen JD, Sauerbrei BA, Hantman AW, Litwin-Kumar A, Escola S (2024). Specific connectivity optimizes learning in thalamocortical loops. Cell Reports 43, 114059. doi:10.1016/j.celrep.2024.114059. The claims file (claims/lakshminarasimhan-2024.yaml) was written from the NIH author manuscript in PubMed Central (PMC11104520) with the supplement (mmc2).

Dandiset. DANDI:000009, version 0.220126.1903, "Maintenance of persistent activity in a frontal thalamocortical loop" (Guo et al. 2017). The paper cites the dandiset without a version (key resources table). This is the only published version, and it is pinned for that reason. The draft holds the same 173 files with the same blobs (checked below); it differs only in metadata.

What the paper used from it. The working memory data of Figure 6 and Figure S6: "5 behavioral sessions from one mouse", 151 ALM and 72 thalamic (VM/VAL) units, correct trials, delay period. The motor control data of the same figures (Sauerbrei et al. 2020) are not in this dandiset, nor in any archive the paper names; a search of the DANDI API for "Sauerbrei" finds only dandiset 000221, a different study. The simulations of Figures 1 to 5 and S1 to S5 are generated by the paper's models and are not deposited.

Method. Each claim's criterion refers to the numbered method notes W1 to W10 at the head of the claims file; the helper tcloop.py says for each parameter where it comes from. Random splits and subsamples use each claim's own seed (tcloop.seed), and each result that depends on them is also computed under the seed plus 1000, 2000, 3000 and 4000.

Claim Data Status
wm-sessions-link dandiset tested
fig6-wm-choice-r2 dandiset tested
fig6c-wm-leading-pcs-drive-choice dandiset tested
figs6d-wm-thalamic-r2 dandiset tested
fig6d-wm-top5-pcs dandiset tested
figs6f-ct-alignment-not-significant dandiset tested
fig6-motor-hand-r2, fig6c-motor-low-variance-pcs, figs6d-motor-thalamic-r2, fig6d-motor-top5-pcs, fig6e-motor-single-trial dandiset blocked: data missing (Sauerbrei et al. 2020 not deposited)
fig6d-more-pcs-in-motor-task dandiset blocked: data missing (needs the motor data)
fig1c to figs5j (24 simulation claims) elsewhere blocked: too large (timed below), except figs5cd-thalamic-recurrence: methods underspecified
In [1]:
import time
import resource
import hashlib
import os
import warnings
from collections import Counter

os.environ.setdefault("OMP_NUM_THREADS", "1")
os.environ.setdefault("OPENBLAS_NUM_THREADS", "1")

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import requests
from scipy import stats

import tcloop as tc

pd.set_option("display.width", 220)
pd.set_option("display.max_columns", 40)
pd.set_option("display.max_rows", 200)
warnings.filterwarnings("ignore", category=RuntimeWarning)
started = time.time()
print("dandiset", tc.DANDISET, "version", tc.VERSION)
dandiset 000009 version 0.220126.1903

The dandiset¶

Every file is listed from the archive, and every extracellular file (137, about 1 MB each) is streamed whole: its units, the region of its electrode group and its trial table. The 36 intracellular files (behavior+icephys) are from a different experiment of Guo et al. 2017 and hold no units; only their metadata is read.

In [2]:
assets = tc.list_assets()
draft = requests.get(f"{tc.API}/dandisets/{tc.DANDISET}/versions/draft/assets/?page_size=1000", timeout=60).json()
draft_blobs = {a["path"]: a["blob"] for a in draft["results"]}
same = sum(draft_blobs.get(a["path"]) == a["blob"] for a in assets)
print(f"{len(assets)} assets in {tc.VERSION}; {same} have the same blob in the draft ({len(draft_blobs)} draft assets)")
ecephys = sorted([a for a in assets if "ecephys" in a["path"]], key=lambda a: a["path"])
icephys = [a for a in assets if "icephys" in a["path"]]
print(len(ecephys), "extracellular files,", len(icephys), "intracellular files,",
      f"{sum(a['size'] for a in icephys) / 1e9:.1f} GB of intracellular data (not read)")
t0 = time.time()
allsess = tc.read_sessions(ecephys, workers=12)
print(f"streamed {len(allsess)} files in {time.time() - t0:.0f} s")
173 assets in 0.220126.1903; 173 have the same blob in the draft (173 draft assets)
137 extracellular files, 36 intracellular files, 12.7 GB of intracellular data (not read)
streamed 137 files in 104 s
In [3]:
# One file in full: every group and every column of every table.
s0 = allsess[0]
import h5py, remfile
f = h5py.File(remfile.File(tc._s3_url(ecephys[0]["asset_id"])), "r")
def walk(g, pre=""):
    for k in g:
        o = g[k]
        if isinstance(o, h5py.Dataset):
            print(f"{pre}/{k}", o.shape, o.dtype)
        else:
            walk(o, f"{pre}/{k}")
walk(f)
print("units columns:", [c.decode() for c in f["units"].attrs["colnames"]])
print("trials columns:", [c.decode() for c in f["intervals/trials"].attrs["colnames"]])
for c in f["intervals/trials"].attrs["colnames"]:
    print(f"  trials/{c.decode()}: {f['intervals/trials'][c].attrs.get('description', '')}")
f.close()
/file_create_date (1,) object
/general/experiment_description () object
/general/experimenter (1,) object
/general/extracellular_ephys/electrodes/filtering (32,) object
/general/extracellular_ephys/electrodes/group (32,) object
/general/extracellular_ephys/electrodes/group_name (32,) object
/general/extracellular_ephys/electrodes/id (32,) int32
/general/extracellular_ephys/electrodes/imp (32,) float64
/general/extracellular_ephys/electrodes/location (32,) object
/general/extracellular_ephys/electrodes/x (32,) float64
/general/extracellular_ephys/electrodes/y (32,) float64
/general/extracellular_ephys/electrodes/z (32,) float64
/general/institution () object
/general/keywords (6,) object
/general/related_publications (1,) object
/general/subject/genotype () object
/general/subject/sex () object
/general/subject/species () object
/general/subject/subject_id () object
/identifier () object
/intervals/trials/cue_end_time (320,) float64
/intervals/trials/cue_start_time (320,) float64
/intervals/trials/id (320,) int32
/intervals/trials/is_good (320,) int32
/intervals/trials/photo_loc_galvo_x (320,) float64
/intervals/trials/photo_loc_galvo_y (320,) float64
/intervals/trials/photo_loc_galvo_z (320,) float64
/intervals/trials/photo_stim_period (320,) object
/intervals/trials/photo_stim_power (320,) float64
/intervals/trials/photo_stim_type (320,) object
/intervals/trials/pole_in_time (320,) float64
/intervals/trials/pole_out_time (320,) float64
/intervals/trials/response (320,) object
/intervals/trials/start_time (320,) float64
/intervals/trials/stim_present (320,) int32
/intervals/trials/stop_time (320,) float64
/intervals/trials/type (320,) object
/session_description () object
/session_start_time () object
/specifications/core/2.1.0/namespace () object
/specifications/core/2.1.0/nwb.base () object
/specifications/core/2.1.0/nwb.behavior () object
/specifications/core/2.1.0/nwb.ecephys () object
/specifications/core/2.1.0/nwb.epoch () object
/specifications/core/2.1.0/nwb.file () object
/specifications/core/2.1.0/nwb.icephys () object
/specifications/core/2.1.0/nwb.image () object
/specifications/core/2.1.0/nwb.misc () object
/specifications/core/2.1.0/nwb.ogen () object
/specifications/core/2.1.0/nwb.ophys () object
/specifications/core/2.1.0/nwb.retinotopy () object
/specifications/hdmf-common/1.0.0/namespace () object
/specifications/hdmf-common/1.0.0/sparse () object
/specifications/hdmf-common/1.0.0/table () object
/timestamps_reference_time () object
/units/cell_type (8,) object
/units/electrodes (8,) int32
/units/electrodes_index (8,) int32
/units/id (8,) int32
/units/sampling_rate (8,) int32
/units/spike_times (149434,) float64
/units/spike_times_index (8,) int32
/units/unit_x (8,) float64
/units/unit_y (8,) float64
/units/unit_z (8,) float64
/units/waveform_mean (8, 29) float32
/units/waveform_sd (8, 29) float32
units columns: ['sampling_rate', 'unit_x', 'unit_y', 'unit_z', 'cell_type', 'spike_times', 'electrodes', 'waveform_mean', 'waveform_sd']
trials columns: ['start_time', 'stop_time', 'type', 'response', 'stim_present', 'is_good', 'photo_stim_type', 'photo_stim_period', 'photo_stim_power', 'photo_loc_galvo_x', 'photo_loc_galvo_y', 'photo_loc_galvo_z', 'cue_end_time', 'cue_start_time', 'pole_in_time', 'pole_out_time']
  trials/start_time: Start time of epoch, in seconds
  trials/stop_time: Stop time of epoch, in seconds
  trials/type: 
  trials/response: 
  trials/stim_present: is this a stim or no-stim trial
  trials/is_good: is this a good or bad trial
  trials/photo_stim_type: 
  trials/photo_stim_period: 
  trials/photo_stim_power: (mW) stimulation power
  trials/photo_loc_galvo_x: (mm) photostim coordinates field
  trials/photo_loc_galvo_y: (mm) photostim coordinates field
  trials/photo_loc_galvo_z: (mm) photostim coordinates field
  trials/cue_end_time: offset of auditory cue
  trials/cue_start_time: onset of auditory cue
  trials/pole_in_time: onset of pole moving in
  trials/pole_out_time: onset of pole moving out

Data check¶

Per subject and session: the region named by the electrode group, the number of units, and the trials. Then the checks of the description against the values for the quantities used: trial outcomes and photostimulation, epoch durations (delay onset to go cue), spike-time order and range, the recording span of each unit, coordinates, and recordings deposited twice.

In [4]:
rows = []
for s in allsess:
    t = s["trials"]
    rows.append(dict(subject=s["subject"], session=s["path"].split("_ses-")[1][:15], region=s["region"],
                     units=len(s["spikes"]), trials=len(t["id"]),
                     correct=int((t["response"] == "correct").sum()),
                     correct_nostim=int(((t["response"] == "correct") & (t["stim_present"] == 0)).sum())))
survey = pd.DataFrame(rows)
by_subject = survey.groupby(["subject", "region"]).agg(sessions=("session", "size"), units=("units", "sum")).unstack(fill_value=0)
print(by_subject.to_string())
print()
print("regions named in the files:", Counter(survey.region))
print("subjects:", survey.subject.nunique(), "sessions:", len(survey), "units:", survey.units.sum())
            sessions              units             
region           ALM SNr Thalamus   ALM SNr Thalamus
subject                                             
anm00229327        0   0        5     0   0       51
anm00229329        0   0        4     0   0       33
anm00234218        0   0        4     0   0       43
anm00237800        0   0        5     0   0       27
anm00239123        0   0        3     0   0       17
anm00242747        0   0        7     0   0       77
anm00260487        0   0       11     0   0      132
anm00260488        0   0        6     0   0       82
anm00260490        0   0        7     0   0       66
anm00260491        0   0        3     0   0       39
anm00261334        0   5        0     0  45        0
anm00261335        2   7        0    32  63        0
anm00261336        0   6        0     0  73        0
anm00264941        1   0        0     8   0        0
anm00264942        6   0        0    99   0        0
anm00264943        5   0        6   151   0       72
anm00264944        5   0        0    98   0        0
anm00267975        6   0        0   123   0        0
anm00279338        4   0        0   114   0        0
anm00313106        0   0        5     0   0       55
anm00313111        0   0        6     0   0       95
anm00322805        5   0        0    83   0        0
anm00322807        8   0        0   199   0        0
anm00323634        5   0        0    59   0        0

regions named in the files: Counter({'Thalamus': 72, 'ALM': 47, 'SNr': 18})
subjects: 24 sessions: 137 units: 1936
In [5]:
mouse = "anm00264943"
ms = [s for s in allsess if s["subject"] == mouse]
print(survey[survey.subject == mouse].to_string(index=False))
for s in ms:
    t = s["trials"]
    delay = t["cue_start_time"] - t["pole_out_time"]
    sample = t["pole_out_time"] - t["pole_in_time"]
    ok = np.isfinite(delay)
    sp = np.concatenate(s["spikes"])
    print(f"\n{s['path'].split('/')[1]}  region {s['region']}")
    print("  type:", dict(Counter(t["type"])), " response:", dict(Counter(t["response"])))
    print("  stim_present:", dict(Counter(t["stim_present"])), " photo_stim_period:", dict(Counter(t["photo_stim_period"])),
          " photo_stim_type:", dict(Counter(t["photo_stim_type"])))
    print("  is_good among correct trials:", dict(Counter(t["is_good"][t["response"] == "correct"])))
    print(f"  delay (go cue - pole out) s: min {np.nanmin(delay):.2f} median {np.nanmedian(delay):.2f} max {np.nanmax(delay):.2f};"
          f" sample (pole out - pole in) s: min {np.nanmin(sample):.2f} median {np.nanmedian(sample):.2f} max {np.nanmax(sample):.2f};"
          f" trials without epoch times: {(~ok).sum()} (types {dict(Counter(t['type'][~ok]))})")
    print(f"  spike times {sp.min():.1f} to {sp.max():.1f} s; trials {t['start_time'].min():.1f} to {t['stop_time'].max():.1f} s;"
          f" spike trains sorted: {all(np.all(np.diff(x) >= 0) for x in s['spikes'])}")
    cov = np.array([(x[-1] - x[0]) for x in s["spikes"]]) / (np.nanmax(t["pole_out_time"]) - np.nanmin(t["pole_out_time"]))
    print(f"  unit recording span (first to last spike) as a fraction of the trial period: median {np.median(cov):.2f},"
          f" range {cov.min():.2f} to {cov.max():.2f}")
    print("  cell_type:", dict(Counter(s["units"]["cell_type"])), " unit_z values:", np.unique(np.round(s["units"]["unit_z"], 3)))
    print("  electrode group location:", s["location"])
    subject         session   region  units  trials  correct  correct_nostim
anm00264943 20170627T094016 Thalamus     11     334      170             138
anm00264943 20170627T094019 Thalamus     13     389      164             125
anm00264943 20170627T094028 Thalamus     18     390      158             125
anm00264943 20170627T094033 Thalamus     10     400      162             130
anm00264943 20170627T094037 Thalamus     10     463      240             201
anm00264943 20170627T094041 Thalamus     10     399      212             173
anm00264943 20170627T094049      ALM     30     239      129             115
anm00264943 20170627T094051      ALM     18     241      152             136
anm00264943 20170627T094054      ALM     39     224      135             115
anm00264943 20170627T094056      ALM     46     239      160             129
anm00264943 20170627T094100      ALM     18     244      141             124

sub-anm00264943_ses-20170627T094016_ecephys+ogen.nwb  region Thalamus
  type: {np.str_('non-performing'): 60, np.str_('lick right'): 159, np.str_('lick left'): 115}  response: {np.str_('N/A'): 60, np.str_('correct'): 170, np.str_('incorrect'): 65, np.str_('early lick'): 39}
  stim_present: {np.int32(0): 270, np.int32(1): 64}  photo_stim_period: {np.str_('N/A'): 270, np.str_('delay'): 64}  photo_stim_type: {np.str_('stimulation'): 334}
  is_good among correct trials: {np.int32(1): 170}
  delay (go cue - pole out) s: min 1.30 median 1.30 max 2.60; sample (pole out - pole in) s: min 1.30 median 1.30 max 5.01; trials without epoch times: 60 (types {np.str_('non-performing'): 60})
  spike times 2454.3 to 5261.7 s; trials 2.3 to 5297.3 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.56, range 0.33 to 0.97
  cell_type: {np.str_('Narrow width spiking'): 2, np.str_('Wide width spiking'): 9}  unit_z values: [-1.599]
  electrode group location: ['brain_region: Thalamus; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094019_ecephys+ogen.nwb  region Thalamus
  type: {np.str_('non-performing'): 50, np.str_('lick left'): 175, np.str_('lick right'): 164}  response: {np.str_('N/A'): 50, np.str_('early lick'): 87, np.str_('incorrect'): 88, np.str_('correct'): 164}
  stim_present: {np.int32(0): 309, np.int32(1): 80}  photo_stim_period: {np.str_('N/A'): 309, np.str_('delay'): 80}  photo_stim_type: {np.str_('stimulation'): 389}
  is_good among correct trials: {np.int32(1): 164}
  delay (go cue - pole out) s: min 1.30 median 1.30 max 3.57; sample (pole out - pole in) s: min 1.30 median 1.30 max 4.11; trials without epoch times: 50 (types {np.str_('non-performing'): 50})
  spike times 2599.0 to 5971.3 s; trials 2.8 to 6007.6 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.92, range 0.28 to 1.03
  cell_type: {np.str_('Wide width spiking'): 11, np.str_('Cannot be determined'): 1, np.str_('Narrow width spiking'): 1}  unit_z values: [-1.599]
  electrode group location: ['brain_region: Thalamus; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094028_ecephys+ogen.nwb  region Thalamus
  type: {np.str_('non-performing'): 30, np.str_('lick left'): 203, np.str_('lick right'): 157}  response: {np.str_('N/A'): 30, np.str_('early lick'): 149, np.str_('incorrect'): 53, np.str_('correct'): 158}
  stim_present: {np.int32(0): 308, np.int32(1): 82}  photo_stim_period: {np.str_('N/A'): 308, np.str_('delay'): 82}  photo_stim_type: {np.str_('stimulation'): 390}
  is_good among correct trials: {np.int32(1): 158}
  delay (go cue - pole out) s: min 1.26 median 1.30 max 3.70; sample (pole out - pole in) s: min 1.30 median 1.30 max 8.55; trials without epoch times: 30 (types {np.str_('non-performing'): 30})
  spike times 3053.7 to 6573.7 s; trials 2.3 to 6611.2 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.89, range 0.16 to 1.00
  cell_type: {np.str_('Wide width spiking'): 15, np.str_('Narrow width spiking'): 1, np.str_('Cannot be determined'): 2}  unit_z values: [-1.706]
  electrode group location: ['brain_region: Thalamus; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094033_ecephys+ogen.nwb  region Thalamus
  type: {np.str_('non-performing'): 40, np.str_('lick right'): 159, np.str_('lick left'): 201}  response: {np.str_('N/A'): 40, np.str_('correct'): 162, np.str_('incorrect'): 57, np.str_('early lick'): 141}
  stim_present: {np.int32(0): 325, np.int32(1): 75}  photo_stim_period: {np.str_('N/A'): 325, np.str_('delay'): 75}  photo_stim_type: {np.str_('stimulation'): 400}
  is_good among correct trials: {np.int32(1): 162}
  delay (go cue - pole out) s: min 1.26 median 1.30 max 4.74; sample (pole out - pole in) s: min 1.30 median 1.30 max 7.83; trials without epoch times: 40 (types {np.str_('non-performing'): 40})
  spike times 2277.4 to 5716.4 s; trials 2.4 to 5748.5 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 1.00, range 0.46 to 1.00
  cell_type: {np.str_('Wide width spiking'): 9, np.str_('Cannot be determined'): 1}  unit_z values: [-1.759]
  electrode group location: ['brain_region: Thalamus; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094037_ecephys+ogen.nwb  region Thalamus
  type: {np.str_('non-performing'): 20, np.str_('lick left'): 196, np.str_('lick right'): 247}  response: {np.str_('N/A'): 20, np.str_('early lick'): 133, np.str_('correct'): 240, np.str_('incorrect'): 70}
  stim_present: {np.int32(0): 362, np.int32(1): 101}  photo_stim_period: {np.str_('N/A'): 362, np.str_('delay'): 101}  photo_stim_type: {np.str_('stimulation'): 463}
  is_good among correct trials: {np.int32(1): 240}
  delay (go cue - pole out) s: min 1.25 median 1.30 max 3.61; sample (pole out - pole in) s: min 1.30 median 1.30 max 8.91; trials without epoch times: 20 (types {np.str_('non-performing'): 20})
  spike times 1921.9 to 6163.6 s; trials 2.3 to 6193.8 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.90, range 0.58 to 0.99
  cell_type: {np.str_('Wide width spiking'): 10}  unit_z values: [-1.493]
  electrode group location: ['brain_region: Thalamus; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094041_ecephys+ogen.nwb  region Thalamus
  type: {np.str_('non-performing'): 50, np.str_('lick left'): 164, np.str_('lick right'): 185}  response: {np.str_('N/A'): 50, np.str_('correct'): 212, np.str_('early lick'): 105, np.str_('incorrect'): 32}
  stim_present: {np.int32(0): 324, np.int32(1): 75}  photo_stim_period: {np.str_('N/A'): 324, np.str_('delay'): 75}  photo_stim_type: {np.str_('stimulation'): 399}
  is_good among correct trials: {np.int32(1): 212}
  delay (go cue - pole out) s: min 1.30 median 1.30 max 4.55; sample (pole out - pole in) s: min 1.30 median 1.30 max 5.24; trials without epoch times: 50 (types {np.str_('non-performing'): 50})
  spike times 1957.2 to 5174.2 s; trials 2.3 to 5203.9 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.98, range 0.82 to 0.98
  cell_type: {np.str_('Wide width spiking'): 10}  unit_z values: [-1.439]
  electrode group location: ['brain_region: Thalamus; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094049_ecephys+ogen.nwb  region ALM
  type: {np.str_('non-performing'): 30, np.str_('lick right'): 122, np.str_('lick left'): 87}  response: {np.str_('N/A'): 30, np.str_('correct'): 129, np.str_('early lick'): 36, np.str_('incorrect'): 44}
  stim_present: {np.int32(0): 192, np.int32(1): 47}  photo_stim_period: {np.str_('N/A'): 192, np.str_('delay'): 47}  photo_stim_type: {np.str_('stimulation'): 239}
  is_good among correct trials: {np.int32(1): 129}
  delay (go cue - pole out) s: min 1.30 median 1.30 max 3.37; sample (pole out - pole in) s: min 1.30 median 1.30 max 6.11; trials without epoch times: 30 (types {np.str_('non-performing'): 30})
  spike times 1304.5 to 3361.9 s; trials 2.4 to 3393.8 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.57, range 0.20 to 1.04
  cell_type: {np.str_('Wide width spiking'): 26, np.str_('Narrow width spiking'): 3, np.str_('Cannot be determined'): 1}  unit_z values: [2.5]
  electrode group location: ['brain_region: ALM; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094051_ecephys+ogen.nwb  region ALM
  type: {np.str_('non-performing'): 10, np.str_('lick right'): 137, np.str_('lick left'): 94}  response: {np.str_('N/A'): 10, np.str_('correct'): 152, np.str_('incorrect'): 38, np.str_('early lick'): 41}
  stim_present: {np.int32(0): 189, np.int32(1): 52}  photo_stim_period: {np.str_('N/A'): 189, np.str_('delay'): 52}  photo_stim_type: {np.str_('stimulation'): 241}
  is_good among correct trials: {np.int32(1): 152}
  delay (go cue - pole out) s: min 1.30 median 1.30 max 3.54; sample (pole out - pole in) s: min 1.30 median 1.30 max 7.41; trials without epoch times: 10 (types {np.str_('non-performing'): 10})
  spike times 1261.5 to 3406.6 s; trials 2.3 to 3439.7 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.59, range 0.30 to 0.99
  cell_type: {np.str_('Wide width spiking'): 16, np.str_('Narrow width spiking'): 2}  unit_z values: [2.5]
  electrode group location: ['brain_region: ALM; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094054_ecephys+ogen.nwb  region ALM
  type: {np.str_('non-performing'): 5, np.str_('lick right'): 121, np.str_('lick left'): 98}  response: {np.str_('N/A'): 5, np.str_('correct'): 135, np.str_('early lick'): 35, np.str_('incorrect'): 49}
  stim_present: {np.int32(0): 176, np.int32(1): 48}  photo_stim_period: {np.str_('N/A'): 176, np.str_('delay'): 48}  photo_stim_type: {np.str_('stimulation'): 224}
  is_good among correct trials: {np.int32(1): 135}
  delay (go cue - pole out) s: min 1.30 median 1.30 max 2.72; sample (pole out - pole in) s: min 1.30 median 1.30 max 4.40; trials without epoch times: 5 (types {np.str_('non-performing'): 5})
  spike times 99.6 to 2223.2 s; trials 2.4 to 2248.2 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.43, range 0.11 to 0.79
  cell_type: {np.str_('Wide width spiking'): 34, np.str_('Cannot be determined'): 1, np.str_('Narrow width spiking'): 4}  unit_z values: [2.5]
  electrode group location: ['brain_region: ALM; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094056_ecephys+ogen.nwb  region ALM
  type: {np.str_('non-performing'): 5, np.str_('lick right'): 136, np.str_('lick left'): 98}  response: {np.str_('N/A'): 5, np.str_('correct'): 160, np.str_('incorrect'): 51, np.str_('early lick'): 22, np.str_('no response'): 1}
  stim_present: {np.int32(0): 183, np.int32(1): 56}  photo_stim_period: {np.str_('N/A'): 183, np.str_('delay'): 56}  photo_stim_type: {np.str_('stimulation'): 239}
  is_good among correct trials: {np.int32(1): 160}
  delay (go cue - pole out) s: min 1.30 median 1.30 max 2.53; sample (pole out - pole in) s: min 1.30 median 1.30 max 4.00; trials without epoch times: 5 (types {np.str_('non-performing'): 5})
  spike times 401.8 to 2604.4 s; trials 2.3 to 2630.0 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.42, range 0.18 to 1.00
  cell_type: {np.str_('Wide width spiking'): 38, np.str_('Narrow width spiking'): 7, np.str_('Cannot be determined'): 1}  unit_z values: [2.5]
  electrode group location: ['brain_region: ALM; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']

sub-anm00264943_ses-20170627T094100_ecephys+ogen.nwb  region ALM
  type: {np.str_('non-performing'): 5, np.str_('lick right'): 115, np.str_('lick left'): 124}  response: {np.str_('N/A'): 5, np.str_('correct'): 141, np.str_('incorrect'): 36, np.str_('early lick'): 62}
  stim_present: {np.int32(0): 197, np.int32(1): 47}  photo_stim_period: {np.str_('N/A'): 197, np.str_('delay'): 47}  photo_stim_type: {np.str_('stimulation'): 244}
  is_good among correct trials: {np.int32(1): 141}
  delay (go cue - pole out) s: min 1.30 median 1.30 max 4.43; sample (pole out - pole in) s: min 1.30 median 1.30 max 3.19; trials without epoch times: 5 (types {np.str_('non-performing'): 5})
  spike times 228.4 to 2315.5 s; trials 2.3 to 2340.0 s; spike trains sorted: True
  unit recording span (first to last spike) as a fraction of the trial period: median 0.54, range 0.15 to 0.93
  cell_type: {np.str_('Wide width spiking'): 16, np.str_('Narrow width spiking'): 2}  unit_z values: [2.5]
  electrode group location: ['brain_region: ALM; brain_subregion: N/A; cortical_layer: N/A; hemisphere: left; coordinate_ref: bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00']
In [6]:
# Coordinates: the electrode-group location and the electrode positions are the same in every file.
locs = Counter(l.split("coordinate_ref")[1] for s in allsess for l in s["location"])
print("coordinate part of the electrode group location, over all files:", dict(locs))

# Recordings deposited twice: identical spike trains, and identical trial tables, across all 137 files.
h_unit, h_trial = {}, {}
for s in allsess:
    for u, x in enumerate(s["spikes"]):
        h_unit.setdefault(hashlib.sha1(np.round(x, 6).tobytes()).hexdigest(), []).append((s["path"], u))
    key = hashlib.sha1(np.round(np.nan_to_num(s["trials"]["pole_out_time"]), 4).tobytes()).hexdigest()
    h_trial.setdefault(key, []).append(s["path"])
dup_units = [v for v in h_unit.values() if len(v) > 1]
dup_trials = [v for v in h_trial.values() if len(v) > 1]
print(f"{sum(len(s['spikes']) for s in allsess)} spike trains; identical pairs: {len(dup_units)}")
for v in dup_units[:10]:
    print("  ", v)
print(f"identical trial tables (delay onsets): {len(dup_trials)}")
for v in dup_trials[:10]:
    print("  ", v)
# Within the paper's mouse, near-identical trains (same spike count and first spike) across sessions:
sig = Counter((len(x), round(float(x[0]), 3)) for s in ms for x in s["spikes"])
print("units of", mouse, "sharing spike count and first spike time:", sum(v > 1 for v in sig.values()))
coordinate part of the electrode group location, over all files: {': bregma; coordinate_ap: 2.50; coordinate_ml: -1.50; coordinate_dv: 0.00': 137}
1936 spike trains; identical pairs: 0
identical trial tables (delay onsets): 0
units of anm00264943 sharing spike count and first spike time: 0

Clock¶

The trial table and the spikes must share a clock. Choice (lick direction of correct trials without photostimulation) is decoded from the spike counts of each session's units in 200 ms windows around delay onset, with a cross-validated nearest-class-mean decoder, and compared with the same decoder on shuffled choices. ALM and thalamic activity in this task should carry little choice information before the sample epoch (before -1.3 s), more during the sample and delay epochs, and most after the go cue (1.3 s). A clock offset of more than a few hundred ms would move or remove this rise.

In [7]:
edges = np.round(np.arange(-2.6, 2.61, 0.2), 2)
rng_clock = np.random.default_rng(tc.seed("clock-check"))
clock = []
for s in ms:
    idx, ch, on = tc.select_trials(s, "T1")
    acc = tc.choice_decoding(s, on, ch, edges, rng_clock)
    null = np.mean([tc.choice_decoding(s, on, rng_clock.permutation(ch), edges, rng_clock) for _ in range(5)], 0)
    clock.append(acc)
    pre = acc[edges[:-1] < -1.4].mean(); dl = acc[(edges[:-1] >= 0) & (edges[:-1] < 1.3)].mean()
    rsp = acc[edges[:-1] >= 1.4].mean()
    print(f"{s['region']:8s} {s['path'].split('_ses-')[1][:15]}  n={len(ch)}  accuracy before sample {pre:.2f}, delay {dl:.2f}, "
          f"after go cue {rsp:.2f}; shuffled choices {null.mean():.2f} (max over windows {null.max():.2f})")
clock = np.array(clock)
fig, ax = plt.subplots(figsize=(7, 3))
for a, s in zip(clock, ms):
    ax.plot(edges[:-1] + 0.1, a, color="C0" if s["region"] == "ALM" else "C1", alpha=0.7)
for x in (-1.3, 0, 1.3):
    ax.axvline(x, color="k", lw=0.5)
ax.set_xlabel("time from delay onset (s)"); ax.set_ylabel("choice decoding accuracy"); ax.set_ylim(0.3, 1.0)
ax.set_title("ALM (blue) and thalamus (orange) sessions of " + mouse)
plt.show()
print(f"plotted accuracy ranges from {clock.min():.2f} to {clock.max():.2f}; none outside the axes")
Thalamus 20170627T094016  n=138  accuracy before sample 0.44, delay 0.52, after go cue 0.63; shuffled choices 0.48 (max over windows 0.53)
Thalamus 20170627T094019  n=125  accuracy before sample 0.47, delay 0.54, after go cue 0.77; shuffled choices 0.50 (max over windows 0.56)
Thalamus 20170627T094028  n=125  accuracy before sample 0.45, delay 0.63, after go cue 0.75; shuffled choices 0.52 (max over windows 0.56)
Thalamus 20170627T094033  n=130  accuracy before sample 0.51, delay 0.61, after go cue 0.72; shuffled choices 0.51 (max over windows 0.55)
Thalamus 20170627T094037  n=201  accuracy before sample 0.45, delay 0.61, after go cue 0.78; shuffled choices 0.49 (max over windows 0.54)
Thalamus 20170627T094041  n=173  accuracy before sample 0.45, delay 0.62, after go cue 0.72; shuffled choices 0.51 (max over windows 0.58)
ALM      20170627T094049  n=115  accuracy before sample 0.45, delay 0.55, after go cue 0.80; shuffled choices 0.50 (max over windows 0.57)
ALM      20170627T094051  n=136  accuracy before sample 0.42, delay 0.72, after go cue 0.87; shuffled choices 0.50 (max over windows 0.56)
ALM      20170627T094054  n=115  accuracy before sample 0.46, delay 0.61, after go cue 0.87; shuffled choices 0.51 (max over windows 0.56)
ALM      20170627T094056  n=129  accuracy before sample 0.48, delay 0.66, after go cue 0.75; shuffled choices 0.50 (max over windows 0.55)
ALM      20170627T094100  n=124  accuracy before sample 0.46, delay 0.71, after go cue 0.74; shuffled choices 0.51 (max over windows 0.57)
No description has been provided for this image
plotted accuracy ranges from 0.36 to 0.96; none outside the axes

wm-sessions-link¶

The dandiset holds the working memory data the paper reanalyzed, five sessions from one mouse with 151 ALM units and 72 thalamic units in total.

Criterion: among the mice with ALM and thalamic units, find one with five sessions whose unit totals are within tolerance (151 +/- 15 ALM, 72 +/- 7 thalamic) under a reading of W1. All sorted units are counted (the files carry no isolation-quality label; cell_type is a spike-width class).

In [8]:
both = by_subject[(by_subject[("units", "ALM")] > 0) & (by_subject[("units", "Thalamus")] > 0)]
print("mice with both ALM and thalamic units:")
print(both.to_string())
fit = []
for subj, r in both.iterrows():
    alm_n, th_n = r[("units", "ALM")], r[("units", "Thalamus")]
    ok = abs(alm_n - 151) <= 15 and abs(th_n - 72) <= 7
    fit.append(ok)
    print(f"{subj}: ALM {alm_n} units in {r[('sessions', 'ALM')]} sessions, thalamus {th_n} units in "
          f"{r[('sessions', 'Thalamus')]} sessions; within tolerance: {ok}")
print("mice that fit:", int(np.sum(fit)))
# Other regions named in the files, for completeness:
print("mice with SNr units:", sorted(survey[survey.region == "SNr"].subject.unique()))
alm_sessions = [s for s in ms if s["region"] == "ALM"]
thal_sessions = [s for s in ms if s["region"] == "Thalamus"]
both_sessions = [s for s in ms if {"ALM", "Thalamus"} <= set(s["region"].split(";"))]
print(f"\n{mouse}: {len(alm_sessions)} ALM sessions with {sum(len(s['spikes']) for s in alm_sessions)} units "
      f"({[len(s['spikes']) for s in alm_sessions]}); {len(thal_sessions)} thalamic sessions with "
      f"{sum(len(s['spikes']) for s in thal_sessions)} units ({[len(s['spikes']) for s in thal_sessions]}); "
      f"sessions holding both: {len(both_sessions)}")
n_sess = len(ms)
print(f"sessions of {mouse} (expected 5, tolerance 0): {n_sess}; within tolerance: {n_sess == 5}")
print(f"ALM units {sum(len(s['spikes']) for s in alm_sessions)} (151 +/- 15), thalamic units "
      f"{sum(len(s['spikes']) for s in thal_sessions)} (72 +/- 7); ALM sessions alone: {len(alm_sessions)}")
mice with both ALM and thalamic units:
            sessions              units             
region           ALM SNr Thalamus   ALM SNr Thalamus
subject                                             
anm00264943        5   0        6   151   0       72
anm00264943: ALM 151 units in 5 sessions, thalamus 72 units in 6 sessions; within tolerance: True
mice that fit: 1
mice with SNr units: ['anm00261334', 'anm00261335', 'anm00261336']

anm00264943: 5 ALM sessions with 151 units ([30, 18, 39, 46, 18]); 6 thalamic sessions with 72 units ([11, 13, 18, 10, 10, 10]); sessions holding both: 0
sessions of anm00264943 (expected 5, tolerance 0): 11; within tolerance: False
ALM units 151 (151 +/- 15), thalamic units 72 (72 +/- 7); ALM sessions alone: 5

Result: partially reproduced. One mouse (anm00264943) has both ALM and thalamic units, and its totals are the paper's exactly: 151 ALM units in five sessions and 72 thalamic units. The thalamic units come from six further sessions, so the mouse has eleven sessions, not the five the expected value requires (tolerance 0), and none holds both regions. The paper's "5 behavioral sessions" matches the five ALM sessions (Figure 6C, n = 5). The only other mouse with ALM units beside units of another region (anm00261335) has SNr, not thalamic, units. All sorted units are counted. The link holds for the mouse and the units; the dependent claims are tested on these eleven sessions, and the six thalamic sessions are paired with the ALM sessions as described below.

Preparing the paper's mouse¶

Correct trials, under reading T1 (no photostimulation) and T2 (all correct trials), aligned to delay onset, binned at 10 ms and smoothed at each sigma of the grid (helper docstring).

In [9]:
t0 = time.time()
PREP = {r: [tc.Prepared(s, r) for s in ms] for r in ("T1", "T2")}
ALM = {r: [p for p in PREP[r] if p.region == "ALM"] for r in PREP}
THAL = {r: [p for p in PREP[r] if p.region == "Thalamus"] for r in PREP}
for r in PREP:
    print(r, "trials per session (left, right):",
          [(int((p.choice == 0).sum()), int((p.choice == 1).sum())) for p in PREP[r]])
    for p in PREP[r]:
        x = p.rates[50]
        assert np.isfinite(x).all()
    print(f"  rates at sigma 50 ms: {min(p.rates[50].min() for p in PREP[r]):.1f} to "
          f"{max(p.rates[50].max() for p in PREP[r]):.1f} spikes/s;"
          f" fraction of unit-trial pairs inside the unit's span: "
          f"{np.mean(np.concatenate([p.span.ravel() for p in PREP[r]])):.2f}")
print(f"prepared in {time.time() - t0:.0f} s; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB")
T1 trials per session (left, right): [(55, 83), (56, 69), (53, 72), (67, 63), (83, 118), (72, 101), (43, 72), (49, 87), (52, 63), (48, 81), (48, 76)]
  rates at sigma 50 ms: 0.0 to 103.2 spikes/s; fraction of unit-trial pairs inside the unit's span: 0.61
T2 trials per session (left, right): [(73, 97), (79, 85), (70, 88), (85, 77), (108, 132), (87, 125), (56, 73), (58, 94), (72, 63), (73, 87), (62, 79)]
  rates at sigma 50 ms: 0.0 to 170.8 spikes/s; fraction of unit-trial pairs inside the unit's span: 0.62
prepared in 2 s; peak memory 0.90 GB

fig6-wm-choice-r2¶

In the working memory task, ALM population activity explains the animal's choice well (R2 = 0.97).

Criterion: test-set R2 of c(t) predicted from the test-set h(t) with the training-set weights, under R1 (per session, mean over the five sessions) and R2 (pooled 151 units subsampled to 53, mean over 20 subsamples), trial readings T1 and T2, mean over 10 splits. Reproduced when within 0.97 +/- 0.097 under one reading. The unit-span reading U2 and the training-set R2 are shown as variants; neither decides the outcome.

In [10]:
CL = "fig6-wm-choice-r2"
choice_res = {}
for off in (0, 1000, 2000, 3000, 4000):
    for r in ("T1", "T2"):
        for span in ((False, True) if off == 0 else (False,)):
            rng = np.random.default_rng(tc.seed(CL, off))
            r1 = tc.readout_per_session(ALM[r], rng, span=span)
            r2p = tc.readout_pooled(ALM[r], rng, span=span)
            choice_res[(off, r, span)] = (r1, r2p)
rows = []
for (off, r, span), (r1, r2p) in choice_res.items():
    rows.append(dict(seed_offset=off, trials=r, units="U2" if span else "U1",
                     R1_test_mean=np.mean([d["test"].mean() for d in r1]),
                     R1_test_median=np.median(np.concatenate([d["test"] for d in r1])),
                     R1_one_split=np.mean([d["test"][0] for d in r1]),
                     R1_train=np.mean([d["train"].mean() for d in r1]),
                     R2_test_mean=r2p["test"].mean(), R2_test_median=np.median(r2p["test"]),
                     R2_one_split=r2p["test"][:tc.N_SUB].mean(), R2_train=r2p["train"].mean()))
choice_tab = pd.DataFrame(rows)
print(choice_tab.round(3).to_string(index=False))
 seed_offset trials units  R1_test_mean  R1_test_median  R1_one_split  R1_train  R2_test_mean  R2_test_median  R2_one_split  R2_train
           0     T1    U1        -1.705          -0.856        -0.251     0.968        -0.247           0.168         0.249     0.992
           0     T1    U2        -0.804          -0.502        -1.330     0.931         0.506           0.660         0.297     1.000
           0     T2    U1        -0.732          -0.348        -0.464     0.954       -29.203           0.340         0.357     0.994
           0     T2    U2        -0.495          -0.080        -0.555     0.965         0.370           0.609         0.559     0.996
        1000     T1    U1        -1.399          -0.635        -0.882     0.961        -0.461          -0.179        -0.928     0.996
        1000     T2    U1        -0.919          -0.174        -0.360     0.957         0.077           0.306        -0.159     0.992
        2000     T1    U1        -1.644          -0.769        -1.419     0.956         0.042           0.317         0.023     0.997
        2000     T2    U1        -0.789          -0.018         0.066     0.961         0.105           0.385        -0.010     0.994
        3000     T1    U1        -1.042          -0.447        -0.974     0.965        -0.616          -0.075        -1.859     0.997
        3000     T2    U1        -0.612          -0.451        -0.577     0.952         0.037           0.363         0.377     0.993
        4000     T1    U1        -2.194          -1.081        -1.972     0.961        -0.287          -0.073        -0.598     0.997
        4000     T2    U1        -0.813          -0.056        -0.630     0.963       -30.607           0.278         0.106     0.995
In [11]:
r1, r2p = choice_res[(0, "T1", False)]
print("Claim seed, T1, U1. Per session (R1):")
for d in r1:
    print(f"  {d['path'].split('_ses-')[1][:15]}  units {d['n'][0]}  test R2 mean {d['test'].mean():.2f} median {np.median(d['test']):.2f}"
          f" (range {d['test'].min():.2f} to {d['test'].max():.2f}); validation {d['val'].mean():.2f}; training {d['train'].mean():.3f};"
          f" sigma chosen {dict(Counter(d['sigma']))}")
print(f"Pooled (R2): sigma chosen {dict(Counter(r2p['sigma']))}; fraction of fits with test R2 > 0: {(r2p['test'] > 0).mean():.2f}")
main = choice_tab[(choice_tab.seed_offset == 0) & (choice_tab.units == "U1")]
best = max(main[["R1_test_mean", "R2_test_mean"]].max())
print(f"\nlargest test R2 over the four readings (R1/R2 x T1/T2), claim seed: {best:.3f}; tolerance band 0.873 to 1")
u1 = choice_tab[choice_tab.units == "U1"]
print(f"over five seeds, readings R1/R2 x T1/T2: test R2 means range {u1[['R1_test_mean', 'R2_test_mean']].min().min():.2f} to "
      f"{u1[['R1_test_mean', 'R2_test_mean']].max().max():.2f}; medians {u1[['R1_test_median', 'R2_test_median']].min().min():.2f} to "
      f"{u1[['R1_test_median', 'R2_test_median']].max().max():.2f}")
Claim seed, T1, U1. Per session (R1):
  20170627T094049  units 30  test R2 mean -2.11 median -1.65 (range -6.91 to 0.00); validation -1.33; training 0.941; sigma chosen {np.int64(10): 3, np.int64(200): 3, np.int64(25): 2, np.int64(100): 2}
  20170627T094051  units 18  test R2 mean -1.44 median -0.97 (range -3.72 to -0.23); validation 0.10; training 0.941; sigma chosen {np.int64(25): 1, np.int64(100): 2, np.int64(10): 2, np.int64(50): 3, np.int64(200): 2}
  20170627T094054  units 39  test R2 mean -3.02 median -0.84 (range -18.66 to 0.84); validation -0.07; training 0.992; sigma chosen {np.int64(200): 7, np.int64(100): 2, np.int64(10): 1}
  20170627T094056  units 46  test R2 mean -1.33 median -0.64 (range -4.94 to 0.88); validation 0.12; training 0.993; sigma chosen {np.int64(200): 5, np.int64(10): 1, np.int64(25): 2, np.int64(50): 1, np.int64(100): 1}
  20170627T094100  units 18  test R2 mean -0.62 median 0.07 (range -3.64 to 0.43); validation 0.27; training 0.973; sigma chosen {np.int64(50): 4, np.int64(25): 4, np.int64(200): 2}
Pooled (R2): sigma chosen {np.int64(10): 30, np.int64(200): 129, np.int64(100): 32, np.int64(25): 5, np.int64(50): 4}; fraction of fits with test R2 > 0: 0.57

largest test R2 over the four readings (R1/R2 x T1/T2), claim seed: -0.247; tolerance band 0.873 to 1
over five seeds, readings R1/R2 x T1/T2: test R2 means range -30.61 to 0.10; medians -1.08 to 0.39
In [12]:
# Diagnostics, not readings of the claim: test R2 against the size of the test set, and how
# reproducible the readout's output on the test set is. Pooled readout (R2), T1, U1, with a second
# generator of the claim (seed + 1). Validation stays at 10%; the training set shrinks.
rng = np.random.default_rng(tc.seed(CL, 1))
for tf in (0.1, 0.3, 0.5):
    d = tc.readout_pooled(ALM["T1"], rng, test_frac=tf)
    r = np.nanmean(d["rel"])
    print(f"test fraction {tf:.1f}: test R2 mean {d['test'].mean():.3f}, median {np.median(d['test']):.3f}, "
          f"fraction > 0 {(d['test'] > 0).mean():.2f}; training R2 {d['train'].mean():.3f}; correlation of the readout's "
          f"outputs on the two halves of the test set {r:.3f} (reliability of the whole test set {2 * r / (1 + r):.3f})")
test fraction 0.1: test R2 mean -0.089, median 0.268, fraction > 0 0.64; training R2 0.993; correlation of the readout's outputs on the two halves of the test set 0.145 (reliability of the whole test set 0.253)
test fraction 0.3: test R2 mean 0.371, median 0.515, fraction > 0 0.82; training R2 0.995; correlation of the readout's outputs on the two halves of the test set 0.269 (reliability of the whole test set 0.424)
test fraction 0.5: test R2 mean -0.333, median 0.313, fraction > 0 0.75; training R2 0.993; correlation of the readout's outputs on the two halves of the test set 0.291 (reliability of the whole test set 0.451)

Result: not reproduced. Under every reading the test-set R2 of the choice readout is far below 0.97. With every unit averaged over all selected trials (U1), under the claim seed, the largest of the four means (R1 or R2, T1 or T2) is -0.247, and the medians run from -0.86 to 0.34; over five seeds no U1 mean exceeds 0.105. The readout fits the training averages almost perfectly (training R2 0.95 to 1.00 under U1, 0.93 to 1.00 under U2) and does not generalize to the test averages of 4 to 9 trials per choice. The U2 variant gives means of at most 0.506 and medians of at most 0.660. In the diagnostics (seed + 1, R2, T1), the readout's outputs on the two halves of a 10% test set correlate at 0.145 (reliability of the whole test set 0.25), and larger test sets do not bring the test R2 near 0.97: the means are -0.089, 0.371 and -0.333 and the medians 0.268, 0.515 and 0.313 for 10%, 30% and 50% test sets. The training-set R2 is close to the paper's 0.97; whether the paper's value was computed on the trials used to fit is asked of the paper's authors, not a reading of the claim.

fig6c-wm-leading-pcs-drive-choice¶

In the working memory task, the leading PCs of ALM activity have a large influence on the readout of choice.

Criterion: alignment |w . u_i| / ||w|| of the readout with PCs 1 to 16, per session with the mean over the five sessions (R1), and on the pooled subsampled population (R2). Readings (a) the PC with the largest mean alignment is PC 1 or 2; (b) the mean alignment over PCs 1 to 3 exceeds the mean over PCs 4 to 16. Reproduced when both hold under one trial reading, partially when one holds.

In [13]:
CL = "fig6c-wm-leading-pcs-drive-choice"
pc_rows, profiles, pc_res = [], {}, {}
for off in (0, 1000, 2000, 3000, 4000):
    for r in ("T1", "T2"):
        for span in ((False, True) if off == 0 else (False,)):
            rng = np.random.default_rng(tc.seed(CL, off))
            r1 = tc.readout_per_session(ALM[r], rng, span=span)
            r2p = tc.readout_pooled(ALM[r], rng, span=span)
            pc_res[(off, r, span)] = (r1, r2p)
            for name, prof, sem in (("R1", np.nanmean([np.nanmean(d["align"], 0) for d in r1], 0),
                                     stats.sem([np.nanmean(d["align"], 0) for d in r1], 0, nan_policy="omit")),
                                    ("R2", np.nanmean(r2p["align"], 0), np.nanstd(r2p["align"], 0) / np.sqrt(len(r2p["align"])))):
                profiles[(off, r, span, name)] = (prof, sem)
                a = int(np.argmax(prof)) + 1
                b = prof[:3].mean() > prof[3:].mean()
                pc_rows.append(dict(seed_offset=off, trials=r, units="U2" if span else "U1", readout=name,
                                    argmax_PC=a, mean_PC1_3=prof[:3].mean(), mean_PC4_16=prof[3:].mean(),
                                    a_holds=a <= 2, b_holds=bool(b)))
pc_tab = pd.DataFrame(pc_rows)
print(pc_tab.round(4).to_string(index=False))
r1t1 = pc_tab[(pc_tab.readout == "R1") & (pc_tab.trials == "T1") & (pc_tab.units == "U1")]
print("R1, T1, U1, reading (b): mean over PCs 1-3 minus mean over PCs 4-16, by seed offset:",
      {int(k): float(f"{v:.2g}") for k, v in zip(r1t1.seed_offset, r1t1.mean_PC1_3 - r1t1.mean_PC4_16)})
 seed_offset trials units readout  argmax_PC  mean_PC1_3  mean_PC4_16  a_holds  b_holds
           0     T1    U1      R1         16      0.1069       0.1065    False     True
           0     T1    U1      R2          2      0.0810       0.0630     True     True
           0     T1    U2      R1         16      0.1049       0.1287    False    False
           0     T1    U2      R2          2      0.0757       0.0645     True     True
           0     T2    U1      R1         16      0.0807       0.0971    False    False
           0     T2    U1      R2          1      0.0679       0.0627     True     True
           0     T2    U2      R1         16      0.1031       0.1138    False    False
           0     T2    U2      R2          1      0.0596       0.0627     True    False
        1000     T1    U1      R1         16      0.1071       0.1057    False     True
        1000     T1    U1      R2          2      0.0855       0.0701     True     True
        1000     T2    U1      R1         16      0.0896       0.1031    False    False
        1000     T2    U1      R2          1      0.0691       0.0625     True     True
        2000     T1    U1      R1         16      0.1052       0.1067    False    False
        2000     T1    U1      R2          2      0.0912       0.0682     True     True
        2000     T2    U1      R1         16      0.0886       0.0990    False    False
        2000     T2    U1      R2         15      0.0672       0.0665    False     True
        3000     T1    U1      R1         16      0.1117       0.1087    False     True
        3000     T1    U1      R2          2      0.0868       0.0653     True     True
        3000     T2    U1      R1         16      0.0860       0.1026    False    False
        3000     T2    U1      R2          1      0.0732       0.0661     True     True
        4000     T1    U1      R1         16      0.1164       0.1082    False     True
        4000     T1    U1      R2          2      0.0811       0.0652     True     True
        4000     T2    U1      R1         16      0.0919       0.1030    False    False
        4000     T2    U1      R2          1      0.0722       0.0595     True     True
R1, T1, U1, reading (b): mean over PCs 1-3 minus mean over PCs 4-16, by seed offset: {0: 0.00032, 1000: 0.0014, 2000: -0.0015, 3000: 0.003, 4000: 0.0082}
In [14]:
fig, axs = plt.subplots(1, 2, figsize=(9, 3), sharey=True)
lo, hi = np.inf, -np.inf
for ax, name in zip(axs, ("R1", "R2")):
    for r, c in (("T1", "C0"), ("T2", "C2")):
        prof, sem = profiles[(0, r, False, name)]
        ax.errorbar(np.arange(1, 17), prof, sem, color=c, label=r, marker="o", ms=3)
        lo, hi = min(lo, (prof - sem).min()), max(hi, (prof + sem).max())
    ax.set_title(f"readout {name}, claim seed, U1"); ax.set_xlabel("PC"); ax.legend()
axs[0].set_ylabel("|w . u_i| / ||w||")
plt.show()
print(f"plotted range {lo:.3f} to {hi:.3f}")
for name in ("R1", "R2"):
    for r in ("T1", "T2"):
        prof, sem = profiles[(0, r, False, name)]
        print(name, r, "alignment PCs 1-16:", np.round(prof, 3))
        print(name, r, "SEM:", np.round(sem, 3))
m = pc_tab[(pc_tab.seed_offset == 0) & (pc_tab.units == "U1")]
print("\nclaim seed, U1: readings where (a) holds:", m[m.a_holds][["trials", "readout"]].values.tolist(),
      "; where (b) holds:", m[m.b_holds][["trials", "readout"]].values.tolist(),
      "; where both hold:", m[m.a_holds & m.b_holds][["trials", "readout"]].values.tolist())
s5 = pc_tab[pc_tab.units == "U1"].groupby("seed_offset").apply(lambda g: bool((g.a_holds & g.b_holds).any()))
print("both hold under some reading, per seed offset:", s5.to_dict())
s5a = pc_tab[pc_tab.units == "U1"].groupby("seed_offset").apply(lambda g: bool((g.a_holds | g.b_holds).any()))
print("at least one holds under some reading, per seed offset:", s5a.to_dict())
# Reference: alignment |w . u| / ||w|| of a random direction w with a fixed unit vector u, in d dimensions.
rng_ref = np.random.default_rng(tc.seed(CL, 1))
for d in sorted({p.n_units for p in ALM["T1"]} | {tc.N_KEEP}):
    x = rng_ref.standard_normal((20000, d))
    print(f"random-direction reference, d = {d}: mean alignment {np.mean(np.abs(x[:, 0]) / np.linalg.norm(x, axis=1)):.3f}")
No description has been provided for this image
plotted range 0.037 to 0.247
R1 T1 alignment PCs 1-16: [0.082 0.123 0.116 0.135 0.082 0.087 0.097 0.071 0.098 0.08  0.104 0.091
 0.116 0.103 0.133 0.188]
R1 T1 SEM: [0.016 0.044 0.025 0.018 0.007 0.014 0.023 0.016 0.018 0.019 0.02  0.017
 0.02  0.033 0.03  0.059]
R1 T2 alignment PCs 1-16: [0.095 0.091 0.056 0.112 0.082 0.078 0.065 0.07  0.071 0.082 0.1   0.114
 0.106 0.105 0.127 0.15 ]
R1 T2 SEM: [0.023 0.043 0.019 0.042 0.02  0.024 0.018 0.011 0.012 0.023 0.018 0.025
 0.021 0.024 0.021 0.052]
R2 T1 alignment PCs 1-16: [0.077 0.11  0.055 0.067 0.067 0.066 0.072 0.071 0.046 0.046 0.065 0.071
 0.073 0.061 0.062 0.052]
R2 T1 SEM: [0.003 0.004 0.004 0.004 0.003 0.004 0.004 0.004 0.003 0.003 0.004 0.005
 0.004 0.003 0.004 0.003]
R2 T2 alignment PCs 1-16: [0.097 0.056 0.051 0.05  0.047 0.057 0.053 0.056 0.071 0.047 0.072 0.065
 0.075 0.064 0.097 0.061]
R2 T2 SEM: [0.004 0.003 0.004 0.003 0.003 0.003 0.003 0.003 0.004 0.002 0.005 0.004
 0.004 0.004 0.006 0.003]

claim seed, U1: readings where (a) holds: [['T1', 'R2'], ['T2', 'R2']] ; where (b) holds: [['T1', 'R1'], ['T1', 'R2'], ['T2', 'R2']] ; where both hold: [['T1', 'R2'], ['T2', 'R2']]
both hold under some reading, per seed offset: {0: True, 1000: True, 2000: True, 3000: True, 4000: True}
at least one holds under some reading, per seed offset: {0: True, 1000: True, 2000: True, 3000: True, 4000: True}
random-direction reference, d = 18: mean alignment 0.192
random-direction reference, d = 30: mean alignment 0.146
random-direction reference, d = 39: mean alignment 0.128
random-direction reference, d = 46: mean alignment 0.119
random-direction reference, d = 53: mean alignment 0.110
In [15]:
# The readout's alignment with every PC, against chance. The squared alignments over all d PCs sum to 1,
# so a random direction has a mean squared alignment of 1/d with each PC and puts a share 16/d of its
# squared norm in PCs 1 to 16.
for r in ("T1", "T2"):
    r1, r2p = pc_res[(0, r, False)]
    sq = r2p["align_all"] ** 2
    d = sq.shape[1]
    top = sq[:, :16].sum(1)
    print(f"R2 {r}: d = {d}; mean squared alignment with PCs 1-3 {sq[:, :3].mean():.4f}, 4-16 {sq[:, 3:16].mean():.4f}, "
          f"17-{d} {sq[:, 16:].mean():.4f}, chance 1/d {1 / d:.4f}; share of the readout's squared norm in PCs 1-16 "
          f"{top.mean():.3f} (range {top.min():.3f} to {top.max():.3f}), chance 16/d {16 / d:.3f}")
    for dd in r1:
        n = int(dd["n"][0])
        print(f"  R1 {r} {dd['path'].split('_ses-')[1][:15]}: {n} units; share in PCs 1-16 {dd['top16'].mean():.3f}, "
              f"chance {min(16, n) / n:.3f}")
sq = pc_res[(0, "T1", False)][1]["align_all"] ** 2
print("R2 T1, mean squared alignment by blocks of PCs (1-8, 9-16, ..., 49-53):",
      np.round([sq[:, a:a + 8].mean() for a in range(0, sq.shape[1], 8)], 4))
R2 T1: d = 53; mean squared alignment with PCs 1-3 0.0096, 4-16 0.0067, 17-53 0.0239, chance 1/d 0.0189; share of the readout's squared norm in PCs 1-16 0.116 (range 0.000 to 0.308), chance 16/d 0.302
  R1 T1 20170627T094049: 30 units; share in PCs 1-16 0.229, chance 0.533
  R1 T1 20170627T094051: 18 units; share in PCs 1-16 0.593, chance 0.889
  R1 T1 20170627T094054: 39 units; share in PCs 1-16 0.180, chance 0.410
  R1 T1 20170627T094056: 46 units; share in PCs 1-16 0.120, chance 0.348
  R1 T1 20170627T094100: 18 units; share in PCs 1-16 0.592, chance 0.889
R2 T2: d = 53; mean squared alignment with PCs 1-3 0.0076, 4-16 0.0069, 17-53 0.0240, chance 1/d 0.0189; share of the readout's squared norm in PCs 1-16 0.113 (range 0.005 to 0.400), chance 16/d 0.302
  R1 T2 20170627T094049: 30 units; share in PCs 1-16 0.172, chance 0.533
  R1 T2 20170627T094051: 18 units; share in PCs 1-16 0.504, chance 0.889
  R1 T2 20170627T094054: 39 units; share in PCs 1-16 0.204, chance 0.410
  R1 T2 20170627T094056: 46 units; share in PCs 1-16 0.045, chance 0.348
  R1 T2 20170627T094100: 18 units; share in PCs 1-16 0.518, chance 0.889
R2 T1, mean squared alignment by blocks of PCs (1-8, 9-16, ..., 49-53): [0.0083 0.0062 0.0076 0.0124 0.0494 0.0272 0.0224]

Result: partially reproduced. The criterion names both readouts, per session (R1, the reading of Figure 6C, n = 5) and pooled and subsampled (R2), and lets only the trial reading vary. Under R2 both readings of "leading" hold for T1 and T2 under the claim seed: the largest alignment is with PC 2 (T1) or PC 1 (T2), and the mean over PCs 1 to 3 exceeds the mean over PCs 4 to 16 (0.081 against 0.063 for T1). Both hold under some reading for all five seeds. Under R1 reading (a) fails for both trial readings, with the largest alignment at PC 16, and (b) holds only for T1, by a margin of 0.0003 (0.1069 against 0.1065); it fails under seed + 2000 (by 0.0015) and holds under the other three seeds. Were (b) to fail under R1 as well, R1 would meet neither reading while R2 meets both, so the claim would still hold only in part. Measured against chance, the leading PCs carry less of the readout than a random direction would. Under R2 the mean squared alignment with PCs 1 to 3 is 0.0096 (T1) and 0.0076 (T2), against 1/53 = 0.0189, and PCs 1 to 16 hold 0.116 and 0.113 of the readout's squared norm, against 16/53 = 0.302. Per session that share is below its chance level in all five sessions under both trial readings (0.045 to 0.593, against 0.348 to 0.889). The readout lies mostly in PCs 17 to 53, and it does not predict test data (fig6-wm-choice-r2).

Thalamic regressions (figs6d-wm-thalamic-r2, fig6d-wm-top5-pcs, figs6f-ct-alignment-not-significant)¶

Each thalamic unit's trial-averaged r(t) (its own session's correct trials, split 80/10/10) is regressed on the trial-averaged ALM population of the five ALM sessions (W9): P1, the 151 pooled units subsampled to 53, 20 subsamples per split; P2, all 151. P3 (each thalamic unit with the ALM units of its own session) does not apply: no session holds both. Each claim runs with its own seed; under the claim seed every reading (T1/T2, P1/P2, U1/U2) is run, and under the four further seeds the readings T1/T2 x P1/P2 with U1.

In [16]:
def run_thal(claim):
    out = {}
    for off in (0, 1000, 2000, 3000, 4000):
        for r in ("T1", "T2"):
            for pool in ("P1", "P2"):
                for span in ((False, True) if off == 0 else (False,)):
                    rng = np.random.default_rng(tc.seed(claim, off))
                    out[(off, r, pool, span)] = tc.thalamic_analysis(ALM[r], THAL[r], rng, pool=pool, span=span)
    return out

t0 = time.time()
TH = {c: run_thal(c) for c in ("figs6d-wm-thalamic-r2", "fig6d-wm-top5-pcs", "figs6f-ct-alignment-not-significant")}
print(f"thalamic regressions in {time.time() - t0:.0f} s; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB")
thalamic regressions in 420 s; peak memory 0.92 GB

figs6d-wm-thalamic-r2¶

ALM activity explains 0.70 +/- 0.01 of the variance of VM/VAL thalamic neurons in the working memory task.

Criterion: test-set R2 from all cortical units of the reading of W9 (53 units in P1), mean over the 72 thalamic units; reproduced when within 0.70 +/- 0.01 under one combination of T and P.

In [17]:
res = TH["figs6d-wm-thalamic-r2"]
rows = []
for (off, r, pool, span), d in res.items():
    rows.append(dict(seed_offset=off, trials=r, pool=pool, units="U2" if span else "U1",
                     mean_test_R2=np.nanmean(d["full"]), median_test_R2=np.nanmedian(d["full"]),
                     sem=stats.sem(d["full"], nan_policy="omit"), n_units=int(np.isfinite(d["full"]).sum()),
                     frac_positive=np.nanmean(d["full"] > 0), min_fits=int(d["n_fits"].min()),
                     mean_train_R2=np.nanmean(d["full_train"])))
s6d = pd.DataFrame(rows)
print(s6d.round(3).to_string(index=False))
m = s6d[(s6d.seed_offset == 0) & (s6d.units == "U1")]
print("\nclaim seed, U1: combinations within 0.69 to 0.71:", m[(m.mean_test_R2 - 0.70).abs() <= 0.01][["trials", "pool"]].values.tolist())
print(f"test R2 means over all seeds and U1 readings: {s6d[s6d.units == 'U1'].mean_test_R2.min():.2f} to {s6d[s6d.units == 'U1'].mean_test_R2.max():.2f}")
d = res[(0, "T1", "P1", False)]
fig, ax = plt.subplots(figsize=(5, 3))
x = np.sort(d["full"]); ax.plot(np.clip(x, -5, 1), np.arange(1, len(x) + 1) / len(x))
ax.set_xlabel("test R2 from all cortical units (clipped at -5)"); ax.set_ylabel("cumulative fraction")
plt.show()
print(f"T1 P1 U1: test R2 range {x.min():.2f} to {x.max():.2f}; {np.sum(x < -5)} units below -5 drawn at -5")
 seed_offset trials pool units  mean_test_R2  median_test_R2   sem  n_units  frac_positive  min_fits  mean_train_R2
           0     T1   P1    U1        -2.068          -1.879 0.090       72          0.000       200          0.740
           0     T1   P1    U2        -1.907          -1.863 0.088       70          0.000         0          0.763
           0     T1   P2    U1        -4.613          -4.555 0.272       72          0.014         9          0.997
           0     T1   P2    U2        -2.385          -2.044 0.173       72          0.028         1          0.994
           0     T2   P1    U1        -2.277          -2.091 0.110       72          0.000       180          0.751
           0     T2   P1    U2        -2.254          -2.129 0.100       72          0.000        40          0.755
           0     T2   P2    U1        -5.161          -4.692 0.393       72          0.014         8          0.998
           0     T2   P2    U2        -3.804          -3.025 0.311       72          0.014         3          0.993
        1000     T1   P1    U1        -2.803          -2.375 0.181       72          0.000       180          0.746
        1000     T1   P2    U1        -4.221          -3.667 0.254       72          0.000         9          0.997
        1000     T2   P1    U1        -3.091          -2.729 0.167       72          0.000       180          0.766
        1000     T2   P2    U1        -4.166          -3.850 0.281       72          0.014         8          0.997
        2000     T1   P1    U1        -2.258          -2.019 0.127       72          0.000       180          0.737
        2000     T1   P2    U1        -4.238          -3.550 0.405       72          0.000        10          0.998
        2000     T2   P1    U1        -2.560          -2.250 0.148       72          0.000       165          0.758
        2000     T2   P2    U1        -5.029          -4.262 0.342       72          0.000         9          0.998
        3000     T1   P1    U1        -1.984          -1.759 0.093       72          0.000       180          0.729
        3000     T1   P2    U1        -4.789          -4.122 0.409       72          0.000         8          0.998
        3000     T2   P1    U1        -2.664          -2.369 0.167       72          0.000       160          0.762
        3000     T2   P2    U1        -5.472          -4.395 0.394       72          0.000        10          0.997
        4000     T1   P1    U1        -2.267          -2.101 0.108       72          0.000       160          0.742
        4000     T1   P2    U1        -4.075          -3.706 0.276       72          0.000         9          0.997
        4000     T2   P1    U1        -3.702          -2.085 0.884       72          0.000       200          0.748
        4000     T2   P2    U1        -4.170          -3.654 0.285       72          0.014         7          0.997

claim seed, U1: combinations within 0.69 to 0.71: []
test R2 means over all seeds and U1 readings: -5.47 to -1.98
No description has been provided for this image
T1 P1 U1: test R2 range -4.49 to -0.85; 0 units below -5 drawn at -5
In [18]:
# Diagnostics, not readings of the claim, with a second generator of the claim (seed + 1).
# (1) Noise ceilings of the thalamic test-set averages, at each sigma: the R2 that each unit's own
# training-set average reaches on its test-set average, and the correlation r between the averages of
# the two halves of the test set (Spearman-Brown reliability of the whole test set, 2r / (1 + r)).
# (2) The main reading (T1, P1, U1) with 30% and 50% test sets (training 60% and 40%).
rng = np.random.default_rng(tc.seed("figs6d-wm-thalamic-r2", 1))
for tf in (0.1, 0.5):
    ceil = tc.thalamic_ceiling(THAL["T1"], rng, test_frac=tf)
    for s in tc.SIGMAS_MS:
        r = np.nanmean(ceil[s]["half"])
        print(f"test fraction {tf}, sigma {s:3d} ms: R2 of the test average from the training average, mean over units "
              f"{np.nanmean(ceil[s]['train']):.3f} (median {np.nanmedian(ceil[s]['train']):.3f}, max {np.nanmax(ceil[s]['train']):.3f}); "
              f"half correlation mean {r:.3f}, reliability {2 * r / (1 + r):.3f}")
for tf in (0.3, 0.5):
    d = tc.thalamic_analysis(ALM["T1"], THAL["T1"], rng, pool="P1", test_frac=tf)
    print(f"T1 P1 U1, test fraction {tf}: mean test R2 from all cortical units {np.nanmean(d['full']):.3f} "
          f"(median {np.nanmedian(d['full']):.3f}, fraction positive {np.nanmean(d['full'] > 0):.2f}); "
          f"training R2 {np.nanmean(d['full_train']):.3f}")
test fraction 0.1, sigma  10 ms: R2 of the test average from the training average, mean over units -0.049 (median -0.066, max 0.548); half correlation mean 0.038, reliability 0.073
test fraction 0.1, sigma  25 ms: R2 of the test average from the training average, mean over units -0.000 (median 0.005, max 0.628); half correlation mean 0.065, reliability 0.123
test fraction 0.1, sigma  50 ms: R2 of the test average from the training average, mean over units 0.040 (median 0.068, max 0.667); half correlation mean 0.096, reliability 0.176
test fraction 0.1, sigma 100 ms: R2 of the test average from the training average, mean over units 0.064 (median 0.095, max 0.703); half correlation mean 0.136, reliability 0.240
test fraction 0.1, sigma 200 ms: R2 of the test average from the training average, mean over units 0.010 (median 0.058, max 0.734); half correlation mean 0.166, reliability 0.284
test fraction 0.5, sigma  10 ms: R2 of the test average from the training average, mean over units -0.714 (median -0.743, max 0.745); half correlation mean 0.164, reliability 0.281
test fraction 0.5, sigma  25 ms: R2 of the test average from the training average, mean over units -0.501 (median -0.429, max 0.818); half correlation mean 0.252, reliability 0.403
test fraction 0.5, sigma  50 ms: R2 of the test average from the training average, mean over units -0.377 (median -0.228, max 0.853); half correlation mean 0.325, reliability 0.491
test fraction 0.5, sigma 100 ms: R2 of the test average from the training average, mean over units -0.322 (median -0.138, max 0.895); half correlation mean 0.388, reliability 0.559
test fraction 0.5, sigma 200 ms: R2 of the test average from the training average, mean over units -0.446 (median 0.007, max 0.916); half correlation mean 0.420, reliability 0.591
T1 P1 U1, test fraction 0.3: mean test R2 from all cortical units -1.574 (median -1.494, fraction positive 0.03); training R2 0.723
T1 P1 U1, test fraction 0.5: mean test R2 from all cortical units -1.716 (median -1.375, fraction positive 0.01); training R2 0.713

Result: not reproduced. No combination of trial and pooling readings gives a mean test-set R2 near 0.70: under the claim seed the means run from -5.16 to -1.91, and no unit has a positive test R2 under P1. The training-set R2 of the same regressions, a diagnostic only, is 0.73 to 0.77 under P1 over the five seeds and near 1 under P2. The diagnostics (seed + 1, T1) show that a mean test-set R2 near 0.70 is out of reach with 10% test sets: the averages of the two halves of a unit's test set correlate at 0.04 to 0.17 on average over the sigma grid (reliability of the whole test set 0.07 to 0.28), and a unit's own training-set average predicts its test-set average with a mean R2 of -0.05 to 0.06. A model that predicted each unit's mean exactly would explain on average at most about 0.28 of the variance of its test-set average. With 30% and 50% test sets the mean test R2 of the main reading is -1.57 and -1.72.

fig6d-wm-top5-pcs¶

In the working memory task, the top 5 ALM PCs capture 0.63 +/- 0.04 of the explainable variance of thalamic neurons.

Criterion: mean normalized R2(5) over the 72 thalamic units under N1 (R2(5)/R2(16)), N2 (R2(5)/R2 from all cortical units) or N3 (each unit's curve rescaled to 0 to 1); reproduced when within 0.63 +/- 0.04 under one combination of T, P and N. Normalization is applied to each unit's mean curve over splits and subsamples.

In [19]:
res = TH["fig6d-wm-top5-pcs"]
rows = []
for (off, r, pool, span), d in res.items():
    for how in ("N1", "N2", "N3"):
        v = tc.normalized(d["r2k"], d["full"], how)[4]
        vt = tc.normalized(d["r2k_train"], d["full_train"], how)[4]
        rows.append(dict(seed_offset=off, trials=r, pool=pool, units="U2" if span else "U1", norm=how,
                         mean=np.nanmean(v), median=np.nanmedian(v), sem=stats.sem(v, nan_policy="omit"),
                         n=int(np.isfinite(v).sum()), mean_train=np.nanmean(vt)))
t5 = pd.DataFrame(rows)
print(t5.round(3).to_string(index=False))
m = t5[(t5.seed_offset == 0) & (t5.units == "U1")]
hit = m[(m["mean"] - 0.63).abs() <= 0.04]
print("\nclaim seed, U1: combinations within 0.59 to 0.67:", hit[["trials", "pool", "norm"]].values.tolist())
for s, g in t5[t5.units == "U1"].groupby("seed_offset"):
    print(f"seed offset {s}: combinations within tolerance: {g[(g['mean'] - 0.63).abs() <= 0.04][['trials', 'pool', 'norm']].values.tolist()}")
d = res[(0, "T1", "P1", False)]
print("\nT1 P1 U1, mean test R2(k), k = 1 to 16:", np.round(np.nanmean(d["r2k"], 1), 3))
print("T1 P1 U1, mean training R2(k), k = 1 to 16:", np.round(np.nanmean(d["r2k_train"], 1), 3))
print("units whose test R2(16) is positive:", int(np.sum(d["r2k"][-1] > 0)), "of", d["r2k"].shape[1])
 seed_offset trials pool units norm   mean  median   sem  n  mean_train
           0     T1   P1    U1   N1  0.040   0.140 0.085 72       0.770
           0     T1   P1    U1   N2  0.043   0.050 0.008 72       0.680
           0     T1   P1    U1   N3  0.836   0.856 0.011 72       0.700
           0     T1   P1    U2   N1 -8.292   0.125 8.309 72       0.760
           0     T1   P1    U2   N2 -0.007   0.035 0.019 72       0.687
           0     T1   P1    U2   N3  0.831   0.855 0.012 72       0.698
           0     T1   P2    U1   N1 -0.186   0.142 0.222 72       0.795
           0     T1   P2    U1   N2  0.001   0.009 0.014 72       0.613
           0     T1   P2    U1   N3  0.776   0.850 0.025 72       0.720
           0     T1   P2    U2   N1  0.091   0.124 0.370 72       0.790
           0     T1   P2    U2   N2 -0.021   0.011 0.039 72       0.624
           0     T1   P2    U2   N3  0.781   0.853 0.025 72       0.728
           0     T2   P1    U1   N1  0.121   0.107 0.017 72       0.771
           0     T2   P1    U1   N2  0.061   0.052 0.008 72       0.674
           0     T2   P1    U1   N3  0.846   0.878 0.012 72       0.698
           0     T2   P1    U2   N1 -0.071   0.081 0.114 72       0.760
           0     T2   P1    U2   N2  0.001   0.026 0.012 72       0.666
           0     T2   P1    U2   N3  0.851   0.862 0.010 72       0.701
           0     T2   P2    U1   N1 -1.015   0.111 0.975 72       0.790
           0     T2   P2    U1   N2 -0.089  -0.000 0.047 72       0.619
           0     T2   P2    U1   N3  0.843   0.893 0.018 72       0.725
           0     T2   P2    U2   N1  5.511   0.066 5.537 72       0.789
           0     T2   P2    U2   N2 -0.095  -0.002 0.078 72       0.621
           0     T2   P2    U2   N3  0.850   0.893 0.017 72       0.735
        1000     T1   P1    U1   N1  0.152   0.187 0.028 72       0.764
        1000     T1   P1    U1   N2  0.068   0.067 0.007 72       0.671
        1000     T1   P1    U1   N3  0.806   0.821 0.012 72       0.696
        1000     T1   P2    U1   N1  0.811   0.207 0.394 72       0.776
        1000     T1   P2    U1   N2 -0.012   0.006 0.015 72       0.596
        1000     T1   P2    U1   N3  0.824   0.858 0.020 72       0.697
        1000     T2   P1    U1   N1  0.161   0.166 0.018 72       0.771
        1000     T2   P1    U1   N2  0.106   0.070 0.034 72       0.688
        1000     T2   P1    U1   N3  0.831   0.862 0.013 72       0.703
        1000     T2   P2    U1   N1  0.007   0.073 0.128 72       0.806
        1000     T2   P2    U1   N2  0.080   0.005 0.128 72       0.656
        1000     T2   P2    U1   N3  0.836   0.906 0.022 72       0.735
        2000     T1   P1    U1   N1  0.308   0.183 0.104 72       0.759
        2000     T1   P1    U1   N2  0.051   0.047 0.009 72       0.646
        2000     T1   P1    U1   N3  0.799   0.812 0.014 72       0.689
        2000     T1   P2    U1   N1  2.005   0.115 3.148 72       0.795
        2000     T1   P2    U1   N2 -0.046   0.003 0.026 72       0.629
        2000     T1   P2    U1   N3  0.823   0.860 0.020 72       0.714
        2000     T2   P1    U1   N1  0.186   0.135 0.073 72       0.769
        2000     T2   P1    U1   N2  0.045   0.045 0.008 72       0.684
        2000     T2   P1    U1   N3  0.855   0.871 0.010 72       0.697
        2000     T2   P2    U1   N1 -0.241   0.079 0.303 72       0.784
        2000     T2   P2    U1   N2  0.039   0.000 0.051 72       0.625
        2000     T2   P2    U1   N3  0.816   0.888 0.025 72       0.714
        3000     T1   P1    U1   N1  0.158   0.164 0.026 72       0.766
        3000     T1   P1    U1   N2  0.064   0.058 0.007 72       0.669
        3000     T1   P1    U1   N3  0.816   0.829 0.013 72       0.701
        3000     T1   P2    U1   N1  0.163   0.108 0.070 72       0.789
        3000     T1   P2    U1   N2  0.028   0.006 0.029 72       0.611
        3000     T1   P2    U1   N3  0.793   0.865 0.029 72       0.715
        3000     T2   P1    U1   N1  0.146   0.141 0.018 72       0.768
        3000     T2   P1    U1   N2  0.058   0.055 0.006 72       0.681
        3000     T2   P1    U1   N3  0.844   0.867 0.011 72       0.695
        3000     T2   P2    U1   N1 -0.013   0.099 0.299 72       0.798
        3000     T2   P2    U1   N2  0.036   0.008 0.043 72       0.641
        3000     T2   P2    U1   N3  0.775   0.815 0.025 72       0.735
        4000     T1   P1    U1   N1  0.171   0.157 0.018 72       0.761
        4000     T1   P1    U1   N2  0.075   0.065 0.007 72       0.661
        4000     T1   P1    U1   N3  0.815   0.832 0.012 72       0.693
        4000     T1   P2    U1   N1  0.402   0.169 0.157 72       0.774
        4000     T1   P2    U1   N2  0.082   0.008 0.099 72       0.586
        4000     T1   P2    U1   N3  0.764   0.871 0.030 72       0.697
        4000     T2   P1    U1   N1  0.131   0.122 0.017 72       0.770
        4000     T2   P1    U1   N2  0.057   0.054 0.008 72       0.682
        4000     T2   P1    U1   N3  0.846   0.856 0.012 72       0.702
        4000     T2   P2    U1   N1  1.236   0.060 1.147 72       0.789
        4000     T2   P2    U1   N2  0.071  -0.002 0.095 72       0.615
        4000     T2   P2    U1   N3  0.840   0.908 0.021 72       0.720

claim seed, U1: combinations within 0.59 to 0.67: []
seed offset 0: combinations within tolerance: []
seed offset 1000: combinations within tolerance: []
seed offset 2000: combinations within tolerance: []
seed offset 3000: combinations within tolerance: []
seed offset 4000: combinations within tolerance: []

T1 P1 U1, mean test R2(k), k = 1 to 16: [ 0.005 -0.009 -0.045 -0.088 -0.152 -0.207 -0.292 -0.363 -0.405 -0.452
 -0.521 -0.603 -0.68  -0.778 -0.853 -0.929]
T1 P1 U1, mean training R2(k), k = 1 to 16: [0.175 0.316 0.413 0.48  0.519 0.546 0.568 0.585 0.598 0.609 0.618 0.626
 0.634 0.641 0.648 0.654]
units whose test R2(16) is positive: 0 of 72
In [20]:
# N1 and N2 are fractions of explainable variance only where the denominator is positive.
for key in [k for k in res if k[0] == 0 and not k[3]]:
    d = res[key]
    pos1, pos2 = d["r2k"][-1] > 0, d["full"] > 0
    n1 = d["r2k"][4, pos1] / d["r2k"][-1, pos1]
    n2 = d["r2k"][4, pos2] / d["full"][pos2]
    print(f"{key[1]} {key[2]} U1: units with test R2(16) > 0: {pos1.sum()} of {len(pos1)} (N1 over them: "
          f"{n1.mean() if len(n1) else float('nan'):.3f}); with test R2 from all units > 0: {pos2.sum()} (N2 over them: "
          f"{n2.mean() if len(n2) else float('nan'):.3f})")
# N3 rescales each curve between its minimum and maximum; where R2(k) falls with k it measures that fall.
d = res[(0, "T1", "P1", False)]
print("T1 P1 U1: units whose test R2(k) is largest at k = 1:", int(np.sum(np.argmax(d["r2k"], 0) == 0)),
      "of", d["r2k"].shape[1])
# A diagnostic, not a reading of the claim: the main reading with 50% test sets (training 40%), with a
# second generator of the claim (seed + 1).
rng = np.random.default_rng(tc.seed("fig6d-wm-top5-pcs", 1))
d5 = tc.thalamic_analysis(ALM["T1"], THAL["T1"], rng, pool="P1", test_frac=0.5)
print("\nT1 P1 U1, 50% test sets: mean test R2(k), k = 1 to 16:", np.round(np.nanmean(d5["r2k"], 1), 3))
print("units whose test R2(16) is positive:", int(np.sum(d5["r2k"][-1] > 0)), "of", d5["r2k"].shape[1])
for how in ("N1", "N2", "N3"):
    print(f"  {how}: mean normalized R2(5) {np.nanmean(tc.normalized(d5['r2k'], d5['full'], how)[4]):.3f}")
T1 P1 U1: units with test R2(16) > 0: 0 of 72 (N1 over them: nan); with test R2 from all units > 0: 0 (N2 over them: nan)
T1 P2 U1: units with test R2(16) > 0: 6 of 72 (N1 over them: 0.817); with test R2 from all units > 0: 0 (N2 over them: nan)
T2 P1 U1: units with test R2(16) > 0: 0 of 72 (N1 over them: nan); with test R2 from all units > 0: 0 (N2 over them: nan)
T2 P2 U1: units with test R2(16) > 0: 10 of 72 (N1 over them: 2.153); with test R2 from all units > 0: 0 (N2 over them: nan)
T1 P1 U1: units whose test R2(k) is largest at k = 1: 48 of 72
T1 P1 U1, 50% test sets: mean test R2(k), k = 1 to 16: [-0.003  0.035  0.043  0.031  0.008 -0.024 -0.057 -0.092 -0.127 -0.168
 -0.209 -0.231 -0.274 -0.307 -0.35  -0.39 ]
units whose test R2(16) is positive: 15 of 72
  N1: mean normalized R2(5) 3.887
  N2: mean normalized R2(5) -0.164
  N3: mean normalized R2(5) 0.871

Result: not reproduced. No combination of T, P and N gives a mean normalized R2(5) within 0.59 to 0.67, under any of the five seeds. The test-set R2(k) is near 0 at k = 1 (0.005 under T1 and P1) and falls as k grows (the regressions on more PCs overfit). Over the five seeds with U1, N1 gives at most 0.31 under P1 and means from -1.02 to 2.01, driven by outliers, under P2; N2 gives -0.09 to 0.11; and N3 gives 0.76 to 0.86. None of these is a fraction of explainable variance. Under the claim seed no unit has a positive test R2(16) under P1 (6 under T1 and P2, 10 under T2 and P2), and no unit has a positive test R2 from all units under any reading, so the denominators of N1 and N2 are not positive. N3 rescales each curve between its minimum and its maximum; 48 of 72 units have their largest test R2(k) at k = 1 (T1, P1), so its value at k = 5 measures the fall of the curve. With 50% test sets (a diagnostic) the mean test R2(k) peaks at 0.043 (k = 3), and N1, N2 and N3 give 3.89, -0.16 and 0.87. On the training set, a diagnostic only, N2 gives 0.68 and N3 0.70 under T1 and P1.

figs6f-ct-alignment-not-significant¶

For individual thalamic neurons, the difference between the alignment of corticothalamic weights with the leading cortical PC and with the readout direction is not significant in either dataset (one-sided paired t tests, p = 0.09 and p = 0.17).

Criterion: a claim of absence on the paper's test. Corticothalamic weights from the regression on all 16 PCs mapped back to unit space; alignment |cos| with PC 1 and with the readout on the same cortical population; one-sided paired t test over the 72 units, PC greater than readout; reproduced when p >= 0.05. The cortical population follows the Figure S6 legend ("in all analysis", P1); T1 is the main trial reading (W2 lists it first). The other readings and the weights of the regression on all units are variants.

In [21]:
res = TH["figs6f-ct-alignment-not-significant"]
rows = []
for (off, r, pool, span), d in res.items():
    for w in ("16 PCs", "all units"):
        a, b = (d["a_pc"], d["a_ro"]) if w == "16 PCs" else (d["a_pc_full"], d["a_ro_full"])
        ok = np.isfinite(a) & np.isfinite(b)
        t = stats.ttest_rel(a[ok], b[ok], alternative="greater")
        t2 = stats.ttest_rel(a[ok], b[ok])
        diff = a[ok] - b[ok]
        rows.append(dict(seed_offset=off, trials=r, pool=pool, units="U2" if span else "U1", weights=w,
                         mean_align_PC1=a[ok].mean(), mean_align_readout=b[ok].mean(),
                         mean_diff=diff.mean(), cohen_dz=diff.mean() / diff.std(ddof=1), t=t.statistic, p=t.pvalue,
                         p_two_sided=t2.pvalue, n=int(ok.sum())))
s6f = pd.DataFrame(rows)
print(s6f.round(4).to_string(index=False))
main = s6f[(s6f.seed_offset == 0) & (s6f.trials == "T1") & (s6f.pool == "P1") & (s6f.units == "U1") & (s6f.weights == "16 PCs")].iloc[0]
print(f"\nmain reading (claim seed, T1, P1, U1, 16 PCs): PC1 {main.mean_align_PC1:.3f}, readout {main.mean_align_readout:.3f}, "
      f"difference {main.mean_diff:.3f}, t = {main.t:.2f}, one-sided p = {main.p:.2g}, n = {main.n}")
sd = s6f[(s6f.trials == "T1") & (s6f.pool == "P1") & (s6f.units == "U1") & (s6f.weights == "16 PCs")]
print("main reading over five seeds, p:", sd.set_index("seed_offset").p.round(4).to_dict())
print("readings with p < 0.05 (claim seed):", s6f[(s6f.seed_offset == 0) & (s6f.p < 0.05)][["trials", "pool", "units", "weights"]].values.tolist())
print("readings with p >= 0.05 (any seed):", s6f[s6f.p >= 0.05][["seed_offset", "trials", "pool", "units", "weights"]].values.tolist())
rng_ref = np.random.default_rng(tc.seed("figs6f-ct-alignment-not-significant", 1))
for d in (16, tc.N_KEEP, 151):
    x = rng_ref.standard_normal((20000, d))
    print(f"random-direction reference, d = {d}: mean alignment {np.mean(np.abs(x[:, 0]) / np.linalg.norm(x, axis=1)):.3f}")
 seed_offset trials pool units   weights  mean_align_PC1  mean_align_readout  mean_diff  cohen_dz        t      p  p_two_sided  n
           0     T1   P1    U1    16 PCs          0.0936              0.0706     0.0230    0.5446   4.6208 0.0000       0.0000 72
           0     T1   P1    U1 all units          0.0181              0.2419    -0.2238  -10.5121 -89.1985 1.0000       0.0000 72
           0     T1   P1    U2    16 PCs          0.1059              0.0668     0.0391    0.7312   6.2049 0.0000       0.0000 72
           0     T1   P1    U2 all units          0.0216              0.2410    -0.2195   -6.0683 -51.4912 1.0000       0.0000 72
           0     T1   P2    U1    16 PCs          0.0932              0.0397     0.0535    0.8022   6.8072 0.0000       0.0000 72
           0     T1   P2    U1 all units          0.0073              0.1617    -0.1543   -4.1540 -35.2475 1.0000       0.0000 72
           0     T1   P2    U2    16 PCs          0.1060              0.0488     0.0573    0.7347   6.2341 0.0000       0.0000 72
           0     T1   P2    U2 all units          0.0120              0.2157    -0.2037   -2.9874 -25.3492 1.0000       0.0000 72
           0     T2   P1    U1    16 PCs          0.0726              0.0632     0.0094    0.2737   2.3222 0.0115       0.0231 72
           0     T2   P1    U1 all units          0.0133              0.2574    -0.2441  -10.6137 -90.0602 1.0000       0.0000 72
           0     T2   P1    U2    16 PCs          0.0757              0.0555     0.0201    0.4526   3.8401 0.0001       0.0003 72
           0     T2   P1    U2 all units          0.0146              0.2522    -0.2376   -8.1232 -68.9280 1.0000       0.0000 72
           0     T2   P2    U1    16 PCs          0.0671              0.0334     0.0336    0.6704   5.6885 0.0000       0.0000 72
           0     T2   P2    U1 all units          0.0053              0.1678    -0.1626   -4.7355 -40.1817 1.0000       0.0000 72
           0     T2   P2    U2    16 PCs          0.0667              0.0315     0.0353    0.7148   6.0656 0.0000       0.0000 72
           0     T2   P2    U2 all units          0.0066              0.2081    -0.2015   -3.6664 -31.1106 1.0000       0.0000 72
        1000     T1   P1    U1    16 PCs          0.0929              0.0674     0.0255    0.5747   4.8769 0.0000       0.0000 72
        1000     T1   P1    U1 all units          0.0181              0.2654    -0.2473  -10.0288 -85.0971 1.0000       0.0000 72
        1000     T1   P2    U1    16 PCs          0.0985              0.0362     0.0623    0.8521   7.2302 0.0000       0.0000 72
        1000     T1   P2    U1 all units          0.0076              0.1863    -0.1787   -3.4592 -29.3526 1.0000       0.0000 72
        1000     T2   P1    U1    16 PCs          0.0707              0.0623     0.0084    0.2526   2.1431 0.0178       0.0355 72
        1000     T2   P1    U1 all units          0.0133              0.2566    -0.2433  -10.2987 -87.3876 1.0000       0.0000 72
        1000     T2   P2    U1    16 PCs          0.0678              0.0311     0.0367    0.7797   6.6159 0.0000       0.0000 72
        1000     T2   P2    U1 all units          0.0053              0.1745    -0.1692   -3.9216 -33.2762 1.0000       0.0000 72
        2000     T1   P1    U1    16 PCs          0.0973              0.0715     0.0257    0.5290   4.4887 0.0000       0.0000 72
        2000     T1   P1    U1 all units          0.0185              0.2518    -0.2333   -9.4590 -80.2624 1.0000       0.0000 72
        2000     T1   P2    U1    16 PCs          0.0980              0.0353     0.0627    0.9003   7.6391 0.0000       0.0000 72
        2000     T1   P2    U1 all units          0.0075              0.1956    -0.1882   -4.2846 -36.3561 1.0000       0.0000 72
        2000     T2   P1    U1    16 PCs          0.0697              0.0662     0.0035    0.0976   0.8279 0.2053       0.4105 72
        2000     T2   P1    U1 all units          0.0134              0.2457    -0.2323  -10.0707 -85.4524 1.0000       0.0000 72
        2000     T2   P2    U1    16 PCs          0.0639              0.0326     0.0313    0.6941   5.8892 0.0000       0.0000 72
        2000     T2   P2    U1 all units          0.0050              0.1812    -0.1762   -3.9505 -33.5209 1.0000       0.0000 72
        3000     T1   P1    U1    16 PCs          0.0925              0.0723     0.0201    0.4956   4.2053 0.0000       0.0001 72
        3000     T1   P1    U1 all units          0.0181              0.2463    -0.2282  -10.5070 -89.1547 1.0000       0.0000 72
        3000     T1   P2    U1    16 PCs          0.0983              0.0327     0.0656    0.9318   7.9067 0.0000       0.0000 72
        3000     T1   P2    U1 all units          0.0073              0.2020    -0.1947   -4.1438 -35.1616 1.0000       0.0000 72
        3000     T2   P1    U1    16 PCs          0.0730              0.0635     0.0096    0.2715   2.3036 0.0121       0.0242 72
        3000     T2   P1    U1 all units          0.0140              0.2500    -0.2360  -11.3327 -96.1614 1.0000       0.0000 72
        3000     T2   P2    U1    16 PCs          0.0672              0.0369     0.0303    0.6427   5.4535 0.0000       0.0000 72
        3000     T2   P2    U1 all units          0.0053              0.1687    -0.1634   -3.6886 -31.2986 1.0000       0.0000 72
        4000     T1   P1    U1    16 PCs          0.0947              0.0682     0.0264    0.5599   4.7512 0.0000       0.0000 72
        4000     T1   P1    U1 all units          0.0179              0.2542    -0.2363   -9.1678 -77.7911 1.0000       0.0000 72
        4000     T1   P2    U1    16 PCs          0.0975              0.0371     0.0604    0.8469   7.1861 0.0000       0.0000 72
        4000     T1   P2    U1 all units          0.0073              0.1872    -0.1799   -4.0161 -34.0774 1.0000       0.0000 72
        4000     T2   P1    U1    16 PCs          0.0701              0.0637     0.0064    0.1940   1.6464 0.0520       0.1041 72
        4000     T2   P1    U1 all units          0.0137              0.2524    -0.2387  -10.7266 -91.0183 1.0000       0.0000 72
        4000     T2   P2    U1    16 PCs          0.0625              0.0372     0.0253    0.5533   4.6952 0.0000       0.0000 72
        4000     T2   P2    U1 all units          0.0050              0.1797    -0.1748   -4.5016 -38.1978 1.0000       0.0000 72

main reading (claim seed, T1, P1, U1, 16 PCs): PC1 0.094, readout 0.071, difference 0.023, t = 4.62, one-sided p = 8.3e-06, n = 72
main reading over five seeds, p: {0: 0.0, 1000: 0.0, 2000: 0.0, 3000: 0.0, 4000: 0.0}
readings with p < 0.05 (claim seed): [['T1', 'P1', 'U1', '16 PCs'], ['T1', 'P1', 'U2', '16 PCs'], ['T1', 'P2', 'U1', '16 PCs'], ['T1', 'P2', 'U2', '16 PCs'], ['T2', 'P1', 'U1', '16 PCs'], ['T2', 'P1', 'U2', '16 PCs'], ['T2', 'P2', 'U1', '16 PCs'], ['T2', 'P2', 'U2', '16 PCs']]
readings with p >= 0.05 (any seed): [[0, 'T1', 'P1', 'U1', 'all units'], [0, 'T1', 'P1', 'U2', 'all units'], [0, 'T1', 'P2', 'U1', 'all units'], [0, 'T1', 'P2', 'U2', 'all units'], [0, 'T2', 'P1', 'U1', 'all units'], [0, 'T2', 'P1', 'U2', 'all units'], [0, 'T2', 'P2', 'U1', 'all units'], [0, 'T2', 'P2', 'U2', 'all units'], [1000, 'T1', 'P1', 'U1', 'all units'], [1000, 'T1', 'P2', 'U1', 'all units'], [1000, 'T2', 'P1', 'U1', 'all units'], [1000, 'T2', 'P2', 'U1', 'all units'], [2000, 'T1', 'P1', 'U1', 'all units'], [2000, 'T1', 'P2', 'U1', 'all units'], [2000, 'T2', 'P1', 'U1', '16 PCs'], [2000, 'T2', 'P1', 'U1', 'all units'], [2000, 'T2', 'P2', 'U1', 'all units'], [3000, 'T1', 'P1', 'U1', 'all units'], [3000, 'T1', 'P2', 'U1', 'all units'], [3000, 'T2', 'P1', 'U1', 'all units'], [3000, 'T2', 'P2', 'U1', 'all units'], [4000, 'T1', 'P1', 'U1', 'all units'], [4000, 'T1', 'P2', 'U1', 'all units'], [4000, 'T2', 'P1', 'U1', '16 PCs'], [4000, 'T2', 'P1', 'U1', 'all units'], [4000, 'T2', 'P2', 'U1', 'all units']]
random-direction reference, d = 16: mean alignment 0.203
random-direction reference, d = 53: mean alignment 0.109
random-direction reference, d = 151: mean alignment 0.065
In [22]:
# Chance levels (a diagnostic, not a reading of the claim). The 16-PC weights lie in the span of PCs 1
# to 16. A random direction in that span has mean alignment c16 with PC 1, and c16 times the share of
# the readout's norm inside the span with the readout (c_ro, per unit and fit). The comparison with
# each alignment divided by its chance level is run with the readout at its own best sigma (main) and
# at the thalamic unit's sigma (same sigma).
c16 = tc.chance_alignment(16)
print(f"c16 = {c16:.3f}")
rows = []
for (off, r, pool, span), d in res.items():
    if off:
        continue
    for ro in ("main", "same sigma"):
        a_ro, c_ro = (d["a_ro"], d["c_ro"]) if ro == "main" else (d["a_ro_same"], d["c_ro_same"])
        x, y = d["a_pc"] / c16, a_ro / c_ro
        ok = np.isfinite(x) & np.isfinite(y)
        raw = stats.ttest_rel(d["a_pc"][ok], a_ro[ok], alternative="greater")
        rel = stats.ttest_rel(x[ok], y[ok])
        rows.append(dict(trials=r, pool=pool, units="U2" if span else "U1", readout_sigma=ro,
                         share_of_readout_in_span=np.nanmean(d["ro16"]), PC1=np.nanmean(d["a_pc"]), PC1_chance=c16,
                         readout=np.nanmean(a_ro), readout_chance=np.nanmean(c_ro),
                         p_raw_greater=raw.pvalue, PC1_over_chance=np.nanmean(x), readout_over_chance=np.nanmean(y),
                         dz_over_chance=np.nanmean(x[ok] - y[ok]) / np.nanstd(x[ok] - y[ok], ddof=1),
                         p_over_chance_two_sided=rel.pvalue))
print(pd.DataFrame(rows).round(4).to_string(index=False))
c16 = 0.203
trials pool units readout_sigma  share_of_readout_in_span    PC1  PC1_chance  readout  readout_chance  p_raw_greater  PC1_over_chance  readout_over_chance  dz_over_chance  p_over_chance_two_sided
    T1   P1    U1          main                    0.2923 0.0936      0.2026   0.0706          0.0592         0.0000           0.4621               1.1911         -2.3594                      0.0
    T1   P1    U1    same sigma                    0.2923 0.0936      0.2026   0.0723          0.0599         0.0000           0.4621               1.2099         -2.0745                      0.0
    T1   P1    U2          main                    0.2804 0.1059      0.2026   0.0668          0.0568         0.0000           0.5228               1.1733         -1.6926                      0.0
    T1   P1    U2    same sigma                    0.2804 0.1059      0.2026   0.0688          0.0586         0.0000           0.5228               1.1727         -1.5089                      0.0
    T1   P2    U1          main                    0.1968 0.0932      0.2026   0.0397          0.0399         0.0000           0.4598               0.9968         -0.9753                      0.0
    T1   P2    U1    same sigma                    0.1968 0.0932      0.2026   0.0332          0.0335         0.0000           0.4598               0.9954         -0.9405                      0.0
    T1   P2    U2          main                    0.2200 0.1060      0.2026   0.0488          0.0446         0.0000           0.5234               1.0914         -0.9435                      0.0
    T1   P2    U2    same sigma                    0.2200 0.1060      0.2026   0.0463          0.0424         0.0000           0.5234               1.0886         -0.8930                      0.0
    T2   P1    U1          main                    0.2703 0.0726      0.2026   0.0632          0.0548         0.0115           0.3584               1.1485         -3.3601                      0.0
    T2   P1    U1    same sigma                    0.2703 0.0726      0.2026   0.0683          0.0568         0.1399           0.3584               1.2072         -2.8760                      0.0
    T2   P1    U2          main                    0.2413 0.0757      0.2026   0.0555          0.0489         0.0001           0.3736               1.1298         -3.1725                      0.0
    T2   P1    U2    same sigma                    0.2413 0.0757      0.2026   0.0638          0.0570         0.0112           0.3736               1.1287         -2.6246                      0.0
    T2   P2    U1          main                    0.1516 0.0671      0.2026   0.0334          0.0307         0.0000           0.3310               1.0879         -1.7410                      0.0
    T2   P2    U1    same sigma                    0.1516 0.0671      0.2026   0.0321          0.0294         0.0000           0.3310               1.0955         -1.6247                      0.0
    T2   P2    U2          main                    0.1483 0.0667      0.2026   0.0315          0.0301         0.0000           0.3294               1.0370         -1.5919                      0.0
    T2   P2    U2    same sigma                    0.1483 0.0667      0.2026   0.0336          0.0324         0.0000           0.3294               1.0281         -1.4877                      0.0

Result: not reproduced. On the main reading (T1, P1, U1, weights from the 16 PCs) the corticothalamic weights are more aligned with PC 1 than with the readout (0.094 against 0.071, mean difference 0.023, dz 0.54, t = 4.62, one-sided p = 8.3e-06, n = 72), under all five seeds, so the paper's test finds the difference the claim says it does not. Every reading with the 16-PC weights gives p < 0.05 under the claim seed; only T2 with P1 gives p >= 0.05 under two of the other seeds (0.21 and 0.052). With the weights of the regression on all units, a variant, the readout alignment is the larger one (one-sided p = 1, two-sided p < 0.001, dz -10.5), which satisfies the criterion's p >= 0.05 by an effect in the other direction. Measured against chance within the 16-PC span, where the 16-PC weights lie, the order reverses: the PC 1 alignment is 0.46 of its chance level (0.094 against 0.203) and the readout alignment 1.19 times its own (0.071 against 0.059; the readout has 0.29 of its norm in the span), a chance-corrected difference of dz -2.36 (two-sided p < 0.001). The same holds with the readout taken at each thalamic unit's sigma (ratio 1.21, raw one-sided p < 0.001). With the readout at the thalamic unit's sigma, one other reading, T2 with P1 and U1, gives a raw one-sided p of 0.140 (cell above); this variant does not decide the outcome. The paper's test thus compares two alignments with different chance levels; the outcome follows the test as the criterion gives it.

The simulation claims¶

The 24 claims on the paper's models (Figures 1 to 5, S1 to S5) need the models run as the paper ran them: 10,000 learning trials of 200 time steps for each of 40 initializations, for every network size and condition, and, for the meta-learning claims, 10,000 epochs of 200 such trials each. One epoch of the paper's own motor control model (thalamocortical__motor.py, commit 2aa94dd, reimplemented in tcloop.rflo_motor) is timed here at the smallest and largest thalamus.

In [23]:
rng = np.random.default_rng(tc.seed("fig1c-tc-learning-improves-with-thalamus"))
per_trial = {}
tc.rflo_motor(1, 1, rng)  # untimed first call, so that the timings below exclude start-up costs
def timed(M, N=256):
    # Fastest of three timings of 3 learning trials, so the estimates below are lower bounds.
    best = np.inf
    for _ in range(3):
        t0 = time.time(); e = tc.rflo_motor(3, M, rng, N=N); best = min(best, (time.time() - t0) / 3)
    return best, e
for M in (1, 8, 32, 128, 256):
    per_trial[M], e = timed(M)
    print(f"M = {M}: {per_trial[M] * 1000:.1f} ms per learning trial; errors of the last 3 trials {np.round(e, 3)}")
n512, _ = timed(1, N=512)
print(f"N = 512, M = 1: {n512 * 1000:.1f} ms per learning trial")

def rate(M):
    return np.interp(np.log2(M), np.log2(list(per_trial)), list(per_trial.values()))
RUNS, TRIALS = 40, 10000
one_set = lambda M: rate(M) * TRIALS * RUNS  # s, 40 runs of 10,000 trials at one M
curve = lambda Ms: sum(one_set(M) for M in Ms)
M128, M256 = [2 ** k for k in range(8)], [2 ** k for k in range(9)]
# Lower bounds per claim: the sets of 40 runs each claim needs at the least (attempt record notes), with
# the motor control trial of 200 steps standing in for every task.
est = {
    "fig1c, fig1d: one curve, M = 1 to 128": curve(M128),
    "fig1cd, figs1d: two curves, M = 1 to 128 (before the rate search)": 2 * curve(M128),
    "fig2d, figs2a, fig2e, figs2b: one meta-learning run, 10,000 epochs of 200 trials at M = 32": rate(32) * 200 * 10000,
    "fig3ab, figs5ab, figs5ef: 3 structures x 2 tasks at M = 1 (RFLO sets only)": 6 * one_set(1),
    "fig3cd: 3 structures x 2 tasks, M = 1 to 256": 6 * curve(M256),
    "fig3ef: 3 structures x 2 tasks x 5 complexities at M = 1": 30 * one_set(1),
    "figs3c: 5 complexities x 2 rho at M = 16": 10 * one_set(16),
    "figs4cd: 5 models x 2 tasks at M = 1": 10 * one_set(1),
    "figs4ab: 8 sets at M = 1": 8 * one_set(1),
    "figs4ef: 16 sets at M = 1": 16 * one_set(1),
    "figs5gh: 12 sets at M = 1 (without the N x N update)": 12 * one_set(1),
    "fig5b: 9 sets at M = 1": 9 * one_set(1),
    "figs5j: 48 sets at M = 1": 48 * one_set(1),
    "fig4ab, fig4ef: 2 ratios x 2 tasks at N = 512 (N up to 2,048 needed)": 4 * n512 * TRIALS * RUNS,
    "fig4cd: 6 rho x 2 ratios x 2 tasks at N = 512 (N = 2,048 needed)": 24 * n512 * TRIALS * RUNS,
}
print(f"\none set of 40 runs at M = 1: {one_set(1) / 3600:.2f} h on one core")
print(pd.DataFrame({"h on one core": [v / 3600 for v in est.values()],
                    "h on four cores": [v / 3600 / 4 for v in est.values()]},
                   index=list(est)).round(1).to_string())
print("notebook limit: 1 h, the rest of this notebook included")
M = 1: 4.7 ms per learning trial; errors of the last 3 trials [0.313 0.255 0.209]
M = 8: 6.1 ms per learning trial; errors of the last 3 trials [0.295 0.276 0.231]
M = 32: 8.9 ms per learning trial; errors of the last 3 trials [0.278 0.249 0.21 ]
M = 128: 22.5 ms per learning trial; errors of the last 3 trials [0.318 0.267 0.248]
M = 256: 49.8 ms per learning trial; errors of the last 3 trials [0.282 0.308 0.282]
N = 512, M = 1: 13.5 ms per learning trial

one set of 40 runs at M = 1: 0.52 h on one core
                                                                                            h on one core  h on four cores
fig1c, fig1d: one curve, M = 1 to 128                                                                 8.4              2.1
fig1cd, figs1d: two curves, M = 1 to 128 (before the rate search)                                    16.9              4.2
fig2d, figs2a, fig2e, figs2b: one meta-learning run, 10,000 epochs of 200 trials at M = 32            4.9              1.2
fig3ab, figs5ab, figs5ef: 3 structures x 2 tasks at M = 1 (RFLO sets only)                            3.1              0.8
fig3cd: 3 structures x 2 tasks, M = 1 to 256                                                         83.9             21.0
fig3ef: 3 structures x 2 tasks x 5 complexities at M = 1                                             15.5              3.9
figs3c: 5 complexities x 2 rho at M = 16                                                              8.3              2.1
figs4cd: 5 models x 2 tasks at M = 1                                                                  5.2              1.3
figs4ab: 8 sets at M = 1                                                                              4.1              1.0
figs4ef: 16 sets at M = 1                                                                             8.3              2.1
figs5gh: 12 sets at M = 1 (without the N x N update)                                                  6.2              1.6
fig5b: 9 sets at M = 1                                                                                4.7              1.2
figs5j: 48 sets at M = 1                                                                             24.8              6.2
fig4ab, fig4ef: 2 ratios x 2 tasks at N = 512 (N up to 2,048 needed)                                  6.0              1.5
fig4cd: 6 rho x 2 ratios x 2 tasks at N = 512 (N = 2,048 needed)                                     36.0              9.0
notebook limit: 1 h, the rest of this notebook included

Result: blocked, too large. In this run (the cell above) one learning trial of the paper's motor control model takes about 9 ms at M = 1 and between two and three times that at M = 128 (the fastest of three timings), so one set of 40 runs of 10,000 trials at M = 1 takes about 1 h on one core. Every simulation claim needs at least six such sets or their equivalent: fig3ab, the smallest, about 6 h on one core and 1.5 h on four; the curve of Figure 1 about 12 h on one core and 3 h on four; one meta-learning run of fig2d 7 to 8 h of forward simulation before any backpropagation, with 40 runs needed. The notebook limit is 1 h, the rest of the notebook included. The timings depend on the machine: the verifier's copy of the previous run gave 5.3 ms at M = 1 and 18.7 ms at M = 128, the round-1 run 9 to 10 ms and 24 to 27 ms. At the fastest of these, fig3ab would take 3.5 h on one core and 0.9 h on four, which with the 10 to 14 minutes of the rest of the notebook still exceeds 1 h; the runner's four cores are also shared with the agent. Every other estimate in the table is larger.

Summary¶

Claim Outcome
wm-sessions-link partially reproduced: mouse anm00264943, 151 ALM units in 5 sessions and 72 thalamic units in 6 other sessions; 11 sessions, not 5
fig6-wm-choice-r2 not reproduced: mean test R2 at most -0.247 under the claim seed with all trials per unit (U1); medians at most 0.340, U2 means at most 0.506 (0.97 expected)
fig6c-wm-leading-pcs-drive-choice partially reproduced: both readings hold under R2 (pooled), only (b) under R1 (per session); the leading PCs carry less of the readout than chance
figs6d-wm-thalamic-r2 not reproduced: mean test R2 -5.16 to -1.91 (0.70 expected)
fig6d-wm-top5-pcs not reproduced: no reading within 0.59 to 0.67
figs6f-ct-alignment-not-significant not reproduced: PC 1 alignment larger than readout alignment, one-sided p = 8.3e-06
Six motor-task claims blocked: data missing
23 simulation claims blocked: too large
figs5cd-thalamic-recurrence blocked: methods underspecified

A failure to reproduce here may be a failure of this attempt, not of the paper: see the reasoning and the differences from the paper's method.

How the analysis differs from the paper's. The smoothing grid, the 10 ms bin and the padding are standard choices the paper does not give. Sigma is chosen per thalamic unit on the validation R2 of each regression: the 16-PC regression for the PC regressions, the regression on all units for that one. The normalizations are applied to each unit's mean curve over splits and subsamples. The noise ceilings, the larger test sets and the chance levels of the alignments are diagnostics added on the verifier's request; none decides an outcome. P3 does not apply, as no session holds both ALM and thalamic units. The thalamic units are regressed on ALM activity from other sessions, as the paper's design implies; their test sets are their own sessions' trials.

What was found about the dataset. The paper's mouse is anm00264943, and its unit totals match the paper's exactly; the thalamic units come from six sessions, not the five the paper states. The files give no interval over which each unit was recorded, though many units fire in only part of their session. The electrode group location gives the same coordinates (AP 2.50, ML -1.50, DV 0.00) in all 137 files, thalamic and SNr recordings included, and the thalamic recordings name no nucleus. photo_stim_type is "stimulation" on every trial, including those without photostimulation; stim_present and photo_stim_period carry the distinction. No spike train or trial table is deposited twice, and choice decoding around delay onset is consistent with spikes and trials sharing a clock in all eleven sessions.

In [24]:
print(f"total time {(time.time() - started) / 60:.1f} min; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB")
total time 9.9 min; peak memory 0.97 GB