Reproducing Zhang, Gao, Cukur & Gallant (2021) from CRCNS vim-4¶
Paper: Zhang T, Gao JS, Cukur T, Gallant JL (2021). Voxel-Based State Space Modeling Recovers Task-Related Cognitive States in Naturalistic fMRI Experiments. Frontiers in Neuroscience 14:565976. doi:10.3389/fnins.2020.565976.
Claims: claims/zhang-2021.yaml, written from the version of record (PMC8145286) and its
supplement (Data_Sheet_1.DOCX), with the paper's code, gallantlab/state-space at commit 6ffb3c3.
Dataset: CRCNS vim-4, "Whole-brain BOLD activity recorded by fMRI during a visual attention task
and a video game task", doi:10.6080/K0668BDF, streamed from the public bucket
s3://crcnsarchive/vim-4/live/. Version: unversioned. CRCNS data sets have no versions; the
files read are those under vim-4/live/ as of 2026-11-14 (data description version 0.8 of
2026-04-06), which is the only published copy of the data files (vim-4/old/ holds only older
versions of the description). The paper cites the data set by its DOI, with no version. The MD5
sums of the files read, from the data set's checksums.md5, are:
| file | MD5 |
|---|---|
| VisualAttention/Data/deconv/S1.hdf | 5989fd2bc00fadf058eac9e7e742ad7d |
| VisualAttention/Data/deconv/S2.hdf | 94a06a22a634efb4370b3061b532744f |
| VisualAttention/Data/deconv/S3.hdf | 16758cb38128a43182c495660ac77eb6 |
| VisualAttention/Data/deconv/S5.hdf | 782fcf8c74b82812fb9fb8e7e106b285 |
| VisualAttention/Data/deconv/S6.hdf | 57fc3c680adac346ca41461e1a891592 |
| VisualAttention/Stimuli/states.hdf | 52e2cee2155281256192c2e9ded39383 |
| VisualAttention/Stimuli/semantics.hdf | 54143a9de19a34d647856693588dfc9d |
| VideoGame/Data/S1.npy | c0ea35bd959465d7e03cf5b369002640 |
| VideoGame/Data/S7.npy | 0ed00d89f585636b9091d56fc1a9ed81 |
| VideoGame/Stimuli/S1.hdf | d66b6a346ebfa13948b71da7a8d810a8 |
| VideoGame/Stimuli/S7.hdf | b5b5bb06946d4d6df1eb9c813d3f5825 |
The notebook prints the bucket's current sums for these files below, so a change can be seen.
The non-deconvolved attention BOLD (VisualAttention/Data/S*.hdf) is read for the encoding-model
threshold of att-weights-cortex, and the mappers (Mappers/S*.hdf) to place weights on fsaverage.
Outside inputs, for the two cortical claims only (the claims file allows an fsaverage atlas): visfAtlas (Rosenke et al. 2021, Cerebral Cortex 31:603, doi:10.1093/cercor/bhaa246), the zip its authors publish at download.brainvoyager.com/data/visfAtlas.zip, SHA-256 2eae192d...799d (checked on reading); and HCP-MMP1.0 projected on fsaverage, doi:10.6084/m9.figshare.3498446.v2 (MD5 sums checked on reading).
| claim | tested here |
|---|---|
| fig1-csi-s2 | tested |
| att-csi-group | tested (5 of 6 subjects; S4 is not released) |
| supp-csi-per-subject | tested (S4 left out, as the claim says) |
| att-passive-lower | tested (5 of 6 subjects) |
| att-classification | tested (5 of 6 subjects) |
| att-weights-cortex | tested with atlas regions in place of the paper's ROIs, which are not public |
| game-csi | tested |
| game-mutual-negative-projection | tested |
| fig3b-state-relations | tested |
| game-classification | tested |
| game-weights-two-groups | tested in S7 only, with atlas regions; S1's game data have no matching mapper |
Method: the helper statespace.py says where each parameter comes from. The state space is the
code's extract_state_space_positions, computed exactly in the space of the 24 principal
components (checked against the code itself below).
import time, resource
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import requests
import statespace as ss
pd.set_option("display.width", 200)
pd.set_option("display.max_columns", 30)
T0 = time.time()
def mem_gb():
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6
Data check¶
# Files in the data set and their current MD5 sums (checksums.md5 in the bucket)
listing = requests.get("https://crcnsarchive.s3-us-west-2.amazonaws.com/?list-type=2&prefix=vim-4/").text
import re
files = [(k, int(s)) for k, s in re.findall(r"<Key>(.*?)</Key>.*?<Size>(\d+)</Size>", listing) if not k.endswith("/")]
print(f"{len(files)} files under vim-4/")
for k, s in files:
print(f" {s/1e6:10.2f} MB {k}")
md5 = dict(l.split()[::-1] for l in requests.get(ss.BASE + "checksums.md5").text.strip().splitlines())
read_files = ["VisualAttention/Data/deconv/S%d.hdf" % i for i in (1, 2, 3, 5, 6)] + [
"VisualAttention/Stimuli/states.hdf", "VisualAttention/Stimuli/semantics.hdf",
"VideoGame/Data/S1.npy", "VideoGame/Data/S7.npy", "VideoGame/Stimuli/S1.hdf", "VideoGame/Stimuli/S7.hdf"]
for f in read_files:
print(md5[f], f)
39 files under vim-4/
3.34 MB vim-4/live/Mappers/S1.hdf
3.48 MB vim-4/live/Mappers/S2.hdf
3.26 MB vim-4/live/Mappers/S3.hdf
3.74 MB vim-4/live/Mappers/S4.hdf
3.20 MB vim-4/live/Mappers/S5.hdf
3.73 MB vim-4/live/Mappers/S6.hdf
3.95 MB vim-4/live/Mappers/S7.hdf
0.00 MB vim-4/live/Mappers/old/README.txt
3.37 MB vim-4/live/Mappers/old/S1.hdf
3.23 MB vim-4/live/Mappers/old/S5.hdf
3.77 MB vim-4/live/Mappers/old/S6.hdf
1148.07 MB vim-4/live/VideoGame/Data/S1.npy
459.36 MB vim-4/live/VideoGame/Data/S7.npy
0.02 MB vim-4/live/VideoGame/Stimuli/S1.hdf
0.05 MB vim-4/live/VideoGame/Stimuli/S7.hdf
1857.89 MB vim-4/live/VisualAttention/Data/S1.hdf
1757.49 MB vim-4/live/VisualAttention/Data/S2.hdf
1710.43 MB vim-4/live/VisualAttention/Data/S3.hdf
1873.59 MB vim-4/live/VisualAttention/Data/S5.hdf
1884.57 MB vim-4/live/VisualAttention/Data/S6.hdf
1114.73 MB vim-4/live/VisualAttention/Data/deconv/S1.hdf
1054.49 MB vim-4/live/VisualAttention/Data/deconv/S2.hdf
1026.26 MB vim-4/live/VisualAttention/Data/deconv/S3.hdf
1124.15 MB vim-4/live/VisualAttention/Data/deconv/S5.hdf
1130.74 MB vim-4/live/VisualAttention/Data/deconv/S6.hdf
33.66 MB vim-4/live/VisualAttention/Stimuli/semantics.hdf
0.07 MB vim-4/live/VisualAttention/Stimuli/states.hdf
2458.41 MB vim-4/live/VisualAttention/Stimuli/trn001.tar.gz
2481.92 MB vim-4/live/VisualAttention/Stimuli/trn002.tar.gz
2495.59 MB vim-4/live/VisualAttention/Stimuli/trn003.tar.gz
0.00 MB vim-4/live/checksums.md5
0.01 MB vim-4/live/docs/attention_categories.txt
0.02 MB vim-4/live/docs/crcns_vim-4_data_description.docx
0.07 MB vim-4/live/docs/crcns_vim-4_data_description.pdf
0.00 MB vim-4/live/filelist.txt
0.02 MB vim-4/old/docs/crcns_vim-4_data_description_v06.docx
0.07 MB vim-4/old/docs/crcns_vim-4_data_description_v06.pdf
0.02 MB vim-4/old/docs/crcns_vim-4_data_description_v07.docx
0.08 MB vim-4/old/docs/crcns_vim-4_data_description_v07.pdf
5989fd2bc00fadf058eac9e7e742ad7d VisualAttention/Data/deconv/S1.hdf
94a06a22a634efb4370b3061b532744f VisualAttention/Data/deconv/S2.hdf
16758cb38128a43182c495660ac77eb6 VisualAttention/Data/deconv/S3.hdf
782fcf8c74b82812fb9fb8e7e106b285 VisualAttention/Data/deconv/S5.hdf
57fc3c680adac346ca41461e1a891592 VisualAttention/Data/deconv/S6.hdf
52e2cee2155281256192c2e9ded39383 VisualAttention/Stimuli/states.hdf
54143a9de19a34d647856693588dfc9d VisualAttention/Stimuli/semantics.hdf
c0ea35bd959465d7e03cf5b369002640 VideoGame/Data/S1.npy
0ed00d89f585636b9091d56fc1a9ed81 VideoGame/Data/S7.npy
d66b6a346ebfa13948b71da7a8d810a8 VideoGame/Stimuli/S1.hdf
b5b5bb06946d4d6df1eb9c813d3f5825 VideoGame/Stimuli/S7.hdf
# Layout of every data file: datasets, shapes and dtypes (no data read)
for f in ["VisualAttention/Data/S%d.hdf" % i for i in (1, 2, 3, 5, 6)] + \
["VisualAttention/Data/deconv/S%d.hdf" % i for i in (1, 2, 3, 5, 6)] + \
["VisualAttention/Stimuli/states.hdf", "VisualAttention/Stimuli/semantics.hdf",
"VideoGame/Stimuli/S1.hdf", "VideoGame/Stimuli/S7.hdf"] + \
["Mappers/S%d.hdf" % i for i in range(1, 8)]:
for name, shape, dtype in ss.hdf_layout(f):
print(f"{f:42s} {name:28s} {str(shape):18s} {dtype}")
for s in ss.GAME_SUBJECTS:
print(f"VideoGame/Data/{s}.npy", ss.npy_layout(f"VideoGame/Data/{s}.npy"))
VisualAttention/Data/S1.hdf human (900, 51608) float32 VisualAttention/Data/S1.hdf passive (3600, 51608) float64 VisualAttention/Data/S1.hdf vehicle (900, 51608) float32 VisualAttention/Data/S2.hdf human (900, 48819) float32 VisualAttention/Data/S2.hdf passive (3600, 48819) float64 VisualAttention/Data/S2.hdf vehicle (900, 48819) float32
VisualAttention/Data/S3.hdf human (900, 47512) float32 VisualAttention/Data/S3.hdf passive (3600, 47512) float64 VisualAttention/Data/S3.hdf vehicle (900, 47512) float32 VisualAttention/Data/S5.hdf human (900, 52044) float32 VisualAttention/Data/S5.hdf passive (3600, 52044) float64 VisualAttention/Data/S5.hdf vehicle (900, 52044) float32
VisualAttention/Data/S6.hdf human (900, 52349) float32 VisualAttention/Data/S6.hdf passive (3600, 52349) float64 VisualAttention/Data/S6.hdf vehicle (900, 52349) float32 VisualAttention/Data/deconv/S1.hdf human (900, 51608) float64 VisualAttention/Data/deconv/S1.hdf passive (900, 51608) float64 VisualAttention/Data/deconv/S1.hdf vehicle (900, 51608) float64
VisualAttention/Data/deconv/S2.hdf human (900, 48819) float64 VisualAttention/Data/deconv/S2.hdf passive (900, 48819) float64 VisualAttention/Data/deconv/S2.hdf vehicle (900, 48819) float64 VisualAttention/Data/deconv/S3.hdf human (900, 47512) float64 VisualAttention/Data/deconv/S3.hdf passive (900, 47512) float64 VisualAttention/Data/deconv/S3.hdf vehicle (900, 47512) float64
VisualAttention/Data/deconv/S5.hdf human (900, 52044) float64 VisualAttention/Data/deconv/S5.hdf passive (900, 52044) float64 VisualAttention/Data/deconv/S5.hdf vehicle (900, 52044) float64 VisualAttention/Data/deconv/S6.hdf human (900, 52349) float64 VisualAttention/Data/deconv/S6.hdf passive (900, 52349) float64 VisualAttention/Data/deconv/S6.hdf vehicle (900, 52349) float64
VisualAttention/Stimuli/states.hdf human (900, 3) float64 VisualAttention/Stimuli/states.hdf passive (900, 3) float64 VisualAttention/Stimuli/states.hdf vehicle (900, 3) float64 VisualAttention/Stimuli/semantics.hdf attentive (900, 935) float64 VisualAttention/Stimuli/semantics.hdf passive (3600, 935) float64 VisualAttention/Stimuli/semantics.hdf passive_selection_indices (114, 2) int64
VideoGame/Stimuli/S1.hdf behavioural_state (1950, 9) bool VideoGame/Stimuli/S1.hdf state_labels (9,) |S20 VideoGame/Stimuli/S7.hdf behavioural_state (1320, 9) float32 VideoGame/Stimuli/S7.hdf state_labels (9,) |S20
Mappers/S1.hdf pixmap_data (1149053,) float64 Mappers/S1.hdf pixmap_indices (1149053,) int32 Mappers/S1.hdf pixmap_indptr (1155715,) int32 Mappers/S1.hdf pixmap_shape (2,) int64 Mappers/S1.hdf pixmask (1883, 1024) bool Mappers/S1.hdf vox_to_fsavg_left_data (162133,) float64 Mappers/S1.hdf vox_to_fsavg_left_indices (162133,) int32 Mappers/S1.hdf vox_to_fsavg_left_indptr (163843,) int32 Mappers/S1.hdf vox_to_fsavg_left_shape (2,) int64 Mappers/S1.hdf vox_to_fsavg_right_data (162350,) float64 Mappers/S1.hdf vox_to_fsavg_right_indices (162350,) int32 Mappers/S1.hdf vox_to_fsavg_right_indptr (163843,) int32 Mappers/S1.hdf vox_to_fsavg_right_shape (2,) int64
Mappers/S2.hdf pixmap_data (1194714,) float64 Mappers/S2.hdf pixmap_indices (1194714,) int32 Mappers/S2.hdf pixmap_indptr (1216516,) int32 Mappers/S2.hdf pixmap_shape (2,) int64 Mappers/S2.hdf pixmask (2060, 1024) bool Mappers/S2.hdf vox_to_fsavg_left_data (163765,) float64 Mappers/S2.hdf vox_to_fsavg_left_indices (163765,) int32 Mappers/S2.hdf vox_to_fsavg_left_indptr (163843,) int32 Mappers/S2.hdf vox_to_fsavg_left_shape (2,) int64 Mappers/S2.hdf vox_to_fsavg_right_data (163946,) float64 Mappers/S2.hdf vox_to_fsavg_right_indices (163946,) int32 Mappers/S2.hdf vox_to_fsavg_right_indptr (163843,) int32 Mappers/S2.hdf vox_to_fsavg_right_shape (2,) int64
Mappers/S3.hdf pixmap_data (1103689,) float64 Mappers/S3.hdf pixmap_indices (1103689,) int32 Mappers/S3.hdf pixmap_indptr (1118107,) int32 Mappers/S3.hdf pixmap_shape (2,) int64 Mappers/S3.hdf pixmask (1960, 1024) bool Mappers/S3.hdf vox_to_fsavg_left_data (161970,) float64 Mappers/S3.hdf vox_to_fsavg_left_indices (161970,) int32 Mappers/S3.hdf vox_to_fsavg_left_indptr (163843,) int32 Mappers/S3.hdf vox_to_fsavg_left_shape (2,) int64 Mappers/S3.hdf vox_to_fsavg_right_data (162187,) float64 Mappers/S3.hdf vox_to_fsavg_right_indices (162187,) int32 Mappers/S3.hdf vox_to_fsavg_right_indptr (163843,) int32 Mappers/S3.hdf vox_to_fsavg_right_shape (2,) int64
Mappers/S4.hdf pixmap_data (1433201,) float64 Mappers/S4.hdf pixmap_indices (1433201,) int32 Mappers/S4.hdf pixmap_indptr (1446878,) int32 Mappers/S4.hdf pixmap_shape (2,) int64 Mappers/S4.hdf pixmask (2268, 1024) bool Mappers/S4.hdf vox_to_fsavg_left_data (158530,) float64 Mappers/S4.hdf vox_to_fsavg_left_indices (158530,) int32 Mappers/S4.hdf vox_to_fsavg_left_indptr (163843,) int32 Mappers/S4.hdf vox_to_fsavg_left_shape (2,) int64 Mappers/S4.hdf vox_to_fsavg_right_data (158811,) float64 Mappers/S4.hdf vox_to_fsavg_right_indices (158811,) int32 Mappers/S4.hdf vox_to_fsavg_right_indptr (163843,) int32 Mappers/S4.hdf vox_to_fsavg_right_shape (2,) int64
Mappers/S5.hdf pixmap_data (1062702,) float64 Mappers/S5.hdf pixmap_indices (1062702,) int32 Mappers/S5.hdf pixmap_indptr (1069914,) int32 Mappers/S5.hdf pixmap_shape (2,) int64 Mappers/S5.hdf pixmask (1907, 1024) bool Mappers/S5.hdf vox_to_fsavg_left_data (160542,) float64 Mappers/S5.hdf vox_to_fsavg_left_indices (160542,) int32 Mappers/S5.hdf vox_to_fsavg_left_indptr (163843,) int32 Mappers/S5.hdf vox_to_fsavg_left_shape (2,) int64 Mappers/S5.hdf vox_to_fsavg_right_data (162351,) float64 Mappers/S5.hdf vox_to_fsavg_right_indices (162351,) int32 Mappers/S5.hdf vox_to_fsavg_right_indptr (163843,) int32 Mappers/S5.hdf vox_to_fsavg_right_shape (2,) int64
Mappers/S6.hdf pixmap_data (1345412,) float64 Mappers/S6.hdf pixmap_indices (1345412,) int32 Mappers/S6.hdf pixmap_indptr (1357327,) int32 Mappers/S6.hdf pixmap_shape (2,) int64 Mappers/S6.hdf pixmask (2279, 1024) bool Mappers/S6.hdf vox_to_fsavg_left_data (160720,) float64 Mappers/S6.hdf vox_to_fsavg_left_indices (160720,) int32 Mappers/S6.hdf vox_to_fsavg_left_indptr (163843,) int32 Mappers/S6.hdf vox_to_fsavg_left_shape (2,) int64 Mappers/S6.hdf vox_to_fsavg_right_data (161940,) float64 Mappers/S6.hdf vox_to_fsavg_right_indices (161940,) int32 Mappers/S6.hdf vox_to_fsavg_right_indptr (163843,) int32 Mappers/S6.hdf vox_to_fsavg_right_shape (2,) int64
Mappers/S7.hdf pixmap_data (1425974,) float64 Mappers/S7.hdf pixmap_indices (1425974,) int32 Mappers/S7.hdf pixmap_indptr (1442220,) int32 Mappers/S7.hdf pixmap_shape (2,) int64 Mappers/S7.hdf pixmask (2284, 1024) bool Mappers/S7.hdf vox_to_fsavg_left_data (165420,) float64 Mappers/S7.hdf vox_to_fsavg_left_indices (165420,) int32 Mappers/S7.hdf vox_to_fsavg_left_indptr (163843,) int32 Mappers/S7.hdf vox_to_fsavg_left_shape (2,) int64 Mappers/S7.hdf vox_to_fsavg_right_data (164706,) float64 Mappers/S7.hdf vox_to_fsavg_right_indices (164706,) int32 Mappers/S7.hdf vox_to_fsavg_right_indptr (163843,) int32 Mappers/S7.hdf vox_to_fsavg_right_shape (2,) int64
VideoGame/Data/S1.npy ((1950, 73594), 'float64') VideoGame/Data/S7.npy ((1320, 87000), 'float32')
# Attention task labels: states.hdf, and the semantic labels they should follow
st = ss.load_attention_states()
for c in ss.CONDITIONS:
v = st[c]
print(c, v.shape, "| human presence values", np.unique(v[:, 0]), "| vehicle", np.unique(v[:, 1]),
"| attention column values", np.unique(v[:, 2]),
"| presence counts (neither, humans, vehicles, both)", np.bincount(ss.presence_code(v), minlength=4))
print("presence columns identical across the three conditions:",
np.array_equal(st["human"][:, :2], st["vehicle"][:, :2]) and np.array_equal(st["human"][:, :2], st["passive"][:, :2]))
X_att = np.vstack([st[c] for c in ss.CONDITIONS])
pcode = ss.presence_code(X_att)
sem = ss.read_hdf("VisualAttention/Stimuli/semantics.hdf")
sel = sem["passive_selection_indices"]
print("passive_selection_indices: %d sections, %d s selected in total (900 TRs x 2 s = 1800 s), range %d to %d s"
% (len(sel), (sel[:, 1] - sel[:, 0]).sum(), sel.min(), sel.max()))
# The code's subsample_passive_data applied to the passive semantic labels should give the attentive labels
from scipy import signal
up = signal.resample(sem["passive"], 7200)
down = signal.resample(np.vstack([up[a:b] for a, b in sel]), 900)
print("correlation of the subsampled passive semantic labels with the attentive ones: %.3f"
% np.corrcoef(down.ravel(), sem["attentive"].ravel())[0, 1])
cats = requests.get(ss.BASE + "docs/attention_categories.txt").text.split()
pres = sem["attentive"] > 0
for col, name in [(0, "human"), (1, "vehicle")]:
y = st["human"][:, col]
r = np.array([np.corrcoef(pres[:, j], y)[0, 1] if pres[:, j].std() > 0 else 0 for j in range(pres.shape[1])])
top = np.argsort(r)[::-1][:3]
print(f"{name} presence: best matching semantic categories", [(cats[j], round(r[j], 2)) for j in top])
passive (900, 3) | human presence values [0. 1.] | vehicle [0. 1.] | attention column values [0.] | presence counts (neither, humans, vehicles, both) [146 258 166 330] human (900, 3) | human presence values [0. 1.] | vehicle [0. 1.] | attention column values [-1.] | presence counts (neither, humans, vehicles, both) [146 258 166 330] vehicle (900, 3) | human presence values [0. 1.] | vehicle [0. 1.] | attention column values [1.] | presence counts (neither, humans, vehicles, both) [146 258 166 330] presence columns identical across the three conditions: True
passive_selection_indices: 114 sections, 1800 s selected in total (900 TRs x 2 s = 1800 s), range 82 to 7168 s
correlation of the subsampled passive semantic labels with the attentive ones: 0.967
human presence: best matching semantic categories [('person.n.01', np.float64(0.88)), ('causal_agent.n.01', np.float64(0.88)), ('organism.n.01', np.float64(0.62))]
vehicle presence: best matching semantic categories [('vehicle.n.01', np.float64(1.0)), ('conveyance.n.03', np.float64(1.0)), ('instrumentality.n.03', np.float64(0.76))]
# Cortical regions on fsaverage, for att-weights-cortex and game-weights-two-groups. The paper's ROIs are
# not public; two public atlases on fsaverage are read into memory and checked against their published
# checksums (visfAtlas, Rosenke et al. 2021; HCP-MMP1.0, Glasser et al. 2016, on fsaverage), and mapped
# to each subject's voxels with the data set's own mappers. A region's mean of a voxel map is the mean
# over the region's fsaverage vertices that the mapper reaches (helper, region_matrix).
atlases = ss.load_atlases()
mappers = {s: ss.load_mapper(s) for s in ss.ATT_SUBJECTS + ["S7"]}
regmat, regvert = {}, {}
for s in ss.ATT_SUBJECTS:
regmat[s], regvert[s] = ss.region_matrix(mappers[s], atlases, ss.ATT_REGIONS)
regmat["game", "S7"], regvert["game", "S7"] = ss.region_matrix(mappers["S7"], atlases, ss.GAME_REGIONS)
print("fsaverage vertices per region (both hemispheres) in each atlas:",
{k: int(sum(np.isin(atlases[a][h], areas).sum() for h in ("lh", "rh"))) for k, (a, areas) in {**ss.ATT_REGIONS, **ss.GAME_REGIONS}.items()})
print("vertices per region that each subject's mapper reaches (attention regions):")
print(pd.DataFrame({s: regvert[s] for s in ss.ATT_SUBJECTS}, index=list(ss.ATT_REGIONS)).T.to_string())
print("S7, video game regions:", dict(zip(ss.GAME_REGIONS, regvert["game", "S7"])))
att_keep = {s: np.nonzero((regmat[s] != 0).any(1))[0] for s in ss.ATT_SUBJECTS}
game_keep = {"S7": np.nonzero((regmat["game", "S7"] != 0).any(1))[0]}
print("voxels the regions reach:", {s: len(v) for s, v in att_keep.items()}, "| S7 video game:", len(game_keep["S7"]))
fsaverage vertices per region (both hemispheres) in each atlas: {'FFA': 1975, 'OFA': 703, 'EBA': 4747, 'MT+': 900, 'PPA': 3029, 'OPA': 1196, 'RSC': 2142, 'LO': 1801, 'FO': 5600, 'IFS': 2622, 'IPS': 14832, 'FEF': 1682, 'SEF': 2014, 'LOS-bodies': 1233, 'ITG-bodies': 1809, 'MTG-bodies': 1705, 'OTS-bodies': 936, 'FFC (HCP)': 1670, 'PHA1-3 (HCP)': 3083, 'POS1 (HCP)': 2013, 'TPJ': 11146, 'precuneus': 7604, 'prefrontal': 57895, 'motor': 7870, 'premotor': 10840, 'SMA': 5071, 'medial prefrontal': 12185}
vertices per region that each subject's mapper reaches (attention regions):
FFA OFA EBA MT+ PPA OPA RSC LO FO IFS IPS FEF SEF LOS-bodies ITG-bodies MTG-bodies OTS-bodies FFC (HCP) PHA1-3 (HCP) POS1 (HCP)
S1 1975 703 4745 899 3016 1196 1633 1801 5596 2616 14789 1682 1990 1233 1808 1704 934 1670 3064 2007
S2 1962 703 4714 880 2879 1193 2066 1798 5541 2602 14496 1673 1958 1215 1807 1692 927 1665 2947 1990
S3 1975 703 4745 898 2989 1196 2079 1800 5550 2598 14672 1680 1960 1233 1808 1704 932 1670 3067 2006
S5 1975 701 4740 899 3020 1189 2026 1801 5565 2611 14708 1682 1963 1227 1809 1704 935 1670 3069 2009
S6 1962 703 4729 899 3008 1192 1670 1798 5586 2613 14632 1651 2011 1220 1807 1702 934 1660 3065 1997
S7, video game regions: {'TPJ': 11146, 'precuneus': 7604, 'prefrontal': 57676, 'motor': 7870, 'premotor': 10840, 'SMA': 5071, 'IPS': 14832, 'FEF': 1682, 'SEF': 2004, 'medial prefrontal': 12113}
voxels the regions reach: {'S1': 5965, 'S2': 5908, 'S3': 5982, 'S5': 5945, 'S6': 6065} | S7 video game: 16509
# Load each attention subject's deconvolved data (stacked passive, human, vehicle), keep the
# 2700 x 2700 Gram matrix, and run the paper's code itself on the full voxel data for comparison.
att = {}
for s in ss.ATT_SUBJECTS:
t = time.time()
d = ss.load_attention_gram(s, X_check=X_att, keep=att_keep[s])
G = d["G"]
# per-condition mean and SD of the voxels, from the Gram matrix diagonal blocks is not enough,
# so recompute from the summaries: sum of squares per TR
Z, _, ve = ss.pca_scores(G, np.arange(len(G)))
P = np.column_stack([X_att, np.ones(len(X_att))])
coef = np.linalg.pinv(P.T @ P) @ (P.T @ Z)
pos_rw = ss.att_positions(Z, X_att, "qr")
cp = d["code_positions"]
corr = [abs(np.corrcoef(pos_rw[:, j], cp[:, j])[0, 1]) for j in range(3)]
# same-frame TRs across conditions: correlation of their voxel patterns (duplicate check)
nrm = np.sqrt(np.diag(G))
same = {f"{a}-{b}": float(np.mean([G[i + 900 * ia, i + 900 * ib] / nrm[i + 900 * ia] / nrm[i + 900 * ib] for i in range(900)]))
for ia, a in enumerate(ss.CONDITIONS) for ib, b in enumerate(ss.CONDITIONS) if ia < ib}
att[s] = dict(G=G, Z=Z, code_pos=cp, ve=ve, n_vox=d["n_vox"], Y_keep=d["Y_keep"])
print(f"{s}: {d['n_vox']} voxels ({d['n_zero_vox']} constant, {d['n_nan']} NaN), voxel means {d['vox_mean_range'][0]:.3f} to "
f"{d['vox_mean_range'][1]:.3f}, SDs {d['vox_sd_range'][0]:.3f} to {d['vox_sd_range'][1]:.3f}; "
f"24 PCs explain {ve:.1%}; |weights| in PC space human {np.linalg.norm(coef[0]):.3g}, vehicle "
f"{np.linalg.norm(coef[1]):.3g}, attention {np.linalg.norm(coef[2]):.3g}; the code's own OLS coefficients in voxel space, norm per row "
f"(human, vehicle, attention, intercept) {np.array2string(d['code_coef_norm'], precision=3)}; |r| rewrite vs code per axis "
f"{np.round(corr, 4)}; mean r of same-frame TRs {same}; {time.time()-t:.0f} s, peak memory {mem_gb():.1f} GB")
nv = [att[s]["n_vox"] for s in att]
print(f"voxels per subject: mean {np.mean(nv):.0f}, SD {np.std(nv, ddof=1):.0f} over {len(nv)} subjects (paper: 48,673 +/- 4,382 over six)")
S1: 51608 voxels (14 constant, 0 NaN), voxel means -0.284 to 0.291, SDs 0.405 to 1.213; 24 PCs explain 84.1%; |weights| in PC space human 117, vehicle 106, attention 9.06e-15; the code's own OLS coefficients in voxel space, norm per row (human, vehicle, attention, intercept) [1.177e+02 1.063e+02 9.710e-14 8.956e+01]; |r| rewrite vs code per axis [1. 1. 0.3407]; mean r of same-frame TRs {'passive-human': 0.11415670411988853, 'passive-vehicle': 0.11058380055559039, 'human-vehicle': 0.23843833730092892}; 26 s, peak memory 3.3 GB
S2: 48819 voxels (0 constant, 0 NaN), voxel means -0.301 to 0.306, SDs 0.894 to 1.203; 24 PCs explain 89.7%; |weights| in PC space human 121, vehicle 123, attention 7.35e-15; the code's own OLS coefficients in voxel space, norm per row (human, vehicle, attention, intercept) [1.211e+02 1.236e+02 1.260e-13 9.676e+01]; |r| rewrite vs code per axis [1. 1. 0.3457]; mean r of same-frame TRs {'passive-human': 0.09946298979776794, 'passive-vehicle': 0.07050453268014109, 'human-vehicle': 0.2569188841368312}; 25 s, peak memory 3.3 GB
S3: 47512 voxels (0 constant, 0 NaN), voxel means -0.086 to 0.095, SDs 0.816 to 1.119; 24 PCs explain 68.4%; |weights| in PC space human 93.7, vehicle 102, attention 8.43e-15; the code's own OLS coefficients in voxel space, norm per row (human, vehicle, attention, intercept) [9.440e+01 1.029e+02 1.437e-13 9.746e+01]; |r| rewrite vs code per axis [1.e+00 1.e+00 2.e-04]; mean r of same-frame TRs {'passive-human': 0.0072509360900333145, 'passive-vehicle': 0.005253922148821593, 'human-vehicle': 0.29216465972261224}; 25 s, peak memory 3.3 GB
S5: 52044 voxels (4 constant, 0 NaN), voxel means -0.280 to 0.291, SDs 0.425 to 1.198; 24 PCs explain 89.1%; |weights| in PC space human 114, vehicle 111, attention 1.18e-14; the code's own OLS coefficients in voxel space, norm per row (human, vehicle, attention, intercept) [1.139e+02 1.115e+02 1.224e-13 9.529e+01]; |r| rewrite vs code per axis [1. 1. 0.074]; mean r of same-frame TRs {'passive-human': 0.050547393407544314, 'passive-vehicle': 0.07425463953364086, 'human-vehicle': 0.19561385310929433}; 42 s, peak memory 3.6 GB
S6: 52349 voxels (0 constant, 0 NaN), voxel means -0.294 to 0.304, SDs 0.475 to 1.203; 24 PCs explain 85.3%; |weights| in PC space human 117, vehicle 114, attention 7.71e-15; the code's own OLS coefficients in voxel space, norm per row (human, vehicle, attention, intercept) [1.170e+02 1.142e+02 1.132e-13 1.092e+02]; |r| rewrite vs code per axis [1. 1. 0.4022]; mean r of same-frame TRs {'passive-human': 0.1106510302784783, 'passive-vehicle': 0.08418480006985153, 'human-vehicle': 0.18299585135107932}; 25 s, peak memory 3.8 GB
voxels per subject: mean 50466, SD 2167 over 5 subjects (paper: 48,673 +/- 4,382 over six)
# Per-condition means of the voxels: the attentive conditions are z-scored per voxel within the condition,
# so the attention variable (-1 human, 0 passive, +1 vehicle) carries no mean difference between them.
for s in ss.ATT_SUBJECTS:
G = att[s]["G"]
# the mean over voxels of each TR's squared norm, per condition, and the norm of each condition's mean pattern
msq = [np.mean(np.diag(G)[sl]) for sl in ss.cond_slices()]
mean_norm = [np.sqrt(max(G[sl, sl].sum(), 0.0)) / 900 for sl in ss.cond_slices()] # rounding can make a zero sum slightly negative
print(f"{s}: mean squared norm per TR {np.round(msq, 0)}; norm of each condition's mean pattern "
f"(passive, human, vehicle) {np.round(mean_norm, 4)}")
S1: mean squared norm per TR [53707. 51245. 51238.]; norm of each condition's mean pattern (passive, human, vehicle) [72.0703 0. 0. ] S2: mean squared norm per TR [53793. 48819. 48819.]; norm of each condition's mean pattern (passive, human, vehicle) [80.2321 0. 0. ] S3: mean squared norm per TR [64109. 47512. 47512.]; norm of each condition's mean pattern (passive, human, vehicle) [15.7897 0. 0. ] S5: mean squared norm per TR [51529. 51911. 51928.]; norm of each condition's mean pattern (passive, human, vehicle) [71.907 0. 0. ] S6: mean squared norm per TR [52209. 52339. 52343.]; norm of each condition's mean pattern (passive, human, vehicle) [72.9403 0. 0. ]
# Clock check for the attention task: CSI of the presence clusters when the presence labels are
# shifted in time within each condition (refitted at each lag). Deconvolved data should peak at lag 0.
lags = [-6, -3, -2, -1, 0, 1, 2, 3, 6, 20]
rng = np.random.default_rng(100)
rows = []
for s in ss.ATT_SUBJECTS:
Z = att[s]["Z"]
for lag in lags:
Xs = X_att.copy()
for sl in ss.cond_slices():
Xs[sl, :2] = np.roll(X_att[sl, :2], lag, axis=0)
pos = ss.att_positions(Z, Xs, "2d")
rows.append(dict(subject=s, lag=lag, csi=ss.att_csis(pos, ss.presence_code(Xs), rng).mean()))
shift = pd.DataFrame(rows).pivot(index="subject", columns="lag", values="csi")
print("mean CSI over conditions, human-vehicle plane, by label lag in TRs (positive: labels moved later)")
print(shift.round(3))
print("lag of the peak per subject:", shift.idxmax(axis=1).to_dict())
mean CSI over conditions, human-vehicle plane, by label lag in TRs (positive: labels moved later)
lag -6 -3 -2 -1 0 1 2 3 6 20
subject
S1 0.028 0.053 0.092 0.268 0.605 0.289 0.100 0.050 0.029 0.018
S2 0.026 0.044 0.093 0.275 0.655 0.288 0.092 0.043 0.027 0.012
S3 0.027 0.041 0.076 0.201 0.451 0.188 0.065 0.037 0.030 0.014
S5 0.028 0.048 0.089 0.260 0.619 0.264 0.093 0.048 0.030 0.012
S6 0.030 0.044 0.083 0.258 0.623 0.271 0.094 0.046 0.036 0.013
lag of the peak per subject: {'S1': 0, 'S2': 0, 'S3': 0, 'S5': 0, 'S6': 0}
# Video game data. Each voxel is z-scored over the session, as the paper's Methods say (helper, load_game);
# the voxel means and SDs printed are those of the data as stored.
game = {}
for s in ss.GAME_SUBJECTS:
t = time.time()
g = ss.load_game(s, keep=game_keep.get(s))
G = g["G"]
Z, _, ve = ss.pca_scores(G, np.arange(len(G)))
g["Z"], g["ve"] = Z, ve
game[s] = g
X = g["X"]
nst = X.sum(1).astype(int)
print(f"{s}: {X.shape[0]} TRs ({X.shape[0]*2.0045/60:.1f} min at TR 2.0045 s), {g['n_vox']} voxels "
f"({g['n_zero_vox']} constant, {g['n_nan']} NaN), voxel means {g['vox_mean_range'][0]:.3f} to {g['vox_mean_range'][1]:.3f}, "
f"SDs {g['vox_sd_range'][0]:.3f} to {g['vox_sd_range'][1]:.3f}; 24 PCs explain {ve:.1%}; {time.time()-t:.0f} s")
print(" state labels (dataset order):", g["labels"])
print(" TRs per state:", dict(zip(g["labels"], X.sum(0).astype(int))))
print(" TRs with 0, 1, 2, 3 states:", np.bincount(nst, minlength=4))
print(" TRs with exactly one state, per state:", dict(zip(g["labels"], X[nst == 1].sum(0).astype(int))))
print(" safe explore and engage close together in", int(((X[:, g['labels'].index('safe explore')] > 0) & (X[:, g['labels'].index('engage close')] > 0)).sum()), "TRs")
mapper_vox = {f"S{i}": ss.read_hdf(f"Mappers/S{i}.hdf", ["vox_to_fsavg_left_shape"])["vox_to_fsavg_left_shape"][1] for i in range(1, 8)}
print("voxels per mapper:", mapper_vox)
old_vox = {f"old/S{i}": ss.read_hdf(f"Mappers/old/S{i}.hdf", ["vox_to_fsavg_left_shape"])["vox_to_fsavg_left_shape"][1] for i in (1, 5, 6)}
print("voxels per superseded mapper (Mappers/old, see its README):", old_vox)
print("game voxels:", {s: game[s]["n_vox"] for s in ss.GAME_SUBJECTS}, "| attention voxels (deconv files):",
{s: att[s]["n_vox"] for s in att})
print(f"elapsed {time.time()-T0:.0f} s, peak memory {mem_gb():.1f} GB")
S1: 1950 TRs (65.1 min at TR 2.0045 s), 73594 voxels (0 constant, 0 NaN), voxel means -0.000 to 0.000, SDs 1.000 to 1.000; 24 PCs explain 32.2%; 23 s
state labels (dataset order): ['flash', 'engage close', 'engage far', 'safe explore', 'unsafe explore', 'run away', 'dead', 'round start', 'kill']
TRs per state: {'flash': np.int64(9), 'engage close': np.int64(72), 'engage far': np.int64(183), 'safe explore': np.int64(488), 'unsafe explore': np.int64(812), 'run away': np.int64(53), 'dead': np.int64(141), 'round start': np.int64(208), 'kill': np.int64(64)}
TRs with 0, 1, 2, 3 states: [ 20 1830 100 0]
TRs with exactly one state, per state: {'flash': np.int64(1), 'engage close': np.int64(58), 'engage far': np.int64(142), 'safe explore': np.int64(477), 'unsafe explore': np.int64(762), 'run away': np.int64(41), 'dead': np.int64(141), 'round start': np.int64(208), 'kill': np.int64(0)}
safe explore and engage close together in 0 TRs
S7: 1320 TRs (44.1 min at TR 2.0045 s), 87000 voxels (0 constant, 0 NaN), voxel means -0.059 to 0.025, SDs 0.094 to 1.009; 24 PCs explain 39.7%; 12 s
state labels (dataset order): ['flash', 'engage close', 'engage far', 'safe explore', 'unsafe explore', 'run away', 'dead', 'round start', 'kill']
TRs per state: {'flash': np.int64(0), 'engage close': np.int64(160), 'engage far': np.int64(199), 'safe explore': np.int64(265), 'unsafe explore': np.int64(414), 'run away': np.int64(16), 'dead': np.int64(75), 'round start': np.int64(176), 'kill': np.int64(119)}
TRs with 0, 1, 2, 3 states: [198 854 234 34]
TRs with exactly one state, per state: {'flash': np.int64(0), 'engage close': np.int64(53), 'engage far': np.int64(122), 'safe explore': np.int64(203), 'unsafe explore': np.int64(305), 'run away': np.int64(4), 'dead': np.int64(42), 'round start': np.int64(123), 'kill': np.int64(2)}
safe explore and engage close together in 2 TRs
voxels per mapper: {'S1': np.int64(51608), 'S2': np.int64(48819), 'S3': np.int64(47512), 'S4': np.int64(39708), 'S5': np.int64(52044), 'S6': np.int64(52349), 'S7': np.int64(87000)}
voxels per superseded mapper (Mappers/old, see its README): {'old/S1': np.int64(81137), 'old/S5': np.int64(84038), 'old/S6': np.int64(86842)}
game voxels: {'S1': 73594, 'S7': 87000} | attention voxels (deconv files): {'S1': 51608, 'S2': 48819, 'S3': 47512, 'S5': 52044, 'S6': 52349}
elapsed 218 s, peak memory 4.1 GB
# Run structure of the video game data: the correlation of consecutive TRs' voxel patterns, whose
# lowest values mark where runs were joined (asked by the verifier, to see whether S1's 65 min are part
# of a 90-min session). The paper's runs are 325 volumes with 10 discarded at each end (305 TRs).
for s in ss.GAME_SUBJECTS:
G = game[s]["G"]
nrm = np.sqrt(np.diag(G))
c = np.array([G[t, t + 1] / nrm[t] / nrm[t + 1] for t in range(len(G) - 1)])
low = np.sort(np.argsort(c)[:8]) + 1
print(f"{s}: {len(G)} TRs; consecutive-TR correlation median {np.median(c):.3f}, 1st percentile {np.percentile(c, 1):.3f}; "
f"the 8 lowest at the start of TRs {low.tolist()} (values {np.round(c[low - 1], 3).tolist()}); "
f"gaps between them {np.diff(np.concatenate([[0], low, [len(G)]])).tolist()}")
S1: 1950 TRs; consecutive-TR correlation median 0.318, 1st percentile 0.079; the 8 lowest at the start of TRs [172, 325, 650, 869, 975, 1300, 1625, 1739] (values [-0.027, -0.462, -0.469, 0.007, -0.477, -0.467, -0.441, 0.005]); gaps between them [172, 153, 325, 219, 106, 325, 325, 114, 211] S7: 1320 TRs; consecutive-TR correlation median 0.377, 1st percentile 0.097; the 8 lowest at the start of TRs [30, 31, 66, 237, 243, 440, 880, 1036] (values [0.051, -0.178, 0.004, 0.037, 0.057, -0.082, -0.027, 0.034]); gaps between them [30, 1, 35, 171, 6, 197, 440, 156, 284]
# Clock check for the video game: CSI (one cluster per state) with the state matrix shifted in time
rng = np.random.default_rng(101)
rows = []
for s in ss.GAME_SUBJECTS:
X, names = ss.game_matrix(game[s]["X"], game[s]["labels"], "dataset")
for lag in [-10, -4, -2, -1, 0, 1, 2, 3, 4, 6, 10]:
Xs = np.roll(X, lag, axis=0)
mem, _, _ = ss.game_members(Xs, names, "a")
rows.append(dict(subject=s, lag=lag, csi=ss.csi(ss.positions(game[s]["Z"], Xs), mem, rng)))
gshift = pd.DataFrame(rows).pivot(index="subject", columns="lag", values="csi")
print(gshift.round(3))
print("lag of the peak per subject:", gshift.idxmax(axis=1).to_dict())
lag -10 -4 -2 -1 0 1 2 3 4 6 10
subject
S1 0.514 0.538 0.569 0.629 0.691 0.729 0.687 0.606 0.60 0.59 0.518
S7 0.454 0.464 0.500 0.510 0.550 0.566 0.553 0.558 0.53 0.53 0.537
lag of the peak per subject: {'S1': 1, 'S7': 1}
Checks of the description against the data, from the outputs above:
- The deconvolved attention files hold 900 TRs per condition for S1, S2, S3, S5 and S6 (30 min each at a 2 s TR, three 10-min runs as the paper says); S4 is absent, as the description says. The passive deconvolved data are already subsampled to the 900 TRs of the attentive movies. The selection indices cover 1800 s, and applying the code's subsampling to the passive semantic labels reproduces the attentive labels (correlation printed above), which is consistent with the passive data and labels sharing the attentive clock.
states.hdfhas the same presence labels in all three conditions; the third column codes the condition as -1 (attend humans), 0 (passive) and +1 (attend vehicles). The description does not give this coding. The vehicle column follows the semantic categoryvehicle.n.01exactly, and the human column followsperson.n.01closely.- The attentive conditions are z-scored per voxel within each condition (voxel means of zero, so the norm of each attentive condition's mean pattern is zero), while the passive TRs, subsampled after z-scoring, are not. With the attention variable coded -1, 0, +1 and an intercept, its OLS weight is the difference of the two attentive means, which is zero: the printed attention weight is at the level of rounding (1e-13), so the third axis of the state space is set by rounding noise. This is analysed in each attention claim below.
- The PC-space rewrite gives the code's human and vehicle axes exactly (|r| = 1.0000); its third axis differs, being noise in both. 24 PCs explain 68 to 90% of the variance here, against about 70% in the paper. The code's own OLS coefficients in voxel space give the same picture: the norm of the attention row is about 1e-13, against about 1e2 for the human and vehicle rows, so the code's third axis is set by rounding too. The R3 values below can therefore move slightly between runs on different machines (S2 attend-humans 0.740 in the first run, 0.739 in this one); two runs of this revision on the same machine gave identical values.
- Labels and BOLD share a clock as far as shifted labels show: the attention CSI peaks at lag 0, as deconvolved data should. The game CSI peaks at lag +1 TR in both subjects (S1 0.729 against 0.691 at lag 0; S7 0.566 against 0.550), as a hemodynamic delay in data that are not deconvolved would give. The paper does not say whether the game labels were shifted; lag 0 is used, and the game CSI and classification are also shown at lag +1. This is consistent with, not proof of, aligned labels.
- Video game: S7 has 1320 TRs (44 min, the paper's 45 min). S1 has 1950 TRs, 65 min, where the
paper says one subject played 90 min in six 15-min runs. The correlation of consecutive TRs
drops to -0.44 to -0.48 exactly at TRs 325, 650, 975, 1300 and 1625, so S1's data are six
blocks of 325 TRs (10.9 min each), as six runs of the 325-volume length the paper gives for its
acquisitions would be. The deposited S1 data are therefore six whole runs, consistent with the
paper's six runs but not with its 15 minutes per run. In S7 the dips at TRs 440 and 880 are
weaker (-0.08 and -0.03), consistent with three runs of 440 TRs (14.7 min). The S7 data are float32 and not z-scored
per voxel over the session (voxel SDs 0.094 to 1.009); S1's are. The paper says the responses
were normalized to zero mean and unit variance (Methods, Preprocessing and Visualization), so
both subjects' data are z-scored per voxel over the session here; S7 as stored is shown as a
variant after game-weights-two-groups. No flash TRs in S7, as the paper says. The S1
game data have 73,594 voxels, which matches no mapper (S1's mapper has 51,608, as the S1
attention data), nor any of the superseded mappers in
Mappers/old(S1 81,137, S5 84,038, S6 86,842), so S1's game weights cannot be put on fsaverage with the files given. S7's data match S7's mapper. The game state columns are not in the order of Table 1. - No recording is deposited twice: same-frame TRs of different conditions are only weakly correlated (printed above), and the subjects' voxel counts all differ.
Attention task: CSI per subject and condition¶
Shared by fig1-csi-s2, att-csi-group and supp-csi-per-subject. The CSI of the four presence clusters within each condition, in the state space fitted once on the three conditions stacked. Because the third axis is undefined in these data, three readings are computed:
- R3, "code": the paper's code run as written on the full voxel data (its third axis is whatever rounding gives on this machine);
- R2, "random third axis": the median over 100 random third axes, orthogonal to the human and vehicle axes in the space of the 24 PCs (the distribution of what an arbitrary third axis gives);
- R1, "2D": the human-vehicle plane alone.
CSI values are means over 10 Monte Carlo seeds. The null refits the state space with permuted presence labels, 1000 times per reading of the claims file: (a) the (human, vehicle) rows shuffled over all TRs, and (b) circularly shifted by a random lag within each condition. Each null draw uses a random third axis (for R3 and R2) or the plane (for R1) and one Monte Carlo seed.
N_PERM = 1000
rng = np.random.default_rng(1)
csi_obs, csi_null, csi_seedsd = {}, {}, {}
for s in ss.ATT_SUBJECTS:
t = time.time()
Z = att[s]["Z"]
r3 = np.array([ss.att_csis(att[s]["code_pos"], pcode, np.random.default_rng(k)) for k in range(10)])
r1 = np.array([ss.att_csis(ss.att_positions(Z, X_att, "2d"), pcode, np.random.default_rng(k)) for k in range(10)])
r2 = np.array([ss.att_csis(ss.att_positions(Z, X_att, "random", rng), pcode, rng) for _ in range(100)])
csi_obs[s] = {"R3": r3.mean(0), "R2": np.median(r2, 0), "R1": r1.mean(0),
"R2_lo": np.percentile(r2, 5, axis=0), "R2_hi": np.percentile(r2, 95, axis=0)}
csi_seedsd[s] = {"R3": r3.std(0), "R1": r1.std(0)}
for reading in "ab":
n3, n2 = [], []
for _ in range(N_PERM):
Xp = ss.shuffle_presence(X_att, reading, rng)
pc_p = ss.presence_code(Xp)
n3.append(ss.att_csis(ss.att_positions(Z, Xp, "random", rng), pc_p, rng))
n2.append(ss.att_csis(ss.att_positions(Z, Xp, "2d"), pc_p, rng))
csi_null[s, reading, "3d"] = np.array(n3)
csi_null[s, reading, "2d"] = np.array(n2)
print(f"{s} done in {time.time()-t:.0f} s")
def pval(obs, null):
return (1 + (null >= obs).sum(0)) / (len(null) + 1)
rows = []
for s in ss.ATT_SUBJECTS:
for ci, c in enumerate(ss.CONDITIONS):
row = dict(subject=s, condition=c, R3_code=csi_obs[s]["R3"][ci], R3_seed_sd=csi_seedsd[s]["R3"][ci],
R2_median=csi_obs[s]["R2"][ci], R2_5pct=csi_obs[s]["R2_lo"][ci], R2_95pct=csi_obs[s]["R2_hi"][ci],
R1_2d=csi_obs[s]["R1"][ci])
for reading in "ab":
row[f"null3d_max_{reading}"] = csi_null[s, reading, "3d"][:, ci].max()
row[f"null2d_max_{reading}"] = csi_null[s, reading, "2d"][:, ci].max()
rows.append(row)
csi_table = pd.DataFrame(rows)
print(csi_table.round(3).to_string())
print(f"null p-values are at most 1/{N_PERM+1} = {1/(N_PERM+1):.4f} when the observed CSI exceeds every null value")
print(f"elapsed {time.time()-T0:.0f} s, peak memory {mem_gb():.1f} GB")
S1 done in 59 s
S2 done in 59 s
S3 done in 59 s
S5 done in 59 s
S6 done in 59 s subject condition R3_code R3_seed_sd R2_median R2_5pct R2_95pct R1_2d null3d_max_a null2d_max_a null3d_max_b null2d_max_b 0 S1 passive 0.620 0.006 0.638 0.616 0.658 0.609 0.055 0.035 0.334 0.315 1 S1 human 0.515 0.007 0.543 0.503 0.609 0.483 0.045 0.037 0.336 0.297 2 S1 vehicle 0.744 0.008 0.762 0.730 0.790 0.716 0.053 0.041 0.088 0.067 3 S2 passive 0.675 0.005 0.657 0.638 0.681 0.632 0.062 0.042 0.352 0.332 4 S2 human 0.743 0.004 0.723 0.683 0.784 0.664 0.040 0.030 0.322 0.283 5 S2 vehicle 0.721 0.004 0.718 0.684 0.779 0.668 0.056 0.036 0.326 0.303 6 S3 passive 0.061 0.003 0.059 0.042 0.082 0.028 0.065 0.047 0.099 0.063 7 S3 human 0.696 0.006 0.703 0.669 0.761 0.647 0.048 0.033 0.339 0.301 8 S3 vehicle 0.761 0.004 0.728 0.699 0.807 0.674 0.043 0.033 0.303 0.272 9 S5 passive 0.614 0.006 0.622 0.602 0.657 0.592 0.094 0.045 0.347 0.284 10 S5 human 0.767 0.005 0.694 0.661 0.775 0.640 0.042 0.031 0.126 0.090 11 S5 vehicle 0.730 0.004 0.698 0.646 0.753 0.626 0.096 0.082 0.340 0.292 12 S6 passive 0.651 0.005 0.637 0.605 0.672 0.599 0.066 0.050 0.297 0.269 13 S6 human 0.605 0.007 0.627 0.595 0.687 0.575 0.048 0.033 0.292 0.265 14 S6 vehicle 0.699 0.004 0.735 0.709 0.796 0.689 0.046 0.033 0.321 0.283 null p-values are at most 1/1001 = 0.0010 when the observed CSI exceeds every null value elapsed 512 s, peak memory 4.1 GB
fig1-csi-s2¶
In subject S2 the four presence states (neither, humans only, vehicles only, both) are significantly separated in the attention-task state space, with a cluster separation index of 0.75 for attend-humans, 0.69 for attend-vehicles and 0.67 for passive viewing.
exp = {"human": (0.75, 0.075), "vehicle": (0.69, 0.069), "passive": (0.67, 0.067)}
t = csi_table[csi_table.subject == "S2"].set_index("condition")
for reading in ["R3_code", "R2_median", "R1_2d"]:
null = "null2d" if reading == "R1_2d" else "null3d"
for c in ["human", "vehicle", "passive"]:
v = t.loc[c, reading]; e, tol = exp[c]
print(f"{reading:9s} {c:8s} CSI {v:.3f} (expected {e} +/- {tol}; within: {abs(v-e) <= tol}); "
f"above every null value: (a) {v > t.loc[c, null + '_max_a']} (max {t.loc[c, null + '_max_a']:.3f}), "
f"(b) {v > t.loc[c, null + '_max_b']} (max {t.loc[c, null + '_max_b']:.3f})")
ok = all(abs(t.loc[c, reading] - exp[c][0]) <= exp[c][1] for c in exp)
print(f" -> {reading}: all three within tolerance: {ok}")
print("R2 5 to 95% range over random third axes:", {c: (round(t.loc[c, 'R2_5pct'], 3), round(t.loc[c, 'R2_95pct'], 3)) for c in exp})
R3_code human CSI 0.743 (expected 0.75 +/- 0.075; within: True); above every null value: (a) True (max 0.040), (b) True (max 0.322)
R3_code vehicle CSI 0.721 (expected 0.69 +/- 0.069; within: True); above every null value: (a) True (max 0.056), (b) True (max 0.326)
R3_code passive CSI 0.675 (expected 0.67 +/- 0.067; within: True); above every null value: (a) True (max 0.062), (b) True (max 0.352)
-> R3_code: all three within tolerance: True
R2_median human CSI 0.723 (expected 0.75 +/- 0.075; within: True); above every null value: (a) True (max 0.040), (b) True (max 0.322)
R2_median vehicle CSI 0.718 (expected 0.69 +/- 0.069; within: True); above every null value: (a) True (max 0.056), (b) True (max 0.326)
R2_median passive CSI 0.657 (expected 0.67 +/- 0.067; within: True); above every null value: (a) True (max 0.062), (b) True (max 0.352)
-> R2_median: all three within tolerance: True
R1_2d human CSI 0.664 (expected 0.75 +/- 0.075; within: False); above every null value: (a) True (max 0.030), (b) True (max 0.283)
R1_2d vehicle CSI 0.668 (expected 0.69 +/- 0.069; within: True); above every null value: (a) True (max 0.036), (b) True (max 0.303)
R1_2d passive CSI 0.632 (expected 0.67 +/- 0.067; within: True); above every null value: (a) True (max 0.042), (b) True (max 0.332)
-> R1_2d: all three within tolerance: False
R2 5 to 95% range over random third axes: {'human': (np.float64(0.683), np.float64(0.784)), 'vehicle': (np.float64(0.684), np.float64(0.779)), 'passive': (np.float64(0.638), np.float64(0.681))}
fig, axes = plt.subplots(1, 3, figsize=(12, 4))
cols = ["#ff5100", "#0084ff", "#91d90d", "#a200ff"]
pos = att["S2"]["code_pos"]
out = 0
for ax, (ci, c) in zip(axes, enumerate(ss.CONDITIONS)):
sl = ss.cond_slices()[ci]
p, k = pos[sl], pcode[sl]
sx = 1 if p[k == 3, 0].mean() > p[k == 0, 0].mean() else -1 # the code's sign rule
sy = 1 if p[k == 3, 1].mean() > p[k == 0, 1].mean() else -1
for j in range(4):
ax.scatter(sx * p[k == j, 0], sy * p[k == j, 1], s=4, alpha=0.4, c=cols[j], label=ss.PRESENCE_NAMES[j])
ax.scatter(sx * p[k == j, 0].mean(), sy * p[k == j, 1].mean(), marker="+", s=300, c="k")
out += int((np.abs(p[:, :2]) > 4).any(1).sum())
ax.set(xlim=(-4, 4), ylim=(-4, 4), title=f"S2 {c}", xlabel="human presence", ylabel="vehicle presence")
axes[0].legend(markerscale=3, fontsize=7)
plt.tight_layout(); plt.show()
print(f"positions range {pos[:, :2].min():.2f} to {pos[:, :2].max():.2f}; {out} TRs outside the axes")
positions range -3.24 to 3.07; 0 TRs outside the axes
Result: reproduced, resting on an assumption about the third axis. With the paper's code (R3) the S2 CSIs are 0.739 (attend-humans), 0.717 (attend-vehicles) and 0.676 (passive), all within tolerance of 0.75, 0.69 and 0.67, and each exceeds every one of 1000 null values under both permutation readings (null maxima 0.040 to 0.062 under (a), 0.322 to 0.352 under (b); p <= 0.001, the bound 1000 permutations reach, not the paper's 1e-5). The median over random third axes (R2) also matches (0.723, 0.718, 0.657). In the human-vehicle plane alone (R1) the attend-humans CSI is 0.664, outside tolerance. The third axis of the state space has no weight in these data, so the values depend on it: over random third axes the attend-humans CSI ranges from 0.683 to 0.784 (5 to 95%), within tolerance throughout.
att-csi-group¶
Across subjects the presence states are distinctly and significantly separated in the attention-task state space, with CSI 0.66 +/- 0.09 for attend-humans, 0.74 +/- 0.03 for attend-vehicles and 0.53 +/- 0.24 for passive viewing (mean +/- std).
exp = {"human": (0.66, 0.09), "vehicle": (0.74, 0.03), "passive": (0.53, 0.24)}
fig_ref = {"human": np.mean([0.51, 0.75, 0.70, 0.66, 0.60]), "vehicle": np.mean([0.79, 0.69, 0.71, 0.74, 0.71]),
"passive": np.mean([0.64, 0.67, 0.05, 0.59, 0.61])}
print("second reference, means of the paper's per-subject values over the same five subjects:",
{c: round(v, 3) for c, v in fig_ref.items()})
for reading in ["R3_code", "R2_median", "R1_2d"]:
null = "2d" if reading == "R1_2d" else "3d"
for c in ["human", "vehicle", "passive"]:
ci = ss.CONDITIONS.index(c)
v = csi_table[csi_table.condition == c][reading].values
e, tol = exp[c]
key = reading.split("_")[0]
sig_a = {r: all(pval(csi_obs[s][key][ci], csi_null[s, r, null][:, ci]) <= 1 / (N_PERM + 1)
for s in ss.ATT_SUBJECTS) for r in "ab"}
grp_null = {r: np.mean([csi_null[s, r, null][:, ci] for s in ss.ATT_SUBJECTS], axis=0) for r in "ab"}
sig_b = {r: bool(v.mean() > grp_null[r].max()) for r in "ab"}
print(f"{reading:9s} {c:8s} mean {v.mean():.3f} +/- {v.std(ddof=1):.3f} (SD over 5) (expected {e} +/- {tol}; "
f"within: {abs(v.mean()-e) <= tol}); every subject above every null value: {sig_a}; "
f"mean above every mean null value: {sig_b} (max mean null a {grp_null['a'].max():.3f}, b {grp_null['b'].max():.3f})")
second reference, means of the paper's per-subject values over the same five subjects: {'human': np.float64(0.644), 'vehicle': np.float64(0.728), 'passive': np.float64(0.512)}
R3_code human mean 0.665 +/- 0.104 (SD over 5) (expected 0.66 +/- 0.09; within: True); every subject above every null value: {'a': True, 'b': True}; mean above every mean null value: {'a': True, 'b': True} (max mean null a 0.029, b 0.110)
R3_code vehicle mean 0.731 +/- 0.023 (SD over 5) (expected 0.74 +/- 0.03; within: True); every subject above every null value: {'a': True, 'b': True}; mean above every mean null value: {'a': True, 'b': True} (max mean null a 0.032, b 0.098)
R3_code passive mean 0.524 +/- 0.260 (SD over 5) (expected 0.53 +/- 0.24; within: True); every subject above every null value: {'a': False, 'b': False}; mean above every mean null value: {'a': True, 'b': True} (max mean null a 0.042, b 0.104)
R2_median human mean 0.658 +/- 0.074 (SD over 5) (expected 0.66 +/- 0.09; within: True); every subject above every null value: {'a': True, 'b': True}; mean above every mean null value: {'a': True, 'b': True} (max mean null a 0.029, b 0.110)
R2_median vehicle mean 0.728 +/- 0.023 (SD over 5) (expected 0.74 +/- 0.03; within: True); every subject above every null value: {'a': True, 'b': True}; mean above every mean null value: {'a': True, 'b': True} (max mean null a 0.032, b 0.098)
R2_median passive mean 0.523 +/- 0.260 (SD over 5) (expected 0.53 +/- 0.24; within: True); every subject above every null value: {'a': False, 'b': False}; mean above every mean null value: {'a': True, 'b': True} (max mean null a 0.042, b 0.104)
R1_2d human mean 0.602 +/- 0.074 (SD over 5) (expected 0.66 +/- 0.09; within: True); every subject above every null value: {'a': True, 'b': True}; mean above every mean null value: {'a': True, 'b': True} (max mean null a 0.020, b 0.096)
R1_2d vehicle mean 0.675 +/- 0.033 (SD over 5) (expected 0.74 +/- 0.03; within: False); every subject above every null value: {'a': True, 'b': True}; mean above every mean null value: {'a': True, 'b': True} (max mean null a 0.025, b 0.085)
R1_2d passive mean 0.492 +/- 0.260 (SD over 5) (expected 0.53 +/- 0.24; within: True); every subject above every null value: {'a': False, 'b': False}; mean above every mean null value: {'a': True, 'b': True} (max mean null a 0.022, b 0.089)
Result: reproduced, resting on an assumption about the third axis. Over the five released subjects, R3 gives mean CSIs of 0.663 +/- 0.104 (attend-humans), 0.730 +/- 0.023 (attend-vehicles) and 0.525 +/- 0.260 (passive), all within the paper's spreads of 0.66 +/- 0.09, 0.74 +/- 0.03 and 0.53 +/- 0.24; R2 gives 0.658, 0.728 and 0.523. Under group reading (b), each mean exceeds the maximum of the mean null CSIs (at most 0.110). Under reading (a), every subject is significant in the attentive conditions but not in passive, where S3's CSI (0.062) does not exceed its null. In the plane alone (R1) the attend-vehicles mean, 0.675, is outside tolerance. The second reference, the means of the paper's own per-subject values over these subjects (0.644, 0.728, 0.512), is also close to the R3 means.
supp-csi-per-subject¶
In each subject and each attention condition the CSI is significant, with the values printed in Supplementary Figures 1 and 2.
supp = {("S1", "human"): 0.51, ("S1", "vehicle"): 0.79, ("S1", "passive"): 0.64,
("S3", "human"): 0.70, ("S3", "vehicle"): 0.71, ("S3", "passive"): 0.05,
("S5", "human"): 0.66, ("S5", "vehicle"): 0.74, ("S5", "passive"): 0.59,
("S6", "human"): 0.60, ("S6", "vehicle"): 0.71, ("S6", "passive"): 0.61}
for reading in ["R3_code", "R2_median", "R1_2d"]:
null = "null2d" if reading == "R1_2d" else "null3d"
rows, n_in, n_sig = [], 0, {"a": 0, "b": 0}
for (s, c), e in supp.items():
if s not in ss.ATT_SUBJECTS:
continue
r = csi_table[(csi_table.subject == s) & (csi_table.condition == c)].iloc[0]
tol = 0.1 * e
inside = abs(r[reading] - e) <= tol + 1e-12
n_in += inside
key, ci = reading.split("_")[0], ss.CONDITIONS.index(c)
nk = "2d" if reading == "R1_2d" else "3d"
rows.append(dict(subject=s, condition=c, expected=e, measured=round(r[reading], 3), within=inside,
null_max_a=round(r[f"{null}_max_a"], 3), p_a=pval(csi_obs[s][key][ci], csi_null[s, "a", nk][:, ci]),
null_max_b=round(r[f"{null}_max_b"], 3), p_b=pval(csi_obs[s][key][ci], csi_null[s, "b", nk][:, ci])))
for rd in "ab":
n_sig[rd] += rows[-1][f"p_{rd}"] < 0.01
print(reading)
print(pd.DataFrame(rows).to_string(index=False))
print(f" {n_in} of 12 within tolerance; significant at p < 0.01 ({N_PERM} permutations): "
f"reading a {n_sig['a']} of 12, reading b {n_sig['b']} of 12\n")
i = ss.CONDITIONS.index("passive")
print("S3 passive: R3 mean over 10 seeds %.3f (seed SD %.3f); R2 5-95%% range %.3f to %.3f"
% (csi_obs["S3"]["R3"][i], csi_seedsd["S3"]["R3"][i], csi_obs["S3"]["R2_lo"][i], csi_obs["S3"]["R2_hi"][i]))
R3_code
subject condition expected measured within null_max_a p_a null_max_b p_b
S1 human 0.51 0.515 True 0.045 0.000999 0.336 0.000999
S1 vehicle 0.79 0.744 True 0.053 0.000999 0.088 0.000999
S1 passive 0.64 0.620 True 0.055 0.000999 0.334 0.000999
S3 human 0.70 0.696 True 0.048 0.000999 0.339 0.000999
S3 vehicle 0.71 0.761 True 0.043 0.000999 0.303 0.000999
S3 passive 0.05 0.061 False 0.065 0.001998 0.099 0.044955
S5 human 0.66 0.767 False 0.042 0.000999 0.126 0.000999
S5 vehicle 0.74 0.730 True 0.096 0.000999 0.340 0.000999
S5 passive 0.59 0.614 True 0.094 0.000999 0.347 0.000999
S6 human 0.60 0.605 True 0.048 0.000999 0.292 0.000999
S6 vehicle 0.71 0.699 True 0.046 0.000999 0.321 0.000999
S6 passive 0.61 0.651 True 0.066 0.000999 0.297 0.000999
10 of 12 within tolerance; significant at p < 0.01 (1000 permutations): reading a 12 of 12, reading b 11 of 12
R2_median
subject condition expected measured within null_max_a p_a null_max_b p_b
S1 human 0.51 0.543 True 0.045 0.000999 0.336 0.000999
S1 vehicle 0.79 0.762 True 0.053 0.000999 0.088 0.000999
S1 passive 0.64 0.638 True 0.055 0.000999 0.334 0.000999
S3 human 0.70 0.703 True 0.048 0.000999 0.339 0.000999
S3 vehicle 0.71 0.728 True 0.043 0.000999 0.303 0.000999
S3 passive 0.05 0.059 False 0.065 0.001998 0.099 0.057942
S5 human 0.66 0.694 True 0.042 0.000999 0.126 0.000999
S5 vehicle 0.74 0.698 True 0.096 0.000999 0.340 0.000999
S5 passive 0.59 0.622 True 0.094 0.000999 0.347 0.000999
S6 human 0.60 0.627 True 0.048 0.000999 0.292 0.000999
S6 vehicle 0.71 0.735 True 0.046 0.000999 0.321 0.000999
S6 passive 0.61 0.637 True 0.066 0.000999 0.297 0.000999
11 of 12 within tolerance; significant at p < 0.01 (1000 permutations): reading a 12 of 12, reading b 11 of 12
R1_2d
subject condition expected measured within null_max_a p_a null_max_b p_b
S1 human 0.51 0.483 True 0.037 0.000999 0.297 0.000999
S1 vehicle 0.79 0.716 True 0.041 0.000999 0.067 0.000999
S1 passive 0.64 0.609 True 0.035 0.000999 0.315 0.000999
S3 human 0.70 0.647 True 0.033 0.000999 0.301 0.000999
S3 vehicle 0.71 0.674 True 0.033 0.000999 0.272 0.000999
S3 passive 0.05 0.028 False 0.047 0.077922 0.063 0.354645
S5 human 0.66 0.640 True 0.031 0.000999 0.090 0.000999
S5 vehicle 0.74 0.626 False 0.082 0.000999 0.292 0.000999
S5 passive 0.59 0.592 True 0.045 0.000999 0.284 0.000999
S6 human 0.60 0.575 True 0.033 0.000999 0.265 0.000999
S6 vehicle 0.71 0.689 True 0.033 0.000999 0.283 0.000999
S6 passive 0.61 0.599 True 0.050 0.000999 0.269 0.000999
10 of 12 within tolerance; significant at p < 0.01 (1000 permutations): reading a 11 of 12, reading b 11 of 12
S3 passive: R3 mean over 10 seeds 0.061 (seed SD 0.003); R2 5-95% range 0.042 to 0.082
Result: reproduced, resting on an assumption about the third axis. With R3, 10 of the 12 per-subject CSIs are within 10% of the values in Supplementary Figures 1 and 2 (11 of 12 with R2, 10 of 12 with R1). The two outside are S3 passive (0.062 against 0.05, a tolerance of 0.005) and S5 attend-humans (0.763 against 0.66, within tolerance under R2 at 0.694). Under permutation reading (a) all 12 R3 CSIs are significant at p < 0.01: eleven exceed every null value (p = 0.001) and S3 passive has p = 0.002. Under reading (b) S3 passive has p = 0.039, so 11 of 12 are significant. The R1 counts are printed above. S3's passive CSI is close to the floor of the measure, as in the paper (0.05).
att-passive-lower¶
Attention increases state separation; the CSI under passive viewing is significantly lower than under the attentive conditions in five of the six subjects.
Readings of the claims file: (a) passive against each attentive condition, both differences significant; (b) passive against the mean of the two attentive CSIs. Null: the condition labels permuted between TRs, presence labels kept, either (i) refitting the state space each time, or (ii) keeping the fitted positions. How the condition labels are permuted is not fixed; two schemes are run: "matched", where at each movie time point the three TRs showing the same frame get the three conditions in random order (each condition keeps the same presence labels), and "global", a shuffle over all TRs. One-sided, passive lower; 1000 permutations, so a subject counts at the paper's threshold when its difference exceeds every null value (p <= 0.001, the bound reached). The observed CSIs are those of R3 (the code's positions); for (i) the refitted null uses the code's QR, which now gives the third axis a real weight, while the observed third axis is noise, so the observed value and the null (i) are not computed the same way for R3; the observed CSIs also average 10 Monte Carlo seeds where each null draw uses one. Null (ii) has neither difference. R1 (the plane) is shown as a variant. The null quantiles of the mean difference are printed for every subject.
rng = np.random.default_rng(2)
def stats_ab(c): # c: CSI (passive, human, vehicle)
return np.array([c[1] - c[0], c[2] - c[0], c[1:].mean() - c[0]])
pl_rows, pl_null = [], {}
for s in ss.ATT_SUBJECTS:
Z = att[s]["Z"]
for variant, obs_pos in [("R3", att[s]["code_pos"]), ("R1", ss.att_positions(Z, X_att, "2d"))]:
obs_c = np.mean([ss.att_csis(obs_pos, pcode, np.random.default_rng(k)) for k in range(10)], axis=0)
obs = stats_ab(obs_c)
for scheme in ["matched", "global"]:
for refit in ["i", "ii"]:
null = []
for _ in range(N_PERM):
mem = ss.shuffle_conditions(900, scheme, rng)
if refit == "i":
Xp = ss.members_to_X(X_att, mem)
p = ss.att_positions(Z, Xp, "qr" if variant == "R3" else "2d")
else:
p = obs_pos
null.append(stats_ab(ss.att_csis(p, pcode, rng, members=mem)))
null = np.array(null)
pl_null[s, variant, scheme, refit] = null
p_one = (1 + (null >= obs).sum(0)) / (N_PERM + 1)
pl_rows.append(dict(subject=s, variant=variant, scheme=scheme, null=refit,
passive=obs_c[0], human=obs_c[1], vehicle=obs_c[2],
d_human=obs[0], d_vehicle=obs[1], d_mean=obs[2],
p_human=p_one[0], p_vehicle=p_one[1], p_mean=p_one[2]))
pl = pd.DataFrame(pl_rows)
pmin = 1 / (N_PERM + 1)
pl["a_at_bound"] = (pl.p_human <= pmin) & (pl.p_vehicle <= pmin)
pl["b_at_bound"] = pl.p_mean <= pmin
pl["a_p05"] = (pl.p_human < 0.05) & (pl.p_vehicle < 0.05)
pl["b_p05"] = pl.p_mean < 0.05
print(pl.round(4).to_string(index=False))
cnt = pl.groupby(["variant", "scheme", "null"])[["a_at_bound", "b_at_bound", "a_p05", "b_p05"]].sum()
print("\nsubjects of 5 with passive significantly lower:")
print(cnt.to_string())
print("\nnull distribution of d_mean (mean attentive CSI minus passive), R3: observed and null quantiles")
for s in ss.ATT_SUBJECTS:
for scheme in ["matched", "global"]:
for refit in ["i", "ii"]:
q = np.percentile(pl_null[s, "R3", scheme, refit][:, 2], [50, 95, 99, 100])
obs = pl[(pl.subject == s) & (pl.variant == "R3") & (pl.scheme == scheme) & (pl.null == refit)].d_mean.iloc[0]
print(f" {s} {scheme:7s} null {refit:2s}: observed {obs:.4f}; null median {q[0]:.4f}, 95% {q[1]:.4f}, 99% {q[2]:.4f}, max {q[3]:.4f}")
print(f"elapsed {time.time()-T0:.0f} s")
subject variant scheme null passive human vehicle d_human d_vehicle d_mean p_human p_vehicle p_mean a_at_bound b_at_bound a_p05 b_p05
S1 R3 matched i 0.6200 0.5153 0.7442 -0.1048 0.1242 0.0097 1.0000 0.0010 0.3207 False False False False
S1 R3 matched ii 0.6200 0.5153 0.7442 -0.1048 0.1242 0.0097 1.0000 0.0010 0.3017 False False False False
S1 R3 global i 0.6200 0.5153 0.7442 -0.1048 0.1242 0.0097 1.0000 0.0010 0.3516 False False False False
S1 R3 global ii 0.6200 0.5153 0.7442 -0.1048 0.1242 0.0097 1.0000 0.0010 0.3407 False False False False
S1 R1 matched i 0.6092 0.4834 0.7160 -0.1258 0.1068 -0.0095 1.0000 0.0010 0.6793 False False False False
S1 R1 matched ii 0.6092 0.4834 0.7160 -0.1258 0.1068 -0.0095 1.0000 0.0010 0.6923 False False False False
S1 R1 global i 0.6092 0.4834 0.7160 -0.1258 0.1068 -0.0095 1.0000 0.0010 0.6693 False False False False
S1 R1 global ii 0.6092 0.4834 0.7160 -0.1258 0.1068 -0.0095 1.0000 0.0010 0.6603 False False False False
S2 R3 matched i 0.6748 0.7426 0.7208 0.0678 0.0461 0.0569 0.0030 0.0140 0.0020 False False True True
S2 R3 matched ii 0.6748 0.7426 0.7208 0.0678 0.0461 0.0569 0.0010 0.0170 0.0010 False True True True
S2 R3 global i 0.6748 0.7426 0.7208 0.0678 0.0461 0.0569 0.0070 0.0480 0.0060 False False True True
S2 R3 global ii 0.6748 0.7426 0.7208 0.0678 0.0461 0.0569 0.0100 0.0539 0.0100 False False False True
S2 R1 matched i 0.6318 0.6637 0.6684 0.0319 0.0367 0.0343 0.0639 0.0410 0.0340 False False False True
S2 R1 matched ii 0.6318 0.6637 0.6684 0.0319 0.0367 0.0343 0.0679 0.0400 0.0370 False False False True
S2 R1 global i 0.6318 0.6637 0.6684 0.0319 0.0367 0.0343 0.1239 0.0849 0.0699 False False False False
S2 R1 global ii 0.6318 0.6637 0.6684 0.0319 0.0367 0.0343 0.1349 0.1019 0.0749 False False False False
S3 R3 matched i 0.0607 0.6959 0.7606 0.6353 0.6999 0.6676 0.0010 0.0010 0.0010 True True True True
S3 R3 matched ii 0.0607 0.6959 0.7606 0.6353 0.6999 0.6676 0.0010 0.0010 0.0010 True True True True
S3 R3 global i 0.0607 0.6959 0.7606 0.6353 0.6999 0.6676 0.0010 0.0010 0.0010 True True True True
S3 R3 global ii 0.0607 0.6959 0.7606 0.6353 0.6999 0.6676 0.0010 0.0010 0.0010 True True True True
S3 R1 matched i 0.0283 0.6474 0.6738 0.6191 0.6455 0.6323 0.0010 0.0010 0.0010 True True True True
S3 R1 matched ii 0.0283 0.6474 0.6738 0.6191 0.6455 0.6323 0.0010 0.0010 0.0010 True True True True
S3 R1 global i 0.0283 0.6474 0.6738 0.6191 0.6455 0.6323 0.0010 0.0010 0.0010 True True True True
S3 R1 global ii 0.0283 0.6474 0.6738 0.6191 0.6455 0.6323 0.0010 0.0010 0.0010 True True True True
S5 R3 matched i 0.6138 0.7671 0.7303 0.1533 0.1165 0.1349 0.0010 0.0010 0.0010 True True True True
S5 R3 matched ii 0.6138 0.7671 0.7303 0.1533 0.1165 0.1349 0.0010 0.0010 0.0010 True True True True
S5 R3 global i 0.6138 0.7671 0.7303 0.1533 0.1165 0.1349 0.0010 0.0010 0.0010 True True True True
S5 R3 global ii 0.6138 0.7671 0.7303 0.1533 0.1165 0.1349 0.0010 0.0010 0.0010 True True True True
S5 R1 matched i 0.5918 0.6396 0.6261 0.0478 0.0343 0.0411 0.0190 0.0659 0.0220 False False False True
S5 R1 matched ii 0.5918 0.6396 0.6261 0.0478 0.0343 0.0411 0.0160 0.0649 0.0190 False False False True
S5 R1 global i 0.5918 0.6396 0.6261 0.0478 0.0343 0.0411 0.0519 0.1239 0.0549 False False False False
S5 R1 global ii 0.5918 0.6396 0.6261 0.0478 0.0343 0.0411 0.0689 0.1189 0.0619 False False False False
S6 R3 matched i 0.6513 0.6053 0.6993 -0.0460 0.0481 0.0011 0.9790 0.0170 0.4655 False False False False
S6 R3 matched ii 0.6513 0.6053 0.6993 -0.0460 0.0481 0.0011 0.9760 0.0260 0.4685 False False False False
S6 R3 global i 0.6513 0.6053 0.6993 -0.0460 0.0481 0.0011 0.9520 0.0470 0.5085 False False False False
S6 R3 global ii 0.6513 0.6053 0.6993 -0.0460 0.0481 0.0011 0.9520 0.0400 0.5015 False False False False
S6 R1 matched i 0.5994 0.5755 0.6889 -0.0239 0.0896 0.0328 0.8212 0.0010 0.0390 False False False True
S6 R1 matched ii 0.5994 0.5755 0.6889 -0.0239 0.0896 0.0328 0.8601 0.0010 0.0509 False False False False
S6 R1 global i 0.5994 0.5755 0.6889 -0.0239 0.0896 0.0328 0.7942 0.0010 0.0849 False False False False
S6 R1 global ii 0.5994 0.5755 0.6889 -0.0239 0.0896 0.0328 0.8112 0.0020 0.1039 False False False False
subjects of 5 with passive significantly lower:
a_at_bound b_at_bound a_p05 b_p05
variant scheme null
R1 global i 1 1 1 1
ii 1 1 1 1
matched i 1 1 1 4
ii 1 1 1 3
R3 global i 2 2 3 3
ii 2 2 2 3
matched i 2 2 3 3
ii 2 3 3 3
null distribution of d_mean (mean attentive CSI minus passive), R3: observed and null quantiles
S1 matched null i : observed 0.0097; null median 0.0014, 95% 0.0350, 99% 0.0463, max 0.0600
S1 matched null ii: observed 0.0097; null median -0.0017, 95% 0.0301, 99% 0.0506, max 0.0718
S1 global null i : observed 0.0097; null median -0.0001, 95% 0.0412, 99% 0.0570, max 0.0858
S1 global null ii: observed 0.0097; null median 0.0006, 95% 0.0412, 99% 0.0603, max 0.0814
S2 matched null i : observed 0.0569; null median -0.0001, 95% 0.0287, 99% 0.0460, max 0.0609
S2 matched null ii: observed 0.0569; null median 0.0012, 95% 0.0288, 99% 0.0417, max 0.0524
S2 global null i : observed 0.0569; null median -0.0013, 95% 0.0382, 99% 0.0504, max 0.0840
S2 global null ii: observed 0.0569; null median -0.0001, 95% 0.0403, 99% 0.0552, max 0.0798
S3 matched null i : observed 0.6676; null median -0.0003, 95% 0.0423, 99% 0.0572, max 0.0719
S3 matched null ii: observed 0.6676; null median -0.0008, 95% 0.0376, 99% 0.0532, max 0.0773
S3 global null i : observed 0.6676; null median -0.0004, 95% 0.0407, 99% 0.0605, max 0.1019
S3 global null ii: observed 0.6676; null median 0.0011, 95% 0.0433, 99% 0.0579, max 0.0869
S5 matched null i : observed 0.1349; null median 0.0007, 95% 0.0323, 99% 0.0448, max 0.0534
S5 matched null ii: observed 0.1349; null median -0.0004, 95% 0.0353, 99% 0.0516, max 0.0663
S5 global null i : observed 0.1349; null median -0.0017, 95% 0.0384, 99% 0.0577, max 0.0787
S5 global null ii: observed 0.1349; null median -0.0023, 95% 0.0379, 99% 0.0585, max 0.0754
S6 matched null i : observed 0.0011; null median -0.0001, 95% 0.0310, 99% 0.0449, max 0.0590
S6 matched null ii: observed 0.0011; null median -0.0008, 95% 0.0311, 99% 0.0502, max 0.0649
S6 global null i : observed 0.0011; null median 0.0018, 95% 0.0413, 99% 0.0586, max 0.0722
S6 global null ii: observed 0.0011; null median 0.0011, 95% 0.0386, 99% 0.0576, max 0.0741
elapsed 1071 s
Result: not reproduced. At the threshold that 1000 permutations allow (the difference exceeding every null value), the passive CSI is significantly lower than the attentive CSIs in 2 of the 5 subjects (S3 and S5) under every combination of reading and null run with the code's positions (R3), and in 1 with the plane (R1), where the criterion needs 4 of 5. At p < 0.05 the counts are at most 3 with R3 and at most 4 with R1 (reading b, matched permutation, refitted). S3 and S5 show the effect clearly (mean differences 0.665 and 0.134, above every null value). In S1 and S6 the attend-humans CSI is below the passive one (S1 0.512 against 0.621; S6 0.606 against 0.652), as in the paper's own figure values for these subjects, and the mean of the two attentive CSIs is within 0.008 of passive (p 0.34 to 0.51). S2's mean difference, 0.0525, lies above the null's 99th percentile under three of the four nulls (0.0416 to 0.0504) and below it under the fourth (0.0562, global, null ii), and below the null's maximum under all four (0.0526 to 0.0840; the closest, 0.0526, under matched permutation and null ii); p = 0.002 to 0.015. The counts are the same under null (ii), which is computed as the observed values are.
att-classification¶
Held-out TRs of the attention task are classified into the 12 labels (four presence states by three attention conditions) from their position in the learned state space at 48.4 +/- 7.6% across subjects, well above the chance of 8.3%.
10-fold cross-validation over the 2700 stacked TRs; in each fold the PCA and the state space are fitted on the training TRs (Methods, Quantification, paragraph 2), the held-out TRs are projected and z-scored with the training statistics, and assigned to the nearest of the 12 training clusters. Readings: folds (a) contiguous tenths or (b) random TRs; nearest cluster by (a) the Euclidean distance to the mean or (b) the density of the cluster's normal. Null: the training TRs' state rows permuted and the full fit repeated, 1000 times. In the training folds the two attentive conditions are no longer exactly zero-mean, so the third axis gets a small fitted weight.
lab12 = pcode + 4 * np.repeat(np.arange(3), 900)
classes12 = np.arange(12)
N_PERM_CLF = 1000
rng = np.random.default_rng(3)
clf_rows, clf_null = [], {}
for s in ss.ATT_SUBJECTS:
t = time.time()
for scheme in ["contig", "random"]:
fs = ss.fold_scores(att[s]["G"], ss.folds(2700, scheme, rng))
for rule in ["euclid", "density"]:
accs = []
for tr, te, Ztr, Zte in fs:
ptr, pte = ss.project_fold(Ztr, Zte, X_att[tr])
accs.append((ss.nearest_cluster(ptr, lab12[tr], pte, classes12, rule) == lab12[te]).mean())
null = np.zeros(N_PERM_CLF)
for k in range(N_PERM_CLF):
a = []
for tr, te, Ztr, Zte in fs:
perm = rng.permutation(len(tr))
ptr, pte = ss.project_fold(Ztr, Zte, X_att[tr][perm])
a.append((ss.nearest_cluster(ptr, lab12[tr][perm], pte, classes12, rule) == lab12[te]).mean())
null[k] = np.mean(a)
clf_null[s, scheme, rule] = null
clf_rows.append(dict(subject=s, folds=scheme, rule=rule, accuracy=np.mean(accs), fold_sd=np.std(accs),
null_mean=null.mean(), null_max=null.max(), p=(1 + (null >= np.mean(accs)).sum()) / (N_PERM_CLF + 1)))
print(f"{s} done in {time.time()-t:.0f} s")
clf = pd.DataFrame(clf_rows)
print((clf.assign(accuracy=100 * clf.accuracy, fold_sd=100 * clf.fold_sd, null_mean=100 * clf.null_mean,
null_max=100 * clf.null_max)).round(2).to_string(index=False))
print("\nacross subjects (percent):")
for (scheme, rule), g in clf.groupby(["folds", "rule"]):
gnull = np.mean([clf_null[s, scheme, rule] for s in ss.ATT_SUBJECTS], axis=0)
m = 100 * g.accuracy.mean()
print(f" folds {scheme:6s} {rule:7s}: {m:.1f} +/- {100*g.accuracy.std(ddof=1):.1f} (SD over 5); within 48.4 +/- 7.6: "
f"{abs(m-48.4) <= 7.6}; chance under this procedure (mean null) {100*gnull.mean():.1f}; max of mean null {100*gnull.max():.1f}; "
f"above every null mean: {m > 100*gnull.max()}")
print(f"elapsed {time.time()-T0:.0f} s")
S1 done in 99 s
S2 done in 101 s
S3 done in 101 s
S5 done in 100 s
S6 done in 100 s
subject folds rule accuracy fold_sd null_mean null_max p
S1 contig euclid 42.33 9.50 8.78 16.78 0.0
S1 contig density 54.48 8.58 8.93 15.15 0.0
S1 random euclid 45.70 4.68 8.15 11.67 0.0
S1 random density 55.52 3.80 7.80 12.19 0.0
S2 contig euclid 46.78 6.82 8.82 17.41 0.0
S2 contig density 56.85 6.19 9.05 16.70 0.0
S2 random euclid 48.30 2.33 7.98 13.78 0.0
S2 random density 60.63 2.59 7.79 11.63 0.0
S3 contig euclid 39.93 13.33 8.98 15.52 0.0
S3 contig density 45.59 15.49 9.28 15.93 0.0
S3 random euclid 42.19 3.22 8.00 12.48 0.0
S3 random density 48.30 3.15 7.82 11.15 0.0
S5 contig euclid 46.15 7.21 8.85 17.30 0.0
S5 contig density 55.04 7.96 9.14 15.93 0.0
S5 random euclid 48.41 3.86 8.04 12.59 0.0
S5 random density 59.44 4.15 7.73 11.15 0.0
S6 contig euclid 43.26 10.73 8.84 18.07 0.0
S6 contig density 57.15 5.33 9.09 16.00 0.0
S6 random euclid 48.56 5.12 7.98 11.48 0.0
S6 random density 57.48 3.72 7.75 11.78 0.0
across subjects (percent):
folds contig density: 53.8 +/- 4.7 (SD over 5); within 48.4 +/- 7.6: True; chance under this procedure (mean null) 9.1; max of mean null 12.1; above every null mean: True
folds contig euclid : 43.7 +/- 2.8 (SD over 5); within 48.4 +/- 7.6: True; chance under this procedure (mean null) 8.9; max of mean null 12.5; above every null mean: True
folds random density: 56.3 +/- 4.9 (SD over 5); within 48.4 +/- 7.6: False; chance under this procedure (mean null) 7.8; max of mean null 9.7; above every null mean: True
folds random euclid : 46.6 +/- 2.8 (SD over 5); within 48.4 +/- 7.6: True; chance under this procedure (mean null) 8.0; max of mean null 9.9; above every null mean: True
elapsed 1573 s
Result: reproduced. The mean accuracy over the five subjects is 43.7% (contiguous folds, Euclidean), 53.3% (contiguous, density), 46.6% (random, Euclidean) and 56.3% (random, density), against 48.4 +/- 7.6%; three of the four readings are within tolerance, and all four exceed every one of 1000 mean null accuracies (maxima 9.7 to 12.5%). Chance under this procedure, the mean of the null, is 7.8 to 9.1%, close to the paper's 8.3%. Per subject the accuracy is 40.4 to 60.6%. The first run gave 44.4% and 53.4% for the contiguous readings; the likeliest cause of the difference is rounding in the third axis of each fold's state space, which carries little weight.
att-weights-cortex¶
The human-presence dimension of the attention-task state space has its weights in face and body areas (FFA, OFA, EBA), MT+, LO, the frontal operculum and the inferior frontal sulcus; the vehicle-presence dimension in RSC, PPA, OPA, IPS, FEF and around the inferior frontal sulcus.
The paper drew its ROIs per subject from functional localizer and retinotopic mapping data (Methods, Preprocessing and Visualization, paragraph 2), which are not public. The claims file lets the author use an outside source, naming an fsaverage atlas through the data set's mappers, and that is done here (an assumption: group atlas regions in place of each subject's localizer ROIs). The category areas come from visfAtlas (Rosenke et al. 2021), whose authors relate its fusiform face areas (mFus, pFus) to the FFA, its lateral body areas (LOS, ITG, MTG) to the EBA and CoS-places to the PPA; IOG-faces is taken as the OFA and TOS-places (right hemisphere only) as the OPA. RSC, LO, FO, IFS, IPS, FEF and SEF come from HCP-MMP1.0 (Glasser et al. 2016) on fsaverage. Other definitions of the body, face and place areas are shown as variants.
Weights, the readings of the claims file: (a) the OLS weights B, (b) the denoised weights B_L, (c) the state directions Q_S, each oriented so that its own state's TRs have a positive mean position. They are computed exactly from the region-averaged responses and the PCA of all voxels (helper, region_weights). Thresholds: (i) none; (ii) voxels whose prediction by the WordNet FIR model (delays 1 to 4, ridge, 10 contiguous folds per condition, on the non-deconvolved BOLD of the three conditions) correlates with the response at one-sided p < 0.05 uncorrected (t test of r), computed for the voxels the regions reach. Per subject and region, the mean weight over the region's vertices. A subject counts when the human-presence weight is positive and above the vehicle-presence weight in FFA, OFA and EBA, and the reverse in RSC, PPA and OPA; 4 of 5 subjects are needed under a reading.
aw_rows, sem_fit = [], {}
for s in ss.ATT_SUBJECTS:
t = time.time()
r, alpha, n, mean_r = ss.semantic_model_r(s, sem, att_keep[s])
p = ss.r_pvalue(r, n)
sig = np.zeros(regmat[s].shape[0], bool)
sig[att_keep[s][p < 0.05]] = True
R_thr, nv_thr = ss.region_matrix(mappers[s], atlases, ss.ATT_REGIONS, voxel_mask=sig)
# variant, not a reading of the claims file: Bonferroni over the region voxels, a far stricter test,
# since the t test of r treats the 5400 autocorrelated TRs as independent
sig_b = np.zeros(regmat[s].shape[0], bool)
sig_b[att_keep[s][p < 0.05 / len(att_keep[s])]] = True
R_b, nv_b = ss.region_matrix(mappers[s], atlases, ss.ATT_REGIONS, voxel_mask=sig_b)
sem_fit[s] = dict(alpha=alpha, n_vox=len(att_keep[s]), n_sig=int(sig.sum()))
Yk = att[s]["Y_keep"].astype(np.float64)
for thr, R in [("i", regmat[s]), ("ii", R_thr), ("ii-bonf", R_b)]:
W = ss.region_weights(att[s]["Z"], X_att, Yk @ R[att_keep[s]])
for reading, w in W.items():
for k, reg in enumerate(ss.ATT_REGIONS):
aw_rows.append(dict(subject=s, threshold=thr, weights=reading, region=reg, human=w[k, 0], vehicle=w[k, 1]))
print(f"{s}: WordNet model ridge parameter {alpha:g} (mean r per parameter {np.round(mean_r, 4).tolist()}), "
f"{n} TRs; {sig.sum()} of {len(att_keep[s])} region voxels significant at p < 0.05 "
f"({sig.sum() / len(att_keep[s]):.0%}); vertices per region after the threshold "
f"{dict(zip(ss.ATT_REGIONS, nv_thr))}; Bonferroni variant: {sig_b.sum()} voxels, vertices per region "
f"{dict(zip(ss.ATT_REGIONS, nv_b))}; {time.time()-t:.0f} s, peak memory {mem_gb():.1f} GB")
aw = pd.DataFrame(aw_rows)
S1: WordNet model ridge parameter 10000 (mean r per parameter [0.023000000044703484, 0.03909999877214432, 0.050700001418590546, 0.05079999938607216, 0.04450000077486038]), 5400 TRs; 3835 of 5965 region voxels significant at p < 0.05 (64%); vertices per region after the threshold {'FFA': 1670, 'OFA': 618, 'EBA': 3737, 'MT+': 789, 'PPA': 2530, 'OPA': 1080, 'RSC': 872, 'LO': 1735, 'FO': 2625, 'IFS': 1288, 'IPS': 10473, 'FEF': 1097, 'SEF': 978, 'LOS-bodies': 1194, 'ITG-bodies': 1598, 'MTG-bodies': 945, 'OTS-bodies': 535, 'FFC (HCP)': 1462, 'PHA1-3 (HCP)': 2103, 'POS1 (HCP)': 1285}; Bonferroni variant: 2266 voxels, vertices per region {'FFA': 1240, 'OFA': 446, 'EBA': 2989, 'MT+': 661, 'PPA': 1590, 'OPA': 843, 'RSC': 290, 'LO': 1530, 'FO': 533, 'IFS': 631, 'IPS': 6485, 'FEF': 690, 'SEF': 242, 'LOS-bodies': 1124, 'ITG-bodies': 1358, 'MTG-bodies': 507, 'OTS-bodies': 226, 'FFC (HCP)': 1088, 'PHA1-3 (HCP)': 969, 'POS1 (HCP)': 568}; 130 s, peak memory 5.8 GB
S2: WordNet model ridge parameter 10000 (mean r per parameter [0.023900000378489494, 0.0364999994635582, 0.04670000076293945, 0.04740000143647194, 0.04179999977350235]), 5400 TRs; 3745 of 5908 region voxels significant at p < 0.05 (63%); vertices per region after the threshold {'FFA': 1578, 'OFA': 570, 'EBA': 4107, 'MT+': 867, 'PPA': 2400, 'OPA': 980, 'RSC': 565, 'LO': 1610, 'FO': 1891, 'IFS': 1375, 'IPS': 10747, 'FEF': 1227, 'SEF': 1058, 'LOS-bodies': 1119, 'ITG-bodies': 1453, 'MTG-bodies': 1535, 'OTS-bodies': 673, 'FFC (HCP)': 1478, 'PHA1-3 (HCP)': 1830, 'POS1 (HCP)': 1269}; Bonferroni variant: 2056 voxels, vertices per region {'FFA': 1182, 'OFA': 418, 'EBA': 3203, 'MT+': 776, 'PPA': 1779, 'OPA': 757, 'RSC': 84, 'LO': 1347, 'FO': 122, 'IFS': 469, 'IPS': 5658, 'FEF': 915, 'SEF': 225, 'LOS-bodies': 988, 'ITG-bodies': 1027, 'MTG-bodies': 1188, 'OTS-bodies': 278, 'FFC (HCP)': 1105, 'PHA1-3 (HCP)': 944, 'POS1 (HCP)': 761}; 129 s, peak memory 5.8 GB
S3: WordNet model ridge parameter 1000 (mean r per parameter [0.031199999153614044, 0.04410000145435333, 0.05480000004172325, 0.0544000007212162, 0.04729999974370003]), 5400 TRs; 3704 of 5982 region voxels significant at p < 0.05 (62%); vertices per region after the threshold {'FFA': 1646, 'OFA': 469, 'EBA': 3767, 'MT+': 742, 'PPA': 2501, 'OPA': 955, 'RSC': 476, 'LO': 1462, 'FO': 1630, 'IFS': 1385, 'IPS': 9217, 'FEF': 1325, 'SEF': 903, 'LOS-bodies': 879, 'ITG-bodies': 1392, 'MTG-bodies': 1496, 'OTS-bodies': 766, 'FFC (HCP)': 1472, 'PHA1-3 (HCP)': 2085, 'POS1 (HCP)': 1182}; Bonferroni variant: 2238 voxels, vertices per region {'FFA': 1209, 'OFA': 315, 'EBA': 2894, 'MT+': 621, 'PPA': 1890, 'OPA': 652, 'RSC': 55, 'LO': 1161, 'FO': 219, 'IFS': 601, 'IPS': 6021, 'FEF': 914, 'SEF': 254, 'LOS-bodies': 681, 'ITG-bodies': 1010, 'MTG-bodies': 1203, 'OTS-bodies': 531, 'FFC (HCP)': 1135, 'PHA1-3 (HCP)': 1222, 'POS1 (HCP)': 511}; 128 s, peak memory 5.8 GB
S5: WordNet model ridge parameter 10000 (mean r per parameter [0.017799999564886093, 0.028200000524520874, 0.03759999945759773, 0.03799999877810478, 0.031599998474121094]), 5400 TRs; 3364 of 5945 region voxels significant at p < 0.05 (57%); vertices per region after the threshold {'FFA': 1529, 'OFA': 359, 'EBA': 3970, 'MT+': 832, 'PPA': 2398, 'OPA': 986, 'RSC': 859, 'LO': 1270, 'FO': 1257, 'IFS': 844, 'IPS': 9976, 'FEF': 814, 'SEF': 608, 'LOS-bodies': 979, 'ITG-bodies': 1546, 'MTG-bodies': 1445, 'OTS-bodies': 405, 'FFC (HCP)': 1292, 'PHA1-3 (HCP)': 1842, 'POS1 (HCP)': 1588}; Bonferroni variant: 1638 voxels, vertices per region {'FFA': 1019, 'OFA': 146, 'EBA': 3179, 'MT+': 688, 'PPA': 1474, 'OPA': 686, 'RSC': 121, 'LO': 917, 'FO': 277, 'IFS': 132, 'IPS': 3786, 'FEF': 289, 'SEF': 80, 'LOS-bodies': 781, 'ITG-bodies': 1170, 'MTG-bodies': 1228, 'OTS-bodies': 219, 'FFC (HCP)': 954, 'PHA1-3 (HCP)': 774, 'POS1 (HCP)': 856}; 130 s, peak memory 6.0 GB
S6: WordNet model ridge parameter 10000 (mean r per parameter [0.026599999517202377, 0.0421999990940094, 0.060499999672174454, 0.06459999829530716, 0.05909999832510948]), 5400 TRs; 4322 of 6065 region voxels significant at p < 0.05 (71%); vertices per region after the threshold {'FFA': 1688, 'OFA': 650, 'EBA': 4326, 'MT+': 875, 'PPA': 2527, 'OPA': 984, 'RSC': 810, 'LO': 1710, 'FO': 2013, 'IFS': 1511, 'IPS': 11755, 'FEF': 1456, 'SEF': 1292, 'LOS-bodies': 1182, 'ITG-bodies': 1673, 'MTG-bodies': 1471, 'OTS-bodies': 787, 'FFC (HCP)': 1415, 'PHA1-3 (HCP)': 1949, 'POS1 (HCP)': 1671}; Bonferroni variant: 2724 voxels, vertices per region {'FFA': 1311, 'OFA': 515, 'EBA': 3373, 'MT+': 768, 'PPA': 1721, 'OPA': 648, 'RSC': 201, 'LO': 1598, 'FO': 410, 'IFS': 820, 'IPS': 7760, 'FEF': 1240, 'SEF': 764, 'LOS-bodies': 1077, 'ITG-bodies': 1438, 'MTG-bodies': 858, 'OTS-bodies': 637, 'FFC (HCP)': 1180, 'PHA1-3 (HCP)': 881, 'POS1 (HCP)': 1115}; 132 s, peak memory 6.0 GB
HUM, VEH = ["FFA", "OFA", "EBA"], ["RSC", "PPA", "OPA"]
def region_ok(g, reg, dim):
h, v = g.loc[reg, "human"], g.loc[reg, "vehicle"]
return (h > 0 and h > v) if dim == "human" else (v > 0 and v > h)
rows = []
for (s, thr, reading), g in aw.groupby(["subject", "threshold", "weights"]):
g = g.set_index("region")
fails = [r for r in HUM if not region_ok(g, r, "human")] + [r for r in VEH if not region_ok(g, r, "vehicle")]
rows.append(dict(subject=s, threshold=thr, weights=reading, holds=not fails, failing_regions=fails))
awc = pd.DataFrame(rows)
print(awc.to_string(index=False))
print("\nsubjects of 5 in which the pattern holds, per reading (4 needed):")
print(awc.groupby(["threshold", "weights"]).holds.sum().to_string())
print("\nsubjects of 5 in which each region has the named dimension positive and above the other:")
cnt = {}
for (thr, reading), g in aw.groupby(["threshold", "weights"]):
cnt[thr, reading] = {f"{reg} ({dim})": int(sum(region_ok(gs.set_index("region"), reg, dim) for _, gs in g.groupby("subject")))
for reg, dim in [(r, "human") for r in HUM + ["MT+", "LO", "FO", "IFS", "SEF", "LOS-bodies", "ITG-bodies",
"MTG-bodies", "OTS-bodies", "FFC (HCP)"]] +
[(r, "vehicle") for r in VEH + ["IPS", "FEF", "IFS", "FO", "PHA1-3 (HCP)", "POS1 (HCP)"]]}
print(pd.DataFrame(cnt).to_string())
for thr in ["i", "ii", "ii-bonf"]:
print(f"\nmean weights, threshold ({thr}), OLS weights B (human / vehicle):")
t_ = aw[(aw.threshold == thr) & (aw.weights == "B")]
print(t_.assign(hv=[f"{h:+.3f} / {v:+.3f}" for h, v in zip(t_.human, t_.vehicle)])
.pivot(index="region", columns="subject", values="hv").loc[list(ss.ATT_REGIONS)].to_string())
print("\nEBA, human minus vehicle weight per subject (the region the outcome rests on):")
eba = aw[aw.region == "EBA"].assign(diff=lambda d: d.human - d.vehicle)
print(eba.pivot_table(index=["threshold", "weights"], columns="subject", values="diff").round(4).to_string())
print("\nrange of every mean weight shown:", {k: (round(float(g[["human", "vehicle"]].min().min()), 4), round(float(g[["human", "vehicle"]].max().max()), 4))
for k, g in aw.groupby("weights")})
subject threshold weights holds failing_regions
S1 i B True []
S1 i B_L True []
S1 i Q_S False [EBA]
S1 ii B True []
S1 ii B_L True []
S1 ii Q_S True []
S1 ii-bonf B True []
S1 ii-bonf B_L True []
S1 ii-bonf Q_S True []
S2 i B False [EBA]
S2 i B_L False [EBA]
S2 i Q_S False [EBA]
S2 ii B False [EBA]
S2 ii B_L False [EBA]
S2 ii Q_S False [EBA]
S2 ii-bonf B True []
S2 ii-bonf B_L True []
S2 ii-bonf Q_S True []
S3 i B False [EBA]
S3 i B_L False [EBA]
S3 i Q_S True []
S3 ii B True []
S3 ii B_L True []
S3 ii Q_S True []
S3 ii-bonf B True []
S3 ii-bonf B_L True []
S3 ii-bonf Q_S True []
S5 i B True []
S5 i B_L True []
S5 i Q_S True []
S5 ii B True []
S5 ii B_L True []
S5 ii Q_S True []
S5 ii-bonf B True []
S5 ii-bonf B_L True []
S5 ii-bonf Q_S True []
S6 i B True []
S6 i B_L True []
S6 i Q_S True []
S6 ii B True []
S6 ii B_L True []
S6 ii Q_S True []
S6 ii-bonf B True []
S6 ii-bonf B_L True []
S6 ii-bonf Q_S False [RSC]
subjects of 5 in which the pattern holds, per reading (4 needed):
threshold weights
i B 3
B_L 3
Q_S 3
ii B 4
B_L 4
Q_S 4
ii-bonf B 5
B_L 5
Q_S 4
subjects of 5 in which each region has the named dimension positive and above the other:
i ii ii-bonf
B B_L Q_S B B_L Q_S B B_L Q_S
FFA (human) 5 5 5 5 5 5 5 5 5
OFA (human) 5 5 5 5 5 5 5 5 5
EBA (human) 3 3 3 4 4 4 5 5 5
MT+ (human) 4 4 4 4 4 4 4 4 4
LO (human) 4 4 5 5 5 5 5 5 5
FO (human) 2 1 1 2 2 2 4 4 4
IFS (human) 2 2 2 2 2 3 5 5 5
SEF (human) 2 2 2 2 2 2 2 2 2
LOS-bodies (human) 3 3 4 5 5 5 5 5 5
ITG-bodies (human) 4 4 4 4 4 4 5 5 5
MTG-bodies (human) 3 3 4 3 3 4 5 5 5
OTS-bodies (human) 3 3 3 3 3 3 4 4 4
FFC (HCP) (human) 5 5 5 5 5 5 5 5 5
RSC (vehicle) 5 5 5 5 5 5 5 5 4
PPA (vehicle) 5 5 5 5 5 5 5 5 5
OPA (vehicle) 5 5 5 5 5 5 5 5 5
IPS (vehicle) 5 5 5 5 5 5 5 5 5
FEF (vehicle) 3 3 2 2 3 2 3 3 2
IFS (vehicle) 3 3 3 3 3 2 0 0 0
FO (vehicle) 3 3 3 3 3 3 1 1 1
PHA1-3 (HCP) (vehicle) 5 5 5 5 5 5 5 5 5
POS1 (HCP) (vehicle) 4 4 4 4 4 4 4 4 4
mean weights, threshold (i), OLS weights B (human / vehicle):
subject S1 S2 S3 S5 S6
region
FFA +0.466 / +0.176 +0.331 / +0.158 +0.387 / +0.145 +0.542 / +0.103 +0.735 / +0.191
OFA +0.475 / +0.145 +0.441 / +0.178 +0.278 / +0.093 +0.368 / -0.115 +0.472 / +0.008
EBA +0.295 / +0.278 +0.335 / +0.416 +0.313 / +0.314 +0.582 / +0.297 +0.512 / +0.300
MT+ +0.177 / +0.419 +0.666 / +0.295 +0.413 / +0.315 +0.701 / +0.499 +0.872 / +0.366
PPA -0.060 / +0.751 +0.257 / +0.886 +0.162 / +0.623 +0.108 / +0.840 +0.128 / +0.800
OPA -0.042 / +0.733 +0.094 / +0.884 +0.180 / +0.580 -0.047 / +0.701 -0.028 / +0.571
RSC -0.266 / +0.259 -0.029 / +0.250 -0.074 / +0.075 -0.175 / +0.336 -0.107 / +0.177
LO +0.489 / +0.417 +0.594 / +0.381 +0.344 / +0.346 +0.407 / +0.286 +0.718 / +0.362
FO -0.218 / +0.044 -0.036 / +0.210 +0.002 / -0.023 +0.055 / +0.193 +0.158 / +0.083
IFS +0.148 / +0.001 +0.135 / +0.353 +0.058 / +0.193 +0.145 / +0.293 +0.259 / +0.164
IPS -0.331 / +0.500 -0.020 / +0.702 +0.093 / +0.420 -0.037 / +0.467 +0.299 / +0.551
FEF +0.253 / +0.380 +0.478 / +0.761 +0.469 / +0.447 +0.430 / +0.457 +0.691 / +0.589
SEF +0.035 / +0.317 +0.387 / +0.491 +0.141 / +0.113 +0.163 / +0.467 +0.539 / +0.484
LOS-bodies +0.592 / +0.504 +0.544 / +0.563 +0.309 / +0.352 +0.490 / +0.426 +0.684 / +0.495
ITG-bodies +0.354 / +0.281 +0.105 / +0.315 +0.264 / +0.216 +0.563 / +0.250 +0.554 / +0.260
MTG-bodies +0.017 / +0.113 +0.430 / +0.417 +0.366 / +0.390 +0.668 / +0.254 +0.344 / +0.202
OTS-bodies -0.033 / +0.064 -0.292 / +0.008 +0.345 / +0.155 +0.217 / +0.045 +0.818 / +0.118
FFC (HCP) +0.525 / +0.165 +0.619 / +0.164 +0.455 / +0.111 +0.695 / +0.023 +0.835 / +0.184
PHA1-3 (HCP) +0.004 / +0.502 +0.188 / +0.669 +0.124 / +0.548 +0.040 / +0.704 +0.087 / +0.559
POS1 (HCP) +0.199 / +0.361 +0.400 / +0.306 +0.076 / +0.344 +0.332 / +0.618 +0.153 / +0.618
mean weights, threshold (ii), OLS weights B (human / vehicle):
subject S1 S2 S3 S5 S6
region
FFA +0.530 / +0.178 +0.453 / +0.140 +0.468 / +0.181 +0.676 / +0.096 +0.838 / +0.194
OFA +0.513 / +0.161 +0.508 / +0.152 +0.333 / +0.097 +0.555 / -0.076 +0.513 / -0.001
EBA +0.399 / +0.320 +0.389 / +0.430 +0.418 / +0.374 +0.708 / +0.313 +0.561 / +0.325
MT+ +0.208 / +0.458 +0.676 / +0.300 +0.491 / +0.349 +0.749 / +0.506 +0.893 / +0.365
PPA -0.052 / +0.838 +0.287 / +0.963 +0.215 / +0.669 +0.114 / +0.934 +0.166 / +0.874
OPA -0.056 / +0.801 +0.153 / +1.000 +0.237 / +0.628 -0.047 / +0.755 +0.004 / +0.659
RSC -0.396 / +0.225 +0.064 / +0.263 +0.006 / +0.048 -0.224 / +0.448 -0.036 / +0.252
LO +0.504 / +0.422 +0.682 / +0.407 +0.436 / +0.408 +0.507 / +0.346 +0.745 / +0.371
FO -0.344 / +0.041 +0.019 / +0.287 +0.082 / +0.028 +0.351 / +0.452 +0.302 / +0.149
IFS +0.181 / +0.001 +0.301 / +0.376 +0.227 / +0.267 +0.337 / +0.377 +0.458 / +0.273
IPS -0.374 / +0.581 +0.058 / +0.811 +0.199 / +0.578 -0.015 / +0.551 +0.380 / +0.625
FEF +0.374 / +0.500 +0.589 / +0.870 +0.485 / +0.477 +0.694 / +0.629 +0.748 / +0.632
SEF +0.100 / +0.420 +0.566 / +0.631 +0.236 / +0.199 +0.346 / +0.632 +0.705 / +0.607
LOS-bodies +0.610 / +0.513 +0.590 / +0.571 +0.493 / +0.448 +0.632 / +0.452 +0.703 / +0.512
ITG-bodies +0.402 / +0.284 +0.159 / +0.307 +0.351 / +0.252 +0.666 / +0.251 +0.604 / +0.270
MTG-bodies +0.126 / +0.138 +0.460 / +0.443 +0.436 / +0.443 +0.804 / +0.286 +0.399 / +0.237
OTS-bodies +0.014 / +0.016 -0.289 / -0.009 +0.381 / +0.174 +0.624 / +0.046 +0.916 / +0.132
FFC (HCP) +0.581 / +0.177 +0.701 / +0.152 +0.505 / +0.135 +0.852 / +0.014 +0.962 / +0.187
PHA1-3 (HCP) +0.034 / +0.577 +0.243 / +0.831 +0.191 / +0.690 +0.092 / +0.879 +0.139 / +0.746
POS1 (HCP) +0.228 / +0.450 +0.556 / +0.430 +0.202 / +0.530 +0.361 / +0.706 +0.197 / +0.663
mean weights, threshold (ii-bonf), OLS weights B (human / vehicle):
subject S1 S2 S3 S5 S6
region
FFA +0.654 / +0.172 +0.518 / +0.155 +0.589 / +0.187 +0.780 / +0.072 +0.992 / +0.151
OFA +0.632 / +0.247 +0.602 / +0.107 +0.453 / +0.161 +0.703 / +0.054 +0.556 / +0.083
EBA +0.521 / +0.375 +0.510 / +0.451 +0.496 / +0.411 +0.812 / +0.322 +0.686 / +0.373
MT+ +0.204 / +0.509 +0.754 / +0.343 +0.532 / +0.359 +0.859 / +0.489 +0.978 / +0.354
PPA -0.079 / +1.005 +0.342 / +1.041 +0.268 / +0.723 +0.160 / +1.050 +0.199 / +0.978
OPA -0.124 / +0.928 +0.185 / +1.054 +0.299 / +0.707 +0.008 / +0.827 +0.114 / +0.729
RSC -0.531 / +0.215 +0.190 / +0.203 -0.049 / +0.020 +0.008 / +0.714 +0.391 / +0.462
LO +0.537 / +0.460 +0.774 / +0.416 +0.504 / +0.456 +0.553 / +0.419 +0.768 / +0.405
FO -0.344 / +0.136 +0.701 / +0.511 +0.052 / -0.073 +0.724 / +0.708 +0.449 / +0.344
IFS +0.227 / +0.045 +0.741 / +0.286 +0.487 / +0.315 +0.689 / +0.500 +0.685 / +0.381
IPS -0.369 / +0.632 +0.209 / +0.952 +0.286 / +0.718 +0.152 / +0.729 +0.484 / +0.711
FEF +0.491 / +0.625 +0.677 / +0.894 +0.551 / +0.579 +0.838 / +0.713 +0.777 / +0.670
SEF +0.235 / +0.563 +0.791 / +0.897 +0.452 / +0.363 +0.630 / +0.720 +0.810 / +0.680
LOS-bodies +0.627 / +0.523 +0.636 / +0.579 +0.549 / +0.479 +0.676 / +0.464 +0.732 / +0.519
ITG-bodies +0.500 / +0.307 +0.310 / +0.278 +0.436 / +0.283 +0.809 / +0.229 +0.694 / +0.291
MTG-bodies +0.343 / +0.231 +0.579 / +0.493 +0.516 / +0.481 +0.901 / +0.320 +0.615 / +0.327
OTS-bodies +0.278 / -0.012 -0.200 / -0.007 +0.485 / +0.194 +0.998 / -0.008 +1.087 / +0.143
FFC (HCP) +0.700 / +0.174 +0.798 / +0.144 +0.607 / +0.161 +0.911 / +0.028 +1.055 / +0.158
PHA1-3 (HCP) +0.049 / +0.837 +0.314 / +1.000 +0.214 / +0.835 +0.338 / +1.074 +0.141 / +1.057
POS1 (HCP) +0.427 / +0.695 +0.692 / +0.595 +0.271 / +0.688 +0.467 / +0.961 +0.306 / +0.774
EBA, human minus vehicle weight per subject (the region the outcome rests on):
subject S1 S2 S3 S5 S6
threshold weights
i B 0.0164 -0.0808 -0.0011 0.2850 0.2120
B_L 0.0052 -0.0856 -0.0107 0.2899 0.2213
Q_S -0.0000 -0.0005 0.0014 0.0034 0.0034
ii B 0.0785 -0.0405 0.0441 0.3948 0.2362
B_L 0.0646 -0.0477 0.0298 0.3992 0.2429
Q_S 0.0005 -0.0002 0.0023 0.0045 0.0037
ii-bonf B 0.1458 0.0596 0.0846 0.4901 0.3128
B_L 0.1309 0.0491 0.0649 0.4941 0.3126
Q_S 0.0011 0.0007 0.0030 0.0055 0.0047
range of every mean weight shown: {'B': (-0.5308, 1.0869), 'B_L': (-0.5268, 1.0731), 'Q_S': (-0.0045, 0.0099)}
Result: reproduced under one reading, resting on assumptions about the regions and on the encoding-model threshold. With the encoding-model threshold (ii), the human-presence weight is positive and above the vehicle-presence weight in FFA, OFA and EBA, and the reverse holds in RSC, PPA and OPA, in 4 of 5 subjects under each of the three weight readings (B, B_L, Q_S); S2 fails in EBA (human minus vehicle weight -0.041 for B, -0.048 for B_L). Without a threshold (i) the pattern holds in 3 of 5 under each reading: EBA fails in S2 and S3 (B, B_L) or S1 and S2 (Q_S); S3's failure under B is a near tie (0.313 against 0.314). The outcome therefore hinges on the threshold. Under (ii) the margins in EBA of the subjects that pass are small in S1 and S3 (B 0.079 and 0.044, B_L 0.065 and 0.030) and large in S5 and S6 (0.24 to 0.40). The t test behind threshold (ii) treats the 5400 TRs as independent, which they are not, so it passes many voxels (57 to 71% of the region voxels). In a variant not in the claims file, a far stricter threshold, Bonferroni over each subject's region voxels (1638 to 2724 voxels pass), the pattern holds in 5 of 5 subjects for B and B_L and in 4 of 5 for Q_S (S6 fails in RSC), and EBA holds in all five under every reading; so the outcome does not rest on the liberal test, but it does rest on thresholding the voxels by the encoding model at all. FFA, OFA, PPA and OPA hold in all five subjects under every reading, and RSC under every reading but one; EBA's atlas definition (the lateral body areas of visfAtlas) is an assumption: LOS-bodies alone holds in 5 of 5 under (ii). Of the other regions the claim names, MT+ (4 of 5) and LO (4 or 5) follow the human-presence dimension and IPS (5 of 5) the vehicle-presence dimension; SEF, FEF, FO and IFS are mixed (counts above). The regions are group-atlas areas, not the subjects' localizer ROIs, and the WordNet model's ridge parameter was chosen per subject (1e3 or 1e4).
Video game task¶
States with no TRs are dropped (flash in S7; Supplementary Figure 4 shows no flash weights for that subject), so S7's state space has 8 dimensions. Because the JSD is unchanged by affine maps, the CSI does not depend on the order or signs of the dimensions; the dataset's column order is used. Both subjects' BOLD is z-scored per voxel over the session, as the paper's Methods say ("The detrended voxel responses were normalized to zero mean and unit variance", Preprocessing and Visualization); S1's data are already z-scored, S7's are not. S7 as stored, the analysis of the earlier rounds, is shown as a variant after game-weights-two-groups.
game-csi¶
In the video game task the behavioural states are distinctly and significantly separated in the 9-dimensional state space, with CSI 0.72 in subject S1 and 0.62 in S7.
rng = np.random.default_rng(4)
exp_g = {"S1": (0.72, 0.072), "S7": (0.62, 0.062)}
game_csi = {}
for s in ss.GAME_SUBJECTS:
X, names = ss.game_matrix(game[s]["X"], game[s]["labels"], "dataset")
Z = game[s]["Z"]
pos = ss.positions(Z, X)
for reading in "abc":
mem, nm, dropped = ss.game_members(X, names, reading)
vals = [ss.csi(pos, mem, np.random.default_rng(k)) for k in range(10)]
null = []
for _ in range(N_PERM):
Xp = X[rng.permutation(len(X))]
memp, _, _ = ss.game_members(Xp, names, reading)
null.append(ss.csi(ss.positions(Z, Xp), memp, rng))
null = np.array(null)
game_csi[s, reading] = np.mean(vals)
e, tol = exp_g[s]
print(f"{s} reading {reading}: {len(mem)} clusters (sizes {[int(m.sum()) for m in mem]}; dropped {dropped}); "
f"CSI {np.mean(vals):.3f} (seed SD {np.std(vals):.3f}); expected {e} +/- {tol}, within: {abs(np.mean(vals)-e) <= tol}; "
f"null mean {null.mean():.3f}, max {null.max():.3f}; above every null value: {np.mean(vals) > null.max()}")
print(f"elapsed {time.time()-T0:.0f} s")
S1 reading a: 8 clusters (sizes [72, 183, 488, 812, 53, 141, 208, 64]; dropped [('flash', 9)]); CSI 0.694 (seed SD 0.003); expected 0.72 +/- 0.072, within: True; null mean 0.192, max 0.258; above every null value: True
S1 reading b: 7 clusters (sizes [58, 142, 477, 762, 41, 141, 208]; dropped [('flash', 1), ('kill', 0)]); CSI 0.702 (seed SD 0.004); expected 0.72 +/- 0.072, within: True; null mean 0.202, max 0.270; above every null value: True
S1 reading c: 3 clusters (sizes [488, 72, 1390]; dropped []); CSI 0.513 (seed SD 0.008); expected 0.72 +/- 0.072, within: False; null mean 0.133, max 0.268; above every null value: True
S7 reading a: 8 clusters (sizes [160, 199, 265, 414, 16, 75, 176, 119]; dropped []); CSI 0.549 (seed SD 0.003); expected 0.62 +/- 0.062, within: False; null mean 0.232, max 0.295; above every null value: True
S7 reading b: 6 clusters (sizes [53, 122, 203, 305, 42, 123]; dropped [('run away', 4), ('kill', 2)]); CSI 0.582 (seed SD 0.003); expected 0.62 +/- 0.062, within: True; null mean 0.195, max 0.259; above every null value: True
S7 reading c: 3 clusters (sizes [265, 160, 897]; dropped []); CSI 0.386 (seed SD 0.010); expected 0.62 +/- 0.062, within: False; null mean 0.075, max 0.118; above every null value: True elapsed 2333 s
# Variant (asked by the verifier): labels moved one TR later (BOLD at TR t+1 paired with the state at t),
# since the game data are not deconvolved. 200 permutations per reading.
rng = np.random.default_rng(41)
for s in ss.GAME_SUBJECTS:
X, names = ss.game_matrix(game[s]["X"], game[s]["labels"], "dataset")
X1 = np.roll(X, 1, axis=0)
X1[0] = 0
Z = game[s]["Z"]
pos = ss.positions(Z, X1)
for reading in "abc":
mem, nm, dropped = ss.game_members(X1, names, reading)
v = np.mean([ss.csi(pos, mem, np.random.default_rng(k)) for k in range(10)])
null = np.array([ss.csi(ss.positions(Z, Xp), ss.game_members(Xp, names, reading)[0], rng)
for Xp in (X1[rng.permutation(len(X1))] for _ in range(200))])
e, tol = exp_g[s]
print(f"{s} lag +1 reading {reading}: CSI {v:.3f} (lag 0: {game_csi[s, reading]:.3f}); expected {e} +/- {tol}, "
f"within: {abs(v - e) <= tol}; null max {null.max():.3f}; above every null value: {v > null.max()}")
S1 lag +1 reading a: CSI 0.728 (lag 0: 0.694); expected 0.72 +/- 0.072, within: True; null max 0.223; above every null value: True
S1 lag +1 reading b: CSI 0.760 (lag 0: 0.702); expected 0.72 +/- 0.072, within: True; null max 0.265; above every null value: True
S1 lag +1 reading c: CSI 0.593 (lag 0: 0.513); expected 0.72 +/- 0.072, within: False; null max 0.227; above every null value: True
S7 lag +1 reading a: CSI 0.564 (lag 0: 0.549); expected 0.62 +/- 0.062, within: True; null max 0.292; above every null value: True
S7 lag +1 reading b: CSI 0.584 (lag 0: 0.582); expected 0.62 +/- 0.062, within: True; null max 0.258; above every null value: True
S7 lag +1 reading c: CSI 0.416 (lag 0: 0.386); expected 0.62 +/- 0.062, within: False; null max 0.103; above every null value: True
Result: reproduced under one reading of the clusters. With one cluster per state from TRs that have exactly one state (reading b), the CSI is 0.702 in S1 and 0.582 in S7, within tolerance of 0.72 and 0.62, and both exceed every null value (null maxima 0.270 and 0.259). With every TR in the cluster of each of its states (reading a), S1 is within (0.694) and S7 just outside (0.549, tolerance down to 0.558). With the three groups of Figure 3A (reading c), both are lower (0.513 and 0.386). All six values exceed their nulls. With the labels moved one TR later, where the CSI peaks, readings (a) and (b) are within tolerance in both subjects (S1 0.728 and 0.760, S7 0.564 and 0.584, each above all 200 null values) and reading (c) is not (0.593 and 0.416). With S7 as stored, not z-scored, the S7 values are 0.549, 0.581 and 0.388 (variant below): the same conclusions.
game-mutual-negative-projection¶
The mutually exclusive states engage close and safe explore each project negatively onto the other's dimension of the video game state space.
Readings of the claims file: sign (a) each dimension oriented so its own state's TRs have a positive mean, (b) the diagonal of R positive; order of the variables in the QR (i) Table 1, (ii) the data set's columns. Null: the rows of the state matrix permuted and refitted, 20,000 times (shared with fig3b-state-relations), one-sided for a negative mean.
N_PERM_G = 20000
rng = np.random.default_rng(5)
proj = {}
for s in ss.GAME_SUBJECTS:
Z = game[s]["Z"]
for order in ["table1", "dataset"]:
X, names = ss.game_matrix(game[s]["X"], game[s]["labels"], order)
perms = [rng.permutation(len(X)) for _ in range(N_PERM_G)]
for sign in ["own", "diag"]:
M = ss.projection_matrix(ss.positions(Z, X, sign), X)
null = np.array([ss.projection_matrix(ss.positions(Z, X[p], sign), X[p]) for p in perms])
proj[s, order, sign] = (M, null, names)
rows = []
for (s, order, sign), (M, null, names) in proj.items():
i, j = names.index("engage close"), names.index("safe explore")
p1 = (1 + (null[:, i, j] <= M[i, j]).sum()) / (N_PERM_G + 1)
p2 = (1 + (null[:, j, i] <= M[j, i]).sum()) / (N_PERM_G + 1)
rows.append(dict(subject=s, order=order, sign=sign, ec_on_se=M[i, j], p_ec_on_se=p1, se_on_ec=M[j, i], p_se_on_ec=p2,
both_negative_p05=(M[i, j] < 0) and (M[j, i] < 0) and p1 < 0.05 and p2 < 0.05))
mn = pd.DataFrame(rows)
print(mn.round(5).to_string(index=False))
print("\nreadings with both means negative and p < 0.05 in both subjects:")
print(mn.groupby(["order", "sign"]).both_negative_p05.sum().to_string())
print(f"elapsed {time.time()-T0:.0f} s")
subject order sign ec_on_se p_ec_on_se se_on_ec p_se_on_ec both_negative_p05
S1 table1 own -0.69727 0.00005 -0.06841 0.00005 True
S1 table1 diag -0.69727 0.00005 -0.06841 0.00005 True
S1 dataset own -1.18723 0.00005 -0.39853 0.00005 True
S1 dataset diag -1.18723 0.00005 -0.39853 0.00005 True
S7 table1 own -0.55517 0.00005 -0.01640 0.95195 False
S7 table1 diag -0.55517 0.00005 -0.01640 0.95195 False
S7 dataset own -0.18978 0.00005 -0.55017 0.00005 True
S7 dataset diag -0.18978 0.00005 -0.55017 0.00005 True
readings with both means negative and p < 0.05 in both subjects:
order sign
dataset diag 2
own 2
table1 diag 1
own 1
elapsed 2491 s
Result: reproduced, resting on an assumption about the order of the variables. With the variables in the order of the data set's columns, engage-close TRs lie at -1.187 (S1) and -0.190 (S7) on the safe-explore dimension, and safe-explore TRs at -0.399 (S1) and -0.550 (S7) on the engage-close dimension, all with p = 5e-5, the bound of 20,000 permutations, under both sign readings. With the order of Table 1, S1 holds (-0.697 and -0.068, p = 5e-5) but in S7 safe explore lies at -0.016 on the engage-close dimension (p = 0.952), so the claim would hold in one subject only. The sign readings give the same values. With S7 as stored the values are -0.191 and -0.548 (data set order, p = 5e-5) and -0.018 (Table 1 order, p = 0.936): the same conclusions.
fig3b-state-relations¶
States of the video game project at significant non-zero positions on other states' dimensions, an asymmetric pattern found in both subjects that differs between them.
For each ordered pair of different states, the mean position of the row state's TRs on the column state's dimension, two-sided permutation p from the same 20,000 permutations; Bonferroni over (a) the off-diagonal pairs or (b) every cell, at 0.01.
res3b = {}
for (s, order, sign), (M, null, names) in proj.items():
d = len(names)
p0 = (1 + (np.abs(null) >= np.abs(M)[None]).sum(0)) / (N_PERM_G + 1)
# centred on the null's mean (asked by the verifier): rows are permuted together, so the null of a pair
# of mutually exclusive states is not centred on zero
mu = null.mean(0)
pc = (1 + (np.abs(null - mu) >= np.abs(M - mu)[None]).sum(0)) / (N_PERM_G + 1)
off = ~np.eye(d, dtype=bool)
for centre, p, bonf, ntest in [(c_, p_, b_, n_) for c_, p_ in [("zero", p0), ("null mean", pc)]
for b_, n_ in [("a", d * (d - 1)), ("b", d * d)]]:
sig = (p < 0.01 / ntest) & off
asym = int((sig != sig.T).sum() // 2)
res3b[s, order, sign, bonf, centre] = (sig, names)
print(f"{s} order {order:7s} sign {sign:4s} centre {centre:9s} Bonferroni {bonf} ({ntest} tests, threshold {0.01/ntest:.2e}): "
f"{int(sig.sum())} significant off-diagonal pairs; pairs significant in one direction only: {asym}")
print(f"smallest attainable p: {1/(N_PERM_G+1):.2e}")
for order in ["table1", "dataset"]:
for sign in ["own", "diag"]:
for bonf, centre in [(b_, c_) for b_ in "ab" for c_ in ["zero", "null mean"]]:
s1, n1 = res3b["S1", order, sign, bonf, centre]
s7, n7 = res3b["S7", order, sign, bonf, centre]
set1 = {(n1[i], n1[j]) for i, j in zip(*np.nonzero(s1))}
set7 = {(n7[i], n7[j]) for i, j in zip(*np.nonzero(s7))}
print(f"order {order:7s} sign {sign:4s} centre {centre:9s} Bonferroni {bonf}: S1 {len(set1)}, S7 {len(set7)}, shared {len(set1 & set7)}, "
f"sets differ: {set1 != set7}")
M, null, names = proj["S1", "table1", "own"]
print("\nS1, Table 1 order, own sign: mean position of row state's TRs on column dimension")
print(pd.DataFrame(M, index=names, columns=names).round(2).to_string())
M, null, names = proj["S7", "table1", "own"]
print("\nS7, Table 1 order, own sign")
print(pd.DataFrame(M, index=names, columns=names).round(2).to_string())
for s in ss.GAME_SUBJECTS:
sig, names = res3b[s, "table1", "own", "a", "zero"]
print(f"\n{s} significant pairs (Table 1 order, own sign, Bonferroni a), row state -> column dimension:")
print(pd.DataFrame(np.where(sig, "x", "."), index=names, columns=names).to_string())
S1 order table1 sign own centre zero Bonferroni a (72 tests, threshold 1.39e-04): 45 significant off-diagonal pairs; pairs significant in one direction only: 11
S1 order table1 sign own centre zero Bonferroni b (81 tests, threshold 1.23e-04): 45 significant off-diagonal pairs; pairs significant in one direction only: 11
S1 order table1 sign own centre null mean Bonferroni a (72 tests, threshold 1.39e-04): 44 significant off-diagonal pairs; pairs significant in one direction only: 12
S1 order table1 sign own centre null mean Bonferroni b (81 tests, threshold 1.23e-04): 44 significant off-diagonal pairs; pairs significant in one direction only: 12
S1 order table1 sign diag centre zero Bonferroni a (72 tests, threshold 1.39e-04): 45 significant off-diagonal pairs; pairs significant in one direction only: 11
S1 order table1 sign diag centre zero Bonferroni b (81 tests, threshold 1.23e-04): 45 significant off-diagonal pairs; pairs significant in one direction only: 11
S1 order table1 sign diag centre null mean Bonferroni a (72 tests, threshold 1.39e-04): 45 significant off-diagonal pairs; pairs significant in one direction only: 11
S1 order table1 sign diag centre null mean Bonferroni b (81 tests, threshold 1.23e-04): 45 significant off-diagonal pairs; pairs significant in one direction only: 11
S1 order dataset sign own centre zero Bonferroni a (72 tests, threshold 1.39e-04): 48 significant off-diagonal pairs; pairs significant in one direction only: 20
S1 order dataset sign own centre zero Bonferroni b (81 tests, threshold 1.23e-04): 48 significant off-diagonal pairs; pairs significant in one direction only: 20
S1 order dataset sign own centre null mean Bonferroni a (72 tests, threshold 1.39e-04): 48 significant off-diagonal pairs; pairs significant in one direction only: 20
S1 order dataset sign own centre null mean Bonferroni b (81 tests, threshold 1.23e-04): 48 significant off-diagonal pairs; pairs significant in one direction only: 20
S1 order dataset sign diag centre zero Bonferroni a (72 tests, threshold 1.39e-04): 48 significant off-diagonal pairs; pairs significant in one direction only: 20
S1 order dataset sign diag centre zero Bonferroni b (81 tests, threshold 1.23e-04): 48 significant off-diagonal pairs; pairs significant in one direction only: 20
S1 order dataset sign diag centre null mean Bonferroni a (72 tests, threshold 1.39e-04): 48 significant off-diagonal pairs; pairs significant in one direction only: 20
S1 order dataset sign diag centre null mean Bonferroni b (81 tests, threshold 1.23e-04): 48 significant off-diagonal pairs; pairs significant in one direction only: 20
S7 order table1 sign own centre zero Bonferroni a (56 tests, threshold 1.79e-04): 25 significant off-diagonal pairs; pairs significant in one direction only: 9
S7 order table1 sign own centre zero Bonferroni b (64 tests, threshold 1.56e-04): 25 significant off-diagonal pairs; pairs significant in one direction only: 9
S7 order table1 sign own centre null mean Bonferroni a (56 tests, threshold 1.79e-04): 26 significant off-diagonal pairs; pairs significant in one direction only: 10
S7 order table1 sign own centre null mean Bonferroni b (64 tests, threshold 1.56e-04): 26 significant off-diagonal pairs; pairs significant in one direction only: 10
S7 order table1 sign diag centre zero Bonferroni a (56 tests, threshold 1.79e-04): 25 significant off-diagonal pairs; pairs significant in one direction only: 9
S7 order table1 sign diag centre zero Bonferroni b (64 tests, threshold 1.56e-04): 25 significant off-diagonal pairs; pairs significant in one direction only: 9
S7 order table1 sign diag centre null mean Bonferroni a (56 tests, threshold 1.79e-04): 26 significant off-diagonal pairs; pairs significant in one direction only: 10
S7 order table1 sign diag centre null mean Bonferroni b (64 tests, threshold 1.56e-04): 26 significant off-diagonal pairs; pairs significant in one direction only: 10
S7 order dataset sign own centre zero Bonferroni a (56 tests, threshold 1.79e-04): 21 significant off-diagonal pairs; pairs significant in one direction only: 11
S7 order dataset sign own centre zero Bonferroni b (64 tests, threshold 1.56e-04): 21 significant off-diagonal pairs; pairs significant in one direction only: 11
S7 order dataset sign own centre null mean Bonferroni a (56 tests, threshold 1.79e-04): 22 significant off-diagonal pairs; pairs significant in one direction only: 12
S7 order dataset sign own centre null mean Bonferroni b (64 tests, threshold 1.56e-04): 22 significant off-diagonal pairs; pairs significant in one direction only: 12
S7 order dataset sign diag centre zero Bonferroni a (56 tests, threshold 1.79e-04): 21 significant off-diagonal pairs; pairs significant in one direction only: 11
S7 order dataset sign diag centre zero Bonferroni b (64 tests, threshold 1.56e-04): 21 significant off-diagonal pairs; pairs significant in one direction only: 11
S7 order dataset sign diag centre null mean Bonferroni a (56 tests, threshold 1.79e-04): 22 significant off-diagonal pairs; pairs significant in one direction only: 12
S7 order dataset sign diag centre null mean Bonferroni b (64 tests, threshold 1.56e-04): 22 significant off-diagonal pairs; pairs significant in one direction only: 12
smallest attainable p: 5.00e-05
order table1 sign own centre zero Bonferroni a: S1 45, S7 25, shared 19, sets differ: True
order table1 sign own centre null mean Bonferroni a: S1 44, S7 26, shared 19, sets differ: True
order table1 sign own centre zero Bonferroni b: S1 45, S7 25, shared 19, sets differ: True
order table1 sign own centre null mean Bonferroni b: S1 44, S7 26, shared 19, sets differ: True
order table1 sign diag centre zero Bonferroni a: S1 45, S7 25, shared 19, sets differ: True
order table1 sign diag centre null mean Bonferroni a: S1 45, S7 26, shared 20, sets differ: True
order table1 sign diag centre zero Bonferroni b: S1 45, S7 25, shared 19, sets differ: True
order table1 sign diag centre null mean Bonferroni b: S1 45, S7 26, shared 20, sets differ: True
order dataset sign own centre zero Bonferroni a: S1 48, S7 21, shared 12, sets differ: True
order dataset sign own centre null mean Bonferroni a: S1 48, S7 22, shared 12, sets differ: True
order dataset sign own centre zero Bonferroni b: S1 48, S7 21, shared 12, sets differ: True
order dataset sign own centre null mean Bonferroni b: S1 48, S7 22, shared 12, sets differ: True
order dataset sign diag centre zero Bonferroni a: S1 48, S7 21, shared 12, sets differ: True
order dataset sign diag centre null mean Bonferroni a: S1 48, S7 22, shared 12, sets differ: True
order dataset sign diag centre zero Bonferroni b: S1 48, S7 21, shared 12, sets differ: True
order dataset sign diag centre null mean Bonferroni b: S1 48, S7 22, shared 12, sets differ: True
S1, Table 1 order, own sign: mean position of row state's TRs on column dimension
dead round start safe explore unsafe explore kill engage close engage far flash run away
dead 0.95 -0.70 -0.70 -0.51 -0.07 -0.07 -0.09 0.00 -0.04
round start 0.77 0.62 -0.70 -0.51 -0.07 -0.07 -0.09 0.00 -0.04
safe explore 0.33 0.53 0.55 -0.52 -0.04 -0.07 -0.09 0.00 -0.04
unsafe explore -0.17 -0.09 0.23 0.48 -0.02 -0.06 -0.06 0.00 -0.04
kill -1.14 -1.09 -1.06 -0.25 1.19 0.15 0.10 -0.01 0.01
engage close -1.19 -0.80 -0.70 -0.01 -0.01 0.84 -0.05 0.00 -0.04
engage far -0.92 -0.69 -0.53 0.21 0.26 0.24 0.84 -0.00 -0.02
flash -0.59 0.93 -0.72 0.54 0.11 0.62 0.46 1.89 1.31
run away -1.08 -0.52 -0.75 0.90 0.52 0.24 -0.04 -0.15 1.48
S7, Table 1 order, own sign
dead round start safe explore unsafe explore kill engage close engage far run away
dead 0.88 0.16 -0.14 -0.18 0.03 0.04 -0.05 0.00
round start 0.23 0.80 0.09 -0.09 0.05 -0.02 -0.08 -0.02
safe explore -0.45 0.11 0.78 0.00 0.04 -0.02 -0.09 -0.02
unsafe explore -0.22 -0.21 -0.02 0.46 0.01 0.00 -0.05 -0.00
kill 0.44 -0.10 -0.62 -0.80 0.37 0.28 0.09 0.05
engage close 0.32 -0.10 -0.56 -0.60 0.10 0.66 -0.10 0.03
engage far 0.31 -0.45 -0.56 -0.22 -0.33 -0.46 0.62 -0.01
run away 0.63 -0.19 -0.79 -0.85 0.73 0.71 -1.05 1.54
S1 significant pairs (Table 1 order, own sign, Bonferroni a), row state -> column dimension:
dead round start safe explore unsafe explore kill engage close engage far flash run away
dead . x x x x x x . x
round start x . x x x x x . x
safe explore x x . x x x x . x
unsafe explore x . x . . x x . x
kill x x x . . x x . x
engage close x x x . . . x . x
engage far x x x . . . . . x
flash . . . . . . . . x
run away x . x x . . . . .
S7 significant pairs (Table 1 order, own sign, Bonferroni a), row state -> column dimension:
dead round start safe explore unsafe explore kill engage close engage far run away
dead . x . x x x x .
round start . . . . . . x .
safe explore x . . . . . x .
unsafe explore x x . . . . x .
kill x . x x . . x .
engage close x . x x . . x .
engage far x x x . x x . .
run away . . . . . . x .
Result: reproduced. Under every sign, order, Bonferroni and null-centre reading, both subjects have significant off-diagonal projections (S1 44 to 48 pairs, S7 21 to 26), some pairs are significant in one direction only (9 to 20), and the two subjects' sets of significant pairs differ (12 to 20 shared). Centring the two-sided test on the null's mean in place of zero changes the counts by at most one pair. With S7 as stored (own sign, zero centre, Bonferroni a, a separate set of 20,000 permutations) S7 has 26 (Table 1 order) and 23 (data set order) significant pairs, 10 and 13 of them in one direction only. The figure's own matrix was not available to compare pair by pair.
game-classification¶
Held-out TRs of the video game task are classified into the nine behavioural states from their position in the learned state space with balanced accuracy 32.8 +/- 3.8% in S1 and 30.4 +/- 4.2% in S7, above the chance of 11%.
Folds and distance as in att-classification. Labels: (a) TRs with exactly one state only; (b) every labelled TR, a prediction correct for each of its states it names, recall per state over the TRs that have it. The state space is fitted on all training TRs with the full state matrix. Classes with no TRs are left out; for the density rule, a class needs more training TRs than dimensions, so classes with fewer than 2 x (dimensions + 1) TRs under the label reading are left out of that rule (listed below). Under labels (a) a class with too few single-state TRs in a training fold is left out of that fold, and the fold's balanced accuracy is taken over the classes it could predict (in the first run such a class was scored with a recall of 0). Null: training state rows permuted, 1000 times. As a variant, the labels moved one TR later (200 permutations).
def game_classification(s, X, names, rng, n_perm):
gc_rows, gc_null = [], {}
n, d = X.shape
nst = X.sum(1)
for scheme in ["contig", "random"]:
fs = ss.fold_scores(game[s]["G"], ss.folds(n, scheme, rng))
for lab in "ab":
use = (nst == 1) if lab == "a" else (nst >= 1)
single = np.where(nst == 1, X.argmax(1), -1)
for rule in ["euclid", "density"]:
counts = X[use].sum(0)
minc = 1 if rule == "euclid" else 2 * (d + 1)
classes = [c for c in range(d) if counts[c] >= minc]
left = [names[c] for c in range(d) if counts[c] < minc]
# held-out TRs scored under this label reading, and which of the classes each has
scored = [(use[te], X[te][use[te]][:, classes] > 0) for tr, te, Ztr, Zte in fs]
def run(perm_rng=None):
accs = []
for (tr, te, Ztr, Zte), (m, H) in zip(fs, scored):
Xtr = X[tr] if perm_rng is None else X[tr][perm_rng.permutation(len(tr))]
ptr, pte = ss.project_fold(Ztr, Zte, Xtr)
if lab == "a":
ntr = Xtr.sum(1)
lab_tr = np.where(ntr == 1, Xtr.argmax(1), -1)
cl = [c for c in classes if (lab_tr == c).sum() > (d if rule == "density" else 0)]
pred = ss.nearest_cluster(ptr, lab_tr, pte[m], cl, rule)
# score only the classes this fold could predict (a class too small to fit
# in this fold would otherwise count with a recall of 0)
accs.append(ss.balanced_accuracy(H[:, [classes.index(c) for c in cl]], pred, cl))
continue
else:
# one cluster per state from every training TR that has it
if rule == "euclid":
means = np.array([ptr[Xtr[:, c] > 0].mean(0) for c in classes])
pred = np.asarray(classes)[((pte[m][:, None] - means[None]) ** 2).sum(-1).argmin(1)]
else:
ll = np.column_stack([ss._logpdf(pte[m], *ss._fit_normal(ptr[Xtr[:, c] > 0])) for c in classes])
pred = np.asarray(classes)[ll.argmax(1)]
accs.append(ss.balanced_accuracy(H, pred, classes))
return np.array(accs)
accs = run()
null = np.array([run(rng).mean() for _ in range(n_perm)])
gc_null[s, scheme, lab, rule] = null
gc_rows.append(dict(subject=s, folds=scheme, labels=lab, rule=rule, n_classes=len(classes), left_out=left,
bal_acc=100 * accs.mean(), fold_sd=100 * accs.std(), chance=100 / len(classes),
null_mean=100 * null.mean(), null_max=100 * null.max(),
p=(1 + (null >= accs.mean()).sum()) / (n_perm + 1)))
return gc_rows, gc_null
rng = np.random.default_rng(6)
gc_rows, gc_null = [], {}
for s in ss.GAME_SUBJECTS:
t = time.time()
X, names = ss.game_matrix(game[s]["X"], game[s]["labels"], "dataset")
r_, n_ = game_classification(s, X, names, rng, N_PERM_CLF)
gc_rows += r_
gc_null.update(n_)
print(f"{s} done in {time.time()-t:.0f} s")
gcl = pd.DataFrame(gc_rows)
exp_c = {"S1": (32.8, 3.8), "S7": (30.4, 4.2)}
gcl["within"] = [abs(r.bal_acc - exp_c[r.subject][0]) <= exp_c[r.subject][1] for r in gcl.itertuples()]
gcl["above_null"] = gcl.bal_acc > gcl.null_max
print(gcl.round(4).to_string(index=False))
print("\nreadings where both subjects are within tolerance and above every null value:")
both = gcl.groupby(["folds", "labels", "rule"]).apply(lambda g: bool((g.within & g.above_null).all()), include_groups=False)
print(both.to_string())
print(f"elapsed {time.time()-T0:.0f} s, peak memory {mem_gb():.1f} GB")
S1 done in 169 s
S7 done in 127 s
subject folds labels rule n_classes left_out bal_acc fold_sd chance null_mean null_max p within above_null
S1 contig a euclid 8 [kill] 46.5060 8.7830 12.5000 13.4113 22.3661 0.001 False True
S1 contig a density 7 [flash, kill] 44.0685 8.5189 14.2857 13.6418 21.2031 0.001 False True
S1 contig b euclid 9 [] 43.8204 7.6884 11.1111 10.7915 17.6408 0.001 False True
S1 contig b density 8 [flash] 42.7645 10.0310 12.5000 11.9583 18.0857 0.001 False True
S1 random a euclid 8 [kill] 53.3891 5.6327 12.5000 13.6208 21.4246 0.001 False True
S1 random a density 7 [flash, kill] 54.6475 4.7685 14.2857 13.8561 19.2839 0.001 False True
S1 random b euclid 9 [] 47.0516 5.9075 11.1111 10.9905 16.1358 0.001 False True
S1 random b density 8 [flash] 49.0994 4.1213 12.5000 12.1439 17.2776 0.001 False True
S7 contig a euclid 8 [] 33.7230 11.9665 12.5000 12.5683 22.2882 0.001 True True
S7 contig a density 6 [run away, kill] 34.0622 14.7085 16.6667 16.1845 26.5581 0.001 True True
S7 contig b euclid 8 [] 27.1962 9.1247 12.5000 11.8910 18.3456 0.001 True True
S7 contig b density 7 [run away] 26.8852 8.8037 14.2857 14.0715 18.7377 0.001 True True
S7 random a euclid 8 [] 41.1634 7.9934 12.5000 12.3662 20.2557 0.001 False True
S7 random a density 6 [run away, kill] 46.4929 6.3174 16.6667 16.3986 22.1453 0.001 False True
S7 random b euclid 8 [] 38.0811 6.4751 12.5000 12.4562 17.6732 0.001 False True
S7 random b density 7 [run away] 36.8980 2.9684 14.2857 14.1959 18.0915 0.001 False True
readings where both subjects are within tolerance and above every null value:
folds labels rule
contig a density False
euclid False
b density False
euclid False
random a density False
euclid False
b density False
euclid False
elapsed 2786 s, peak memory 6.0 GB
# Variant (asked by the verifier): labels moved one TR later, 200 permutations per reading.
rng = np.random.default_rng(61)
rows = []
for s in ss.GAME_SUBJECTS:
X, names = ss.game_matrix(game[s]["X"], game[s]["labels"], "dataset")
X1 = np.roll(X, 1, axis=0)
X1[0] = 0
rows += game_classification(s, X1, names, rng, 200)[0]
g1 = pd.DataFrame(rows)
g1["within"] = [abs(r.bal_acc - exp_c[r.subject][0]) <= exp_c[r.subject][1] for r in g1.itertuples()]
g1["above_null"] = g1.bal_acc > g1.null_max
print(g1.drop(columns=["left_out"]).round(4).to_string(index=False))
print("readings at lag +1 where both subjects are within tolerance and above every null value:")
print(g1.groupby(["folds", "labels", "rule"]).apply(lambda g: bool((g.within & g.above_null).all()), include_groups=False).to_string())
subject folds labels rule n_classes bal_acc fold_sd chance null_mean null_max p within above_null
S1 contig a euclid 8 53.1116 9.8063 12.5000 13.2898 18.9649 0.005 False True
S1 contig a density 7 51.6198 9.8642 14.2857 13.6655 19.9476 0.005 False True
S1 contig b euclid 9 48.7849 7.6602 11.1111 10.3941 15.7307 0.005 False True
S1 contig b density 8 45.6579 8.8446 12.5000 12.0243 17.7394 0.005 False True
S1 random a euclid 8 56.6957 5.1883 12.5000 13.4896 20.2171 0.005 False True
S1 random a density 7 60.4719 7.5519 14.2857 13.9652 17.4508 0.005 False True
S1 random b euclid 9 50.4050 6.9219 11.1111 10.9283 15.2753 0.005 False True
S1 random b density 8 54.6677 5.1940 12.5000 12.1666 15.7282 0.005 False True
S7 contig a euclid 8 33.5505 15.2679 12.5000 12.2569 18.8651 0.005 True True
S7 contig a density 6 34.6877 14.8814 16.6667 16.0978 23.1078 0.005 False True
S7 contig b euclid 8 28.4908 8.4750 12.5000 11.7606 16.3959 0.005 True True
S7 contig b density 7 28.3688 10.0272 14.2857 14.3865 19.6398 0.005 True True
S7 random a euclid 8 42.7763 7.1159 12.5000 11.9229 17.4425 0.005 False True
S7 random a density 6 52.1730 5.7604 16.6667 15.8971 20.6258 0.005 False True
S7 random b euclid 8 36.0080 6.6323 12.5000 12.2082 16.7591 0.005 False True
S7 random b density 7 41.0022 5.3860 14.2857 14.2898 17.8161 0.005 False True
readings at lag +1 where both subjects are within tolerance and above every null value:
folds labels rule
contig a density False
euclid False
b density False
euclid False
random a density False
euclid False
b density False
euclid False
Result: partially reproduced. Every reading is far above its null (p = 0.001; chance under this procedure 10.8 to 16.4%, against the paper's 11%). S7's balanced accuracy is within the paper's 30.4 +/- 4.2% with contiguous folds (26.9 to 34.1%) and above it with random folds (36.9 to 46.5%). S1's is above the paper's 32.8 +/- 3.8% under every reading (42.8 to 54.6%), so no reading puts both subjects within tolerance. With the labels one TR later the accuracies rise (S1 45.7 to 60.5%, S7 28.4 to 52.2%) and the same holds. With S7 as stored, S7 gives 26.4 to 33.8% (contiguous) and 36.4 to 47.1% (random), so the outcome is the same. Random folds put neighbouring, autocorrelated TRs in training and test sets and give higher values than contiguous folds; the outcome does not depend on this, since S1 is above tolerance under both. S1's data are six whole runs of 325 TRs (65 min, data check), where the paper reports 90 min, so the S1 data may differ from those the paper analysed, which could account for S1 being above the paper's value.
game-weights-two-groups¶
The video game state dimensions fall into two groups, dead, round start, safe explore, unsafe explore and flash in TPJ, precuneus and prefrontal cortex (default-mode areas), and kill, engage close, engage far and run away in motor, premotor and supplementary motor areas, IPS, FEF and SEF; the weights are largely consistent across the two subjects.
S1's video game data (73,594 voxels) match no mapper in the data set (current or superseded, data check), so S1's weights cannot be placed on the cortex: only S7 can be tested by region, and the consistency between subjects cannot be measured. Regions from HCP-MMP1.0 on fsaverage (the assumption of att-weights-cortex; the areas of each region are listed in the helper): TPJ, precuneus and prefrontal cortex for the first group; motor, premotor and supplementary motor cortex, IPS, FEF and SEF for the second. Weights as in att-weights-cortex, Q_S under both orders of the variables. Thresholds: (i) none; (ii) voxels whose prediction by the nine-state OLS model (10 contiguous folds) correlates with the response at one-sided p < 0.05 Bonferroni-corrected over all of the subject's voxels.
A dimension of the first group counts when its mean weight is positive in each of TPJ, precuneus and prefrontal cortex and the mean over these three regions is above the mean over the six regions of the second group; a dimension of the second group, the reverse. One dimension may fail. A stricter variant asks every own region to be above every other region. The prefrontal region is large (most of the frontal lobe outside motor and premotor cortex); as a variant, the medial prefrontal areas alone (the default-mode part) replace it.
G1, G2 = ["dead", "round start", "safe explore", "unsafe explore", "flash"], ["kill", "engage close", "engage far", "run away"]
R1_, R2_ = ["TPJ", "precuneus", "prefrontal"], ["motor", "premotor", "SMA", "IPS", "FEF", "SEF"]
s = "S7"
X7, names7 = ss.game_matrix(game[s]["X"], game[s]["labels"], "dataset")
Yk = game[s]["Y_keep"].astype(np.float64)
r7 = ss.cv_ols_r(Yk, X7)
p7 = ss.r_pvalue(r7, len(X7))
sig7 = np.zeros(game[s]["n_vox"], bool)
sig7[game_keep[s][p7 < 0.05 / game[s]["n_vox"]]] = True
R_thr7, nv_thr7 = ss.region_matrix(mappers[s], atlases, ss.GAME_REGIONS, voxel_mask=sig7)
print(f"{s}: {sig7.sum()} of {len(game_keep[s])} region voxels significant (Bonferroni over {game[s]['n_vox']}); "
f"vertices per region after the threshold {dict(zip(ss.GAME_REGIONS, nv_thr7))}")
gw_rows = []
for thr, R in [("i", regmat["game", s]), ("ii", R_thr7)]:
S = Yk @ R[game_keep[s]]
for order in ["dataset", "table1"]:
Xo, nameso = ss.game_matrix(game[s]["X"], game[s]["labels"], order)
W = ss.region_weights(game[s]["Z"], Xo, S)
for reading, w in W.items():
if reading != "Q_S" and order == "table1":
continue # B and B_L do not depend on the order
for j, st_ in enumerate(nameso):
for k, reg in enumerate(ss.GAME_REGIONS):
gw_rows.append(dict(threshold=thr, weights=reading if reading != "Q_S" else f"Q_S ({order})",
state=st_, region=reg, w=w[k, j]))
gw = pd.DataFrame(gw_rows)
tab = gw[(gw.threshold == "i") & (gw.weights == "B")].pivot(index="state", columns="region", values="w")
print("\nS7 mean weights, threshold (i), OLS weights B:")
print(tab.loc[[x for x in G1 + G2 if x in tab.index], R1_ + R2_].round(3).to_string())
print("range of every mean weight:", {k: (round(float(g.w.min()), 4), round(float(g.w.max()), 4)) for k, g in gw.groupby("weights")})
S7: 5329 of 16509 region voxels significant (Bonferroni over 87000); vertices per region after the threshold {'TPJ': 4410, 'precuneus': 3320, 'prefrontal': 13235, 'motor': 2826, 'premotor': 7327, 'SMA': 2619, 'IPS': 9784, 'FEF': 1040, 'SEF': 1078, 'medial prefrontal': 1335}
S7 mean weights, threshold (i), OLS weights B:
region TPJ precuneus prefrontal motor premotor SMA IPS FEF SEF
state
dead 0.064 -0.015 -0.010 0.110 0.086 0.040 0.087 0.081 0.063
round start 0.068 0.144 0.050 0.008 0.067 -0.002 0.073 -0.040 0.039
safe explore -0.058 -0.180 -0.008 -0.073 -0.236 -0.198 -0.241 -0.198 -0.174
unsafe explore -0.011 0.080 -0.022 -0.112 -0.128 -0.068 -0.105 -0.159 -0.125
kill 0.070 0.078 0.057 0.222 0.233 0.174 0.192 0.276 0.219
engage close -0.055 -0.079 -0.027 0.104 0.094 0.173 0.060 0.179 0.142
engage far -0.029 -0.081 -0.024 -0.008 0.176 0.084 0.146 0.130 0.101
run away -0.019 0.130 -0.095 0.227 0.197 0.171 0.144 0.481 0.226
range of every mean weight: {'B': (-0.4198, 0.6036), 'B_L': (-0.3245, 0.4571), 'Q_S (dataset)': (-0.0073, 0.0055), 'Q_S (table1)': (-0.0063, 0.0048)}
rows = []
for (thr, reading), g in gw.groupby(["threshold", "weights"]):
t_ = g.pivot(index="state", columns="region", values="w")
fails, fails_strict = [], []
for st_ in t_.index:
own, other = (R1_, R2_) if st_ in G1 else (R2_, R1_)
ok = (t_.loc[st_, own] > 0).all() and t_.loc[st_, own].mean() > t_.loc[st_, other].mean()
ok_strict = (t_.loc[st_, own] > 0).all() and t_.loc[st_, own].min() > t_.loc[st_, other].max()
if not ok: fails.append(st_)
if not ok_strict: fails_strict.append(st_)
rows.append(dict(threshold=thr, weights=reading, n_dims=len(t_), failing=fails, holds=len(fails) <= 1,
failing_strict=fails_strict, holds_strict=len(fails_strict) <= 1))
gwc = pd.DataFrame(rows)
print("S7: dimensions failing the grouping (one may fail):")
print(gwc.to_string(index=False))
def grouping_fails(gw_, r1):
out = {}
for (thr, reading), g in gw_.groupby(["threshold", "weights"]):
t_ = g.pivot(index="state", columns="region", values="w")
out[thr, reading] = [st_ for st_ in t_.index
if not (lambda own, other: (t_.loc[st_, own] > 0).all() and t_.loc[st_, own].mean() > t_.loc[st_, other].mean())(
*((r1, R2_) if st_ in G1 else (R2_, r1)))]
return out
# Variant not from the paper: the medial prefrontal areas only in place of the whole prefrontal region
print("\nS7, medial prefrontal in place of prefrontal: dimensions failing (one may fail)")
for k, v in grouping_fails(gw, ["TPJ", "precuneus", "medial prefrontal"]).items():
print(f" threshold {k[0]:3s} {k[1]:14s} {len(v)} failing: {v}")
# Variant not from the paper: correlation across all voxels between the weight maps of every pair of
# dimensions, average-linkage clustering on 1 - r cut into two groups (both subjects; no mapper needed)
from scipy.cluster import hierarchy
from scipy.spatial.distance import squareform
for s in ss.GAME_SUBJECTS:
for key in ["B_vox", "BL_vox"]:
r = np.corrcoef(game[s][key])
cut = hierarchy.fcluster(hierarchy.linkage(squareform(1 - r, checks=False), "average"), 2, "maxclust")
nm = game[s]["map_names"]
print(f"\n{s} {key[:-4]} maps: clusters", {k: [nm[i] for i in np.nonzero(cut == k)[0]] for k in (1, 2)})
print(pd.DataFrame(r, index=nm, columns=nm).round(2).to_string())
S7: dimensions failing the grouping (one may fail):
threshold weights n_dims failing holds failing_strict holds_strict
i B 8 [dead, engage far, safe explore, unsafe explore] False [dead, engage far, round start, safe explore, unsafe explore] False
i B_L 8 [dead, safe explore, unsafe explore] False [dead, round start, safe explore, unsafe explore] False
i Q_S (dataset) 8 [dead, engage far, run away, safe explore, unsafe explore] False [dead, engage far, kill, run away, safe explore, unsafe explore] False
i Q_S (table1) 8 [dead, engage close, run away, safe explore, unsafe explore] False [dead, engage close, engage far, kill, run away, safe explore, unsafe explore] False
ii B 8 [dead, safe explore, unsafe explore] False [dead, safe explore, unsafe explore] False
ii B_L 8 [dead, safe explore, unsafe explore] False [dead, safe explore, unsafe explore] False
ii Q_S (dataset) 8 [dead, round start, run away, safe explore, unsafe explore] False [dead, round start, run away, safe explore, unsafe explore] False
ii Q_S (table1) 8 [dead, engage close, run away, safe explore, unsafe explore] False [dead, engage close, kill, run away, safe explore, unsafe explore] False
S7, medial prefrontal in place of prefrontal: dimensions failing (one may fail)
threshold i B 4 failing: ['dead', 'engage far', 'safe explore', 'unsafe explore']
threshold i B_L 3 failing: ['dead', 'safe explore', 'unsafe explore']
threshold i Q_S (dataset) 5 failing: ['dead', 'engage far', 'run away', 'safe explore', 'unsafe explore']
threshold i Q_S (table1) 5 failing: ['dead', 'engage close', 'run away', 'safe explore', 'unsafe explore']
threshold ii B 3 failing: ['dead', 'safe explore', 'unsafe explore']
threshold ii B_L 3 failing: ['dead', 'safe explore', 'unsafe explore']
threshold ii Q_S (dataset) 5 failing: ['dead', 'round start', 'run away', 'safe explore', 'unsafe explore']
threshold ii Q_S (table1) 5 failing: ['dead', 'engage close', 'run away', 'safe explore', 'unsafe explore']
S1 B maps: clusters {1: ['flash', 'engage close', 'engage far', 'safe explore', 'unsafe explore', 'run away', 'dead', 'round start'], 2: ['kill']}
flash engage close engage far safe explore unsafe explore run away dead round start kill
flash 1.00 0.03 -0.00 0.29 0.16 -0.23 0.12 0.30 -0.23
engage close 0.03 1.00 0.59 0.12 0.41 0.46 -0.02 0.00 -0.03
engage far -0.00 0.59 1.00 0.06 0.39 0.49 -0.00 -0.03 0.13
safe explore 0.29 0.12 0.06 1.00 0.78 0.02 0.63 0.81 -0.63
unsafe explore 0.16 0.41 0.39 0.78 1.00 0.43 0.51 0.58 -0.57
run away -0.23 0.46 0.49 0.02 0.43 1.00 -0.01 -0.03 0.06
dead 0.12 -0.02 -0.00 0.63 0.51 -0.01 1.00 0.78 -0.33
round start 0.30 0.00 -0.03 0.81 0.58 -0.03 0.78 1.00 -0.46
kill -0.23 -0.03 0.13 -0.63 -0.57 0.06 -0.33 -0.46 1.00
S1 BL maps: clusters {1: ['flash', 'safe explore', 'unsafe explore', 'dead', 'round start'], 2: ['engage close', 'engage far', 'run away', 'kill']}
flash engage close engage far safe explore unsafe explore run away dead round start kill
flash 1.00 -0.01 -0.05 0.44 0.18 -0.28 0.13 0.49 -0.37
engage close -0.01 1.00 0.56 -0.16 0.28 0.53 -0.41 -0.34 -0.09
engage far -0.05 0.56 1.00 -0.23 0.20 0.49 -0.30 -0.34 0.12
safe explore 0.44 -0.16 -0.23 1.00 0.75 -0.18 0.59 0.81 -0.82
unsafe explore 0.18 0.28 0.20 0.75 1.00 0.33 0.41 0.52 -0.78
run away -0.28 0.53 0.49 -0.18 0.33 1.00 -0.23 -0.22 0.08
dead 0.13 -0.41 -0.30 0.59 0.41 -0.23 1.00 0.81 -0.43
round start 0.49 -0.34 -0.34 0.81 0.52 -0.22 0.81 1.00 -0.61
kill -0.37 -0.09 0.12 -0.82 -0.78 0.08 -0.43 -0.61 1.00
S7 B maps: clusters {1: ['safe explore', 'unsafe explore'], 2: ['engage close', 'engage far', 'run away', 'dead', 'round start', 'kill']}
engage close engage far safe explore unsafe explore run away dead round start kill
engage close 1.00 0.27 -0.48 -0.36 0.29 0.23 -0.04 0.04
engage far 0.27 1.00 -0.51 -0.14 -0.06 0.27 -0.18 -0.09
safe explore -0.48 -0.51 1.00 0.22 -0.33 -0.42 -0.13 -0.24
unsafe explore -0.36 -0.14 0.22 1.00 -0.27 -0.32 -0.31 -0.45
run away 0.29 -0.06 -0.33 -0.27 1.00 0.25 0.04 0.35
dead 0.23 0.27 -0.42 -0.32 0.25 1.00 0.17 0.21
round start -0.04 -0.18 -0.13 -0.31 0.04 0.17 1.00 0.08
kill 0.04 -0.09 -0.24 -0.45 0.35 0.21 0.08 1.00
S7 BL maps: clusters {1: ['safe explore', 'unsafe explore'], 2: ['engage close', 'engage far', 'run away', 'dead', 'round start', 'kill']}
engage close engage far safe explore unsafe explore run away dead round start kill
engage close 1.00 0.32 -0.61 -0.47 0.51 0.30 -0.03 0.28
engage far 0.32 1.00 -0.59 -0.16 -0.08 0.34 -0.26 -0.06
safe explore -0.61 -0.59 1.00 0.26 -0.47 -0.55 -0.15 -0.32
unsafe explore -0.47 -0.16 0.26 1.00 -0.41 -0.45 -0.40 -0.61
run away 0.51 -0.08 -0.47 -0.41 1.00 0.35 0.03 0.60
dead 0.30 0.34 -0.55 -0.45 0.35 1.00 0.31 0.27
round start -0.03 -0.26 -0.15 -0.40 0.03 0.31 1.00 0.12
kill 0.28 -0.06 -0.32 -0.61 0.60 0.27 0.12 1.00
# Variant: S7's video game BOLD as stored, without the z-scoring per voxel the paper describes (the analysis
# of the first two rounds, asked by the verifier to see what rests on it). The same measures for S7, with
# fewer permutations: game-csi (200), the two projections and fig3b pair counts (20,000, own sign, zero
# centre, Bonferroni a), game-classification (200) and the grouping of game-weights-two-groups.
t = time.time()
rng = np.random.default_rng(71)
raw = ss.load_game("S7", keep=game_keep["S7"], zscore=False)
raw["Z"] = ss.pca_scores(raw["G"], np.arange(len(raw["G"])))[0]
X, names = ss.game_matrix(raw["X"], raw["labels"], "dataset")
pos = ss.positions(raw["Z"], X)
for reading in "abc":
mem = ss.game_members(X, names, reading)[0]
v = np.mean([ss.csi(pos, mem, np.random.default_rng(k)) for k in range(10)])
null = np.array([ss.csi(ss.positions(raw["Z"], Xp), ss.game_members(Xp, names, reading)[0], rng)
for Xp in (X[rng.permutation(len(X))] for _ in range(200))])
print(f"S7 as stored, game-csi reading {reading}: CSI {v:.3f} (z-scored: {game_csi['S7', reading]:.3f}); "
f"within 0.62 +/- 0.062: {abs(v - 0.62) <= 0.062}; null max {null.max():.3f}")
for order in ["dataset", "table1"]:
Xo, nameso = ss.game_matrix(raw["X"], raw["labels"], order)
perms = [rng.permutation(len(Xo)) for _ in range(N_PERM_G)]
M = ss.projection_matrix(ss.positions(raw["Z"], Xo, "own"), Xo)
null = np.array([ss.projection_matrix(ss.positions(raw["Z"], Xo[q], "own"), Xo[q]) for q in perms])
i, j = nameso.index("engage close"), nameso.index("safe explore")
pl = [(1 + (null[:, a, b] <= M[a, b]).sum()) / (N_PERM_G + 1) for a, b in [(i, j), (j, i)]]
d = len(nameso)
p0 = (1 + (np.abs(null) >= np.abs(M)[None]).sum(0)) / (N_PERM_G + 1)
sig = (p0 < 0.01 / (d * (d - 1))) & ~np.eye(d, dtype=bool)
print(f"S7 as stored, order {order}: engage close on safe explore {M[i, j]:.3f} (p {pl[0]:.5f}), safe explore on "
f"engage close {M[j, i]:.3f} (p {pl[1]:.5f}); fig3b significant off-diagonal pairs (Bonferroni a, own sign, "
f"zero centre) {int(sig.sum())}, one direction only {int((sig != sig.T).sum() // 2)}")
game["S7 as stored"] = raw
gr = pd.DataFrame(game_classification("S7 as stored", X, names, rng, 200)[0])
gr["within"] = (gr.bal_acc - 30.4).abs() <= 4.2
print(gr[["folds", "labels", "rule", "bal_acc", "null_max", "p", "within"]].round(3).to_string(index=False))
Yr = raw["Y_keep"].astype(np.float64)
pr = ss.r_pvalue(ss.cv_ols_r(Yr, X), len(X))
sig_r = np.zeros(raw["n_vox"], bool)
sig_r[game_keep["S7"][pr < 0.05 / raw["n_vox"]]] = True
rows = []
for thr, R in [("i", regmat["game", "S7"]), ("ii", ss.region_matrix(mappers["S7"], atlases, ss.GAME_REGIONS, voxel_mask=sig_r)[0])]:
S = Yr @ R[game_keep["S7"]]
for order in ["dataset", "table1"]:
Xo, nameso = ss.game_matrix(raw["X"], raw["labels"], order)
for reading, w in ss.region_weights(raw["Z"], Xo, S).items():
if reading != "Q_S" and order == "table1":
continue
rows += [dict(threshold=thr, weights=reading if reading != "Q_S" else f"Q_S ({order})", state=st_, region=reg, w=w[k, j])
for j, st_ in enumerate(nameso) for k, reg in enumerate(ss.GAME_REGIONS)]
print(f"S7 as stored, game-weights-two-groups ({sig_r.sum()} region voxels pass threshold ii): dimensions failing (one may fail)")
for k, v in grouping_fails(pd.DataFrame(rows), R1_).items():
print(f" threshold {k[0]:3s} {k[1]:14s} {len(v)} failing: {v}")
del game["S7 as stored"], raw, Yr
print(f"{time.time()-t:.0f} s; elapsed {time.time()-T0:.0f} s, peak memory {mem_gb():.1f} GB")
S7 as stored, game-csi reading a: CSI 0.549 (z-scored: 0.549); within 0.62 +/- 0.062: False; null max 0.292
S7 as stored, game-csi reading b: CSI 0.581 (z-scored: 0.582); within 0.62 +/- 0.062: True; null max 0.255
S7 as stored, game-csi reading c: CSI 0.388 (z-scored: 0.386); within 0.62 +/- 0.062: False; null max 0.103
S7 as stored, order dataset: engage close on safe explore -0.191 (p 0.00005), safe explore on engage close -0.548 (p 0.00005); fig3b significant off-diagonal pairs (Bonferroni a, own sign, zero centre) 23, one direction only 13
S7 as stored, order table1: engage close on safe explore -0.552 (p 0.00005), safe explore on engage close -0.018 (p 0.93575); fig3b significant off-diagonal pairs (Bonferroni a, own sign, zero centre) 26, one direction only 10
folds labels rule bal_acc null_max p within contig a euclid 33.846 23.820 0.005 True contig a density 32.370 24.608 0.005 True contig b euclid 27.526 16.301 0.005 True contig b density 26.392 19.541 0.005 True random a euclid 41.769 19.140 0.005 False random a density 47.061 20.756 0.005 False random b euclid 36.385 16.750 0.005 False random b density 37.903 17.619 0.005 False
S7 as stored, game-weights-two-groups (5329 region voxels pass threshold ii): dimensions failing (one may fail) threshold i B 4 failing: ['dead', 'engage far', 'safe explore', 'unsafe explore'] threshold i B_L 4 failing: ['dead', 'engage far', 'safe explore', 'unsafe explore'] threshold i Q_S (dataset) 5 failing: ['dead', 'engage far', 'run away', 'safe explore', 'unsafe explore'] threshold i Q_S (table1) 5 failing: ['dead', 'engage close', 'run away', 'safe explore', 'unsafe explore'] threshold ii B 3 failing: ['dead', 'safe explore', 'unsafe explore'] threshold ii B_L 3 failing: ['dead', 'safe explore', 'unsafe explore'] threshold ii Q_S (dataset) 5 failing: ['dead', 'round start', 'run away', 'safe explore', 'unsafe explore'] threshold ii Q_S (table1) 5 failing: ['dead', 'engage close', 'run away', 'safe explore', 'unsafe explore'] 82 s; elapsed 2937 s, peak memory 6.0 GB
Result: not reproduced in S7, resting on assumptions about the regions; S1 cannot be placed on the cortex. In S7 three to five of the eight dimensions fail the grouping under every reading, where one may fail: dead, safe explore and unsafe explore under every reading, and engage far, run away, round start or engage close under some. Safe explore has negative OLS weights in all nine regions (-0.008 to -0.241, threshold i). With the denoised weights, and with the Bonferroni threshold (ii) and the OLS weights, three fail. With the medial prefrontal areas (12,185 fsaverage vertices) in place of the whole prefrontal region (57,895) the same dimensions fail under every reading, so the result does not rest on how coarsely the prefrontal region is drawn, within these two choices. With S7 as stored, not z-scored, three to five fail as well (four with the denoised weights at threshold i), so the outcome does not rest on the normalization either. S1's game data match no mapper, so S1 and the consistency between the two subjects could not be tested, and the outcome rests on S7 alone. In the variant not taken from the paper, the correlation of S1's denoised weight maps across voxels splits the nine dimensions into exactly the paper's two groups (flash, safe explore, unsafe explore, dead, round start; engage close, engage far, run away, kill), while S7's maps split into safe and unsafe explore against the rest. The regions are HCP-MMP1.0 areas chosen to match the names in the paper, not the paper's ROIs.
Summary¶
A failure to reproduce here may be a failure of this attempt, not of the paper: see the reasoning and the differences from the paper's method.
| claim | outcome |
|---|---|
| fig1-csi-s2 | reproduced (assumption: third axis as the code gives it) |
| att-csi-group | reproduced (same assumption) |
| supp-csi-per-subject | reproduced (10 of 12 values; all significant under reading a) |
| att-passive-lower | not reproduced (2 of 5 subjects at the bound reached) |
| att-classification | reproduced |
| att-weights-cortex | reproduced under the encoding-model threshold (4 of 5 subjects; 5 of 5 under a stricter Bonferroni variant), 3 of 5 without it; atlas regions in place of the paper's ROIs |
| game-csi | reproduced (one reading of the clusters) |
| game-mutual-negative-projection | reproduced (assumption: data set's column order) |
| fig3b-state-relations | reproduced |
| game-classification | partially reproduced (S1 above the paper's value) |
| game-weights-two-groups | not reproduced: fails in S7 under every reading (atlas regions), with S7 z-scored or as stored; S1 cannot be mapped |
How the analysis differs from the paper's:
- The attention claims over subjects use five of the paper's six subjects: S4 is not released.
- The state space is the paper's code, computed exactly in the space of the 24 PCs; the code itself is run on the full voxels for the reported attention CSIs (R3).
- The attention variable has no weight in the deposited data, so the third axis of the attention state space is set by rounding; three readings are shown and the outcomes rest on the code's.
- Permutations: 1000 (20,000 for the game projections), so p-values reach 1e-3 (5e-5), not the paper's 1e-5. How labels are permuted, how folds are formed, the cluster distance, and how multi-state TRs enter are the claims file's readings, each run.
- S7's game state space has 8 dimensions (no flash TRs).
- The paper's functional ROIs are not public; the two cortical claims use group-atlas regions on fsaverage (visfAtlas and HCP-MMP1.0) through the data set's mappers, an assumption.
- The game labels are used at lag 0; the CSI peaks at lag +1, shown as a variant.
- The video game BOLD is z-scored per voxel over the session, as the paper's Methods say; S7's deposited data are not, and S7 as stored is shown as a variant.
What was found about the data set:
- The attentive conditions of the deconvolved data are z-scored per voxel within each condition,
so the attention variable (coded -1, 0, +1 in
states.hdf, a coding the description does not give) carries no mean difference between them. - S1's video game data hold 1950 TRs (65 min) in six blocks of 325 TRs, where the paper and the description say one subject played 90 min in six 15-min runs; S7's hold 44 min, as stated.
- S1's video game data have 73,594 voxels, a voxel set no mapper in the data set matches, current or superseded.
- No functional ROI, localizer or retinotopy data are deposited.
- The code's attention coefficients are at the level of rounding (about 1e-13), so the R3 CSIs can move slightly between runs on different machines.
- S7's video game BOLD is not z-scored per voxel over the session (voxel SDs 0.094 to 1.009), unlike S1's.
- The state columns of the video game files are not in the order of Table 1.