STRF and LN model performance on Wehr's recordings (Asari & Zador 2009, Figure 4)¶
Paper. Asari H, Zador AM (2009). Long-lasting context dependence constrains neural encoding models in rodent auditory cortex. J Neurophysiol 102:2638-2656. doi:10.1152/jn.00577.2009
Dataset. CRCNS ac-1, doi:10.6080/K0KW5CXR, the wehr/
folder: Michael Wehr's whole-cell recordings of A1 neurons to natural sounds (Machens et al. 2004),
one file per trial, with the stimuli and the authors' STRFanalysis.m. Streamed from the public
S3 bucket as in reproduce_asari_2009.ipynb, which gives the version (unversioned; MD5 sums of
the zip files in asari.MD5).
Claims. claims/asari-2009.yaml. This notebook tests one claim, fig4-strf-performance-low; the
others are in reproduce_asari_2009.ipynb.
| claim | tested here |
|---|---|
| fig4-strf-performance-low | tested |
Methods (Eqs. 46-53 and the claim's criterion) and where each detail comes from are in the
docstring of wehr_strf.py. The paper reanalysed 20 of these cells without naming them. Two
readings of the cells: the 16 cells with natural sounds heard at least twice, using only those
stimuli (repeated, main), and all 25 cells with every stimulus, a stimulus heard once given half
its total power as predictable power, as STRFanalysis.m does (code).
import os
import time
import resource
from concurrent.futures import ProcessPoolExecutor
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["OPENBLAS_NUM_THREADS"] = "1"
import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import asari
import wehr_strf as ws
pd.set_option("display.width", 220)
pd.set_option("display.max_columns", 30)
T0 = time.time()
A = asari.Archive()
cells = ws.wehr_cells(A)
print("cells in wehr/Summary.mat:", len(cells))
print("windows (ms):", ws.WINDOWS_MS, "| parameters per model:", len(ws.FREQS) * 45)
print("centre frequencies (kHz):", np.round(ws.FREQS / 1000, 2))
with ProcessPoolExecutor(3) as ex:
done = list(ex.map(ws.run_cell, cells))
info = pd.DataFrame([d["info"] for d in done])
res = pd.DataFrame([r for d in done for r in d["rows"]])
print(f"analysed in {(time.time() - T0) / 60:.1f} min; peak memory of this process "
f"{resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB")
cells in wehr/Summary.mat: 25 windows (ms): [180, 324, 548, 884, 1364, 2004, 2772, 3540, 4052] | parameters per model: 765 centre frequencies (kHz): [ 0.4 0.5 0.63 0.8 1.01 1.27 1.6 2.02 2.54 3.2 4.03 5.08 6.4 8.06 10.16 12.8 16.13]
analysed in 29.8 min; peak memory of this process 0.22 GB
Data check¶
print("experiments:", dict(pd.Series([c["experiment_description"] for c in cells]).value_counts()))
info["stimuli_heard_once"] = info.n_stimuli - info.n_repeated
info["trials_range"] = info.trials.map(lambda t: (min(t), max(t)))
info["stimulus_s"] = info.seconds.map(lambda s: (round(min(s), 2), round(max(s), 2)))
print(info[["cell", "n_stimuli", "n_repeated", "stimuli_heard_once", "trials_range", "stimulus_s", "recording_types",
"sf", "stim_sf", "reliability", "resp_range", "spec_range"]].round(3).to_string())
print("\nrecording types:", sorted({t for x in info.recording_types for t in x}),
"| response sampling rates (Hz):", sorted({s for x in info.sf for s in x}),
"| stimulus sampling rates (Hz):", sorted({s for x in info.stim_sf for s in x}))
print("cells with stimuli heard at least twice:", int((info.n_repeated > 0).sum()), "of", len(info))
print("reliability is the predictable over the total power (Eq. 52) of the repeated stimuli, 4-ms bins;"
" resp_range in mV after centring each trial; spec_range in dB after centring each frequency")
experiments: {'Auditory cortical responses to as many natural sounds as possible.': np.int64(15), 'Repeated presentation of a fixed subset of sounds to auditory cortical cell.': np.int64(10)}
cell n_stimuli n_repeated stimuli_heard_once trials_range stimulus_s recording_types sf stim_sf reliability resp_range spec_range
0 20020508-mw-003 11 11 0 (10, 20) (15.0, 31.75) [Whole-cell] [4000] [97656.0] 0.720 (-6.677103, 30.148925) (-107.970565, 61.8264)
1 20020530-mw-001 7 7 0 (10, 14) (15.0, 15.0) [Whole-cell] [4000] [97656.0] 0.360 (-2.554422, 28.115348) (-147.223765, 54.522522)
2 20020602-mw-001 5 5 0 (10, 10) (15.0, 15.0) [Whole-cell] [4000] [97656.0] 0.111 (-6.682663, 20.680965) (-70.016062, 54.522522)
3 20020604-mw-001 9 9 0 (6, 19) (15.0, 15.0) [Whole-cell] [4000] [97656.0] 0.535 (-8.848427, 60.616722) (-70.016062, 61.8264)
4 20020604-mw-002 3 3 0 (9, 20) (15.0, 15.0) [Whole-cell] [4000] [97656.0] 0.404 (-4.371708, 44.099027) (-70.016062, 54.522522)
5 20020604-mw-003 8 8 0 (15, 20) (15.0, 15.0) [Whole-cell] [4000] [97656.0] 0.447 (-8.538276, 51.970549) (-70.016062, 61.8264)
6 20020605-mw-002 5 5 0 (10, 20) (15.0, 15.0) [Whole-cell] [4000] [97656.0] 0.307 (-12.808398, 125.667225) (-147.223765, 52.771509)
7 20020605-mw-003 3 3 0 (20, 20) (15.0, 15.0) [Whole-cell] [4000] [97656.0] 0.490 (-6.31408, 73.079893) (-147.223765, 52.771509)
8 20020608-mw-001 6 6 0 (10, 10) (15.0, 15.0) [Whole-cell] [4000] [97656.0] 0.782 (-1.266283, 45.398218) (-70.016062, 54.522522)
9 20020608-mw-002 10 10 0 (20, 25) (15.0, 15.0) [Whole-cell] [4000] [97656.0] 0.554 (-16.347997, 75.001535) (-172.991479, 76.362881)
10 20030328-mw-001 16 0 16 (1, 1) (22.0, 31.5) [Whole-cell] [4000] [97656.0] NaN (-5.885623, 45.782533) (-174.218596, 68.107024)
11 20030401-mw-001 18 18 0 (2, 2) (22.0, 31.5) [Whole-cell] [4000] [97656.0] 0.579 (-4.309444, 65.823735) (-174.218596, 68.107024)
12 20030401-mw-003 12 0 12 (1, 1) (22.5, 31.0) [Whole-cell] [4000] [97656.0] NaN (-19.938404, 45.739068) (-155.428777, 68.107024)
13 20030403-mw-001 18 18 0 (2, 2) (22.0, 31.5) [Whole-cell] [4000] [97656.0] 0.547 (-6.596996, 67.776048) (-174.218596, 68.107024)
14 20030404-mw-001 9 0 9 (1, 1) (22.5, 31.0) [Whole-cell] [4000] [97656.0] NaN (-57.871387, 35.74531) (-155.428777, 68.107024)
15 20030404-mw-002 11 11 0 (2, 2) (18.0, 31.5) [Whole-cell] [4000] [97656.0] 0.562 (-3.995434, 47.138105) (-150.321362, 55.121743)
16 20030407-mw-001 18 18 0 (2, 2) (22.0, 31.5) [Whole-cell] [4000] [97656.0] 0.537 (-9.093807, 61.424426) (-174.218596, 68.107024)
17 20030407-mw-002 18 7 11 (1, 2) (22.0, 31.5) [Whole-cell] [4000] [97656.0] 0.459 (-8.044187, 71.487) (-174.218596, 68.107024)
18 20030407-mw-003 7 0 7 (1, 1) (18.0, 31.5) [Whole-cell] [4000] [97656.0] NaN (-5.33829, 46.591987) (-150.321362, 54.109026)
19 20030407-mw-004 16 0 16 (1, 1) (22.0, 31.5) [Whole-cell] [4000] [97656.0] NaN (-5.982797, 51.357746) (-174.218596, 68.107024)
20 20030407-mw-005 7 0 7 (1, 1) (22.5, 31.0) [Whole-cell] [4000] [97656.0] NaN (-4.963506, 24.577792) (-155.428777, 60.588679)
21 20030409-mw-001 18 0 18 (1, 1) (22.0, 31.5) [Whole-cell] [4000] [97656.0] NaN (-8.457505, 43.999068) (-174.218596, 68.107024)
22 20030409-mw-002 11 0 11 (1, 1) (22.5, 31.0) [Whole-cell] [4000] [97656.0] NaN (-6.327676, 39.227397) (-155.428777, 68.107024)
23 20030410-mw-001 33 30 3 (1, 2) (18.0, 31.5) [Whole-cell] [4000] [97656.0] 0.587 (-12.794413, 74.560752) (-174.218596, 68.107024)
24 20030410-mw-002 6 0 6 (1, 1) (22.5, 31.0) [Whole-cell] [4000] [97656.0] NaN (-3.97601, 30.636121) (-155.428777, 60.588679)
recording types: ['Whole-cell'] | response sampling rates (Hz): [4000] | stimulus sampling rates (Hz): [97656.0]
cells with stimuli heard at least twice: 16 of 25
reliability is the predictable over the total power (Eq. 52) of the repeated stimuli, 4-ms bins; resp_range in mV after centring each trial; spec_range in dB after centring each frequency
Every file is a whole-cell recording at 4 kHz, one trial per file, with one trigger for the stimulus. The stimuli are sampled at 97.656 kHz. The predictable fraction of the response power (reliability above) is well above zero in every cell with repeated stimuli, which is consistent with the traces and the stimuli sharing a clock: a misaligned trial would lower it.
fig4-strf-performance-low¶
Linear STRF models of 20 A1 cells from Machens et al. (2004) predicted less than about 20% of the predictable response power, and extending the window from 180 ms to about 4 s did not improve them significantly, with or without a static nonlinearity; the LN model did only slightly better.
Criterion: reproduced when, under one reading, the mean performance is at most 0.22 at every
window for STRF and LN, and the one-sided paired Wilcoxon test (validation performance at 4052 ms
against 180 ms, over cells, at 0.05) finds no improvement for either. Readings: validation (lower)
or training (upper) performance; spectrogram window 10 or 20 ms; contiguous folds or folds by
stimulus; the cells (repeated, code); and two details of this implementation, the samples
scored and validation pooled over folds or averaged over folds.
def readings(res):
out = {}
for cfg, g in res[res.reading == "repeated"].groupby("config"):
out[(cfg, "repeated")] = g
code_rows = res[(res.config == "main") & (res.reading == "code")]
same = res[(res.config == "main") & (res.reading == "repeated") & ~res.cell.isin(code_rows.cell)]
out[("main", "code")] = pd.concat([same, code_rows])
return out
def summarize(g, val):
rows = []
for model in ["strf", "ln"]:
col = f"{model}_{val}"
p = g.pivot(index="cell", columns="window_ms", values=col)
w = stats.wilcoxon(p[4052], p[180], alternative="greater")
fr = stats.friedmanchisquare(*[p[c] for c in p.columns])
rows.append(dict(model=model.upper(), measure=val, n_cells=len(p), **{f"{c}": p[c].mean() for c in p.columns},
max_mean=p.mean().max(), wilcoxon_p=w.pvalue, median_gain_4052_vs_180=(p[4052] - p[180]).median(),
friedman_p=fr.pvalue))
return rows
R = readings(res)
rows = []
for (cfg, cells_reading), g in R.items():
for val in ["valid", "train", "valid_foldmean"]:
for r in summarize(g, val):
rows.append(dict(config=cfg, cells=cells_reading, **r))
tab = pd.DataFrame(rows)
print("mean performance over cells at each window (ms), the largest mean, and the tests of 4052 against 180 ms")
print(tab.round(3).to_string())
mean performance over cells at each window (ms), the largest mean, and the tests of 4052 against 180 ms
config cells model measure n_cells 180 324 548 884 1364 2004 2772 3540 4052 max_mean wilcoxon_p median_gain_4052_vs_180 friedman_p
0 folds by stimulus repeated STRF valid 16 0.138 0.146 0.160 0.165 0.160 0.156 0.157 0.156 0.156 0.165 0.042 0.012 0.053
1 folds by stimulus repeated LN valid 16 0.088 0.095 0.025 -0.008 0.054 0.041 0.110 0.093 0.081 0.110 0.450 0.000 0.098
2 folds by stimulus repeated STRF train 16 0.230 0.248 0.282 0.294 0.293 0.290 0.290 0.291 0.285 0.294 0.001 0.054 0.000
3 folds by stimulus repeated LN train 16 0.270 0.290 0.328 0.347 0.333 0.335 0.335 0.338 0.331 0.347 0.001 0.064 0.000
4 folds by stimulus repeated STRF valid_foldmean 16 0.115 0.123 0.129 0.129 0.127 0.127 0.127 0.127 0.127 0.129 0.202 0.007 0.655
5 folds by stimulus repeated LN valid_foldmean 16 -0.152 -0.112 -0.142 -0.170 -0.153 -0.198 -0.149 -0.160 -0.180 -0.112 0.450 0.013 0.304
6 main repeated STRF valid 16 0.163 0.177 0.193 0.196 0.198 0.197 0.195 0.195 0.196 0.198 0.001 0.024 0.001
7 main repeated LN valid 16 0.127 0.134 0.144 0.149 0.165 0.171 0.144 0.146 0.145 0.171 0.106 0.015 0.109
8 main repeated STRF train 16 0.237 0.268 0.302 0.321 0.397 0.450 0.329 0.329 0.328 0.450 0.000 0.085 0.000
9 main repeated LN train 16 0.278 0.318 0.338 0.364 0.445 0.504 0.375 0.375 0.372 0.504 0.000 0.100 0.000
10 main repeated STRF valid_foldmean 16 0.212 0.221 0.281 0.322 0.431 0.499 0.830 0.788 0.671 0.830 0.025 0.028 0.032
11 main repeated LN valid_foldmean 16 -0.091 -0.055 -0.068 -0.092 -0.069 -0.086 -0.123 -0.118 -0.133 -0.055 0.248 0.016 0.023
12 own samples repeated STRF valid 16 0.170 0.189 0.201 0.204 0.203 0.201 0.208 0.197 0.196 0.208 0.005 0.026 0.003
13 own samples repeated LN valid 16 0.143 0.157 0.173 0.181 0.183 0.172 0.191 0.162 0.145 0.191 0.174 0.015 0.121
14 own samples repeated STRF train 16 0.242 0.286 0.339 0.359 0.368 0.400 0.473 0.336 0.328 0.473 0.002 0.084 0.000
15 own samples repeated LN train 16 0.247 0.302 0.347 0.376 0.385 0.427 0.503 0.373 0.372 0.503 0.000 0.113 0.000
16 own samples repeated STRF valid_foldmean 16 0.156 0.166 0.285 0.230 0.279 0.308 0.143 0.540 0.671 0.671 0.005 0.031 0.169
17 own samples repeated LN valid_foldmean 16 0.087 0.096 0.252 0.128 0.141 0.002 -0.015 -0.016 -0.133 0.252 0.065 0.035 0.078
18 window 20 ms repeated STRF valid 16 0.157 0.170 0.186 0.189 0.192 0.191 0.190 0.191 0.191 0.192 0.001 0.015 0.000
19 window 20 ms repeated LN valid 16 0.126 0.115 0.121 0.138 0.144 0.138 0.133 0.135 0.137 0.144 0.232 0.019 0.084
20 window 20 ms repeated STRF train 16 0.228 0.260 0.298 0.322 0.317 0.333 0.323 0.324 0.324 0.333 0.000 0.088 0.000
21 window 20 ms repeated LN train 16 0.248 0.291 0.328 0.364 0.358 0.376 0.370 0.371 0.371 0.376 0.000 0.113 0.000
22 window 20 ms repeated STRF valid_foldmean 16 0.204 0.228 0.267 0.333 0.463 0.540 0.653 0.862 0.776 0.862 0.022 0.024 0.007
23 window 20 ms repeated LN valid_foldmean 16 -0.094 -0.101 -0.123 -0.129 -0.123 -0.153 -0.185 -0.160 -0.179 -0.094 0.353 0.009 0.745
24 main code STRF valid 25 0.154 0.168 0.177 0.180 0.183 0.182 0.181 0.181 0.182 0.183 0.000 0.021 0.000
25 main code LN valid 25 0.108 0.115 0.123 0.128 0.139 0.139 0.120 0.124 0.117 0.139 0.144 0.018 0.128
26 main code STRF train 25 0.227 0.260 0.285 0.302 0.355 0.386 0.308 0.311 0.313 0.386 0.000 0.083 0.000
27 main code LN train 25 0.241 0.277 0.296 0.319 0.377 0.414 0.331 0.334 0.336 0.414 0.000 0.096 0.000
28 main code STRF valid_foldmean 25 0.184 0.194 0.232 0.259 0.330 0.373 0.585 0.558 0.483 0.585 0.011 0.014 0.111
29 main code LN valid_foldmean 25 -0.035 -0.010 -0.017 -0.033 -0.045 -0.081 -0.087 -0.069 -0.172 -0.010 0.308 0.017 0.046
crit = []
for (cfg, cr, val), g in tab.groupby(["config", "cells", "measure"]):
d = g.set_index("model")
crit.append(dict(config=cfg, cells=cr, measure=val, max_mean_STRF=d.max_mean["STRF"], max_mean_LN=d.max_mean["LN"],
wilcoxon_p_STRF=d.wilcoxon_p["STRF"], wilcoxon_p_LN=d.wilcoxon_p["LN"],
low=(d.max_mean <= 0.22).all(), no_improvement=(d.wilcoxon_p >= 0.05).all()))
crit = pd.DataFrame(crit)
crit["criterion_met"] = crit.low & crit.no_improvement
print(crit.round(3).to_string())
main = R[("main", "repeated")]
gain = (main.ln_valid - main.strf_valid)
print("\nLN minus STRF validation performance (main reading), over cells and windows: mean", round(gain.mean(), 3),
"| median", round(gain.median(), 3), "| range", (round(gain.min(), 3), round(gain.max(), 3)))
pc = main.pivot(index="cell", columns="window_ms", values="strf_valid")
print("STRF validation performance per cell, range over cells at each window:")
print(pd.DataFrame({"min": pc.min(), "max": pc.max()}).round(3).T.to_string())
print("chosen ridge value at a grid edge:", int(res.ridge_at_edge.sum()), "of", len(res), "cell x window x reading fits")
config cells measure max_mean_STRF max_mean_LN wilcoxon_p_STRF wilcoxon_p_LN low no_improvement criterion_met 0 folds by stimulus repeated train 0.294 0.347 0.001 0.001 False False False 1 folds by stimulus repeated valid 0.165 0.110 0.042 0.450 True False False 2 folds by stimulus repeated valid_foldmean 0.129 -0.112 0.202 0.450 True True True 3 main code train 0.386 0.414 0.000 0.000 False False False 4 main code valid 0.183 0.139 0.000 0.144 True False False 5 main code valid_foldmean 0.585 -0.010 0.011 0.308 False False False 6 main repeated train 0.450 0.504 0.000 0.000 False False False 7 main repeated valid 0.198 0.171 0.001 0.106 True False False 8 main repeated valid_foldmean 0.830 -0.055 0.025 0.248 False False False 9 own samples repeated train 0.473 0.503 0.002 0.000 False False False 10 own samples repeated valid 0.208 0.191 0.005 0.174 True False False 11 own samples repeated valid_foldmean 0.671 0.252 0.005 0.065 False False False 12 window 20 ms repeated train 0.333 0.376 0.000 0.000 False False False 13 window 20 ms repeated valid 0.192 0.144 0.001 0.232 True False False 14 window 20 ms repeated valid_foldmean 0.862 -0.094 0.022 0.353 False False False LN minus STRF validation performance (main reading), over cells and windows: mean -0.043 | median -0.024 | range (np.float64(-0.564), np.float64(0.176)) STRF validation performance per cell, range over cells at each window: window_ms 180 324 548 884 1364 2004 2772 3540 4052 min 0.021 0.014 0.012 0.013 0.019 0.006 0.009 0.010 0.01 max 0.340 0.338 0.395 0.406 0.396 0.396 0.387 0.366 0.37 chosen ridge value at a grid edge: 0 of 675 cell x window x reading fits
fig, ax = plt.subplots(figsize=(6, 4))
for model, c in [("strf", "0.6"), ("ln", "k")]:
p = main.pivot(index="cell", columns="window_ms", values=f"{model}_valid").mean()
q = main.pivot(index="cell", columns="window_ms", values=f"{model}_train").mean()
ax.plot(np.array(p.index) / 1000, p.values, "x-", color=c, label=f"{model.upper()} validation")
ax.plot(np.array(q.index) / 1000, q.values, "o--", mfc="none", color=c, label=f"{model.upper()} training")
ax.set_xlabel("window length (s)"); ax.set_ylabel("model performance (Eq. 53)"); ax.set_ylim(-0.1, 1)
ax.legend(fontsize=8); plt.show()
print("plotted means range from", round(min(main[[c for c in main.columns if c.endswith(('_valid', '_train'))]].groupby(main.window_ms).mean().min()), 3),
"to", round(max(main[[c for c in main.columns if c.endswith(('_valid', '_train'))]].groupby(main.window_ms).mean().max()), 3), "(all inside the axes)")
plotted means range from 0.127 to 0.504 (all inside the axes)
Result: not reproduced (resting on the pooled validation performance, the cells and the test). The performance is low, as stated: with validation pooled over the folds, the mean over the 16 cells is at most 0.198 for STRF and 0.171 for LN at any window (main reading), and at most 0.208 and 0.191 in every other reading, all under 0.22; the training (upper) estimates reach 0.29 to 0.50, so the paper's 20% fits the validation estimate. But the STRF does improve with the window: its validation performance rises from 0.163 at 180 ms to 0.196 at 4052 ms, a median gain of 0.024 per cell, and the one-sided Wilcoxon test finds the improvement in every pooled reading (p = 0.000 to 0.042). The LN model shows no significant improvement (p = 0.106 to 0.450), and it does worse than the STRF, not slightly better (mean difference -0.043). Over all 25 cells, with a stimulus heard once given half its total power as predictable power, the results are the same (STRF at most 0.183, Wilcoxon p = 0.000). The criterion is met in one combination only, folds by stimulus with validation averaged over folds as STRFanalysis.m averages it (STRF at most 0.129, p = 0.202; LN p = 0.450); with the code's contiguous folds the fold average is unstable (STRF means up to 0.83), as folds of a stimulus heard twice can hold little predictable power. The main reading departs from STRFanalysis.m in two places: it pools the validation data over folds where the code averages per-fold values, and it scores every window on the same samples (those at least 4052 ms after stimulus onset) where the code scores each window on its own samples. The reason for not taking the one combination that meets the criterion is that it gives the LN model a negative validation performance at every window (mean -0.112 to -0.198), which does not fit Figure 4, where LN does slightly better than the STRF. The chosen ridge value is inside the grid in all 675 fits.
Summary¶
| claim | outcome |
|---|---|
| fig4-strf-performance-low | not reproduced (assumptions: pooled validation performance, the cells, the test) |
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.
Differences from the paper's method: the paper reanalysed 20 of Wehr's cells without naming them; the data set holds 25, of which 16 have natural sounds heard at least twice, and both sets are run. The spectrogram, binning, ridge grid, lowess and folds are reimplemented from the Methods and STRFanalysis.m (see wehr_strf.py); the validation performance is pooled over the validation folds, where STRFanalysis.m averages over folds, and every window is scored on the same samples, where the code scores each on its own; the code's choices are shown as variants, and the only combination that meets the criterion (folds by stimulus, fold average) gives LN a negative performance (-0.112 to -0.198). The test of "did not improve significantly" is the claims file's.
What was found about the data set: Wehr's 25 cells are all whole-cell recordings at 4 kHz with one trial per file; 9 cells have only stimuli heard once, which give no estimate of the predictable power.
print(f"total run time {(time.time() - T0) / 60:.1f} min; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.1f} GB")
total run time 29.8 min; peak memory 0.2 GB