Nishimoto and Gallant (2011) on CRCNS mt-2¶

Paper: Nishimoto S, Gallant JL (2011), "A Three-Dimensional Spatiotemporal Receptive Field Model Explains Responses of Area MT Neurons to Naturalistic Movies", J Neurosci 31(41):14551-14564, doi:10.1523/jneurosci.6801-10.2011.

Dataset: CRCNS mt-2, "Extracellular recordings from area MT of awake macaques in response to naturalistic movies", doi:10.6080/K0DN4374, read from the public bucket crcnsarchive/mt-2/live/. CRCNS data sets are not versioned; the version is recorded as unversioned and the next cell prints the MD5 sums of checksums.md5 for the 45 files read, so a later change can be detected. The live folder is the only copy in the bucket (there is no old folder), so it is the version pinned.

Claims: claims/nishimoto-2011.yaml, written from the version of record (main text, Methods and legends; the paper has no supplement beyond a movie of stimulus spectra and links no code).

The model cannot be fitted here at the paper's size (about 6000 filters at 11 delays, boosted five times, for 12 models and 45 neurons) within the time limit. The filter bank follows the paper's rules (about 7000 complex and 1100 simple channels), and the regression weights are constrained to be pooled over space onto 763 regressors (see mt2.py). To measure what this costs, the main model (compressive and divisive) is also fitted for every neuron with a finer pooling (1465 regressors), and for three neurons with a finer one still (3085 regressors, with every simple channel of the bank), in the second notebook, finer_pooling.ipynb. Every difference from the paper is listed in the summary and in the attempt record.

Claim Tested here
fig3b-mean-prediction tested
fig3b-explainable-variance blocked: data_missing (no single repeats)
fig3a-example-neuron tested
fig2b-contrast-normalization-no-effect tested
fig2b-compressive-improves tested
fig2b-expansive-decreases tested
fig2b-divisive-improves tested
fig2b-compressive-divisive-best tested
fig2b-no-interaction tested
complex-cells-dominate tested
fig6a-null-on-plane tested
fig6a-excitatory-on-plane tested
fig6b-suppressive-off-plane tested
fig7a-partial-ring tested
fig7a-no-corr-prediction-hv tested
fig7b-pattern-index tested
fig7c-hv-pattern-correlation tested
fig7c-no-corr-prediction-pattern tested
natural-movie-control tested
fig8-recovery-simulated tested
In [1]:
import os, time, resource
os.environ.setdefault("OMP_NUM_THREADS", "2")
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from concurrent.futures import ProcessPoolExecutor
from scipy.stats import wilcoxon, ranksums, pearsonr, spearmanr
import mt2

T0 = time.time()
sizes = mt2.list_sizes()
names = sorted(sizes)
md5 = mt2.checksums()
print(len(names), "files;", sum(sizes.values()) / 1e9, "GB")
for n in names:
    print(n, md5[n], sizes[n])
45 files; 17.007579372 GB
ct0001_arg0466d_128.mat a51fd67bed934d6eab81ead8ec1634fb 284621393
ct0002_arg0466d_128.mat 8239d4b03750d2530f31b1142e4400f8 281394133
ct0005_arg0466d_128.mat 413ba796c27bc4cb6c800de12c8a935d 279482493
ct0006_arg0466d_128.mat 907f6117c004dc2f77ed73db0fe57c7d 277528046
ct0008_arg0466d_128.mat b5801d55a497c8c7a9ea3ae5de855596 529318245
ct0009_arg0466d_128.mat d6d68ec0cb6302994fa5465d7e3f6600 545261528
ct0010_arg0466d_128.mat 0e8084d949ff2db39e0bfeca53a6f85d 288531587
ct0011_arg0466d_128.mat ae32d99c8331ef7b0e9632dfa9be93a7 270340370
ct0013_arg0466d_128.mat 830a8ba0ea6578e9418291ce57403844 521647299
ct0014_arg0466d_128.mat 0957c866b3bbfbf2ad93dfe5f125c586 550762785
ct0018_arg0466d_128.mat 5c97c392a779014848c4864d935977e1 539741382
ct0021_arg0466d_128.mat 4424cea85f699f6ee7e3cb0f8f0af9d4 544944067
ct0023_arg0466d_128.mat ffd4ba0ae5475a48ddabf69bdd88e876 277357986
ct0024_arg0466d_128.mat d4299339b1bdddd23cfee5155dcba808 535831284
ct0026_arg0466d_128.mat 854813c759ef9aebdaa4328e6ca6d8f6 548229433
ct0027_arg0466d_128.mat 8e5bd265a30129586e0c207d76076204 546923909
ct0028_arg0466d_128.mat 2985754e5b0ae965a31f082bd4194e45 286693220
ct0030_arg0466d_128.mat e9b165a80665a7573977248a0e9fdb6a 542587359
ct0031_arg0466d_128.mat bff4c34ea5ff733805a47116a03a18cb 555215405
ct0032_arg0466d_128.mat 437eb39869d2bef721a9d457ad410ecc 279515219
ct0037_arg0466d_128.mat 961d0c9d5c9d60ff65b703baa6e53df7 288270188
ct0039_arg0466d_128.mat 87a26b596477d498cf9a5d55054dd9ad 557894199
ct0040_arg0466d_128.mat acd8fb73c1734ca64005e59735b32a3d 566252087
ct0041_arg0466d_128.mat bb5e17fbf697fde167fc9e3364921ab6 280000567
ct0042_arg0466d_128.mat ef75289fa4c7c6cd2cee25108e614c2c 566435195
ct0043_arg0466d_128.mat f830a5b98854abcc8abb1b03e51e4219 283575762
ct0047_arg0466d_128.mat aeb1620cfcc66836dd386759e521ed78 303610038
ct0048_arg0466d_128.mat 238aa815f3061c581fd53366ed5bb621 287785184
ct0049_arg0466d_128.mat e4a0a925906cf53d7b97dfd13892c751 312723408
ct0050_arg0466d_128.mat 52fbe8074bb8e497e2185ef00ec6bd88 556884708
ct0053_arg0466d_128.mat 78435da103227c79c49e4062241e4438 568371267
ct0055_arg0466d_128.mat 7ab63a2dc54ba004e1f12d9a7b11e8db 569302279
ct0057_arg0466d_128.mat b8137f06f5e4c41609b78fd75b9f8aa0 296735895
ct0058_arg0466d_128.mat c482aa48b1b38c7a868e703527cec71c 305560534
ct0124_arg0466d_128.mat 04d0183052ef91b527578c33f09c61e2 273534812
ct0125_arg0466d_128.mat 837b1ac4482396749546001b9dae4492 264982523
ct0127_arg0466d_128.mat 8e4360f52b1a6f4a99a3f697ad791490 249446869
ct0128_arg0466d_128.mat 752a1b3ddc25d7bcb3fa3baf6eb4aa2f 237707993
ct0130_arg0466d_128.mat 3620eb217ac8f8db98c86163ce72e801 271177924
ct0131_arg0466d_128.mat e6ac1da2be9c603aad8601d53e9d8b8c 244765818
ct0132_arg0466d_128.mat 15219e1c6c016bd249c14fcf7d745487 242423766
ct0133_arg0466d_128.mat 56230a448b8979499364864b54e593a5 247899683
ct0137_arg0466d_128.mat 1739595770751aad510f4cae6091f0d5 250639393
ct0140_arg0466d_128.mat f73da14c9d13da0cc256561eae970a85 248748725
ct0141_arg0466d_128.mat 25d6acc0b004de86a017994658128f7a 246923412

Fitting every neuron¶

Each neuron's file is streamed, its frames reduced to 32 x 32 pixels, the filter bank applied with and without luminance and contrast normalization, and the 12 models of Figure 2 fitted by boosting with early stopping (mt2.process_neuron). For the compressive and divisive model it also fits the readings the claims file names (delays 1 to 10, folds as random partitions, sigma chosen on held-out data, the 12 ms Gaussian as a full width), early stopping with a patience of 500 steps, the complex-only and simple-only models, the null model neurons of Figure 6 and the simulated neurons of Figure 8, and drives the fitted model with gratings and plaids. Two neurons run at a time.

Null model neurons (fig6a-null-on-plane): 150 neurons, the k-th on the movies of neuron k mod 45 (movie reading (a)), each under the four combinations of the rate reading (rectified (a), offset (b)) and the delay reading (all delays (a), one delay (b)); and 150 more on the movies of one neuron, ct0001 (movie reading (b)), with readings (a) and (a) only, for time.

In [2]:
COMBOS = [("a", "a"), ("a", "b"), ("b", "a"), ("b", "b")]
SIM = "ct0001_arg0466d_128.mat"
specs = {n: [] for n in names}
for i in range(150):
    for ra, da in COMBOS:
        specs[names[i % len(names)]].append((("a", i), ra, da))
N_RUN = int(os.environ.get("MT2_N", len(names)))  # a subset while developing
for i in range(150 if N_RUN >= len(names) else 10):
    specs[SIM].append((("b", i), "a", "a"))
order = [SIM] + [n for n in sorted(names, key=lambda n: -sizes[n]) if n != SIM]
if N_RUN < len(names):
    order = [SIM] + [n for n in sorted(names, key=lambda n: sizes[n]) if n != SIM][:N_RUN - 1]
t = time.time()
with ProcessPoolExecutor(2) as ex:
    futs = {n: ex.submit(mt2.process_neuron, n, specs[n], n == SIM, 10 * names.index(n), 2) for n in order}
    R = {n: f.result() for n, f in futs.items()}
names_run = [n for n in names if n in R]
print(f"{len(R)} neurons in {(time.time() - t) / 60:.1f} min; per neuron "
      f"{np.median([R[n]['t_total'] for n in R]):.0f} s median, loading {np.median([R[n]['t_load'] for n in R]):.0f} s")
print("peak memory of a worker:", resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss / 1e6, "GB")
45 neurons in 57.5 min; per neuron 112 s median, loading 27 s
peak memory of a worker: 5.083596 GB

Data check¶

In [3]:
rows = []
for n in names_run:
    o = R[n]
    rows.append(dict(file=n[:6], cellid=o["cellid"], monkey=o["cellid"][0], frames=o["n_frames"],
                     crange=o["n_crange"], train_rows=o["n_train"], nan_in_crange=o["nan_train"],
                     val_sets="+".join(f"{k}:{v}" for k, v in o["sets"].items()),
                     reps_enh=o["repeats"].get("enhanced"), reps_nat=o["repeats"].get("natural"),
                     mean_count=round(o["mean_count"], 3),
                     motion_train=round(o["motion"]["train"], 3), motion_enh=round(o["motion"]["enhanced"], 3),
                     motion_nat=round(o["motion"].get("natural", np.nan), 3),
                     stim_min=o["stim_range"][0], stim_max=o["stim_range"][1], offset=o["offset"]))
D = pd.DataFrame(rows)
pd.set_option("display.width", 250, "display.max_columns", 30, "display.max_rows", 60)
print(D.to_string())
print("\nneurons by monkey:", D.monkey.value_counts().to_dict(), "; unique cell ids:", D.cellid.nunique())
print("training frames (crange):", D.crange.min(), "to", D.crange.max(), "mean", round(D.crange.mean()))
print("total frames per file:", sorted(D.frames.unique()))
print("files with a natural-movie validation set (nrange):", (D.motion_nat.notna()).sum())
print("validation repeats (largest per-frame denominator) enhanced:", D.reps_enh.min(), "to", D.reps_enh.max(),
      "; natural:", D.reps_nat.min(), "to", D.reps_nat.max())
print("frames with responses removed inside crange: median", D.nan_in_crange.median(), "range",
      D.nan_in_crange.min(), "to", D.nan_in_crange.max())
print("training-frame count denominators seen (repeats of training frames):",
      sorted({d for n in names_run for d in R[n]["train_denominators"]}))
nat = D[D.motion_nat.notna()]
print(f"\nmotion (mean absolute frame difference / mean contrast): training {D.motion_train.median():.3f}, "
      f"enhanced validation {D.motion_enh.median():.3f}, nrange {nat.motion_nat.median():.3f} (medians); "
      f"nrange below the other validation half in {(nat.motion_nat < nat.motion_enh).sum()} of {len(nat)}")
vc = pd.DataFrame([dict(file=n[:6], set=k, **v) for n in names_run for k, v in R[n]["val_check"].items()])
print(f"\nvalidation sets: {len(vc)}; made of contiguous frames: {int(vc.contiguous.sum())}; "
      f"with frames without a response: {int((vc.n_nan > 0).sum())} (val_corr smooths and trims each set as one segment)")
rs = pd.DataFrame([dict(file=n[:6], set=k, max_den=v[0], share_found=v[1]) for n in names_run for k, v in R[n]["repeats_strict"].items()])
print(f"repeat estimate with tolerance 1e-6 and denominators up to 100: largest denominator {rs.max_den.min()} to {rs.max_den.max()}; "
      f"share of distinct values with a denominator found: {rs.share_found.min():.2f} to {rs.share_found.max():.2f}")
print("ranges.trange length in every file:", sorted({R[n]["trange_len"] for n in names_run}))
      file cellid monkey  frames  crange  train_rows  nan_in_crange                    val_sets  reps_enh  reps_nat  mean_count  motion_train  motion_enh  motion_nat  stim_min  stim_max  offset
0   ct0001  f0024      f   22000   20000       19501            479               enhanced:2000        11       NaN       0.162         0.327       0.347         NaN       0.0     255.0       0
1   ct0002  f0027      f   22000   20000       19720            260               enhanced:2000        19       NaN       0.087         0.334       0.355         NaN       0.0     255.0       0
2   ct0005  f0032      f   22000   20000       19861            119               enhanced:2000        21       NaN       0.210         0.346       0.373         NaN       0.0     255.0       0
3   ct0006  f0033      f   22000   20000       19976              4               enhanced:2000        20       NaN       0.080         0.344       0.369         NaN       0.0     255.0       0
4   ct0008  f0035      f   42000   40000       38828           1152               enhanced:2000        19       NaN       0.139         0.357       0.385         NaN       0.0     255.0       0
5   ct0009  f0037      f   42000   35794       35370            404               enhanced:2000        21       NaN       0.475         0.317       0.339         NaN       0.0     255.0       0
6   ct0010  f0038      f   22000   20000       19680            300               enhanced:2000        20       NaN       0.073         0.314       0.330         NaN       0.0     255.0       0
7   ct0011  f0039      f   22000   20000       19412            568               enhanced:2000        19       NaN       0.101         0.376       0.413         NaN       0.0     255.0       3
8   ct0013  f0041      f   42000   40000       39173            807               enhanced:2000        20       NaN       1.195         0.356       0.387         NaN       0.0     255.0       0
9   ct0014  f0042      f   42000   40000       39464            516               enhanced:2000        21       NaN       0.300         0.305       0.325         NaN       0.0     255.0       0
10  ct0018  f0050      f   42000   40000       39387            593               enhanced:2000        22       NaN       0.234         0.321       0.346         NaN       0.0     255.0       0
11  ct0021  f0056      f   42000   40000       39340            640               enhanced:2000        20       NaN       1.171         0.314       0.337         NaN       0.0     255.0       0
12  ct0023  f0058      f   22000   20000       19477            503               enhanced:2000        11       NaN       0.078         0.337       0.376         NaN       0.0     255.0       0
13  ct0024  f0059      f   42000   40000       39424            556               enhanced:2000        21       NaN       0.260         0.326       0.353         NaN       0.0     255.0       0
14  ct0026  f0061      f   42000   40000       39506            474               enhanced:2000        23       NaN       0.489         0.325       0.343         NaN       0.0     255.0       0
15  ct0027  f0064      f   42000   40000       39621            359               enhanced:2000        20       NaN       0.106         0.322       0.343         NaN       0.0     255.0       3
16  ct0028  f0068      f   22000   17908       17656            232               enhanced:2000        10       NaN       0.101         0.334       0.304         NaN       0.0     255.0       0
17  ct0030  f0071      f   42000   24705       23963            722               enhanced:2000        10       NaN       0.112         0.324       0.295         NaN       0.0     255.0       0
18  ct0031  f0073      f   44000   40000       39673            307  natural:2000+enhanced:2000        19      11.0       0.135         0.335       0.315       0.226       0.0     255.0       0
19  ct0032  f0076      f   22000   20000       19893             87               enhanced:2000        22       NaN       0.045         0.344       0.319         NaN       0.0     255.0       3
20  ct0037  f0083      f   22000   20000       19915             65               enhanced:2000        21       NaN       0.054         0.322       0.292         NaN       0.0     255.0       0
21  ct0039  f0086      f   44000   31967       31663            284  natural:2000+enhanced:2000        21      21.0       0.447         0.337       0.314       0.225       0.0     255.0       0
22  ct0040  f0087      f   44000   40000       39513            467  natural:2000+enhanced:2000        21      21.0       0.064         0.331       0.307       0.225       0.0     255.0       0
23  ct0041  f0089      f   22000   20000       19841            139               enhanced:2000        11       NaN       0.310         0.353       0.328         NaN       0.0     255.0       0
24  ct0042  f0090      f   44000   40000       39713            267  natural:2000+enhanced:2000        21      20.0       0.217         0.330       0.309       0.223       0.0     255.0       0
25  ct0043  f0093      f   22000   20000       19356            624               enhanced:2000        12       NaN       0.128         0.358       0.325         NaN       0.0     255.0       3
26  ct0047  f0100      f   24000   20000       19832            148  natural:2000+enhanced:2000        19      21.0       0.398         0.338       0.313       0.224       0.0     255.0       3
27  ct0048  f0102      f   22000   20000       19744            236               enhanced:2000        21       NaN       0.815         0.330       0.301         NaN       0.0     255.0       0
28  ct0049  f0104      f   24000   20000       19802            178  natural:2000+enhanced:2000        18      11.0       0.083         0.326       0.293       0.212       0.0     255.0       0
29  ct0050  f0105      f   44000   40000       39686            294  natural:2000+enhanced:2000        20      22.0       0.270         0.355       0.334       0.244       0.0     255.0       0
30  ct0053  f0110      f   44000   40000       39707            273  natural:2000+enhanced:2000        20      20.0       0.081         0.334       0.308       0.226       0.0     255.0       0
31  ct0055  f0112      f   44000   40000       38531           1449  natural:2000+enhanced:2000        20      21.0       0.196         0.335       0.306       0.226       0.0     255.0       0
32  ct0057  f0114      f   24000   20000       19886             94  natural:2000+enhanced:2000        21      10.0       1.404         0.396       0.363       0.278       0.0     255.0       0
33  ct0058  f0116      f   24000   20000       19678            302  natural:2000+enhanced:2000        22      20.0       0.090         0.353       0.325       0.236       0.0     255.0       0
34  ct0124  v0383      v   24000   20000       19794            186  natural:2000+enhanced:2000        22      18.0       0.128         0.304       0.301       0.172       0.0     255.0       6
35  ct0125  v0384      v   24000   20000       19871            109  natural:2000+enhanced:2000        33      33.0       0.682         0.334       0.330       0.196       0.0     255.0       6
36  ct0127  v0387      v   22000   20000       19851            129               enhanced:2000        26       NaN       0.447         0.318       0.316         NaN       0.0     255.0       0
37  ct0128  v0388      v   22000   20000       19770            210               enhanced:2000        25       NaN       0.102         0.361       0.354         NaN       0.0     255.0       3
38  ct0130  v0390      v   24000   20000       19851            129  natural:2000+enhanced:2000        24      11.0       0.954         0.305       0.300       0.173       0.0     255.0       6
39  ct0131  v0393      v   22000   20000       19819            161               enhanced:2000        28       NaN       0.228         0.334       0.330         NaN       0.0     255.0       6
40  ct0132  v0394      v   22000   20000       19831            149               enhanced:2000        24       NaN       0.064         0.329       0.324         NaN       0.0     255.0       3
41  ct0133  v0395      v   22000   19842        7093          12729               enhanced:2000        15       NaN       0.310         0.316       0.307         NaN       0.0     255.0       0
42  ct0137  v0419      v   22000   20000       19887             93               enhanced:2000        26       NaN       0.400         0.305       0.298         NaN       0.0     255.0       6
43  ct0140  v0422      v   22000   20000       19826            154               enhanced:2000        24       NaN       0.485         0.320       0.316         NaN       0.0     255.0       3
44  ct0141  v0424      v   22000   20000       19868            112               enhanced:2000        25       NaN       0.659         0.328       0.324         NaN       0.0     255.0       3

neurons by monkey: {'f': 34, 'v': 11} ; unique cell ids: 45
training frames (crange): 17908 to 40000 mean 26894
total frames per file: [np.int64(22000), np.int64(24000), np.int64(42000), np.int64(44000)]
files with a natural-movie validation set (nrange): 14
validation repeats (largest per-frame denominator) enhanced: 10 to 33 ; natural: 10.0 to 33.0
frames with responses removed inside crange: median 273.0 range 4 to 12729
training-frame count denominators seen (repeats of training frames): [1, 2, 3, 4, 5]

motion (mean absolute frame difference / mean contrast): training 0.331, enhanced validation 0.325, nrange 0.225 (medians); nrange below the other validation half in 14 of 14

validation sets: 59; made of contiguous frames: 59; with frames without a response: 0 (val_corr smooths and trims each set as one segment)
repeat estimate with tolerance 1e-6 and denominators up to 100: largest denominator 10 to 33; share of distinct values with a denominator found: 0.96 to 1.00
ranges.trange length in every file: [0]
In [4]:
# Everything one file holds (ct0125, which has a natural-movie set): no field holds single repeats
for k, shp, dt, cls, empty in mt2.list_keys("ct0125_arg0466d_128.mat"):
    print(f"{k:16s} shape {shp}  {dt}  MATLAB class {cls}{'  (MATLAB empty)' if empty else ''}")
cellid           shape (5, 1)  uint16  MATLAB class char
psths            shape (1, 24000)  float32  MATLAB class single
ranges           shape None  group  MATLAB class struct
ranges/crange    shape (20000, 1)  float64  MATLAB class double
ranges/nrange    shape (2000, 1)  float64  MATLAB class double
ranges/trange    shape (2,)  uint64  MATLAB class double  (MATLAB empty)
ranges/vrange    shape (4000, 1)  float64  MATLAB class double
rawStims         shape (24000, 128, 128)  uint8  MATLAB class uint8
In [5]:
# Recordings deposited twice: identical validation responses or identical training movies
V = {n: R[n]["psth"][-2000:] for n in names_run}
dup = []
for i, a in enumerate(names_run):
    for b in names_run[i + 1:]:
        if len(R[a]["psth"]) == len(R[b]["psth"]):
            c = np.corrcoef(V[a], V[b])[0, 1]
            if c > 0.9:
                dup.append((a[:6], b[:6], round(c, 3)))
print("pairs of neurons with validation responses correlated above 0.9:", dup if dup else "none")
same_resp = [(a[:6], b[:6]) for i, a in enumerate(names_run) for b in names_run[i + 1:]
             if len(R[a]["psth"]) == len(R[b]["psth"]) and np.allclose(np.nan_to_num(R[a]["psth"]), np.nan_to_num(R[b]["psth"]))]
print("pairs with identical response arrays:", same_resp if same_resp else "none")
pairs of neurons with validation responses correlated above 0.9: none
pairs with identical response arrays: none
In [6]:
# Clock: the prediction of the compressive and divisive model against the validation response
# shifted in time (the response moved k frames later is compared with the prediction).
sh = R[names_run[0]]["fits"][mt2.MAIN]["shift_r"][0]
S = np.array([R[n]["fits"][mt2.MAIN]["shift_r"][1] for n in names_run])
peak = sh[np.argmax(S, 1)]
print("shift of the peak correlation (frames): counts", dict(zip(*np.unique(peak, return_counts=True))))
print(f"mean r at shift 0: {S[:, sh == 0].mean():.3f}; at |shift| >= 20 frames: {S[:, np.abs(sh) >= 20].mean():.3f}")
off = np.array([R[n]["offset"] for n in names_run])
print("delay-window offset chosen on held-out training data (frames earlier):", dict(zip(*np.unique(off, return_counts=True))))
dw = np.array([np.abs(R[n]["fits"][mt2.MAIN]["w"].reshape(mt2.DELAYS, -1)).sum(1) for n in names_run])
dw = dw / dw.sum(1, keepdims=True)
print("share of absolute weight per delay (median over neurons), delays 0..10:", np.round(np.median(dw, 0), 3))
oc = pd.DataFrame({n[:6]: {o: round(np.mean(list(v[1].values())), 3) for o, v in R[n]["offsets"].items()} for n in names_run}).T
print("validation r of the compressive and divisive model under each offset: mean", oc.mean().round(3).to_dict())
fig, ax = plt.subplots(figsize=(5, 3))
ax.plot(sh, S.T, color="0.7", lw=0.5)
ax.plot(sh, S.mean(0), "k", lw=2)
ax.set_xlabel("response shift (frames)"); ax.set_ylabel("r")
print("plotted r range:", S.min().round(3), "to", S.max().round(3))
shift of the peak correlation (frames): counts {np.int64(-1): np.int64(9), np.int64(0): np.int64(29), np.int64(1): np.int64(3), np.int64(2): np.int64(2), np.int64(4): np.int64(2)}
mean r at shift 0: 0.442; at |shift| >= 20 frames: 0.012
delay-window offset chosen on held-out training data (frames earlier): {np.int64(0): np.int64(31), np.int64(3): np.int64(9), np.int64(6): np.int64(5)}
share of absolute weight per delay (median over neurons), delays 0..10: [0.079 0.051 0.06  0.078 0.115 0.115 0.078 0.063 0.069 0.053 0.131]
validation r of the compressive and divisive model under each offset: mean {0: 0.448, 3: 0.442, 6: 0.427}
plotted r range: -0.23 to 0.705
No description has been provided for this image

Per-neuron prediction accuracy¶

Following the paper (Results, Control to identify any bias, paragraph 2: "the predictions reported throughout this manuscript reflect the average prediction for both natural and motion-enhanced and natural movies (when the latter were available)"), a neuron's accuracy is the mean of its two validation correlations where it has both sets, and the motion-enhanced correlation otherwise. Which part of vrange is natural is read from nrange (see the data check).

In [7]:
def acc(r):
    return float(np.mean(list(r.values())))

models = mt2.MODELS
IDX = [n[:6] for n in names_run]
A = {m: pd.Series([acc(R[n]["fits"][m]["r"]) for n in names_run], index=IDX) for m in models}
A_enh = {m: pd.Series([R[n]["fits"][m]["r"]["enhanced"] for n in names_run], index=IDX) for m in models}
monkey = np.array([R[n]["cellid"][0] for n in names_run])
def label(m):
    lum, a, div = m
    return f"{'lum ' if lum else ''}{ {1.0: 'linear', 0.5: 'compressive', 2.0: 'expansive'}[a]}{' +div' if div else ''}"
print(pd.DataFrame({"mean r": [A[m].mean() for m in models], "mean r (enhanced only)": [A_enh[m].mean() for m in models]},
                   index=[label(m) for m in models]).round(3))
                      mean r  mean r (enhanced only)
linear                 0.413                   0.410
compressive            0.432                   0.427
expansive              0.351                   0.349
linear +div            0.426                   0.429
compressive +div       0.448                   0.443
expansive +div         0.358                   0.371
lum linear             0.412                   0.406
lum compressive        0.427                   0.420
lum expansive          0.346                   0.339
lum linear +div        0.425                   0.420
lum compressive +div   0.442                   0.436
lum expansive +div     0.364                   0.360

fig3b-mean-prediction¶

The compressive and divisive V1 filter model predicts the validation responses of the 52 MT neurons with an average correlation of r = 0.52. (Expected 0.52 +- 0.052, over the 45 neurons in the dataset.)

In [8]:
main = A[mt2.MAIN]
print(f"mean r, compressive and divisive model, {len(main)} neurons: {main.mean():.3f} (median {main.median():.3f}, "
      f"range {main.min():.3f} to {main.max():.3f})")
print(f"within 0.468 to 0.572: {0.468 <= main.mean() <= 0.572}")
print(f"motion-enhanced validation only: {A_enh[mt2.MAIN].mean():.3f}")
for mk in np.unique(monkey):
    print(f"monkey {mk}: n = {(monkey == mk).sum()}, mean r {main[monkey == mk].mean():.3f}")
rd_ = {}
rd_["delays 1 to 10 (b)"] = [acc(R[n]["fits"][mt2.MAIN]["delays_b"]["r"]) for n in names_run]
rd_["Gaussian 12 ms as FWHM (b)"] = [acc(R[n]["fits"][mt2.MAIN]["r_smooth_b"]) for n in names_run]
rd_["folds as random partitions (b)"] = [acc(R[n]["fits"][mt2.MAIN]["folds_b"]["r"]) for n in names_run]
rd_["sigma chosen on held-out data (a)"] = [acc(min(R[n]["sigma_a"].values(), key=lambda v: v[0])[1]) for n in names_run]
rd_["delay offset 0 for every neuron"] = [acc(R[n]["offsets"][0][1]) for n in names_run]
rd_["early stopping after 500 steps"] = [acc(R[n]["fits"][mt2.MAIN]["patience500"]["r"]) for n in names_run]
for k, v in rd_.items():
    print(f"reading {k}: mean r {np.mean(v):.3f}")
sig_choice = [min(R[n]["sigma_a"], key=lambda s: R[n]["sigma_a"][s][0]) for n in names_run]
print("sigma chosen (fraction of mean pooled response):", dict(zip(*np.unique(sig_choice, return_counts=True))))
print(f"neurons between 0.2 and 0.8 (Figure 3B span): {((main >= 0.2) & (main <= 0.8)).sum()} of {len(main)}; "
      f"below 0.2: {(main < 0.2).sum()}, above 0.8: {(main > 0.8).sum()}")
fig, ax = plt.subplots(figsize=(4, 3))
ax.hist(main, bins=np.arange(-0.1, 1.01, 0.05), color="0.4")
ax.set_xlabel("prediction correlation"); ax.set_ylabel("neurons")
print(f"without ct0133 (7093 training frames left): mean r {main[main.index != 'ct0133'].mean():.3f} over 44")

# Boosting: steps per fold (the cap is 20000; stopping after 50 steps without a lower held-out error)
its = np.array([R[n]["fits"][mt2.MAIN]["its"] for n in names_run])
its_all = np.concatenate([R[n]["fits"][m]["its"] for n in names_run for m in models])
its500 = np.array([R[n]["fits"][mt2.MAIN]["patience500"]["its"] for n in names_run])
print(f"\nsteps per fold, main model: median {np.median(its):.0f}, range {its.min()} to {its.max()}; "
      f"all 12 models: range {its_all.min()} to {its_all.max()}, folds at the cap {(its_all >= 20000).sum()} of {its_all.size}")
print(f"with a patience of 500: steps median {np.median(its500):.0f}, range {its500.min()} to {its500.max()}; "
      f"mean r {np.mean(rd_['early stopping after 500 steps']):.3f} against {main.mean():.3f}")
mean r, compressive and divisive model, 45 neurons: 0.448 (median 0.454, range 0.221 to 0.730)
within 0.468 to 0.572: False
motion-enhanced validation only: 0.443
monkey f: n = 34, mean r 0.458
monkey v: n = 11, mean r 0.417
reading delays 1 to 10 (b): mean r 0.449
reading Gaussian 12 ms as FWHM (b): mean r 0.380
reading folds as random partitions (b): mean r 0.446
reading sigma chosen on held-out data (a): mean r 0.451
reading delay offset 0 for every neuron: mean r 0.448
reading early stopping after 500 steps: mean r 0.449
sigma chosen (fraction of mean pooled response): {np.float64(0.01): np.int64(33), np.float64(1.0): np.int64(12)}
neurons between 0.2 and 0.8 (Figure 3B span): 45 of 45; below 0.2: 0, above 0.8: 0
without ct0133 (7093 training frames left): mean r 0.450 over 44
steps per fold, main model: median 156, range 58 to 562; all 12 models: range 50 to 643, folds at the cap 0 of 2700
with a patience of 500: steps median 613, range 508 to 1101; mean r 0.449 against 0.448
No description has been provided for this image

Result: not reproduced with the 2 x 2 pooling of this notebook; reproduced with the finer pooling of finer_pooling.ipynb, which decides the outcome. Here the compressive and divisive model predicts the 45 neurons with a mean correlation of 0.448 (median 0.454, range 0.221 to 0.730), below the tolerance band of 0.468 to 0.572. No reading reaches it: delays 1 to 10 give 0.449, folds as random partitions 0.446, sigma chosen on held-out data 0.451, offset 0 for every neuron 0.448, and the 12 ms Gaussian read as a full width 0.380. Without ct0133, which keeps 7093 training frames, the mean is 0.450. No fold of any model reached the cap of 20000 steps, and a patience of 500 in place of 50 changes the mean by less than 0.002, so the stopping rule does not lower the correlations. All 45 neurons lie between 0.2 and 0.8, as in Figure 3B.

fig3b-explainable-variance¶

Blocked: the files hold only the response averaged over repeats (psths), so the noise ceiling of David and Gallant (2005), which needs the single repeats, cannot be estimated. The data check shows the repeat counts can be inferred (per-frame denominators) but not the trial responses.

fig3a-example-neuron¶

For one example neuron the correlation between model predictions and observed responses is r = 0.72 (expected 0.72 +- 0.072; the paper's neuron had 10 validation repeats).

In [9]:
ex = A[mt2.MAIN]
hit = ex[(ex >= 0.648) & (ex <= 0.792)]
reps = {n[:6]: R[n]["repeats"] for n in names_run}
print(f"neurons with r in 0.648 to 0.792: {len(hit)}")
for k, v in hit.items():
    print(f"  {k}  r = {v:.3f}  repeat estimate {reps[k]}")
print("highest r:", ex.sort_values().tail(5).round(3).to_dict())
print("neurons whose motion-enhanced validation set shows 10 repeats:", [k for k, v in reps.items() if v.get("enhanced") == 10])
print("the two neurons with 10 repeats:", {k: round(ex[k], 3) for k in ("ct0028", "ct0030") if k in ex})
strict = {n[:6]: R[n]["repeats_strict"] for n in names_run}
for k in hit.index:
    print(f"  {k}: largest denominator at tolerance 1e-6 {strict[k]}")
neurons with r in 0.648 to 0.792: 3
  ct0013  r = 0.710  repeat estimate {'enhanced': 20}
  ct0021  r = 0.708  repeat estimate {'enhanced': 20}
  ct0039  r = 0.730  repeat estimate {'natural': 21, 'enhanced': 21}
highest r: {'ct0125': 0.605, 'ct0024': 0.633, 'ct0021': 0.708, 'ct0013': 0.71, 'ct0039': 0.73}
neurons whose motion-enhanced validation set shows 10 repeats: ['ct0028', 'ct0030']
the two neurons with 10 repeats: {'ct0028': np.float64(0.278), 'ct0030': np.float64(0.409)}
  ct0013: largest denominator at tolerance 1e-6 {'enhanced': (20, 0.9581151832460733)}
  ct0021: largest denominator at tolerance 1e-6 {'enhanced': (20, 0.961352657004831)}
  ct0039: largest denominator at tolerance 1e-6 {'natural': (21, 0.9875), 'enhanced': (21, 0.9834710743801653)}

Result: reproduced. Three neurons have a prediction correlation within 0.648 to 0.792 (ct0013 0.710, ct0021 0.708, ct0039 0.730). Their validation sets show 20 to 21 repeats by the per-frame denominators, at either tolerance. The two neurons that show 10 repeats give 0.278 (ct0028) and 0.409 (ct0030), so the paper's example neuron cannot be identified.

Figure 2B: the 12 models¶

Each model's change of predictive power relative to the simplest model (linear, no luminance or divisive normalization) is computed under the three readings of the claims file: (a) the percent change of the mean correlation; (b) the same with the mean squared correlation; (c) the mean over neurons of each neuron's percent change. Significance: Wilcoxon signed-rank test across neurons on the per-neuron correlations, Bonferroni corrected over 11 comparisons (5 as a variant).

In [10]:
base = (False, 1.0, False)
def change(m, Atab=A):
    a, b = Atab[m], Atab[base]
    pa = 100 * (a.mean() / b.mean() - 1)
    pb = 100 * ((a**2).mean() / (b**2).mean() - 1)
    pc = 100 * np.mean((a - b) / np.abs(b))
    p = wilcoxon(a, b).pvalue if m != base else np.nan
    return pa, pb, pc, p
rows = []
for m in models:
    pa, pb, pc, p = change(m)
    rows.append(dict(model=label(m), mean_r=A[m].mean(), pct_a=pa, pct_b=pb, pct_c=pc,
                     n_better=int((A[m] > A[base]).sum()), p=p, p_bonf11=min(1, p * 11) if m != base else np.nan,
                     p_bonf5=min(1, p * 5) if m != base else np.nan))
T2 = pd.DataFrame(rows).set_index("model")
print(T2.round(4).to_string())
print("\nreading (c) is sensitive to neurons with small baseline r: smallest baseline r", A[base].min().round(3),
      "; reading (c) without neurons whose baseline r < 0.1:",
      {label(m): round(100 * np.mean(((A[m] - A[base]) / A[base])[A[base] >= 0.1]), 1) for m in models if m != base})
print("by monkey, reading (a):", {mk: {label(m): round(100 * (A[m][monkey == mk].mean() / A[base][monkey == mk].mean() - 1), 1)
                                     for m in models if m != base} for mk in np.unique(monkey)})
                      mean_r    pct_a    pct_b    pct_c  n_better       p  p_bonf11  p_bonf5
model                                                                                       
linear                0.4135   0.0000   0.0000   0.0000         0     NaN       NaN      NaN
compressive           0.4324   4.5830   9.2124   4.7640        40  0.0000    0.0000   0.0000
expansive             0.3509 -15.1219 -26.8570 -15.7449         0  0.0000    0.0000   0.0000
linear +div           0.4256   2.9379   5.1276   3.8688        30  0.0051    0.0562   0.0255
compressive +div      0.4480   8.3600  16.1349   9.4224        40  0.0000    0.0000   0.0000
expansive +div        0.3578 -13.4696 -24.4783 -13.1933         7  0.0000    0.0000   0.0000
lum linear            0.4122  -0.2956  -1.3898   0.6449        26  0.4136    1.0000   1.0000
lum compressive       0.4267   3.2071   6.1006   3.9907        35  0.0000    0.0005   0.0002
lum expansive         0.3462 -16.2680 -28.5438 -16.6998         2  0.0000    0.0000   0.0000
lum linear +div       0.4249   2.7550   4.6093   3.8777        33  0.0059    0.0652   0.0296
lum compressive +div  0.4416   6.7922  12.8841   8.0945        38  0.0000    0.0000   0.0000
lum expansive +div    0.3644 -11.8695 -21.5813 -11.7196         6  0.0000    0.0000   0.0000

reading (c) is sensitive to neurons with small baseline r: smallest baseline r 0.213 ; reading (c) without neurons whose baseline r < 0.1: {'compressive': np.float64(4.8), 'expansive': np.float64(-15.7), 'linear +div': np.float64(3.9), 'compressive +div': np.float64(9.4), 'expansive +div': np.float64(-13.2), 'lum linear': np.float64(0.6), 'lum compressive': np.float64(4.0), 'lum expansive': np.float64(-16.7), 'lum linear +div': np.float64(3.9), 'lum compressive +div': np.float64(8.1), 'lum expansive +div': np.float64(-11.7)}
by monkey, reading (a): {np.str_('f'): {'compressive': np.float64(3.8), 'expansive': np.float64(-13.4), 'linear +div': np.float64(1.1), 'compressive +div': np.float64(6.8), 'expansive +div': np.float64(-15.0), 'lum linear': np.float64(-0.6), 'lum compressive': np.float64(2.5), 'lum expansive': np.float64(-14.7), 'lum linear +div': np.float64(1.8), 'lum compressive +div': np.float64(5.4), 'lum expansive +div': np.float64(-12.0)}, np.str_('v'): {'compressive': np.float64(7.4), 'expansive': np.float64(-21.3), 'linear +div': np.float64(9.5), 'compressive +div': np.float64(14.2), 'expansive +div': np.float64(-7.8), 'lum linear': np.float64(0.7), 'lum compressive': np.float64(5.6), 'lum expansive': np.float64(-22.0), 'lum linear +div': np.float64(6.3), 'lum compressive +div': np.float64(11.8), 'lum expansive +div': np.float64(-11.4)}}

fig2b-contrast-normalization-no-effect¶

Luminance and contrast normalization of the stimulus does not significantly change prediction accuracy compared with the simplest model. (Claim of absence: reproduced when the Bonferroni-corrected p over 11 comparisons is not below 0.05.)

In [11]:
m = (True, 1.0, False)
pa, pb, pc, p = change(m)
print(f"luminance and contrast normalization, linear, no divisive: mean r {A[m].mean():.3f} against {A[base].mean():.3f}")
print(f"change: (a) {pa:.1f}%  (b) {pb:.1f}%  (c) {pc:.1f}%; better in {(A[m] > A[base]).sum()} of {len(IDX)}")
print(f"Wilcoxon p = {p:.4g}; Bonferroni x11 = {min(1, 11 * p):.4g}; x5 (variant) = {min(1, 5 * p):.4g}")
print(f"motion-enhanced validation only: p = {wilcoxon(A_enh[m], A_enh[base]).pvalue:.4g}")
luminance and contrast normalization, linear, no divisive: mean r 0.412 against 0.413
change: (a) -0.3%  (b) -1.4%  (c) 0.6%; better in 26 of 45
Wilcoxon p = 0.4136; Bonferroni x11 = 1; x5 (variant) = 1
motion-enhanced validation only: p = 0.8933

Result: reproduced. Luminance and contrast normalization changes the mean correlation from 0.413 to 0.412 (reading (a) -0.3%, (b) -1.4%, (c) 0.6%; better in 26 of 45). Wilcoxon p = 0.414, Bonferroni-corrected p = 1 over 11 and over 5 comparisons, so the paper's test finds no effect.

fig2b-compressive-improves¶

A compressive static output nonlinearity consistently increases predictions over the simplest model, by about 16% without and about 19% with divisive normalization (each +- 4 points, corrected p < 0.01).

In [12]:
def report(ms, expect):
    for m, e in zip(ms, expect):
        pa, pb, pc, p = change(m)
        print(f"{label(m)}: (a) {pa:.1f}%  (b) {pb:.1f}%  (c) {pc:.1f}%  [expected {e} +- 4]; "
              f"better in {(A[m] > A[base]).sum()} of {len(IDX)}; p = {p:.3g}, x11 = {min(1, 11 * p):.3g}, x5 = {min(1, 5 * p):.3g}")
        for rdg, v in zip("abc", (pa, pb, pc)):
            print(f"   reading ({rdg}) within tolerance: {abs(v - e) <= 4}")
report([(False, 0.5, False), (False, 0.5, True)], [16, 19])
compressive: (a) 4.6%  (b) 9.2%  (c) 4.8%  [expected 16 +- 4]; better in 40 of 45; p = 8.03e-09, x11 = 8.84e-08, x5 = 4.02e-08
   reading (a) within tolerance: False
   reading (b) within tolerance: False
   reading (c) within tolerance: False
compressive +div: (a) 8.4%  (b) 16.1%  (c) 9.4%  [expected 19 +- 4]; better in 40 of 45; p = 1.59e-09, x11 = 1.75e-08, x5 = 7.93e-09
   reading (a) within tolerance: False
   reading (b) within tolerance: True
   reading (c) within tolerance: False

Result: partially reproduced. The compressive nonlinearity improves predictions without and with divisive normalization in 40 of 45 neurons each, with corrected p below 1e-7 in both cases. The sizes are smaller than read from Figure 2B: 4.6% and 8.4% under reading (a), 9.2% and 16.1% under reading (b), 4.8% and 9.4% under reading (c), against 16 and 19 (+-4). Only reading (b) with divisive normalization is within tolerance, so no reading puts both values within it.

fig2b-expansive-decreases¶

An expansive static output nonlinearity always decreases predictions relative to the simplest model, by about 36% without and about 24% with divisive normalization.

In [13]:
report([(False, 2.0, False), (False, 2.0, True)], [-36, -24])
expansive: (a) -15.1%  (b) -26.9%  (c) -15.7%  [expected -36 +- 4]; better in 0 of 45; p = 5.68e-14, x11 = 6.25e-13, x5 = 2.84e-13
   reading (a) within tolerance: False
   reading (b) within tolerance: False
   reading (c) within tolerance: False
expansive +div: (a) -13.5%  (b) -24.5%  (c) -13.2%  [expected -24 +- 4]; better in 7 of 45; p = 4.11e-09, x11 = 4.52e-08, x5 = 2.05e-08
   reading (a) within tolerance: False
   reading (b) within tolerance: True
   reading (c) within tolerance: False

Result: partially reproduced. The expansive nonlinearity lowers predictions without divisive normalization in all 45 neurons and with it in 38 of 45 (corrected p below 1e-7 for both). The sizes are -15.1% and -13.5% under reading (a), -26.9% and -24.5% under reading (b), -15.7% and -13.2% under reading (c), against -36 and -24 (+-4). Reading (b) matches the value with divisive normalization but not the one without it.

fig2b-divisive-improves¶

Divisive normalization significantly improves predictions over the simplest model, by about 8% with the linear static nonlinearity.

In [14]:
report([(False, 1.0, True)], [8])
linear +div: (a) 2.9%  (b) 5.1%  (c) 3.9%  [expected 8 +- 4]; better in 30 of 45; p = 0.00511, x11 = 0.0562, x5 = 0.0255
   reading (a) within tolerance: False
   reading (b) within tolerance: True
   reading (c) within tolerance: False

Result: not reproduced. Divisive normalization with the linear nonlinearity raises the mean correlation by 2.9% (a), 5.1% (b) or 3.9% (c); reading (b) is within 8 +- 4. It is better in 30 of 45 neurons, Wilcoxon p = 0.0051, but the Bonferroni-corrected p is 0.056 over 11 comparisons (0.026 over 5), so the claim's test (corrected p < 0.01) is not met.

fig2b-compressive-divisive-best¶

The model with both a compressive nonlinearity and divisive normalization predicts significantly better than the model with the compressive nonlinearity alone, and is the simplest model that gives accurate predictions.

In [15]:
cd, c = (False, 0.5, True), (False, 0.5, False)
p = wilcoxon(A[cd], A[c]).pvalue
print(f"compressive + divisive {A[cd].mean():.3f} against compressive {A[c].mean():.3f}; better in {(A[cd] > A[c]).sum()} of {len(IDX)}")
print(f"Wilcoxon p = {p:.4g}; x11 = {min(1, 11 * p):.4g}; x5 = {min(1, 5 * p):.4g}; x12 = {min(1, 12 * p):.4g}")
print("models against compressive + divisive (positive = better than it):")
for m in models:
    if m == cd:
        continue
    pm = wilcoxon(A[m], A[cd]).pvalue
    print(f"  {label(m):28s} mean diff {A[m].mean() - A[cd].mean():+.4f}  p = {pm:.3g}  x11 = {min(1, 11 * pm):.3g}  x12 = {min(1, 12 * pm):.3g}")
compressive + divisive 0.448 against compressive 0.432; better in 34 of 45
Wilcoxon p = 0.0001551; x11 = 0.001706; x5 = 0.0007754; x12 = 0.001861
models against compressive + divisive (positive = better than it):
  linear                       mean diff -0.0346  p = 1.59e-09  x11 = 1.75e-08  x12 = 1.9e-08
  compressive                  mean diff -0.0156  p = 0.000155  x11 = 0.00171  x12 = 0.00186
  expansive                    mean diff -0.0971  p = 5.68e-14  x11 = 6.25e-13  x12 = 6.82e-13
  linear +div                  mean diff -0.0224  p = 7.39e-10  x11 = 8.12e-09  x12 = 8.86e-09
  expansive +div               mean diff -0.0903  p = 5.68e-14  x11 = 6.25e-13  x12 = 6.82e-13
  lum linear                   mean diff -0.0358  p = 1.83e-10  x11 = 2.01e-09  x12 = 2.19e-09
  lum compressive              mean diff -0.0213  p = 2.84e-06  x11 = 3.12e-05  x12 = 3.41e-05
  lum expansive                mean diff -0.1018  p = 5.68e-14  x11 = 6.25e-13  x12 = 6.82e-13
  lum linear +div              mean diff -0.0232  p = 1.15e-07  x11 = 1.27e-06  x12 = 1.38e-06
  lum compressive +div         mean diff -0.0065  p = 0.364  x11 = 1  x12 = 1
  lum expansive +div           mean diff -0.0836  p = 5.68e-14  x11 = 6.25e-13  x12 = 6.82e-13

Result: reproduced. The compressive and divisive model (mean r 0.448) beats the compressive model (0.432) in 34 of 45 neurons, Wilcoxon p = 0.00016, corrected p = 0.0017 over 11, 0.0019 over 12 and 0.0008 over 5. No other model is better on average; the closest, the same model with luminance normalization, is lower by 0.0065 (p = 0.38).

fig2b-no-interaction¶

The effects of the compressive and expansive nonlinearities do not depend on whether divisive normalization is present.

In [16]:
for div in (False, True):
    for rdg, ref in (("a", base), ("b", (False, 1.0, div))):
        for a_ in (0.5, 2.0):
            m = (False, a_, div)
            d = A[m] - A[ref]
            p = wilcoxon(A[m], A[ref]).pvalue
            print(f"divisive {div!s:5s} reading ({rdg}) {label(m):22s} against {label(ref):14s}: mean diff {d.mean():+.4f}, "
                  f"p = {p:.3g}, x11 = {min(1, 11 * p):.3g}")
divisive False reading (a) compressive            against linear        : mean diff +0.0189, p = 8.03e-09, x11 = 8.84e-08
divisive False reading (a) expansive              against linear        : mean diff -0.0625, p = 5.68e-14, x11 = 6.25e-13
divisive False reading (b) compressive            against linear        : mean diff +0.0189, p = 8.03e-09, x11 = 8.84e-08
divisive False reading (b) expansive              against linear        : mean diff -0.0625, p = 5.68e-14, x11 = 6.25e-13
divisive True  reading (a) compressive +div       against linear        : mean diff +0.0346, p = 1.59e-09, x11 = 1.75e-08
divisive True  reading (a) expansive +div         against linear        : mean diff -0.0557, p = 4.11e-09, x11 = 4.52e-08
divisive True  reading (b) compressive +div       against linear +div   : mean diff +0.0224, p = 7.39e-10, x11 = 8.12e-09
divisive True  reading (b) expansive +div         against linear +div   : mean diff -0.0678, p = 5.68e-14, x11 = 6.25e-13

Result: reproduced. Without divisive normalization the compressive model is better than the linear one (+0.019, corrected p = 8.8e-8) and the expansive one worse (-0.063, 6.3e-13). With divisive normalization the same holds against the simplest model (reading (a): +0.035, p = 1.8e-8; -0.056, p = 4.5e-8) and against the linear divisive model (reading (b): +0.022, p = 8.1e-9; -0.068, p = 6.3e-13).

complex-cells-dominate¶

Most of the response variance is captured by the model complex cells, and the model simple cells have only a small effect on prediction performance. (Reproduced when the complex-only model reaches at least half of the full model's mean squared correlation and drops the mean correlation less than the simple-only model does.)

In [17]:
full = A[mt2.MAIN]
co = pd.Series([acc(R[n]["fits"][mt2.MAIN]["complex_only"]["r"]) for n in names_run], index=IDX)
so = pd.Series([acc(R[n]["fits"][mt2.MAIN]["simple_only"]["r"]) for n in names_run], index=IDX)
print(f"mean r: full {full.mean():.3f}, complex only {co.mean():.3f}, simple only {so.mean():.3f}")
print(f"mean r^2: full {(full**2).mean():.4f}, complex only {(co**2).mean():.4f} "
      f"(ratio {(co**2).mean() / (full**2).mean():.3f}), simple only {(so**2).mean():.4f} (ratio {(so**2).mean() / (full**2).mean():.3f})")
print(f"drop of mean r: complex only {full.mean() - co.mean():.4f}, simple only {full.mean() - so.mean():.4f}")
print(f"Wilcoxon full vs complex only p = {wilcoxon(full, co).pvalue:.3g}; full vs simple only p = {wilcoxon(full, so).pvalue:.3g}")
print("regressors: complex", int((R[names_run[0]]["rd"][:, 5] == 0).sum()), ", simple", int((R[names_run[0]]["rd"][:, 5] == 1).sum()))
mean r: full 0.448, complex only 0.448, simple only 0.194
mean r^2: full 0.2155, complex only 0.2156 (ratio 1.001), simple only 0.0539 (ratio 0.250)
drop of mean r: complex only -0.0001, simple only 0.2545
Wilcoxon full vs complex only p = 0.0544; full vs simple only p = 5.68e-14
regressors: complex 545 , simple 218

Result: reproduced. With complex-cell regressors only, the mean correlation is 0.448, as for the full model (mean r squared ratio 1.001; the complex-only model is higher by 0.0002 on average, Wilcoxon p = 0.049); with simple-cell regressors only it falls to 0.194 (ratio 0.250, p = 5.7e-14). Here the simple cells are limited to 0.75 cycles per cRF and SF 0 (218 of 763 regressors).

Spectral receptive fields: the optimal plane¶

The optimal plane, on-plane ratio and horizontal-vertical ratio are computed as in mt2.py, under the claims file's readings: balance of the two constraints (a) coverage with symmetry breaking ties, (b) both scaled and summed; quantity (a) fitted weights, (b) weights times spectral amplitude; sign split (a) per weight at each delay, (b) after summing over delays.

In [18]:
rd = R[names_run[0]]["rd"]
amp = mt2.regressor_amplitude(rd)
near, side, PTH, PV = mt2.plane_geometry(rd)
RCOMB = [(b, q, s) for b in "ab" for q in "ab" for s in "ab"]

def plane_stats(w, sd):
    out = {}
    for b, q, s in RCOMB:
        E, I = mt2.split_weights(w, sd, amp, quantity=q, sign=s)
        j = mt2.optimal_plane(E, near, side, balance=b)
        out[(b, q, s)] = dict(exc=mt2.on_plane_ratio(E, near[:, j]), sup=mt2.on_plane_ratio(I, near[:, j]),
                              th=PTH[j], v=PV[j], hv_a=mt2.hv_ratio(E, rd, PTH[j], near[:, j], "a"),
                              hv_b=mt2.hv_ratio(E, rd, PTH[j], near[:, j], "b"))
    return out

real = {n: plane_stats(R[n]["fits"][mt2.MAIN]["w"], R[n]["fits"][mt2.MAIN]["sd"]) for n in names_run}
nulls = {}
for n in names_run:
    sdn = R[n]["fits"][mt2.MAIN]["sd"]
    for nl in R[n].get("nulls", []):
        key = (nl["id"][0], nl["rate"], nl["delay"])
        nulls.setdefault(key, []).append(plane_stats(nl["w"], sdn))
print({k: len(v) for k, v in nulls.items()})
{('a', 'a', 'a'): 150, ('a', 'a', 'b'): 150, ('a', 'b', 'a'): 150, ('a', 'b', 'b'): 150, ('b', 'a', 'a'): 150}

fig6a-null-on-plane¶

For 150 model MT neurons with random weights, the average excitatory on-plane ratio is 0.36 (expected 0.36 +- 0.036).

In [19]:
rows = []
for key, lst in sorted(nulls.items()):
    for rc in RCOMB:
        v = np.array([x[rc]["exc"] for x in lst])
        rows.append(dict(movies=key[0], rate=key[1], delays=key[2], balance=rc[0], quantity=rc[1], sign=rc[2],
                         n=len(v), mean_exc=v.mean(), sd=v.std(), within=0.324 <= v.mean() <= 0.396))
NT = pd.DataFrame(rows)
print(NT.round(3).to_string())
print("\ncombinations within 0.324 to 0.396:", int(NT.within.sum()), "of", len(NT))
   movies rate delays balance quantity sign    n  mean_exc     sd  within
0       a    a      a       a        a    a  150     0.396  0.072    True
1       a    a      a       a        a    b  150     0.422  0.072   False
2       a    a      a       a        b    a  150     0.341  0.060    True
3       a    a      a       a        b    b  150     0.367  0.064    True
4       a    a      a       b        a    a  150     0.378  0.076    True
5       a    a      a       b        a    b  150     0.402  0.077   False
6       a    a      a       b        b    a  150     0.324  0.064   False
7       a    a      a       b        b    b  150     0.346  0.068    True
8       a    a      b       a        a    a  150     0.445  0.093   False
9       a    a      b       a        a    b  150     0.461  0.093   False
10      a    a      b       a        b    a  150     0.398  0.081   False
11      a    a      b       a        b    b  150     0.416  0.084   False
12      a    a      b       b        a    a  150     0.428  0.095   False
13      a    a      b       b        a    b  150     0.443  0.096   False
14      a    a      b       b        b    a  150     0.380  0.083    True
15      a    a      b       b        b    b  150     0.396  0.087    True
16      a    b      a       a        a    a  150     0.499  0.130   False
17      a    b      a       a        a    b  150     0.508  0.129   False
18      a    b      a       a        b    a  150     0.476  0.131   False
19      a    b      a       a        b    b  150     0.484  0.131   False
20      a    b      a       b        a    a  150     0.468  0.131   False
21      a    b      a       b        a    b  150     0.477  0.129   False
22      a    b      a       b        b    a  150     0.441  0.128   False
23      a    b      a       b        b    b  150     0.449  0.127   False
24      a    b      b       a        a    a  150     0.523  0.130   False
25      a    b      b       a        a    b  150     0.533  0.130   False
26      a    b      b       a        b    a  150     0.497  0.133   False
27      a    b      b       a        b    b  150     0.506  0.134   False
28      a    b      b       b        a    a  150     0.481  0.129   False
29      a    b      b       b        a    b  150     0.490  0.129   False
30      a    b      b       b        b    a  150     0.452  0.136   False
31      a    b      b       b        b    b  150     0.460  0.134   False
32      b    a      a       a        a    a  150     0.403  0.076   False
33      b    a      a       a        a    b  150     0.429  0.077   False
34      b    a      a       a        b    a  150     0.350  0.063    True
35      b    a      a       a        b    b  150     0.375  0.069    True
36      b    a      a       b        a    a  150     0.389  0.078    True
37      b    a      a       b        a    b  150     0.412  0.081   False
38      b    a      a       b        b    a  150     0.333  0.065    True
39      b    a      a       b        b    b  150     0.356  0.072    True

combinations within 0.324 to 0.396: 12 of 40

Result: reproduced. The mean excitatory on-plane ratio of the 150 null model neurons is within 0.324 to 0.396 in 12 of 40 combinations of readings. With every reading (a) it is 0.395 (SD 0.072), at the upper edge; null neurons made non-negative by an offset (rate reading (b)) give 0.44 to 0.53, outside the tolerance in every combination.

fig6a-excitatory-on-plane¶

Excitatory spectral receptive fields of MT neurons tend to lie on a single plane; their average on-plane ratio is 0.59 (+- 0.059), significantly above the null model's 0.36 (rank-sum p < 0.01).

In [20]:
rows = []
for rc in RCOMB:
    v = np.array([real[n][rc]["exc"] for n in names_run])
    for key, lst in sorted(nulls.items()):
        nv = np.array([x[rc]["exc"] for x in lst])
        st = ranksums(v, nv)
        rows.append(dict(balance=rc[0], quantity=rc[1], sign=rc[2], mean_exc=v.mean(), null=f"{key[0]}{key[1]}{key[2]}",
                         null_mean=nv.mean(), p=st.pvalue, higher=v.mean() > nv.mean(),
                         ok=(0.531 <= v.mean() <= 0.649) and st.pvalue < 0.01 and v.mean() > nv.mean()))
ET = pd.DataFrame(rows)
print(ET.round(4).to_string())
print("\ncombinations meeting the criterion:", int(ET.ok.sum()), "of", len(ET))
for mk in np.unique(monkey):
    print(f"monkey {mk}, reading aaa: mean {np.mean([real[n][('a','a','a')]['exc'] for n, mm in zip(names_run, monkey) if mm == mk]):.3f}")
   balance quantity sign  mean_exc null  null_mean       p  higher    ok
0        a        a    a    0.5916  aaa     0.3956  0.0000    True  True
1        a        a    a    0.5916  aab     0.4449  0.0000    True  True
2        a        a    a    0.5916  aba     0.4986  0.0001    True  True
3        a        a    a    0.5916  abb     0.5234  0.0050    True  True
4        a        a    a    0.5916  baa     0.4034  0.0000    True  True
5        a        a    b    0.5963  aaa     0.4220  0.0000    True  True
6        a        a    b    0.5963  aab     0.4609  0.0000    True  True
7        a        a    b    0.5963  aba     0.5082  0.0002    True  True
8        a        a    b    0.5963  abb     0.5325  0.0098    True  True
9        a        a    b    0.5963  baa     0.4289  0.0000    True  True
10       a        b    a    0.5697  aaa     0.3407  0.0000    True  True
11       a        b    a    0.5697  aab     0.3976  0.0000    True  True
12       a        b    a    0.5697  aba     0.4756  0.0001    True  True
13       a        b    a    0.5697  abb     0.4974  0.0031    True  True
14       a        b    a    0.5697  baa     0.3500  0.0000    True  True
15       a        b    b    0.5756  aaa     0.3670  0.0000    True  True
16       a        b    b    0.5756  aab     0.4159  0.0000    True  True
17       a        b    b    0.5756  aba     0.4839  0.0002    True  True
18       a        b    b    0.5756  abb     0.5058  0.0050    True  True
19       a        b    b    0.5756  baa     0.3750  0.0000    True  True
20       b        a    a    0.5771  aaa     0.3782  0.0000    True  True
21       b        a    a    0.5771  aab     0.4277  0.0000    True  True
22       b        a    a    0.5771  aba     0.4685  0.0000    True  True
23       b        a    a    0.5771  abb     0.4811  0.0001    True  True
24       b        a    a    0.5771  baa     0.3892  0.0000    True  True
25       b        a    b    0.5795  aaa     0.4020  0.0000    True  True
26       b        a    b    0.5795  aab     0.4426  0.0000    True  True
27       b        a    b    0.5795  aba     0.4766  0.0000    True  True
28       b        a    b    0.5795  abb     0.4902  0.0004    True  True
29       b        a    b    0.5795  baa     0.4122  0.0000    True  True
30       b        b    a    0.5504  aaa     0.3237  0.0000    True  True
31       b        b    a    0.5504  aab     0.3796  0.0000    True  True
32       b        b    a    0.5504  aba     0.4411  0.0000    True  True
33       b        b    a    0.5504  abb     0.4521  0.0001    True  True
34       b        b    a    0.5504  baa     0.3329  0.0000    True  True
35       b        b    b    0.5576  aaa     0.3465  0.0000    True  True
36       b        b    b    0.5576  aab     0.3958  0.0000    True  True
37       b        b    b    0.5576  aba     0.4487  0.0000    True  True
38       b        b    b    0.5576  abb     0.4599  0.0001    True  True
39       b        b    b    0.5576  baa     0.3565  0.0000    True  True

combinations meeting the criterion: 40 of 40
monkey f, reading aaa: mean 0.555
monkey v, reading aaa: mean 0.705

Result: reproduced. The mean excitatory on-plane ratio is 0.550 to 0.596 across the eight readings, within 0.531 to 0.649 in all of them, and above every null set by a rank-sum test (p from below 1e-4 to 0.0078), so all 40 combinations meet the criterion. With every reading (a) it is 0.592; monkey f 0.556, monkey v 0.705.

fig6b-suppressive-off-plane¶

Suppressive spectral receptive fields tend to avoid the optimal excitatory plane; their average on-plane ratio is 0.18 (+- 0.018), significantly below the null model (the null model's suppressive ratios; its excitatory ratios as a variant).

In [21]:
rows = []
for rc in RCOMB:
    v = np.array([real[n][rc]["sup"] for n in names_run])
    for key, lst in sorted(nulls.items()):
        ns_ = np.array([x[rc]["sup"] for x in lst])
        ne_ = np.array([x[rc]["exc"] for x in lst])
        p1, p2 = ranksums(v, ns_).pvalue, ranksums(v, ne_).pvalue
        rows.append(dict(balance=rc[0], quantity=rc[1], sign=rc[2], mean_sup=v.mean(), null=f"{key[0]}{key[1]}{key[2]}",
                         null_sup=ns_.mean(), p_vs_null_sup=p1, null_exc=ne_.mean(), p_vs_null_exc=p2,
                         ok=(0.162 <= v.mean() <= 0.198) and p1 < 0.01 and v.mean() < ns_.mean()))
ST = pd.DataFrame(rows)
print(ST.round(4).to_string())
print("\ncombinations meeting the criterion:", int(ST.ok.sum()), "of", len(ST))
   balance quantity sign  mean_sup null  null_sup  p_vs_null_sup  null_exc  p_vs_null_exc     ok
0        a        a    a    0.1677  aaa    0.2005         0.0029    0.3956            0.0   True
1        a        a    a    0.1677  aab    0.1957         0.0097    0.4449            0.0   True
2        a        a    a    0.1677  aba    0.1644         0.8898    0.4986            0.0  False
3        a        a    a    0.1677  abb    0.1458         0.2342    0.5234            0.0  False
4        a        a    a    0.1677  baa    0.1955         0.0058    0.4034            0.0   True
5        a        a    b    0.1538  aaa    0.2072         0.0000    0.4220            0.0  False
6        a        a    b    0.1538  aab    0.1987         0.0001    0.4609            0.0  False
7        a        a    b    0.1538  aba    0.1625         0.3695    0.5082            0.0  False
8        a        a    b    0.1538  abb    0.1483         0.8590    0.5325            0.0  False
9        a        a    b    0.1538  baa    0.2042         0.0000    0.4289            0.0  False
10       a        b    a    0.1072  aaa    0.1431         0.0003    0.3407            0.0  False
11       a        b    a    0.1072  aab    0.1344         0.0025    0.3976            0.0  False
12       a        b    a    0.1072  aba    0.1287         0.1125    0.4756            0.0  False
13       a        b    a    0.1072  abb    0.1112         0.8590    0.4974            0.0  False
14       a        b    a    0.1072  baa    0.1378         0.0008    0.3500            0.0  False
15       a        b    b    0.0940  aaa    0.1419         0.0000    0.3670            0.0  False
16       a        b    b    0.0940  aab    0.1341         0.0000    0.4159            0.0  False
17       a        b    b    0.0940  aba    0.1222         0.0766    0.4839            0.0  False
18       a        b    b    0.0940  abb    0.1079         0.6066    0.5058            0.0  False
19       a        b    b    0.0940  baa    0.1352         0.0000    0.3750            0.0  False
20       b        a    a    0.1708  aaa    0.2091         0.0008    0.3782            0.0   True
21       b        a    a    0.1708  aab    0.2027         0.0050    0.4277            0.0   True
22       b        a    a    0.1708  aba    0.1675         0.9736    0.4685            0.0  False
23       b        a    a    0.1708  abb    0.1656         0.7910    0.4811            0.0  False
24       b        a    a    0.1708  baa    0.2031         0.0030    0.3892            0.0   True
25       b        a    b    0.1587  aaa    0.2194         0.0000    0.4020            0.0  False
26       b        a    b    0.1587  aab    0.2057         0.0001    0.4426            0.0  False
27       b        a    b    0.1587  aba    0.1695         0.4248    0.4766            0.0  False
28       b        a    b    0.1587  abb    0.1656         0.6299    0.4902            0.0  False
29       b        a    b    0.1587  baa    0.2138         0.0000    0.4122            0.0  False
30       b        b    a    0.1115  aaa    0.1489         0.0003    0.3237            0.0  False
31       b        b    a    0.1115  aab    0.1438         0.0010    0.3796            0.0  False
32       b        b    a    0.1115  aba    0.1266         0.2769    0.4411            0.0  False
33       b        b    a    0.1115  abb    0.1201         0.6514    0.4521            0.0  False
34       b        b    a    0.1115  baa    0.1407         0.0016    0.3329            0.0  False
35       b        b    b    0.0978  aaa    0.1506         0.0000    0.3465            0.0  False
36       b        b    b    0.0978  aab    0.1420         0.0000    0.3958            0.0  False
37       b        b    b    0.0978  aba    0.1217         0.0929    0.4487            0.0  False
38       b        b    b    0.0978  abb    0.1167         0.2575    0.4599            0.0  False
39       b        b    b    0.0978  baa    0.1404         0.0000    0.3565            0.0  False

combinations meeting the criterion: 6 of 40

Result: reproduced. With the fitted weights split per delay (quantity (a), sign (a)), the mean suppressive on-plane ratio is 0.168 (balance (a)) or 0.171 (balance (b)), within 0.162 to 0.198, and below the null model's suppressive ratios of 0.195 to 0.209 for the null sets with rectified rates (rank-sum p 0.0009 to 0.0080). Six of 40 combinations meet the criterion. With the other readings the ratio is 0.094 to 0.159, below the tolerance band, and null sets made non-negative by an offset have suppressive ratios of 0.11 to 0.17 that do not differ from the real ones.

fig7a-partial-ring¶

The horizontal-vertical ratio is distributed continuously; few neurons form a full ring or a single peak, and most form a partial ring. (Reproduced when, under one combination, more than half of the neurons fall between the extremes and fewer than a quarter fall in each extreme; extremes (a) < 0.2 and >= 0.8, (b) < 0.1 and >= 0.9.)

In [22]:
rows = []
HV = {}
for rc in RCOMB:
    for proj in ("a", "b"):
        v = np.array([real[n][rc][f"hv_{proj}"] for n in names_run])
        HV[(rc, proj)] = v
        for ext, (lo, hi) in (("a", (0.2, 0.8)), ("b", (0.1, 0.9))):
            fl, fr = np.mean(v < lo), np.mean(v >= hi)
            mid = 1 - fl - fr
            rows.append(dict(balance=rc[0], quantity=rc[1], sign=rc[2], amplitudes=proj, extremes=ext,
                             median=np.median(v), low=fl, ring=fr, between=mid,
                             ok=mid > 0.5 and fl < 0.25 and fr < 0.25))
HT = pd.DataFrame(rows)
print(HT.round(3).to_string())
print("\ncombinations meeting the criterion:", int(HT.ok.sum()), "of", len(HT))
v = HV[(("a", "a", "a"), "a")]
print("ratios, reading aaa/a: range", np.round(v.min(), 3), "to", np.round(v.max(), 3), "; infinite:", int(np.isinf(v).sum()))
fig, ax = plt.subplots(figsize=(4, 3))
ax.hist(np.clip(v, 0, 3), bins=30, color="0.4"); ax.set_xlabel("horizontal-vertical ratio (clipped at 3)")
print("points above 3 (clipped):", int((v > 3).sum()))
   balance quantity sign amplitudes extremes  median    low   ring  between     ok
0        a        a    a          a        a   0.534  0.067  0.222    0.711   True
1        a        a    a          a        b   0.534  0.022  0.222    0.756   True
2        a        a    a          b        a   0.657  0.022  0.244    0.733   True
3        a        a    a          b        b   0.657  0.000  0.156    0.844   True
4        a        a    b          a        a   0.557  0.089  0.244    0.667   True
5        a        a    b          a        b   0.557  0.022  0.244    0.733   True
6        a        a    b          b        a   0.622  0.022  0.289    0.689  False
7        a        a    b          b        b   0.622  0.000  0.222    0.778   True
8        a        b    a          a        a   0.556  0.067  0.289    0.644  False
9        a        b    a          a        b   0.556  0.022  0.289    0.689  False
10       a        b    a          b        a   0.667  0.022  0.333    0.644  False
11       a        b    a          b        b   0.667  0.000  0.178    0.822   True
12       a        b    b          a        a   0.501  0.111  0.311    0.578  False
13       a        b    b          a        b   0.501  0.022  0.311    0.667  False
14       a        b    b          b        a   0.605  0.022  0.333    0.644  False
15       a        b    b          b        b   0.605  0.000  0.200    0.800   True
16       b        a    a          a        a   0.507  0.111  0.200    0.689   True
17       b        a    a          a        b   0.507  0.067  0.178    0.756   True
18       b        a    a          b        a   0.671  0.022  0.178    0.800   True
19       b        a    a          b        b   0.671  0.000  0.089    0.911   True
20       b        a    b          a        a   0.515  0.133  0.200    0.667   True
21       b        a    b          a        b   0.515  0.067  0.178    0.756   True
22       b        a    b          b        a   0.624  0.022  0.156    0.822   True
23       b        a    b          b        b   0.624  0.000  0.089    0.911   True
24       b        b    a          a        a   0.462  0.133  0.178    0.689   True
25       b        b    a          a        b   0.462  0.067  0.111    0.822   True
26       b        b    a          b        a   0.603  0.022  0.133    0.844   True
27       b        b    a          b        b   0.603  0.000  0.067    0.933   True
28       b        b    b          a        a   0.466  0.133  0.178    0.689   True
29       b        b    b          a        b   0.466  0.089  0.133    0.778   True
30       b        b    b          b        a   0.605  0.022  0.156    0.822   True
31       b        b    b          b        b   0.605  0.000  0.067    0.933   True

combinations meeting the criterion: 25 of 32
ratios, reading aaa/a: range 0.055 to 1.652 ; infinite: 0
points above 3 (clipped): 0
No description has been provided for this image

Result: reproduced. In 25 of 32 combinations more than half of the neurons fall between the extremes and fewer than a quarter in each. With every reading (a) and extremes (a), 6.7% of neurons have ratios below 0.2, 22.2% at or above 0.8, and 71.1% between them (median 0.534, range 0.055 to 1.652).

fig7a-no-corr-prediction-hv¶

Prediction performance is not significantly correlated with the horizontal-vertical ratio. (Pearson correlation, t test; reproduced when p > 0.10, not reproduced when p < 0.05.)

In [23]:
pr_ = A[mt2.MAIN].values
rows = []
for (rc, proj), v in HV.items():
    ok = np.isfinite(v)
    r, p = pearsonr(pr_[ok], v[ok])
    rows.append(dict(balance=rc[0], quantity=rc[1], sign=rc[2], amplitudes=proj, n=int(ok.sum()), r=r, p=p))
CT = pd.DataFrame(rows)
print(CT.round(4).to_string())
print("\np > 0.10:", int((CT.p > 0.10).sum()), "; p < 0.05:", int((CT.p < 0.05).sum()), "of", len(CT))
   balance quantity sign amplitudes   n       r       p
0        a        a    a          a  45 -0.2813  0.0612
1        a        a    a          b  45 -0.2488  0.0993
2        a        a    b          a  45 -0.1416  0.3535
3        a        a    b          b  45 -0.1368  0.3701
4        a        b    a          a  45 -0.3797  0.0101
5        a        b    a          b  45 -0.2851  0.0577
6        a        b    b          a  45 -0.3219  0.0311
7        a        b    b          b  45 -0.2193  0.1478
8        b        a    a          a  45 -0.1720  0.2586
9        b        a    a          b  45 -0.2241  0.1388
10       b        a    b          a  45 -0.1196  0.4338
11       b        a    b          b  45 -0.1717  0.2594
12       b        b    a          a  45 -0.2537  0.0926
13       b        b    a          b  45 -0.2075  0.1714
14       b        b    b          a  45 -0.1808  0.2346
15       b        b    b          b  45 -0.1931  0.2036

p > 0.10: 10 ; p < 0.05: 2 of 16

Result: partially reproduced. With every reading (a), the correlation of prediction accuracy with the horizontal-vertical ratio is r = -0.281, p = 0.061, between the claim's bounds of 0.05 and 0.10. Across the 16 readings p > 0.10 in 10 and p < 0.05 in 2 (r from -0.380 to -0.120); every coefficient is negative.

fig7b-pattern-index¶

Simulated plaid responses give pattern indices that form a continuum, mostly from -6 to 2, with highly pattern-selective neurons rare. (Reproduced when more than half of the neurons are within -6.6 to 2.2 and fewer than 10% exceed 2.2.)

In [24]:
def peak_pair(n):
    E, _ = mt2.split_weights(R[n]["fits"][mt2.MAIN]["w"])
    sel = (rd[:, 5] == 0) & (rd[:, 0] > 0) & (rd[:, 2] > 0)
    j = np.where(sel)[0][np.argmax(E[sel])]
    return (rd[j, 0], rd[j, 2])
pk = {n: peak_pair(n) for n in names_run}
vals, cnt = np.unique([f"{a}|{b}" for a, b in pk.values()], return_counts=True)
pop = tuple(float(x) for x in vals[np.argmax(cnt)].split("|"))
print("peak (SF cycles/cRF, TF Hz) counts:", dict(zip(vals, cnt)), "; population pair:", pop)
PI = {}
for fr in ("a", "b"):
    for sep in (120, 90):
        PI[(fr, sep)] = np.array([mt2.pattern_index(R[n]["fits"][mt2.MAIN]["plaid"][pk[n] if fr == "a" else pop]["grating"],
                                                    R[n]["fits"][mt2.MAIN]["plaid"][pk[n] if fr == "a" else pop][f"plaid{sep}"], sep)
                                  for n in names_run])
rows = []
for k, v in PI.items():
    rows.append(dict(frequency=k[0], separation=k[1], median=np.median(v), min=v.min(), max=v.max(),
                     in_range=np.mean((v >= -6.6) & (v <= 2.2)), above_2_2=np.mean(v > 2.2), above_1_28=np.mean(v > 1.28),
                     ok=np.mean((v >= -6.6) & (v <= 2.2)) > 0.5 and np.mean(v > 2.2) < 0.10))
PT = pd.DataFrame(rows)
print(PT.round(3).to_string())
print("\ncombinations meeting the criterion:", int(PT.ok.sum()), "of", len(PT))
# Readings of the simulated response (the paper does not say; it names Poisson noise for the null model only):
# rectified rates without noise, and Poisson spike counts over 1 s presentations averaged over 5, 10 or 20
# repeats (the paper's validation repeats), 20 draws each.
rows, PIN, PIR = [], {}, {}
for fr in ("a", "b"):
    for sep in (120, 90):
        tun = [R[n]["fits"][mt2.MAIN]["plaid"][pk[n] if fr == "a" else pop] for n in names_run]
        v = np.array([mt2.pattern_index(np.maximum(t["grating"], 0), np.maximum(t[f"plaid{sep}"], 0), sep) for t in tun])
        PIR[(fr, sep)] = v
        inr = np.mean((v >= -6.6) & (v <= 2.2))
        rows.append(dict(response="rectified", frequency=fr, separation=sep, flat=int(np.isnan(v).sum()), median=np.nanmedian(v), in_range=inr,
                         above_2_2=np.mean(v > 2.2), ok=inr > 0.5 and np.mean(v > 2.2) < 0.10, draws_ok="-"))
        for nrep in (5, 10, 20):
            rng = np.random.default_rng(1000 + nrep)
            draws = [np.array([mt2.pattern_index(mt2.noisy_tuning(t["grating"], nrep, rng), mt2.noisy_tuning(t[f"plaid{sep}"], nrep, rng), sep)
                               for t in tun]) for _ in range(20)]
            PIN[(nrep, fr, sep)] = draws[0]
            inr = [np.mean((d >= -6.6) & (d <= 2.2)) for d in draws]
            ok = [np.mean((d >= -6.6) & (d <= 2.2)) > 0.5 and np.mean(d > 2.2) < 0.10 for d in draws]
            rows.append(dict(response=f"Poisson, {nrep} repeats", frequency=fr, separation=sep, flat=int(np.isnan(draws[0]).sum()),
                             median=np.median([np.nanmedian(d) for d in draws]), in_range=np.median(inr),
                             above_2_2=np.median([np.mean(d > 2.2) for d in draws]), ok=np.median(inr) > 0.5, draws_ok=f"{sum(ok)} of 20"))
print("\nflat: neurons whose rectified responses are zero in every direction (index undefined, counted outside the range)")
print(pd.DataFrame(rows).round(3).to_string())
print("rectified, every neuron's index, reading (a), 120 degrees: range", np.nanmin(PIR[("a", 120)]).round(2), "to", np.nanmax(PIR[("a", 120)]).round(2))
peak (SF cycles/cRF, TF Hz) counts: {np.str_('1.5|15.0'): np.int64(2), np.str_('1.5|30.0'): np.int64(1), np.str_('1.5|7.5'): np.int64(2), np.str_('3.0|15.0'): np.int64(8), np.str_('3.0|30.0'): np.int64(2), np.str_('3.0|7.5'): np.int64(1), np.str_('6.0|15.0'): np.int64(16), np.str_('6.0|3.75'): np.int64(3), np.str_('6.0|30.0'): np.int64(1), np.str_('6.0|7.5'): np.int64(9)} ; population pair: (6.0, 15.0)
  frequency  separation  median     min    max  in_range  above_2_2  above_1_28     ok
0         a         120  -8.603 -13.484 -4.375     0.178        0.0         0.0  False
1         a          90 -10.642 -13.603 -7.495     0.000        0.0         0.0  False
2         b         120  -8.808 -14.561 -4.900     0.089        0.0         0.0  False
3         b          90 -10.652 -13.328 -5.284     0.022        0.0         0.0  False

combinations meeting the criterion: 0 of 4
/home/runner/work/encore/encore/executed/nishimoto-2011/.venv/lib/python3.13/site-packages/numpy/lib/_function_base_impl.py:3037: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/runner/work/encore/encore/executed/nishimoto-2011/.venv/lib/python3.13/site-packages/numpy/lib/_function_base_impl.py:3038: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
flat: neurons whose rectified responses are zero in every direction (index undefined, counted outside the range)
               response frequency  separation  flat  median  in_range  above_2_2     ok  draws_ok
0             rectified         a         120     0  -5.067     0.644        0.0   True         -
1    Poisson, 5 repeats         a         120     0  -4.875     0.689        0.0   True  20 of 20
2   Poisson, 10 repeats         a         120     0  -4.992     0.678        0.0   True  20 of 20
3   Poisson, 20 repeats         a         120     0  -5.217     0.644        0.0   True  20 of 20
4             rectified         a          90     0  -6.887     0.489        0.0  False         -
5    Poisson, 5 repeats         a          90     0  -5.558     0.600        0.0   True  20 of 20
6   Poisson, 10 repeats         a          90     0  -6.056     0.578        0.0   True  19 of 20
7   Poisson, 20 repeats         a          90     0  -6.374     0.533        0.0   True  16 of 20
8             rectified         b         120     2  -5.161     0.578        0.0   True         -
9    Poisson, 5 repeats         b         120     2  -5.190     0.622        0.0   True  20 of 20
10  Poisson, 10 repeats         b         120     2  -5.324     0.578        0.0   True  20 of 20
11  Poisson, 20 repeats         b         120     2  -5.353     0.578        0.0   True  20 of 20
12            rectified         b          90     3  -5.866     0.533        0.0   True         -
13   Poisson, 5 repeats         b          90     3  -5.335     0.600        0.0   True  20 of 20
14  Poisson, 10 repeats         b          90     3  -5.718     0.578        0.0   True  20 of 20
15  Poisson, 20 repeats         b          90     3  -5.826     0.556        0.0   True  20 of 20
rectified, every neuron's index, reading (a), 120 degrees: range -10.97 to 0.31
In [25]:
# How much the rectification clips: per neuron, the share of the 24 grating and 12 plaid directions whose
# model response is below zero (per-neuron peak frequency), and the index with and without rectification
for sep in (120, 90):
    tun = [R[n]["fits"][mt2.MAIN]["plaid"][pk[n]] for n in names_run]
    fg = np.array([np.mean(t["grating"] < 0) for t in tun])
    fp = np.array([np.mean(t[f"plaid{sep}"] < 0) for t in tun])
    fa = (24 * fg + 12 * fp) / 36
    pu, pr = PI[("a", sep)], PIR[("a", sep)]
    print(f"\n{sep} degree plaids: share of directions clipped, median {np.median(fa):.2f} (range {fa.min():.2f} to {fa.max():.2f}); "
          f"gratings {np.median(fg):.2f}, plaids {np.median(fp):.2f}")
    print(f"  Spearman, clipped share against the rectified index: rho = {spearmanr(fa, pr)[0]:.3f}, p = {spearmanr(fa, pr)[1]:.3g}; "
          f"against its change (rectified - unrectified): rho = {spearmanr(fa, pr - pu)[0]:.3f}, p = {spearmanr(fa, pr - pu)[1]:.3g}")
    bins = [(0, 0), (1e-9, 0.25), (0.25 + 1e-9, 0.5), (0.5 + 1e-9, 1)]
    rows = []
    for lo, hi in bins:
        s = (fa >= lo) & (fa <= hi)
        rows.append(dict(clipped=f"{lo:.2f} to {hi:.2f}" if hi else "none", n=int(s.sum()),
                         median_unrectified=np.median(pu[s]) if s.any() else np.nan,
                         median_rectified=np.median(pr[s]) if s.any() else np.nan,
                         in_range_unrectified=int(((pu >= -6.6) & (pu <= 2.2) & s).sum()),
                         in_range_rectified=int(((pr >= -6.6) & (pr <= 2.2) & s).sum())))
    print(pd.DataFrame(rows).round(2).to_string(index=False))
    if sep == 120:
        print(pd.DataFrame({"gratings_clipped": fg, "plaids_clipped": fp, "index_unrectified": pu, "index_rectified": pr},
                           index=IDX).round(2).to_string())
120 degree plaids: share of directions clipped, median 0.25 (range 0.00 to 0.58); gratings 0.29, plaids 0.17
  Spearman, clipped share against the rectified index: rho = 0.451, p = 0.00186; against its change (rectified - unrectified): rho = 0.569, p = 4.59e-05
     clipped  n  median_unrectified  median_rectified  in_range_unrectified  in_range_rectified
        none  8               -8.33             -8.33                     2                   2
0.00 to 0.25 17               -8.74             -6.27                     1                  10
0.25 to 0.50 18               -9.01             -4.25                     5                  15
0.50 to 1.00  2               -8.59             -5.22                     0                   2
        gratings_clipped  plaids_clipped  index_unrectified  index_rectified
ct0001              0.00            0.00              -8.06            -8.06
ct0002              0.38            0.25              -6.56            -4.65
ct0005              0.33            0.25              -7.45            -1.83
ct0006              0.17            0.08             -10.91            -5.96
ct0008              0.25            0.25              -8.37            -8.84
ct0009              0.38            0.17              -9.49            -4.68
ct0010              0.54            0.58              -8.37            -4.25
ct0011              0.29            0.25             -10.51            -4.96
ct0013              0.17            0.00             -11.25            -8.36
ct0014              0.50            0.25             -10.15            -5.07
ct0018              0.46            0.25              -9.99            -3.04
ct0021              0.38            0.33              -9.52            -4.36
ct0023              0.62            0.50              -8.81            -6.19
ct0024              0.54            0.25             -13.48           -10.07
ct0026              0.42            0.42              -6.23             0.31
ct0027              0.46            0.58              -4.41            -1.73
ct0028              0.00            0.00              -8.64            -8.64
ct0030              0.00            0.00              -8.84            -8.84
ct0031              0.46            0.50             -10.87            -4.04
ct0032              0.00            0.00              -8.60            -8.60
ct0037              0.50            0.25              -6.91            -9.82
ct0039              0.42            0.25              -6.57            -3.76
ct0040              0.38            0.17              -8.52            -2.66
ct0041              0.12            0.00             -10.74            -8.30
ct0042              0.29            0.08              -8.17            -4.95
ct0043              0.29            0.17              -9.00            -1.55
ct0047              0.38            0.17             -11.76            -7.75
ct0048              0.25            0.17             -10.01            -7.87
ct0049              0.21            0.00              -6.79            -6.23
ct0050              0.12            0.08              -8.45            -8.53
ct0053              0.33            0.33              -6.61            -4.14
ct0055              0.33            0.25              -5.81            -1.67
ct0057              0.12            0.00              -9.20            -7.97
ct0058              0.00            0.00              -4.37            -4.37
ct0124              0.38            0.33             -10.62            -4.95
ct0125              0.25            0.00              -8.76            -6.55
ct0127              0.25            0.00              -7.51            -6.27
ct0128              0.00            0.00              -4.83            -4.83
ct0130              0.00            0.00             -10.97           -10.97
ct0131              0.33            0.08              -8.45            -3.54
ct0132              0.25            0.08              -5.21            -1.62
ct0133              0.25            0.00              -8.45            -3.39
ct0137              0.29            0.08             -11.31            -5.77
ct0140              0.29            0.08              -8.74            -7.45
ct0141              0.00            0.00              -7.45            -7.45

90 degree plaids: share of directions clipped, median 0.28 (range 0.00 to 0.58); gratings 0.29, plaids 0.17
  Spearman, clipped share against the rectified index: rho = 0.543, p = 0.000116; against its change (rectified - unrectified): rho = 0.644, p = 1.85e-06
     clipped  n  median_unrectified  median_rectified  in_range_unrectified  in_range_rectified
        none  8              -10.95            -10.95                     0                   0
0.00 to 0.25 14              -10.64             -8.31                     0                   5
0.25 to 0.50 21              -10.56             -3.74                     0                  16
0.50 to 1.00  2              -11.73             -6.16                     0                   1

Result: reproduced, on the rectified responses (assumed). The paper does not say whether the simulated responses were rectified or carried noise. Read as firing rates, which cannot be negative, the rectified responses give pattern indices within -6.6 to 2.2 for 64% of neurons with the per-neuron peak frequency and 120 degree plaids (median -5.10), and none above 2.2, which meets the criterion; with 90 degree plaids 49%, and with the population frequency 58% (120 degrees) and 53% (90 degrees). With Poisson noise added to the rectified rates the criterion is met in at least 17 of 20 draws under every combination and number of repeats. The unrectified model outputs give strongly component-like indices under all four combinations (medians -8.6 to -10.7, 0% to 18% within the range), so the outcome rests on the rectification. Without noise, rectified or not, no neuron has an index above 2.2. How much of this comes from clipping is shown in the second cell: with the per-neuron peak frequency, the rectification sets a median of 25% of the grating and plaid directions to zero with 120 degree plaids (28% with 90 degree plaids, range 0% to 58%), and the change of the index grows with that share (Spearman rho 0.568, p = 4.7e-5, and 0.642 with 90 degree plaids). The 8 neurons with no direction clipped keep their unrectified indices (median -8.33, 2 of 8 within the range with 120 degree plaids, 0 of 8 with 90 degrees), while 27 of the 37 clipped neurons fall within the range with 120 degree plaids. So the indices move into the paper's range through the clipping of the tuning curves: the outcome rests on reading the simulated responses as rectified firing rates, and these outputs do not tell whether the paper's simulated cells were rectified.

fig7c-hv-pattern-correlation¶

The horizontal-vertical ratio is significantly correlated with the simulated pattern index (r = 0.46 +- 0.046, p < 0.01).

In [26]:
rows = []
for (rc, proj), hv in HV.items():
    for k, piv in PI.items():
        ok = np.isfinite(hv)
        r, p = pearsonr(hv[ok], piv[ok])
        rows.append(dict(balance=rc[0], quantity=rc[1], sign=rc[2], amplitudes=proj, frequency=k[0], separation=k[1],
                         r=r, p=p, ok=(0.414 <= r <= 0.506) and p < 0.01))
CC = pd.DataFrame(rows)
print(CC.round(4).to_string())
print("\ncombinations meeting the criterion:", int(CC.ok.sum()), "of", len(CC), "; r range", CC.r.min().round(3), "to", CC.r.max().round(3),
      "; positive with p < 0.01:", int(((CC.r > 0) & (CC.p < 0.01)).sum()))
hv0 = HV[(("a", "a", "a"), "a")]
ok0 = np.isfinite(hv0)
rows = []
for (rc, proj), hv in HV.items():
    for k, piv in PIR.items():
        ok = np.isfinite(hv)
        r, p = pearsonr(hv[ok], piv[ok])
        rows.append(dict(balance=rc[0], quantity=rc[1], sign=rc[2], amplitudes=proj, frequency=k[0], separation=k[1],
                         r=r, p=p, ok=(0.414 <= r <= 0.506) and p < 0.01))
CR = pd.DataFrame(rows)
print("\nwith the pattern indices of rectified responses: combinations meeting the criterion:", int(CR.ok.sum()), "of", len(CR),
      "; r range", CR.r.min().round(3), "to", CR.r.max().round(3), "; positive with p < 0.01:", int(((CR.r > 0) & (CR.p < 0.01)).sum()))
print(CR[(CR.balance == "a") & (CR.quantity == "a") & (CR.sign == "a")].round(4).to_string())
print("\nwith the noisy pattern indices (first draw), ratio reading aaa/a:")
for k, piv in PIN.items():
    r, p = pearsonr(hv0[ok0], piv[ok0])
    print(f"  {k[0]} repeats, frequency ({k[1]}), {k[2]} degrees: r = {r:.3f}, p = {p:.3g}")
   balance quantity sign amplitudes frequency  separation       r       p     ok
0        a        a    a          a         a         120  0.2314  0.1261  False
1        a        a    a          a         a          90  0.0687  0.6536  False
2        a        a    a          a         b         120 -0.1004  0.5118  False
3        a        a    a          a         b          90 -0.2223  0.1421  False
4        a        a    a          b         a         120  0.2921  0.0515  False
5        a        a    a          b         a          90  0.1628  0.2853  False
6        a        a    a          b         b         120 -0.1432  0.3479  False
7        a        a    a          b         b          90 -0.2784  0.0640  False
8        a        a    b          a         a         120  0.1970  0.1946  False
9        a        a    b          a         a          90  0.1328  0.3846  False
10       a        a    b          a         b         120 -0.1068  0.4850  False
11       a        a    b          a         b          90 -0.1625  0.2862  False
12       a        a    b          b         a         120  0.2620  0.0821  False
13       a        a    b          b         a          90  0.2148  0.1564  False
14       a        a    b          b         b         120 -0.1442  0.3447  False
15       a        a    b          b         b          90 -0.2256  0.1362  False
16       a        b    a          a         a         120  0.2790  0.0634  False
17       a        b    a          a         a          90 -0.0746  0.6265  False
18       a        b    a          a         b         120 -0.0047  0.9754  False
19       a        b    a          a         b          90 -0.2606  0.0839  False
20       a        b    a          b         a         120  0.3303  0.0267  False
21       a        b    a          b         a          90  0.0993  0.5163  False
22       a        b    a          b         b         120 -0.1214  0.4269  False
23       a        b    a          b         b          90 -0.3428  0.0212  False
24       a        b    b          a         a         120  0.2762  0.0663  False
25       a        b    b          a         a          90 -0.0434  0.7769  False
26       a        b    b          a         b         120  0.0132  0.9313  False
27       a        b    b          a         b          90 -0.2164  0.1533  False
28       a        b    b          b         a         120  0.3179  0.0333  False
29       a        b    b          b         a          90  0.1289  0.3989  False
30       a        b    b          b         b         120 -0.1108  0.4686  False
31       a        b    b          b         b          90 -0.3031  0.0430  False
32       b        a    a          a         a         120  0.1720  0.2585  False
33       b        a    a          a         a          90  0.1217  0.4259  False
34       b        a    a          a         b         120 -0.2070  0.1725  False
35       b        a    a          a         b          90 -0.2150  0.1561  False
36       b        a    a          b         a         120  0.0977  0.5232  False
37       b        a    a          b         a          90  0.1327  0.3847  False
38       b        a    a          b         b         120  0.0101  0.9478  False
39       b        a    a          b         b          90 -0.1432  0.3482  False
40       b        a    b          a         a         120  0.1493  0.3277  False
41       b        a    b          a         a          90  0.1165  0.4458  False
42       b        a    b          a         b         120 -0.2289  0.1304  False
43       b        a    b          a         b          90 -0.1659  0.2761  False
44       b        a    b          b         a         120  0.0754  0.6225  False
45       b        a    b          b         a          90  0.1408  0.3561  False
46       b        a    b          b         b         120 -0.0241  0.8749  False
47       b        a    b          b         b          90 -0.0883  0.5642  False
48       b        b    a          a         a         120  0.1362  0.3724  False
49       b        b    a          a         a          90 -0.0311  0.8394  False
50       b        b    a          a         b         120 -0.1628  0.2853  False
51       b        b    a          a         b          90 -0.1443  0.3441  False
52       b        b    a          b         a         120  0.0672  0.6608  False
53       b        b    a          b         a          90  0.0664  0.6648  False
54       b        b    a          b         b         120 -0.0747  0.6260  False
55       b        b    a          b         b          90 -0.1804  0.2358  False
56       b        b    b          a         a         120  0.0429  0.7794  False
57       b        b    b          a         a          90 -0.0765  0.6174  False
58       b        b    b          a         b         120 -0.1313  0.3898  False
59       b        b    b          a         b          90 -0.1017  0.5062  False
60       b        b    b          b         a         120  0.0463  0.7628  False
61       b        b    b          b         a          90  0.0533  0.7279  False
62       b        b    b          b         b         120 -0.1090  0.4759  False
63       b        b    b          b         b          90 -0.2023  0.1826  False

combinations meeting the criterion: 0 of 64 ; r range -0.343 to 0.33 ; positive with p < 0.01: 0

with the pattern indices of rectified responses: combinations meeting the criterion: 0 of 64 ; r range -0.075 to 0.298 ; positive with p < 0.01: 0
  balance quantity sign amplitudes frequency  separation       r       p     ok
0       a        a    a          a         a         120  0.0961  0.5299  False
1       a        a    a          a         a          90 -0.0158  0.9181  False
2       a        a    a          a         b         120     NaN     NaN  False
3       a        a    a          a         b          90     NaN     NaN  False
4       a        a    a          b         a         120  0.0843  0.5821  False
5       a        a    a          b         a          90 -0.0682  0.6562  False
6       a        a    a          b         b         120     NaN     NaN  False
7       a        a    a          b         b          90     NaN     NaN  False

with the noisy pattern indices (first draw), ratio reading aaa/a:
  5 repeats, frequency (a), 120 degrees: r = 0.177, p = 0.244
  10 repeats, frequency (a), 120 degrees: r = 0.162, p = 0.288
  20 repeats, frequency (a), 120 degrees: r = 0.115, p = 0.452
  5 repeats, frequency (a), 90 degrees: r = 0.096, p = 0.532
  10 repeats, frequency (a), 90 degrees: r = 0.058, p = 0.704
  20 repeats, frequency (a), 90 degrees: r = -0.016, p = 0.916
  5 repeats, frequency (b), 120 degrees: r = nan, p = nan
  10 repeats, frequency (b), 120 degrees: r = nan, p = nan
  20 repeats, frequency (b), 120 degrees: r = nan, p = nan
  5 repeats, frequency (b), 90 degrees: r = nan, p = nan
  10 repeats, frequency (b), 90 degrees: r = nan, p = nan
  20 repeats, frequency (b), 90 degrees: r = nan, p = nan

Result: not reproduced. Across the 64 combinations of readings the correlation of the horizontal-vertical ratio with the pattern index of the unrectified responses ranges from -0.343 to 0.331, and none is positive with p < 0.01. With the indices of the rectified responses (the reading adopted for fig7b-pattern-index) it ranges from -0.074 to 0.299 (r = 0.097, p = 0.53 with every first reading), again with no positive correlation at p < 0.01, and with the noisy indices, ratio reading aaa/a and the per-neuron frequency, r is 0.150 or less (p 0.33 or more).

fig7c-no-corr-prediction-pattern¶

Prediction performance is not significantly correlated with the pattern index.

In [27]:
rows = []
for k, piv in PI.items():
    r, p = pearsonr(pr_, piv)
    rows.append(dict(frequency=k[0], separation=k[1], r=r, p=p))
print(pd.DataFrame(rows).round(4).to_string())
print("with the pattern indices of rectified responses:")
for k, piv in PIR.items():
    r, p = pearsonr(pr_, piv)
    print(f"  frequency ({k[0]}), {k[1]} degrees: r = {r:.3f}, p = {p:.3g}")
print("with the noisy pattern indices (first draw):")
for k, piv in PIN.items():
    r, p = pearsonr(pr_, piv)
    print(f"  {k[0]} repeats, frequency ({k[1]}), {k[2]} degrees: r = {r:.3f}, p = {p:.3g}")
  frequency  separation       r       p
0         a         120 -0.2311  0.1266
1         a          90  0.0188  0.9023
2         b         120 -0.1370  0.3695
3         b          90  0.2876  0.0554
with the pattern indices of rectified responses:
  frequency (a), 120 degrees: r = -0.052, p = 0.733
  frequency (a), 90 degrees: r = 0.140, p = 0.358
  frequency (b), 120 degrees: r = nan, p = nan
  frequency (b), 90 degrees: r = nan, p = nan
with the noisy pattern indices (first draw):
  5 repeats, frequency (a), 120 degrees: r = -0.151, p = 0.324
  10 repeats, frequency (a), 120 degrees: r = -0.113, p = 0.459
  20 repeats, frequency (a), 120 degrees: r = -0.079, p = 0.607
  5 repeats, frequency (a), 90 degrees: r = 0.015, p = 0.924
  10 repeats, frequency (a), 90 degrees: r = 0.010, p = 0.949
  20 repeats, frequency (a), 90 degrees: r = 0.081, p = 0.596
  5 repeats, frequency (b), 120 degrees: r = nan, p = nan
  10 repeats, frequency (b), 120 degrees: r = nan, p = nan
  20 repeats, frequency (b), 120 degrees: r = nan, p = nan
  5 repeats, frequency (b), 90 degrees: r = nan, p = nan
  10 repeats, frequency (b), 90 degrees: r = nan, p = nan
  20 repeats, frequency (b), 90 degrees: r = nan, p = nan

Result: reproduced. With the pattern indices of the rectified responses (the reading adopted for fig7b-pattern-index), the per-neuron peak frequency and 120 degree plaids, r = -0.053, p = 0.73, above 0.10; with 90 degree plaids p = 0.359. The unrectified indices give p = 0.127 (first readings), 0.899, 0.371 and 0.055, and the noisy indices with the per-neuron frequency give p of 0.38 or more.

natural-movie-control¶

Models fit on motion-enhanced movies predict responses to natural movies without motion enhancement as well as responses to new motion-enhanced movies (mean r = 0.533 against 0.537, 15 neurons; Wilcoxon signed-rank p > 0.10).

In [28]:
nn = [n for n in names_run if "natural" in R[n]["fits"][mt2.MAIN]["r"]]
rn = np.array([R[n]["fits"][mt2.MAIN]["r"]["natural"] for n in nn])
re_ = np.array([R[n]["fits"][mt2.MAIN]["r"]["enhanced"] for n in nn])
st = wilcoxon(rn, re_)
print(f"{len(nn)} neurons with both validation sets ({', '.join(R[n]['cellid'] for n in nn)})")
print(f"mean r natural {rn.mean():.3f} [expected 0.533 +- 0.053: {abs(rn.mean() - 0.533) <= 0.053}], "
      f"motion-enhanced {re_.mean():.3f} [expected 0.537 +- 0.054: {abs(re_.mean() - 0.537) <= 0.054}]")
print(f"Wilcoxon signed-rank p = {st.pvalue:.4g}; natural higher in {(rn > re_).sum()} of {len(nn)}; mean difference {np.mean(rn - re_):+.3f}")
for n, a_, b_ in zip(nn, rn, re_):
    print(f"  {n[:6]}  natural {a_:.3f}  enhanced {b_:.3f}")
14 neurons with both validation sets (f0073, f0086, f0087, f0090, f0100, f0104, f0105, f0110, f0112, f0114, f0116, v0383, v0384, v0390)
mean r natural 0.493 [expected 0.533 +- 0.053: True], motion-enhanced 0.462 [expected 0.537 +- 0.054: False]
Wilcoxon signed-rank p = 0.2412; natural higher in 10 of 14; mean difference +0.031
  ct0031  natural 0.623  enhanced 0.458
  ct0039  natural 0.768  enhanced 0.691
  ct0040  natural 0.550  enhanced 0.357
  ct0042  natural 0.571  enhanced 0.567
  ct0047  natural 0.209  enhanced 0.521
  ct0049  natural 0.453  enhanced 0.483
  ct0050  natural 0.573  enhanced 0.462
  ct0053  natural 0.464  enhanced 0.380
  ct0055  natural 0.493  enhanced 0.293
  ct0057  natural 0.576  enhanced 0.575
  ct0058  natural 0.234  enhanced 0.388
  ct0124  natural 0.223  enhanced 0.305
  ct0125  natural 0.607  enhanced 0.602
  ct0130  natural 0.555  enhanced 0.378

Result: partially reproduced with the 2 x 2 pooling of this notebook; finer_pooling.ipynb, with the finer pooling, decides the outcome. The files hold the natural-movie validation set for 14 neurons, not 15. The Wilcoxon signed-rank test finds no difference (p = 0.241; natural higher in 10 of 14, mean difference +0.031). The natural-movie mean, 0.493, is within 0.533 +- 0.053, but the motion-enhanced mean, 0.462, is below 0.537 +- 0.054.

fig8-recovery-simulated¶

The estimation procedure correctly recovers the spectral receptive fields of three simulated MT neurons. (Reproduced when each recovered spectral receptive field correlates better with its own true one than with the other two.)

In [29]:
sims = R[SIM]["sims"] if SIM in R else []
def spec(w):
    E, _ = mt2.split_weights(w)
    keys = sorted({(r_[0], r_[1], r_[2]) for r_ in rd[rd[:, 5] == 0]})
    idx = {k: i for i, k in enumerate(keys)}
    out = np.zeros(len(keys))
    for j in np.where(rd[:, 5] == 0)[0]:
        out[idx[(rd[j, 0], rd[j, 1], rd[j, 2])]] += E[j]
    return out
for noise in ("a", "b"):
    S_ = [s for s in sims if s["noise"] == noise]
    M = np.array([[np.corrcoef(spec(a["w"]), spec(b["w_true"]))[0, 1] for b in S_] for a in S_])
    print(f"noise reading ({noise}): rows recovered A, B, C; columns true A, B, C")
    print(np.round(M, 3))
    print("  each recovered field closest to its own:", bool(np.all(np.argmax(M, 1) == np.arange(3))))
noise reading (a): rows recovered A, B, C; columns true A, B, C
[[ 0.835 -0.016  0.015]
 [-0.029  0.57  -0.046]
 [ 0.133 -0.018  0.501]]
  each recovered field closest to its own: True
noise reading (b): rows recovered A, B, C; columns true A, B, C
[[ 0.791 -0.026  0.021]
 [-0.029  0.6   -0.043]
 [ 0.072 -0.051  0.672]]
  each recovered field closest to its own: True

Result: reproduced. For each of the three simulated neurons the recovered spectral receptive field correlates best with its own true field: with Poisson noise 0.835, 0.570 and 0.501 on the diagonal against at most 0.133 off it, and without noise 0.791, 0.600 and 0.672 against at most 0.072.

Summary¶

Claim Outcome
fig3b-mean-prediction reproduced with the finer pooling (0.518, finer_pooling.ipynb); 0.448 here
fig3b-explainable-variance blocked: data_missing
fig3a-example-neuron reproduced
fig2b-contrast-normalization-no-effect reproduced
fig2b-compressive-improves partially reproduced (significant, smaller)
fig2b-expansive-decreases partially reproduced (significant; under reading (a) both sizes outside tolerance, under reading (b) one)
fig2b-divisive-improves not reproduced (corrected p = 0.056; 0.084 with the finer pooling, finer_pooling_fig2b.ipynb)
fig2b-compressive-divisive-best reproduced
fig2b-no-interaction reproduced
complex-cells-dominate reproduced
fig6a-null-on-plane reproduced (12 of 40 combinations)
fig6a-excitatory-on-plane reproduced
fig6b-suppressive-off-plane reproduced (6 of 40 combinations)
fig7a-partial-ring reproduced
fig7a-no-corr-prediction-hv partially reproduced (p = 0.061)
fig7b-pattern-index reproduced on the rectified responses (assumed); not on the unrectified outputs
fig7c-hv-pattern-correlation not reproduced
fig7c-no-corr-prediction-pattern reproduced
natural-movie-control reproduced with the finer pooling (finer_pooling.ipynb); partially here
fig8-recovery-simulated reproduced

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

How the analysis differs from the paper's:

  • The regression weights are constrained to be pooled over space (763 regressors at 11 delays), where the paper fits each of its 5956 filters; the filter bank itself follows the paper's rules (about 7000 complex and 1100 simple channels). Simple cells enter the regression only at 0.75 cycles per cRF and SF 0. A finer pooling of the main model (1465 regressors, finer_pooling.ipynb) raises the mean correlation from 0.448 to 0.518. Four of the Figure 2B models refitted with it (finer_pooling_fig2b.ipynb) give the same outcomes for fig2b-compressive-improves, fig2b-divisive-improves, fig2b-compressive-divisive-best and fig2b-no-interaction; the expansive models and the spectral analyses here rest on the 2 x 2 pooling only.
  • The paper does not give the temporal envelope of its Gabor filters. Here it spans 11 frames (SD 2 frames), centred on the frame, and the 11-frame delay window is moved 0, 3 or 6 frames earlier per neuron, chosen on held-out training data (0 for 31 neurons).
  • Five temporal frequencies (0 to 30 Hz) and five spatial frequencies (0 to 6 cycles per cRF), an octave apart; sigma of divisive normalization 1% of the mean pooled response (and chosen on held-out data as a reading); boosting step 1% of the response SD; early stopping after 50 steps without improvement.
  • 45 neurons where the paper has 52, and 14 with a natural-movie validation set where it has 15.
  • The simulated pattern indices are taken from the rectified model responses, which the paper does not specify.
  • Plaid and grating parameters, the plane search grid and the quadrant geometry of the horizontal-vertical ratio are this attempt's choices; the paper gives none.

What was found about the dataset:

  • 45 of the paper's 52 neurons (34 from monkey f, 11 from monkey v); no recording appears twice.
  • The files hold only responses averaged over repeats, so the explainable variance cannot be computed.
  • 14 files have an undocumented ranges.nrange, the first 2000 frames of a 4000-frame vrange; its frames carry less motion than the rest of vrange in all 14 (0.225 against 0.325, median frame difference over contrast), consistent with the natural movies of the paper's control. ranges.trange is empty in every file and not described.
  • The per-frame denominators of the averaged validation responses imply 10 to 33 repeats, where the paper reports 5 to 20; training frames carry denominators up to 5.
  • Training frames run from 17,908 to 40,000 per neuron (mean 26,894; the paper gives 20,000 to 40,000, mean 27,120). In ct0133, 12,729 of 19,842 training frames have no response.
In [30]:
print(f"notebook run time {(time.time() - T0) / 60:.1f} min")
notebook run time 57.9 min