Reproducing Timme et al. (2016) from CRCNS ssc-3¶

Paper. Timme NM, Ito S, Myroshnychenko M, Nigam S, Shimono M, Yeh F-C, Hottowy P, Litke AM, Beggs JM (2016). High-degree neurons feed cortical computations. PLoS Comput Biol 12(5): e1004858. doi:10.1371/journal.pcbi.1004858. The claims file was written from the version of record (PMC4861348, Europe PMC full text). Its displayed equations, missing from that flattened text, were read from the version of record's JATS XML. The TE procedure the paper reuses is that of its reference [44], Timme et al. (2014), PLoS One 9: e115764 (PMC4275261).

Data set. CRCNS ssc-3, ssc-3/live/data.tar.gz in the public CRCNS bucket, streamed and decompressed in memory. CRCNS data sets are not versioned, so the version is recorded as unversioned; the paper cites the data set by its DOI and no version, and this is the only copy the bucket holds (ssc-3/live/, no old/). The MD5 sum of the archive, from the data set's checksums.md5, is 1a5bd3d304c5442290a7c9c1f1b5def6; the loading cell checks the streamed bytes against it. The archive holds 25 MATLAB files, one per recording.

Claims.

Claim Tested here
data-recordings tested
fig4ac-te-lognormal tested
fig4bd-heavy-tailed-degree tested
fig4bd-out-tail-longer tested
fig5a-in-degree-uncorrelated tested
fig5b-out-degree-positive tested
fig5ab-correlations-beyond-null tested
fig5cd-pooled-trends tested
fig6-information-gain-not-rising tested, with sampled receivers and combinations
table1-pid-examples tested (no recorded data)
fig7b-connectivity-patterns tested (model simulation)
fig7c-degree-modified-rule-matches tested (model simulation)
fig7d-degree-rule-highest-conditioned-mi tested (model simulation)
figs1-larger-model tested (model simulation)

How the TE networks are built (bins, past states, jitter, sub-networks) and where each choice comes from is in the docstring of hdn.py. The significance test uses the paper's 5000 jittered surrogates per pair, with one approximation needed to fit the time limit: for pairs whose jitter moves more than 50 relevant sender spikes, the jittered counts are drawn from a normal distribution with their exact moments, in place of jittering every spike. The first cell of the TE networks section compares the two on two recordings at both time scales. A surrogate whose TE equals the real TE counts as exceeding it, and the literal strict rule is shown as a variant; the TE networks section gives the reasons.

In [1]:
import itertools
import math
import time
import warnings

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

import hdn

warnings.filterwarnings("ignore")
pd.set_option("display.width", 200)
pd.set_option("display.max_rows", 200)
started = time.time()
recs, md5 = hdn.load_all()
print(f"CRCNS {hdn.DATASET} ({hdn.DATASET_DOI}), version {hdn.DATASET_VERSION}: {len(recs)} recordings "
      f"streamed in {time.time() - started:.0f} s")
print("MD5 of the streamed archive:", md5, "| checksums.md5:", hdn.DATA_MD5, "| equal:", md5 == hdn.DATA_MD5)
CRCNS ssc-3 (10.6080/K07D2S2F), version unversioned: 25 recordings streamed in 10 s
MD5 of the streamed archive: 1a5bd3d304c5442290a7c9c1f1b5def6 | checksums.md5: 1a5bd3d304c5442290a7c9c1f1b5def6 | equal: True

Data check¶

In [2]:
rows = []
for r in recs:
    n = np.array([len(s) for s in r["spikes"]])
    allsp = np.concatenate(r["spikes"])
    rows.append({
        "file": r["name"], "recording_id": r["recording_id"], "nNeurons": r["n_neurons_field"],
        "trains": len(r["spikes"]), "length_ms": r["length_ms"], "first_ms": allsp.min(), "last_ms": allsp.max(),
        "spikes_min": n.min(), "spikes_max": n.max(), "under_100": int((n < 100).sum()),
        "sorted": all(np.all(np.diff(s) >= 0) for s in r["spikes"]),
        "on_50us_grid": bool(np.allclose(np.round(allsp * 20) / 20, allsp)),
        "x_um": f"{np.nanmin(r['x']):.0f} to {np.nanmax(r['x']):.0f}", "y_um": f"{np.nanmin(r['y']):.0f} to {np.nanmax(r['y']):.0f}",
        "timescale": r["timescale"], "sampling": r["sampling"]})
info = pd.DataFrame(rows)
print(info.to_string(index=False))
print("\nnNeurons equals the number of spike trains in every file:", bool((info.nNeurons == info.trains).all()))
print("Spike times sorted within every train:", bool(info.sorted.all()), "| on the 0.05 ms grid (20 kHz):", bool(info.on_50us_grid.all()))
print("Every spike within [0, recordinglength]:", bool(((info.first_ms >= 0) & (info.last_ms <= info.length_ms)).all()))
print("Recording lengths (ms):", info.length_ms.value_counts().to_dict())
print("Recording dates:", sorted(set(r[:10] for r in info.recording_id)))
# recordings deposited twice: identical spike trains in two files
sig = {}
for r in recs:
    for k, s in enumerate(r["spikes"]):
        sig.setdefault((len(s), round(float(s[0]), 2), round(float(s[-1]), 2)), []).append((r["name"], k))
shared = [v for v in sig.values() if len({f for f, _ in v}) > 1]
print("Spike trains with the same count, first and last spike in two files:", len(shared))
print("Distinct recording IDs:", info.recording_id.nunique(), "of", len(info))
     file recording_id  nNeurons  trains  length_ms  first_ms    last_ms  spikes_min  spikes_max  under_100  sorted  on_50us_grid          x_um        y_um     timescale sampling
 DataSet1 2012-02-09-0       166     166  3600000.0   8005.85 3599995.65         105      113781          0    True          True  -960 to 1063 -608 to 575 1 millisecond   20 kHz
 DataSet2 2012-02-10-1       443     443  3600000.0   8001.90 3599983.50         100      116644          0    True          True -1051 to 1067 -562 to 600 1 millisecond   20 kHz
 DataSet3 2012-02-11-0        99      99  3600000.0   8010.80 3599487.50         769       98955          0    True          True   -944 to 768 -474 to 589 1 millisecond   20 kHz
 DataSet4 2012-02-12-0        98      98  3600000.0   8002.30 3598396.00         164       43409          0    True          True   -915 to 927 -395 to 602 1 millisecond   20 kHz
 DataSet5 2012-02-13-1       367     367  3600000.0   8000.00 3599988.90         105      118238          0    True          True -1009 to 1079 -559 to 603 1 millisecond   20 kHz
 DataSet6 2012-02-14-0       286     286  3600000.0   8002.25 3598476.65         115       57686          0    True          True  -1097 to 982 -578 to 570 1 millisecond   20 kHz
 DataSet7 2012-02-15-1       172     172  3600000.0   8000.05 3599401.10         115       25488          0    True          True   -953 to 945 -591 to 585 1 millisecond   20 kHz
 DataSet8 2012-02-16-1       191     191  3600000.0   8006.45 3598472.80         132       53838          0    True          True  -1003 to 896 -487 to 483 1 millisecond   20 kHz
 DataSet9 2012-02-17-0       333     333  3600000.0   8000.00 3599969.15         105       78168          0    True          True  -1032 to 911 -558 to 598 1 millisecond   20 kHz
DataSet10 2012-02-18-0       368     368  3600000.0   8002.25 3599992.70         101      122251          0    True          True  -1056 to 983 -564 to 550 1 millisecond   20 kHz
DataSet11 2013-01-02-0       243     243  3600000.0      1.35 3599997.90         105      136974          0    True          True  -945 to 1055 -552 to 563 1 millisecond   20 kHz
DataSet12 2013-01-03-0       346     346  3600000.0      0.10 3599998.30         136      192998          0    True          True -1031 to 1025 -591 to 484 1 millisecond   20 kHz
DataSet13 2013-01-03-1       381     381  3600000.0      0.90 3599992.50         160       86010          0    True          True -1031 to 1026 -504 to 606 1 millisecond   20 kHz
DataSet14 2013-01-04-0       304     304  3600000.0      0.05 3599997.95         168      139358          0    True          True  -945 to 1009 -574 to 600 1 millisecond   20 kHz
DataSet15 2013-01-04-1       206     206  3600000.0      2.60 3599990.80         159      148787          0    True          True  -1042 to 945 -581 to 450 1 millisecond   20 kHz
DataSet16 2013-01-05-0       594     594  3600000.0      0.30 3600000.00         100      160381          0    True          True  -992 to 1063 -603 to 568 1 millisecond   20 kHz
DataSet17 2013-01-05-1       435     435  3600000.0      4.25 3599980.10         104       60968          0    True          True -1033 to 1022 -501 to 594 1 millisecond   20 kHz
DataSet18 2013-01-06-0       180     180  3600000.0      0.30 3599565.55         680      166213          0    True          True   -945 to 945 -603 to 457 1 millisecond   20 kHz
DataSet19 2013-01-06-1       262     262  2887498.0   2000.40 2886987.70         100      131153          0    True          True -1046 to 1032 -580 to 546 1 millisecond   20 kHz
DataSet20 2013-01-07-0       534     534  3600000.0      0.10 3599990.60         103      278878          0    True          True -1093 to 1097 -606 to 604 1 millisecond   20 kHz
DataSet21 2013-01-07-1       444     444  3600000.0      2.40 3599998.85         102       41495          0    True          True -1047 to 1036 -604 to 595 1 millisecond   20 kHz
DataSet22 2013-01-08-0       384     384  3600000.0     13.40 3599969.65         120      204641          0    True          True -1090 to 1062 -533 to 510 1 millisecond   20 kHz
DataSet23 2013-01-08-1       310     310  3600000.0     29.40 3599588.15         104       58223          0    True          True  -945 to 1032 -592 to 586 1 millisecond   20 kHz
DataSet24 2013-01-09-0       358     358  3600000.0      1.30 3599992.70         116      195923          0    True          True  -944 to 1077 -534 to 568 1 millisecond   20 kHz
DataSet25 2013-01-09-1       231     231  3600000.0      1.00 3599975.75         194       68362          0    True          True  -1099 to 946 -578 to 505 1 millisecond   20 kHz

nNeurons equals the number of spike trains in every file: True
Spike times sorted within every train: True | on the 0.05 ms grid (20 kHz): True
Every spike within [0, recordinglength]: True
Recording lengths (ms): {3600000.0: 24, 2887498.0: 1}
Recording dates: ['2012-02-09', '2012-02-10', '2012-02-11', '2012-02-12', '2012-02-13', '2012-02-14', '2012-02-15', '2012-02-16', '2012-02-17', '2012-02-18', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08', '2013-01-09']
Spike trains with the same count, first and last spike in two files: 0
Distinct recording IDs: 25 of 25

The descriptor says the data are in ms at 20 kHz, with recordings of "approximately 1 hour" (3600000 ms "for most data sets") and positions in um with the origin at the array's centre on a 2 mm by 1 mm array. The values agree: spike times sit on the 0.05 ms grid, positions span about -1100 to 1100 um in x and -600 to 600 um in y, 24 recordings last 3600000 ms and one (DataSet19) 2887498 ms (48 min). The first ten recordings have no spike in their first 8 s. No spike train appears in two files and the 25 recording IDs are distinct, so no recording is deposited twice. The files hold spike times only: there are no trials or other data streams whose clock could differ from the spikes', so the clock check of the protocol does not apply.

data-recordings¶

The analysis used 25 recordings of somatosensory cortex cultures, with 7735 neurons in total after removing neurons with fewer than 100 spikes in the 60 min recording, an average of 309.4 neurons per recording and an average firing rate of 2.10 Hz.

In [3]:
counts = np.array([len(r["spikes"]) for r in recs])
spk = [np.array([len(s) for s in r["spikes"]]) for r in recs]
keep = [n >= 100 for n in spk]
rate_len = np.concatenate([n / (r["length_ms"] / 1000) for n, r in zip(spk, recs)])
rate_60 = np.concatenate([n / 3600.0 for n in spk])
print("Recordings:", len(recs))
print("Neurons as deposited:", counts.sum(), "| mean per recording:", round(counts.mean(), 1))
print("Neurons with 100 or more spikes:", sum(k.sum() for k in keep), "(the deposit already applies the threshold)")
print(f"Mean rate per neuron, (a) spikes over each recording's length: {rate_len.mean():.3f} Hz; "
      f"(b) spikes over 60 min: {rate_60.mean():.3f} Hz")
print(f"Rates range from {rate_len.min():.3f} to {rate_len.max():.1f} Hz")
Recordings: 25
Neurons as deposited: 7735 | mean per recording: 309.4
Neurons with 100 or more spikes: 7735 (the deposit already applies the threshold)
Mean rate per neuron, (a) spikes over each recording's length: 2.132 Hz; (b) spikes over 60 min: 2.103 Hz
Rates range from 0.028 to 77.5 Hz

Result: reproduced. The data set holds 25 recordings and 7735 neurons (309.4 per recording), every one with at least 100 spikes, so the deposit already applies the paper's threshold. The mean rate is 2.103 Hz with spikes counted over 60 min (reading b) and 2.132 Hz over each recording's own length (reading a); both are within 0.21 Hz of 2.10 Hz.

TE networks¶

TE from every neuron to every other, at both time scales, with the jitter test (hdn.te_network). Two details of the test are open, and every reading is run:

  • Which two bins form the past state ([44]'s text gives bins t-1 and t-2, its Table 1 and the paper's delay windows imply t-2 and t-3; see hdn.py). Both are run.
  • How a surrogate whose TE equals the real TE is counted. [44] takes as the p-value "the percentage of the TE values from jittered data that were larger than the TE value obtained from the data" (Transfer Entropy Analysis, paragraph 6), and the claims file (M-SIG) says "larger". When the jitter cannot change the counts of a pair, every surrogate ties with the real TE, so under a strict "larger" the pair is called significant with no evidence. Both rules are run: ties counted as not exceeding (strict, the literal text) and ties counted as exceeding (the standard permutation p-value). Each test runs to completion for both decisions.

The first cell checks the normal approximation against the full jitter of every spike on two recordings at both bin sizes, pair by pair, under both tie rules.

In [4]:
check = []
for name in ["DataSet1", "DataSet7"]:
    r = next(x for x in recs if x["name"] == name)
    for scale, bin_ms in hdn.TIME_SCALES.items():
        trains, T = hdn.bin_trains(r["spikes"], bin_ms, r["length_ms"])
        off = ~np.eye(len(trains), dtype=bool)
        t = time.time()
        ex = hdn.te_network(trains, T, hdn.N_SURROGATES, hdn.MAX_EXCEED, 1, 10**9, 2, 3, False)
        t_exact = time.time() - t
        ap = hdn.te_network(trains, T, hdn.N_SURROGATES, hdn.MAX_EXCEED, 1, 50, 2, 3, False)
        for rule, col in [("ties exceed", 4), ("strict", 3)]:
            e, a = (ex[col] < hdn.MAX_EXCEED) & off, (ap[col] < hdn.MAX_EXCEED) & off
            check.append({"recording": name, "scale": scale, "rule": rule, "pairs": int(off.sum()),
                          "significant_exact": int(e.sum()), "significant_approx": int(a.sum()), "both": int((e & a).sum()),
                          "exact_only": int((e & ~a).sum()), "approx_only": int((~e & a).sum()),
                          "agreement_of_union": round((e & a).sum() / max((e | a).sum(), 1), 3), "seconds_exact": round(t_exact)})
print(pd.DataFrame(check).to_string(index=False))
recording      scale        rule  pairs  significant_exact  significant_approx  both  exact_only  approx_only  agreement_of_union  seconds_exact
 DataSet1 1.6-6.4 ms ties exceed  27390                110                 119   104           6           15               0.832             27
 DataSet1 1.6-6.4 ms      strict  27390               2937                2946  2930           7           16               0.992             27
 DataSet1  3.5-14 ms ties exceed  27390                413                 428   393          20           35               0.877             56
 DataSet1  3.5-14 ms      strict  27390               2131                2144  2110          21           34               0.975             56
 DataSet7 1.6-6.4 ms ties exceed  29412                381                 392   363          18           29               0.885             34
 DataSet7 1.6-6.4 ms      strict  29412               3530                3542  3512          18           30               0.987             34
 DataSet7  3.5-14 ms ties exceed  29412               1089                1090  1024          65           66               0.887            108
 DataSet7  3.5-14 ms      strict  29412               3011                3012  2945          66           67               0.957            108
In [5]:
NETS = {}
rows = []
t_all = time.time()
for past_name, (p0, p1) in hdn.PAST_READINGS.items():
    for scale, bin_ms in hdn.TIME_SCALES.items():
        for r in recs:
            trains, T = hdn.bin_trains(r["spikes"], bin_ms, r["length_ms"])
            te, nte, ran, gt, ge, n_rel, n_mov = hdn.te_network(trains, T, hdn.N_SURROGATES, hdn.MAX_EXCEED, 1, 50, p0, p1, False)
            n = len(trains)
            off = ~np.eye(n, dtype=bool)
            sig_s, sig_t = (gt < hdn.MAX_EXCEED) & off, (ge < hdn.MAX_EXCEED) & off
            NETS[past_name, scale, r["name"]] = {"trains": trains, "T": T, "te": te, "nte": nte,
                                                 "sig": {"ties": sig_t, "strict": sig_s}, "ge": ge}
            rows.append({"past": past_name, "scale": scale, "recording": r["name"], "neurons": n,
                         "expected_by_chance": round(0.001 * n * (n - 1)),
                         "sig_ties": int(sig_t.sum()), "sig_strict": int(sig_s.sum()),
                         "strict_zero_exceed": int((sig_s & (ran == hdn.N_SURROGATES) & (gt == 0)).sum()),
                         "strict_no_movable_spike": int((sig_s & (n_mov == 0)).sum()),
                         "strict_no_relevant_spike": int((sig_s & (n_rel == 0)).sum()),
                         "density_ties": sig_t.sum() / (n * (n - 1)), "density_strict": sig_s.sum() / (n * (n - 1)),
                         "eff_N_ties": int((sig_t.any(0) | sig_t.any(1)).sum()), "eff_N_strict": int((sig_s.any(0) | sig_s.any(1)).sum())})
net_info = pd.DataFrame(rows)
net_info["eff_k_ties"] = net_info.sig_ties / net_info.eff_N_ties.clip(lower=1)
net_info["eff_k_strict"] = net_info.sig_strict / net_info.eff_N_strict.clip(lower=1)
print(f"{time.time() - t_all:.0f} s")
print(net_info.round(4).to_string(index=False))
agg = net_info.groupby(["past", "scale"]).agg(
    neurons=("neurons", "sum"), chance=("expected_by_chance", "sum"), sig_ties=("sig_ties", "sum"), sig_strict=("sig_strict", "sum"),
    strict_zero_exceed=("strict_zero_exceed", "sum"), strict_no_movable_spike=("strict_no_movable_spike", "sum"),
    strict_no_relevant_spike=("strict_no_relevant_spike", "sum"),
    density_ties_median=("density_ties", "median"), density_strict_median=("density_strict", "median"),
    eff_N_ties_mean=("eff_N_ties", "mean"), eff_N_strict_mean=("eff_N_strict", "mean"),
    eff_k_ties_mean=("eff_k_ties", "mean"), eff_k_strict_mean=("eff_k_strict", "mean"))
agg["ties_x_chance"] = agg.sig_ties / agg.chance
agg["strict_x_chance"] = agg.sig_strict / agg.chance
print()
print(agg.round(4).T.to_string())
1737 s
   past      scale recording  neurons  expected_by_chance  sig_ties  sig_strict  strict_zero_exceed  strict_no_movable_spike  strict_no_relevant_spike  density_ties  density_strict  eff_N_ties  eff_N_strict  eff_k_ties  eff_k_strict
t-2,t-3 1.6-6.4 ms  DataSet1      166                  27       119        2946                2900                     2168                      2168        0.0043          0.1076          77           160      1.5455       18.4125
t-2,t-3 1.6-6.4 ms  DataSet2      443                 196       493       17951               17702                    13490                     13490        0.0025          0.0917         303           443      1.6271       40.5214
t-2,t-3 1.6-6.4 ms  DataSet3       99                  10      1222        1249                1009                       17                        17        0.1260          0.1287          95            97     12.8632       12.8763
t-2,t-3 1.6-6.4 ms  DataSet4       98                  10       288         333                 263                       30                        30        0.0303          0.0350          89            94      3.2360        3.5426
t-2,t-3 1.6-6.4 ms  DataSet5      367                 134       174       21666               21559                    17085                     17085        0.0013          0.1613         151           367      1.1523       59.0354
t-2,t-3 1.6-6.4 ms  DataSet6      286                  82      1056       11158               10851                     8299                      8298        0.0130          0.1369         203           285      5.2020       39.1509
t-2,t-3 1.6-6.4 ms  DataSet7      172                  29       392        3542                3414                     2398                      2398        0.0133          0.1204         108           172      3.6296       20.5930
t-2,t-3 1.6-6.4 ms  DataSet8      191                  36      1546        2347                1949                      602                       602        0.0426          0.0647         175           190      8.8343       12.3526
t-2,t-3 1.6-6.4 ms  DataSet9      333                 111       686       22245               22030                    18102                     18101        0.0062          0.2012         204           333      3.3627       66.8018
t-2,t-3 1.6-6.4 ms DataSet10      368                 135       223       31873               31763                    26120                     26118        0.0017          0.2360         150           366      1.4867       87.0847
t-2,t-3 1.6-6.4 ms DataSet11      243                  59      3681        4318                3373                      423                       423        0.0626          0.0734         230           243     16.0043       17.7695
t-2,t-3 1.6-6.4 ms DataSet12      346                 119      3937        6317                5433                     1736                      1736        0.0330          0.0529         331           346     11.8943       18.2572
t-2,t-3 1.6-6.4 ms DataSet13      381                 145      1551        2702                2145                      848                       846        0.0107          0.0187         354           378      4.3814        7.1481
t-2,t-3 1.6-6.4 ms DataSet14      304                  92      6134        6703                5353                      400                       400        0.0666          0.0728         293           304     20.9352       22.0493
t-2,t-3 1.6-6.4 ms DataSet15      206                  42      3551        3832                3100                      172                       172        0.0841          0.0907         203           206     17.4926       18.6019
t-2,t-3 1.6-6.4 ms DataSet16      594                 352      2527       39791               39011                    30994                     30990        0.0072          0.1130         484           594      5.2211       66.9882
t-2,t-3 1.6-6.4 ms DataSet17      435                 189       621       10494               10161                     7809                      7809        0.0033          0.0556         319           435      1.9467       24.1241
t-2,t-3 1.6-6.4 ms DataSet18      180                  32      4816        4844                3996                       19                        19        0.1495          0.1503         180           180     26.7556       26.9111
t-2,t-3 1.6-6.4 ms DataSet19      262                  68      2453        6944                6487                     3687                      3687        0.0359          0.1015         220           261     11.1500       26.6054
t-2,t-3 1.6-6.4 ms DataSet20      534                 285       963       29758               29355                    23569                     23569        0.0034          0.1046         366           534      2.6311       55.7266
t-2,t-3 1.6-6.4 ms DataSet21      444                 197       884        6427                5998                     4291                      4291        0.0045          0.0327         350           443      2.5257       14.5079
t-2,t-3 1.6-6.4 ms DataSet22      384                 147      7077        7422                5789                      215                       215        0.0481          0.0505         376           383     18.8218       19.3786
t-2,t-3 1.6-6.4 ms DataSet23      310                  96      5810        6313                4991                      346                       346        0.0607          0.0659         299           309     19.4314       20.4304
t-2,t-3 1.6-6.4 ms DataSet24      358                 128      3106        8486                7705                     4377                      4366        0.0243          0.0664         335           358      9.2716       23.7039
t-2,t-3 1.6-6.4 ms DataSet25      231                  53      1880        1979                1417                       58                        58        0.0354          0.0372         223           230      8.4305        8.6043
t-2,t-3  3.5-14 ms  DataSet1      166                  27       428        2144                2035                     1416                      1416        0.0156          0.0783         136           166      3.1471       12.9157
t-2,t-3  3.5-14 ms  DataSet2      443                 196      1036       12472               12065                     9118                      9111        0.0053          0.0637         366           443      2.8306       28.1535
t-2,t-3  3.5-14 ms  DataSet3       99                  10      3152        3169                2924                       11                        11        0.3249          0.3266          98            98     32.1633       32.3367
t-2,t-3  3.5-14 ms  DataSet4       98                  10       493         518                 399                       19                        19        0.0519          0.0545          91            91      5.4176        5.6923
t-2,t-3  3.5-14 ms  DataSet5      367                 134       526       14121               13891                    10717                     10715        0.0039          0.1051         229           367      2.2969       38.4768
t-2,t-3  3.5-14 ms  DataSet6      286                  82      2629        9483                8954                     5679                      5679        0.0323          0.1163         236           286     11.1398       33.1573
t-2,t-3  3.5-14 ms  DataSet7      172                  29      1090        3012                2795                     1455                      1454        0.0371          0.1024         134           172      8.1343       17.5116
t-2,t-3  3.5-14 ms  DataSet8      191                  36      3785        4291                3636                      361                       361        0.1043          0.1182         184           191     20.5707       22.4660
t-2,t-3  3.5-14 ms  DataSet9      333                 111      1890       16715               16255                    12539                     12537        0.0171          0.1512         258           333      7.3256       50.1952
t-2,t-3  3.5-14 ms DataSet10      368                 135       981       22397               22071                    17664                     17645        0.0073          0.1658         274           368      3.5803       60.8614
t-2,t-3  3.5-14 ms DataSet11      243                  59      8088        8403                7135                      216                       216        0.1375          0.1429         235           243     34.4170       34.5802
t-2,t-3  3.5-14 ms DataSet12      346                 119      8754       10055                8423                      983                       980        0.0733          0.0842         334           346     26.2096       29.0607
t-2,t-3  3.5-14 ms DataSet13      381                 145      4062        4788                3626                      551                       526        0.0281          0.0331         373           379     10.8901       12.6332
t-2,t-3  3.5-14 ms DataSet14      304                  92     16841       17148               14776                      233                       233        0.1828          0.1862         301           304     55.9502       56.4079
t-2,t-3  3.5-14 ms DataSet15      206                  42      6921        7027                6091                       74                        74        0.1639          0.1664         206           206     33.5971       34.1117
t-2,t-3  3.5-14 ms DataSet16      594                 352      6364       30617               29103                    20157                     20104        0.0181          0.0869         525           594     12.1219       51.5438
t-2,t-3  3.5-14 ms DataSet17      435                 189      2320        8206                7268                     4740                      4740        0.0123          0.0435         376           435      6.1702       18.8644
t-2,t-3  3.5-14 ms DataSet18      180                  32      9023        9033                7996                        7                         7        0.2800          0.2804         179           179     50.4078       50.4637
t-2,t-3  3.5-14 ms DataSet19      262                  68      5531        8637                7830                     2478                      2475        0.0809          0.1263         249           262     22.2129       32.9656
t-2,t-3  3.5-14 ms DataSet20      534                 285      2321       20513               19792                    14923                     14920        0.0082          0.0721         452           534      5.1350       38.4139
t-2,t-3  3.5-14 ms DataSet21      444                 197      3126        6141                4925                     2397                      2397        0.0159          0.0312         420           444      7.4429       13.8311
t-2,t-3  3.5-14 ms DataSet22      384                 147     14339       14499               11784                       96                        96        0.0975          0.0986         383           384     37.4386       37.7578
t-2,t-3  3.5-14 ms DataSet23      310                  96     14910       15206               12756                      228                       228        0.1557          0.1587         308           310     48.4091       49.0516
t-2,t-3  3.5-14 ms DataSet24      358                 128      6341        9893                8729                     2937                      2926        0.0496          0.0774         348           358     18.2213       27.6341
t-2,t-3  3.5-14 ms DataSet25      231                  53      5078        5111                3930                       18                        18        0.0956          0.0962         227           230     22.3700       22.2217
t-1,t-2 1.6-6.4 ms  DataSet1      166                  27       134        3173                3124                     2266                      2266        0.0049          0.1158          61           163      2.1967       19.4663
t-1,t-2 1.6-6.4 ms  DataSet2      443                 196       516       19157               18909                    14195                     14194        0.0026          0.0978         312           443      1.6538       43.2438
t-1,t-2 1.6-6.4 ms  DataSet3       99                  10      1269        1303                1075                       17                        17        0.1308          0.1343          95            98     13.3579       13.2959
t-1,t-2 1.6-6.4 ms  DataSet4       98                  10       410         466                 373                       30                        30        0.0431          0.0490          88            93      4.6591        5.0108
t-1,t-2 1.6-6.4 ms  DataSet5      367                 134       215       22759               22638                    18104                     18104        0.0016          0.1694         159           367      1.3522       62.0136
t-1,t-2 1.6-6.4 ms  DataSet6      286                  82      1178       11794               11458                     8698                      8697        0.0145          0.1447         215           285      5.4791       41.3825
t-1,t-2 1.6-6.4 ms  DataSet7      172                  29       463        3759                3638                     2543                      2543        0.0157          0.1278         109           172      4.2477       21.8547
t-1,t-2 1.6-6.4 ms  DataSet8      191                  36      1903        2809                2347                      637                       637        0.0524          0.0774         175           191     10.8743       14.7068
t-1,t-2 1.6-6.4 ms  DataSet9      333                 111       714       23400               23186                    18927                     18926        0.0065          0.2117         212           333      3.3679       70.2703
t-1,t-2 1.6-6.4 ms DataSet10      368                 135       303       33144               33027                    27368                     27366        0.0022          0.2454         154           366      1.9675       90.5574
t-1,t-2 1.6-6.4 ms DataSet11      243                  59      4171        4865                3878                      459                       459        0.0709          0.0827         233           243     17.9013       20.0206
t-1,t-2 1.6-6.4 ms DataSet12      346                 119      4598        7209                6131                     1882                      1882        0.0385          0.0604         330           346     13.9333       20.8353
t-1,t-2 1.6-6.4 ms DataSet13      381                 145      1926        3233                2601                      910                       906        0.0133          0.0223         358           380      5.3799        8.5079
t-1,t-2 1.6-6.4 ms DataSet14      304                  92      6585        7224                5884                      422                       422        0.0715          0.0784         297           303     22.1717       23.8416
t-1,t-2 1.6-6.4 ms DataSet15      206                  42      4179        4503                3706                      184                       184        0.0990          0.1066         203           206     20.5862       21.8592
t-1,t-2 1.6-6.4 ms DataSet16      594                 352      2882       42019               41147                    32628                     32624        0.0082          0.1193         510           594      5.6510       70.7391
t-1,t-2 1.6-6.4 ms DataSet17      435                 189      1070       11324               10819                     8320                      8320        0.0057          0.0600         360           435      2.9722       26.0322
t-1,t-2 1.6-6.4 ms DataSet18      180                  32      5502        5534                4569                       21                        21        0.1708          0.1718         180           180     30.5667       30.7444
t-1,t-2 1.6-6.4 ms DataSet19      262                  68      2716        7427                6881                     3888                      3888        0.0397          0.1086         233           261     11.6567       28.4559
t-1,t-2 1.6-6.4 ms DataSet20      534                 285      1121       31383               30926                    24955                     24955        0.0039          0.1103         392           533      2.8597       58.8799
t-1,t-2 1.6-6.4 ms DataSet21      444                 197      1136        6907                6356                     4598                      4598        0.0058          0.0351         380           444      2.9895       15.5563
t-1,t-2 1.6-6.4 ms DataSet22      384                 147      8636        9023                7144                      237                       237        0.0587          0.0614         379           382     22.7863       23.6204
t-1,t-2 1.6-6.4 ms DataSet23      310                  96      6788        7333                5853                      364                       364        0.0709          0.0766         307           310     22.1107       23.6548
t-1,t-2 1.6-6.4 ms DataSet24      358                 128      3504        9274                8435                     4617                      4607        0.0274          0.0726         336           358     10.4286       25.9050
t-1,t-2 1.6-6.4 ms DataSet25      231                  53      2338        2450                1817                       66                        66        0.0440          0.0461         226           230     10.3451       10.6522
t-1,t-2  3.5-14 ms  DataSet1      166                  27       518        2380                2263                     1490                      1490        0.0189          0.0869         136           165      3.8088       14.4242
t-1,t-2  3.5-14 ms  DataSet2      443                 196      1624       14089               13493                     9524                      9517        0.0083          0.0720         392           443      4.1429       31.8036
t-1,t-2  3.5-14 ms  DataSet3       99                  10      3308        3326                3114                       12                        12        0.3410          0.3428          99            99     33.4141       33.5960
t-1,t-2  3.5-14 ms  DataSet4       98                  10       879         909                 762                       19                        19        0.0925          0.0956          96            98      9.1562        9.2755
t-1,t-2  3.5-14 ms  DataSet5      367                 134       793       15235               14907                    11345                     11341        0.0059          0.1134         244           367      3.2500       41.5123
t-1,t-2  3.5-14 ms  DataSet6      286                  82      3166       10415                9765                     5970                      5970        0.0388          0.1278         248           286     12.7661       36.4161
t-1,t-2  3.5-14 ms  DataSet7      172                  29      1346        3422                3134                     1525                      1524        0.0458          0.1163         143           172      9.4126       19.8953
t-1,t-2  3.5-14 ms  DataSet8      191                  36      5049        5574                4761                      389                       389        0.1391          0.1536         183           190     27.5902       29.3368
t-1,t-2  3.5-14 ms  DataSet9      333                 111      2004       17669               17203                    13110                     13108        0.0181          0.1598         262           333      7.6489       53.0601
t-1,t-2  3.5-14 ms DataSet10      368                 135      1171       23661               23315                    18542                     18524        0.0087          0.1752         289           368      4.0519       64.2962
t-1,t-2  3.5-14 ms DataSet11      243                  59     11140       11468                9948                      235                       235        0.1894          0.1950         240           243     46.4167       47.1934
t-1,t-2  3.5-14 ms DataSet12      346                 119     11633       13033               10920                     1053                      1050        0.0975          0.1092         337           346     34.5193       37.6676
t-1,t-2  3.5-14 ms DataSet13      381                 145      6029        6822                5270                      601                       574        0.0416          0.0471         376           381     16.0346       17.9055
t-1,t-2  3.5-14 ms DataSet14      304                  92     19261       19596               17048                      248                       248        0.2091          0.2127         302           304     63.7781       64.4605
t-1,t-2  3.5-14 ms DataSet15      206                  42      8887        9016                7860                       78                        78        0.2104          0.2135         206           206     43.1408       43.7670
t-1,t-2  3.5-14 ms DataSet16      594                 352      8119       33548               31628                    21223                     21165        0.0230          0.0952         543           594     14.9521       56.4781
t-1,t-2  3.5-14 ms DataSet17      435                 189      4522       10713                9050                     5044                      5044        0.0240          0.0567         401           435     11.2768       24.6276
t-1,t-2  3.5-14 ms DataSet18      180                  32     11847       11856               10606                        7                         7        0.3677          0.3680         180           180     65.8167       65.8667
t-1,t-2  3.5-14 ms DataSet19      262                  68      6385        9642                8753                     2600                      2598        0.0934          0.1410         252           262     25.3373       36.8015
t-1,t-2  3.5-14 ms DataSet20      534                 285      3143       22347               21321                    15767                     15764        0.0110          0.0785         474           534      6.6308       41.8483
t-1,t-2  3.5-14 ms DataSet21      444                 197      5268        8454                6550                     2566                      2566        0.0268          0.0430         426           444     12.3662       19.0405
t-1,t-2  3.5-14 ms DataSet22      384                 147     21578       21763               18194                      113                       113        0.1467          0.1480         382           383     56.4869       56.8225
t-1,t-2  3.5-14 ms DataSet23      310                  96     18589       18910               16306                      242                       242        0.1941          0.1974         310           310     59.9645       61.0000
t-1,t-2  3.5-14 ms DataSet24      358                 128      7850       11650               10121                     3077                      3063        0.0614          0.0912         349           358     22.4928       32.5419
t-1,t-2  3.5-14 ms DataSet25      231                  53      6915        6960                5605                       22                        22        0.1302          0.1310         229           230     30.1965       30.2609

past                          t-1,t-2                   t-2,t-3             
scale                      1.6-6.4 ms    3.5-14 ms   1.6-6.4 ms    3.5-14 ms
neurons                     7735.0000    7735.0000    7735.0000    7735.0000
chance                      2774.0000    2774.0000    2774.0000    2774.0000
sig_ties                   64257.0000  171024.0000   55190.0000  130029.0000
sig_strict                281472.0000  312458.0000  261640.0000  263599.0000
strict_zero_exceed        265922.0000  281897.0000  247754.0000  239189.0000
strict_no_movable_spike   176336.0000  114802.0000  167255.0000  109017.0000
strict_no_relevant_spike  176313.0000  114663.0000  167234.0000  108888.0000
density_ties_median            0.0274       0.0614       0.0243       0.0496
density_strict_median          0.0978       0.1278       0.0907       0.1024
eff_N_ties_mean              252.1600     283.9600     244.7200     276.8800
eff_N_strict_mean            308.6400     309.2400     308.4400     308.9200
eff_k_ties_mean               10.0598      24.9861       8.7933      19.5040
eff_k_strict_mean             31.6443      38.7959      29.2471      32.4523
ties_x_chance                 23.1640      61.6525      19.8955      46.8742
strict_x_chance              101.4679     112.6381      94.3187      95.0249

The false-positive rate of each rule, measured on the data. Each neuron's binned train is shifted circularly by its own random offset (10% to 90% of the recording), which keeps every neuron's rate and bursts and removes the timing between neurons, so every pair is independent and a test at p < 0.001 should call at most 0.1% of the pairs significant. Five recordings (every fifth), both time scales, bins t-2 and t-3. The rate times the number of pairs gives the connections expected by chance in each of these recordings, compared with its significant connections. The rates at stricter counts (fewer than k of 5000 surrogates at or above the real TE) set the threshold of a variant, calibrated: the largest k whose pooled rate is at most 0.001, or k = 1 if none is.

In [6]:
rng = np.random.default_rng(31)
rows = []
for name in ["DataSet1", "DataSet6", "DataSet11", "DataSet16", "DataSet21"]:
    r = next(x for x in recs if x["name"] == name)
    for scale, bin_ms in hdn.TIME_SCALES.items():
        trains, T = hdn.bin_trains(r["spikes"], bin_ms, r["length_ms"])
        shifted = type(trains)()
        for tr in trains:
            shifted.append(np.sort((tr + rng.integers(int(0.1 * T), int(0.9 * T))) % T))
        out = hdn.te_network(shifted, T, hdn.N_SURROGATES, hdn.MAX_EXCEED, 2, 50, 2, 3, False)
        off = ~np.eye(len(trains), dtype=bool)
        rows.append({"recording": name, "scale": scale, "pairs": int(off.sum()),
                     "fp_rate_ties": ((out[4] < hdn.MAX_EXCEED) & off).sum() / off.sum(),
                     "fp_rate_strict": ((out[3] < hdn.MAX_EXCEED) & off).sum() / off.sum(),
                     **{f"fp_ge<{k}": ((out[4] < k) & off).sum() / off.sum() for k in range(1, hdn.MAX_EXCEED)}})
fp = pd.DataFrame(rows)
print(fp.to_string(index=False, float_format=lambda v: f"{v:.4g}"))
print("\nPooled false-positive rate, ties exceeding:", round(fp.fp_rate_ties.mul(fp.pairs).sum() / fp.pairs.sum(), 5),
      "| strict:", round(fp.fp_rate_strict.mul(fp.pairs).sum() / fp.pairs.sum(), 5), "| nominal: 0.001")

# connections expected by chance in the tested recordings: false-positive rate times pairs,
# against the significant connections of the real network (bins t-2 and t-3)
share = fp.merge(net_info[net_info.past == "t-2,t-3"][["recording", "scale", "sig_ties", "sig_strict"]], on=["recording", "scale"])
share["chance_ties"] = share.fp_rate_ties * share.pairs
share["chance_share_ties"] = share.chance_ties / share.sig_ties
share["chance_strict"] = share.fp_rate_strict * share.pairs
share["chance_share_strict"] = share.chance_strict / share.sig_strict
print()
print(share[["recording", "scale", "pairs", "sig_ties", "chance_ties", "chance_share_ties", "sig_strict", "chance_strict",
             "chance_share_strict"]].to_string(index=False, float_format=lambda v: f"{v:.3g}"))
print("Pooled share expected by chance, ties exceeding:", round(share.chance_ties.sum() / share.sig_ties.sum(), 3),
      "| strict:", round(share.chance_strict.sum() / share.sig_strict.sum(), 3))

# a stricter threshold, run as a variant: fewer than k of 5000 surrogates at or above the real TE, with
# k the largest whose pooled false-positive rate on shifted trains is at most the nominal 0.001, or
# k = 1 (no surrogate at or above), the strictest the 5000 surrogates allow, if none reaches it
pooled_k = {k: float(fp[f"fp_ge<{k}"].mul(fp.pairs).sum() / fp.pairs.sum()) for k in range(1, hdn.MAX_EXCEED)}
print("\nPooled false-positive rate with fewer than k of 5000 surrogates at or above the real TE:",
      {k: round(v, 5) for k, v in pooled_k.items()}, "| k = 5:", round(float(fp.fp_rate_ties.mul(fp.pairs).sum() / fp.pairs.sum()), 5))
K_CAL = max([k for k, v in pooled_k.items() if v <= 0.001], default=1)
print("Calibrated threshold: fewer than", K_CAL, "surrogates at or above the real TE; pooled false-positive rate",
      round(pooled_k[K_CAL], 5), "| by recording and time scale:", fp[f"fp_ge<{K_CAL}"].min().round(5), "to", fp[f"fp_ge<{K_CAL}"].max().round(5))
cal = []
for scale in hdn.TIME_SCALES:
    for r in recs:
        net = NETS["t-2,t-3", scale, r["name"]]
        off = ~np.eye(len(net["trains"]), dtype=bool)
        net["sig"]["calibrated"] = (net["ge"] < K_CAL) & off
        cal.append({"scale": scale, "recording": r["name"], "sig_calibrated": int(net["sig"]["calibrated"].sum()),
                    "sig_ties": int(net["sig"]["ties"].sum())})
cal = pd.DataFrame(cal)
print(cal.groupby("scale")[["sig_calibrated", "sig_ties"]].sum().to_string())
share["chance_calibrated"] = share[f"fp_ge<{K_CAL}"] * share.pairs
share = share.merge(cal, on=["recording", "scale", "sig_ties"])
print("Pooled share expected by chance in the tested recordings, calibrated:",
      round(share.chance_calibrated.sum() / share.sig_calibrated.sum(), 3))
recording      scale  pairs  fp_rate_ties  fp_rate_strict   fp_ge<1   fp_ge<2   fp_ge<3   fp_ge<4
 DataSet1 1.6-6.4 ms  27390     0.0005476          0.1612 0.0001095 0.0003286 0.0004381 0.0005476
 DataSet1  3.5-14 ms  27390      0.003505          0.1026  0.001899  0.002337  0.002811  0.003249
 DataSet6 1.6-6.4 ms  81510      0.001239          0.1537 0.0005275 0.0007361 0.0009201  0.001055
 DataSet6  3.5-14 ms  81510      0.005067          0.1065  0.003178  0.003975  0.004466  0.004723
DataSet11 1.6-6.4 ms  58806      0.005033         0.03183  0.003095  0.003945  0.004421  0.004659
DataSet11  3.5-14 ms  58806       0.01284          0.0259   0.00903   0.01025   0.01117   0.01212
DataSet16 1.6-6.4 ms 352242      0.001669          0.1421 0.0009823   0.00119    0.0014  0.001536
DataSet16  3.5-14 ms 352242      0.005354          0.0962  0.003688  0.004318  0.004733  0.005076
DataSet21 1.6-6.4 ms 196692     0.0004474          0.1262  9.66e-05  0.000239 0.0003254 0.0003966
DataSet21  3.5-14 ms 196692      0.001647         0.07027 0.0007575  0.001012   0.00122  0.001464

Pooled false-positive rate, ties exceeding: 0.00318 | strict: 0.10772 | nominal: 0.001

recording      scale  pairs  sig_ties  chance_ties  chance_share_ties  sig_strict  chance_strict  chance_share_strict
 DataSet1 1.6-6.4 ms  27390       119           15              0.126        2946       4.42e+03                  1.5
 DataSet1  3.5-14 ms  27390       428           96              0.224        2144       2.81e+03                 1.31
 DataSet6 1.6-6.4 ms  81510      1056          101             0.0956       11158       1.25e+04                 1.12
 DataSet6  3.5-14 ms  81510      2629          413              0.157        9483       8.68e+03                0.915
DataSet11 1.6-6.4 ms  58806      3681          296             0.0804        4318       1.87e+03                0.434
DataSet11  3.5-14 ms  58806      8088          755             0.0933        8403       1.52e+03                0.181
DataSet16 1.6-6.4 ms 352242      2527          588              0.233       39791          5e+04                 1.26
DataSet16  3.5-14 ms 352242      6364     1.89e+03              0.296       30617       3.39e+04                 1.11
DataSet21 1.6-6.4 ms 196692       884           88             0.0995        6427       2.48e+04                 3.86
DataSet21  3.5-14 ms 196692      3126          324              0.104        6141       1.38e+04                 2.25
Pooled share expected by chance, ties exceeding: 0.158 | strict: 1.272

Pooled false-positive rate with fewer than k of 5000 surrogates at or above the real TE: {1: 0.00201, 2: 0.00243, 3: 0.00273, 4: 0.00297} | k = 5: 0.00318
Calibrated threshold: fewer than 1 surrogates at or above the real TE; pooled false-positive rate 0.00201 | by recording and time scale: 0.0001 to 0.00903
            sig_calibrated  sig_ties
scale                               
1.6-6.4 ms           41534     55190
3.5-14 ms           105835    130029
Pooled share expected by chance in the tested recordings, calibrated: 0.132
In [7]:
# degree against firing rate (bins t-2 and t-3), Spearman per recording and time scale
rows = []
for scale in hdn.TIME_SCALES:
    for r in recs:
        rate = np.array([len(s) for s in r["spikes"]]) / (r["length_ms"] / 1000)
        for rule in ["ties", "strict"]:
            sig = NETS["t-2,t-3", scale, r["name"]]["sig"][rule]
            rows.append({"scale": scale, "recording": r["name"], "rule": rule,
                         "rho_total": stats.spearmanr(rate, sig.sum(0) + sig.sum(1))[0],
                         "rho_in": stats.spearmanr(rate, sig.sum(0))[0], "rho_out": stats.spearmanr(rate, sig.sum(1))[0]})
rate_deg = pd.DataFrame(rows)
print("Spearman correlation of degree with firing rate, median (min to max) over the 25 recordings:")
for (scale, rule), sub in rate_deg.groupby(["scale", "rule"]):
    print(f"  {scale}, {rule}: " + "; ".join(f"{c[4:]} {sub[c].median():.2f} ({sub[c].min():.2f} to {sub[c].max():.2f})"
                                          for c in ["rho_total", "rho_in", "rho_out"]))
Spearman correlation of degree with firing rate, median (min to max) over the 25 recordings:
  1.6-6.4 ms, strict: total -0.31 (-0.87 to 0.92); in -0.20 (-0.88 to 0.84); out -0.40 (-0.88 to 0.84)
  1.6-6.4 ms, ties: total 0.75 (0.53 to 0.92); in 0.71 (0.38 to 0.88); out 0.58 (0.43 to 0.87)
  3.5-14 ms, strict: total 0.22 (-0.82 to 0.93); in 0.36 (-0.83 to 0.78); out 0.01 (-0.79 to 0.88)
  3.5-14 ms, ties: total 0.81 (0.56 to 0.93); in 0.73 (0.47 to 0.86); out 0.62 (0.37 to 0.89)

Which tie rule is used. The paper states its threshold as p < 0.001 (Methods, Effective Connectivity Detection, paragraph 5), so the test it describes calls at most 0.1% of independent pairs significant. The false-positive rate is printed above for both rules on shifted trains; the rule whose rate is near the stated 0.001 is the procedure the paper describes, and the other is not (protocol: a procedure whose chance level is far from the paper's differs from it). The analysis below uses ties counted as exceeding (ties), with bins t-2 and t-3, and shows the strict rule and bins t-1 and t-2 as variants. [44] reports effective N and k for its cortical networks over all ten of its time scales: "The mean ± STD in the original data (sub-networks) was 241±103 (42±7) for cortical networks" (Fig 12C legend) and "22±30 (3.7±0.7) for cortical networks" (Fig 12D legend); the table above gives both for each rule here. On degree and rate, [44] writes "firing rate and neuron degree were correlated in the sub-networks, especially for shorter time scales" (Results, paragraph before Fig 3), and on its null model of 400 independent Poisson neurons, "The null model produced less connectivity than expected by chance from multiple comparisons for all time scales" (same paragraph). These passages come from [44] (doi:10.1371/journal.pone.0115764, PMC4275261), which is not under paper/.

In [8]:
# name: (past bins, tie rule, sub-network mode, information gain, sub-networks, combinations per n);
# the variants use 100 sub-networks per recording and 20 combinations per n, for time
CONFIGS = {
    "main": ("t-2,t-3", "ties", "strongest", True, hdn.N_SUBNETS, hdn.N_GAIN_COMBOS),
    "strict": ("t-2,t-3", "strict", "strongest", True, 100, 20),
    "past t-1,t-2": ("t-1,t-2", "ties", "strongest", True, 100, 20),
    "sub random": ("t-2,t-3", "ties", "random", False, 100, 20),
    "calibrated": ("t-2,t-3", "calibrated", "strongest", True, 100, 20),
}
RES = {c: {} for c in CONFIGS}
t_all = time.time()
for c, (past_name, rule, mode, do_gain, n_sub, n_comb) in CONFIGS.items():
    for scale in hdn.TIME_SCALES:
        for r in recs:
            net = NETS[past_name, scale, r["name"]]
            seed = 1000 * list(hdn.TIME_SCALES).index(scale) + int(r["name"].replace("DataSet", ""))
            RES[c][scale, r["name"]] = hdn.analyse_recording(net["trains"], net["T"], net["sig"][rule], net["nte"], seed,
                                                             past=hdn.PAST_READINGS[past_name], sub_mode=mode, gains=do_gain,
                                                             n_sub=n_sub, gain_combos=n_comb)
    print(f"{c}: done at {time.time() - t_all:.0f} s")
rows = []
for c in CONFIGS:
    for (scale, name), a in RES[c].items():
        e = np.array(a["sub_info"]["edges"])
        rows.append({"config": c, "scale": scale, "recording": name, "subnetworks": len(a["subs"]), "draws": a["sub_info"]["draws"],
                     "draws_unconnectable": a["sub_info"]["unconnectable"], "draws_under_75": a["sub_info"]["too_few"],
                     "edges_before_trim_median": np.median(e) if len(e) else np.nan, "edges_before_trim_min": e.min() if len(e) else np.nan,
                     "subnet_triples": len(a["sub_triples"]), "full_triples_total": a["n_full_total"], "full_triples_used": len(a["full_triples"])})
summ = pd.DataFrame(rows)
print(summ[summ.config == "main"].to_string(index=False))
print()
print(summ.groupby(["config", "scale"]).agg(recordings_complete=("subnetworks", lambda v: int((v == v.max()).sum())), subnetworks=("subnetworks", "max"),
      draws=("draws", "sum"), draws_under_75=("draws_under_75", "sum"), draws_unconnectable=("draws_unconnectable", "sum"),
      edges_before_trim_median=("edges_before_trim_median", "median"), edges_before_trim_min=("edges_before_trim_min", "min")).to_string())
VARIANTS = {   # name: (config, PID form)
    "main": ("main", "claims"), "strict ties": ("strict", "claims"), "past t-1,t-2": ("past t-1,t-2", "claims"),
    "sub (b) random": ("sub random", "claims"), "PID Eq 8": ("main", "eq8"),
    "calibrated": ("calibrated", "claims")}
main: done at 652 s
strict: done at 921 s
past t-1,t-2: done at 1199 s
sub random: done at 1404 s
calibrated: done at 1703 s
config      scale recording  subnetworks  draws  draws_unconnectable  draws_under_75  edges_before_trim_median  edges_before_trim_min  subnet_triples  full_triples_total  full_triples_used
  main 1.6-6.4 ms  DataSet1          500    581                    0              81                      83.0                     54           38880                 132                132
  main 1.6-6.4 ms  DataSet2            6   5000                    0            4994                      53.0                     38             439                 687                687
  main 1.6-6.4 ms  DataSet3          500    500                    0               0                     375.5                    179           44639               10852               3000
  main 1.6-6.4 ms  DataSet4          500    500                    0               0                     123.0                     77           46129                 825                825
  main 1.6-6.4 ms  DataSet5            0   5000                    0            5000                      54.0                     41               0                 111                111
  main 1.6-6.4 ms  DataSet6          500    500                    0               0                     133.0                     75           38841                4977               3000
  main 1.6-6.4 ms  DataSet7          500    500                    0               0                     136.5                     85           33750                1023               1023
  main 1.6-6.4 ms  DataSet8          500    500                    0               0                     185.0                    102           37562               11178               3000
  main 1.6-6.4 ms  DataSet9          500    527                    0              27                     103.0                     61           37078                2050               2050
  main 1.6-6.4 ms DataSet10          380   5000                    0            4620                      64.0                     43           24268                 220                220
  main 1.6-6.4 ms DataSet11          500    500                    0               0                     223.0                    109           42893               47993               3000
  main 1.6-6.4 ms DataSet12          500    505                    0               5                     143.0                     65           33233               37470               3000
  main 1.6-6.4 ms DataSet13          500    806                    0             306                      80.0                     44           30520                5983               3000
  main 1.6-6.4 ms DataSet14          500    500                    0               0                     212.5                     90           31068               93359               3000
  main 1.6-6.4 ms DataSet15          500    500                    0               0                     251.0                    118           31370               44201               3000
  main 1.6-6.4 ms DataSet16          500    692                    0             192                      85.0                     52           29663               12250               3000
  main 1.6-6.4 ms DataSet17          148   5000                    0            4852                      58.0                     36           10354                1125               1125
  main 1.6-6.4 ms DataSet18          500    500                    0               0                     393.0                    197           36738               81724               3000
  main 1.6-6.4 ms DataSet19          500    500                    0               0                     211.0                     94           45147               23116               3000
  main 1.6-6.4 ms DataSet20          500   1006                    0             506                      74.0                     46           27434                2134               2134
  main 1.6-6.4 ms DataSet21          500   2322                    0            1822                      64.0                     39           29121                1886               1886
  main 1.6-6.4 ms DataSet22          500    500                    0               0                     174.0                     89           35108              114989               3000
  main 1.6-6.4 ms DataSet23          500    500                    0               0                     200.0                    107           40252               89319               3000
  main 1.6-6.4 ms DataSet24          500    520                    0              20                     121.5                     55           32174               23060               3000
  main 1.6-6.4 ms DataSet25          500    501                    0               1                     133.0                     72           39438               12327               3000
  main  3.5-14 ms  DataSet1          500    529                    0              29                     108.0                     59           33767                1023               1023
  main  3.5-14 ms  DataSet2          500   1872                    0            1372                      65.5                     40           25800                2514               2514
  main  3.5-14 ms  DataSet3          500    500                    0               0                     882.0                    605           51879               61775               3000
  main  3.5-14 ms  DataSet4          500    500                    0               0                     176.0                    107           43379                2555               2555
  main  3.5-14 ms  DataSet5          500    770                    0             270                      79.0                     47           32732                1160               1160
  main  3.5-14 ms  DataSet6          500    500                    0               0                     177.0                     77           36977               21831               3000
  main  3.5-14 ms  DataSet7          500    500                    0               0                     200.0                     83           29439                5981               3000
  main  3.5-14 ms  DataSet8          500    500                    0               0                     298.0                    123           31967               51185               3000
  main  3.5-14 ms  DataSet9          500    504                    0               4                     140.5                     62           39010               11265               3000
  main  3.5-14 ms DataSet10          500    595                    0              95                      90.0                     57           29180                2673               2673
  main  3.5-14 ms DataSet11          500    500                    0               0                     393.5                    206           46345              207957               3000
  main  3.5-14 ms DataSet12          500    500                    0               0                     227.5                     89           35700              163369               3000
  main  3.5-14 ms DataSet13          500    526                    0              26                     115.0                     53           29064               29974               3000
  main  3.5-14 ms DataSet14          500    500                    0               0                     476.0                    251           31612              587116               3000
  main  3.5-14 ms DataSet15          500    500                    0               0                     415.5                    178           33507              142895               3000
  main  3.5-14 ms DataSet16          500    514                    0              14                     132.0                     53           30752               70434               3000
  main  3.5-14 ms DataSet17          500    544                    0              44                      97.0                     55           41550               15773               3000
  main  3.5-14 ms DataSet18          500    500                    0               0                     697.0                    322           39909              268694               3000
  main  3.5-14 ms DataSet19          500    500                    0               0                     294.0                    125           49146               95536               3000
  main  3.5-14 ms DataSet20          500    604                    0             104                      92.0                     48           28634               12525               3000
  main  3.5-14 ms DataSet21          500    609                    0             109                      91.0                     49           25746               17482               3000
  main  3.5-14 ms DataSet22          500    500                    0               0                     265.0                    115           32396              404169               3000
  main  3.5-14 ms DataSet23          500    500                    0               0                     413.0                    221           42025              543559               3000
  main  3.5-14 ms DataSet24          500    501                    0               1                     180.0                     60           34313               87355               3000
  main  3.5-14 ms DataSet25          500    500                    0               0                     274.0                    144           40350               80051               3000

                         recordings_complete  subnetworks  draws  draws_under_75  draws_unconnectable  edges_before_trim_median  edges_before_trim_min
config       scale                                                                                                                                    
calibrated   1.6-6.4 ms                   20          100  27393           19471                 5738                     129.5                     40
             3.5-14 ms                    25          100   2809             309                    0                     185.5                     46
main         1.6-6.4 ms                   21          500  33460           22426                    0                     133.0                     36
             3.5-14 ms                    25          500  14568            2068                    0                     180.0                     40
past t-1,t-2 1.6-6.4 ms                   24          100   8734            6331                    0                     147.0                     37
             3.5-14 ms                    25          100   2631             131                    0                     205.0                     43
strict       1.6-6.4 ms                   25          100   2514              14                    0                     221.0                     59
             3.5-14 ms                    25          100   2505               5                    0                     267.5                     67
sub random   1.6-6.4 ms                   23          100  17577           15273                    0                     129.0                     38
             3.5-14 ms                    25          100   2863             363                    0                     184.0                     42

Networks. With bins t-2 and t-3, ties counted as exceeding give 55190 significant connections at 1.6 to 6.4 ms and 130029 at 3.5 to 14 ms, 19.9 and 46.9 times the 2774 expected by chance at p < 0.001; the strict rule gives 261640 and 263599 (94 and 95 times). Of the strict rule's connections, 247754 and 239189 had no surrogate above the real TE in all 5000, and 167255 and 109017 had no sender spike whose jitter could change the counts, so every surrogate tied. On shifted trains, where every pair is independent, the strict rule calls 10.8% of pairs significant (2.6% to 16.1% by recording and time scale) and the tie-counting rule 0.32% (0.04% to 1.3%), against the nominal 0.1%. The strict rule's false-positive rate is about 100 times the stated p < 0.001, so it is not the paper's test; the tie-counting rule's pooled rate is about three times the nominal one, and it is used below. Multiplied by the number of pairs, these rates give the connections expected by chance in the five tested recordings: 8% to 30% of the significant connections under the tie-counting rule (pooled 15.8%; DataSet16 at 3.5 to 14 ms, 1885 of 6364), and more than the significant connections themselves in most of them under the strict rule. No stricter count of the 5000 surrogates brings the pooled rate down to 0.1%: with no surrogate at or above the real TE (k = 1, the strictest) it is 0.20% (0.01% to 0.90% by recording and time scale), and 13.2% of the significant connections in the tested recordings are expected by chance. This threshold gives 41534 and 105835 connections and is run as the variant calibrated, to show which way the excess false positives move each result. Its networks have an effective N of 245 and 277 and an effective k of 8.8 and 19.5 (mean over recordings), against [44]'s 241 +- 103 and 22 +- 30 for cortical networks; the strict rule's have 308 and 29 to 32. Degree rises with firing rate under the tie-counting rule (median Spearman 0.75 and 0.81 for total degree), as [44] reports for its networks; under the strict rule it does not (median -0.31 and 0.22, ranging from -0.87 to 0.93). This is what the test's power rising with firing rate would also give, so under the tie-counting rule a high-degree neuron is mostly a high-rate neuron, which qualifies what "high-degree" means in fig4bd and fig5b. The normal approximation agrees less well with the full jitter under the tie-counting rule than under the strict one: the two share 83% to 89% of the connections either finds (95.7% to 99.2% under the strict rule), and the approximation finds 0.1% to 8.2% more.

Sub-networks. Draws with fewer than 75 connections among the 50 neurons are redrawn, as the claims file says. At 3.5 to 14 ms every recording gives its 500 sub-networks. At 1.6 to 6.4 ms 21 of 25 do; within 5000 draws DataSet2 gives 6, DataSet5 none, DataSet10 380 and DataSet17 148, and these partial sets are used as they are (DataSet5 drops out of reading (s) at that scale).

fig4ac-te-lognormal¶

The significant TE connection weights, raw and normalized, are roughly log-normally distributed at both time scales and vary over several orders of magnitude.

Reading (f) uses every significant connection; reading (s) the connections kept in the 500 sub-networks, each counted once per recording. The full table is for the main analysis (ties counted as exceeding, bins t-2 and t-3, the 75 strongest connections per sub-network); the verdict under each variant follows it.

In [9]:
def lognorm_pmf(x, a, mu, s):
    # paper, Eq 21: alpha / (sigma sqrt(2 pi)) exp(-(log10 x - mu)^2 / (2 sigma^2))
    return a / (s * np.sqrt(2 * np.pi)) * np.exp(-(np.log10(x) - mu) ** 2 / (2 * s ** 2))

def fit_r2(x, y):
    lx = np.log10(x)
    m = (y * lx).sum() / y.sum()
    sd = np.sqrt((y * (lx - m) ** 2).sum() / y.sum())
    try:
        # start from the moments of the binned distribution; alpha starts at the log bin width
        p, _ = curve_fit(lognorm_pmf, x, y, p0=[lx[1] - lx[0], m, sd], maxfev=20000)
        pred = lognorm_pmf(x, *p)
        return 1 - ((y - pred) ** 2).sum() / ((y - y.mean()) ** 2).sum(), p
    except RuntimeError:
        return np.nan, None

def sub_edges(c, scale, name):
    e = set()
    for g, s_e, r_e in RES[c][scale, name]["subs"]:
        e.update(zip(s_e.tolist(), r_e.tolist()))
    return np.array(sorted(e), dtype=np.int64).reshape(-1, 2)

def fig4ac_table(c):
    past, rule = CONFIGS[c][:2]
    rows, curves = [], {}
    for scale in hdn.TIME_SCALES:
        for reading in ["f", "s"]:
            for measure in ["te", "nte"]:
                vals = []
                for r in recs:
                    net = NETS[past, scale, r["name"]]
                    if reading == "f":
                        v = net[measure][net["sig"][rule]]
                    else:
                        e = sub_edges(c, scale, r["name"])
                        v = net[measure][e[:, 0], e[:, 1]]
                    if (v > 0).sum() > 0:
                        vals.append(v[v > 0])
                pooled = np.concatenate(vals)
                edges = np.logspace(np.log10(pooled.min()), np.log10(pooled.max()), 101)
                centers = np.sqrt(edges[:-1] * edges[1:])
                pmfs = np.array([np.histogram(v, edges)[0] / len(v) for v in vals])
                r2_avg, p = fit_r2(centers, pmfs.mean(0))
                r2_each = np.array([fit_r2(centers, y)[0] for y in pmfs])
                p1, p99 = np.percentile(pooled, [1, 99])
                spread_each = np.array([np.percentile(v, 99) / np.percentile(v, 1) for v in vals])
                curves[scale, reading, measure] = (centers, pmfs, p)
                rows.append({"scale": scale, "reading": reading, "measure": measure, "recordings": len(vals), "n_values": len(pooled),
                             "R2_average": r2_avg, "R2_rec_median": np.nanmedian(r2_each), "R2_rec_min": np.nanmin(r2_each),
                             "p1": p1, "p99": p99, "p99/p1": p99 / p1, "p99/p1_rec_min": spread_each.min(),
                             "min": pooled.min(), "max": pooled.max(), "mu_log10": p[1] if p is not None else np.nan,
                             "sigma_log10": p[2] if p is not None else np.nan})
    return pd.DataFrame(rows), curves

def fig4ac_verdict(t, reading):
    sub = t[t.reading == reading]
    return "reproduced" if bool(((sub.R2_average >= 0.9) & (sub["p99/p1"] >= 100)).all()) else "not met"

fig4, curves = fig4ac_table("main")
print(fig4.to_string(index=False, float_format=lambda v: f"{v:.3g}"))
print("\nCriterion (each reading): R2 >= 0.9 and p99/p1 >= 100 for both scales and both measures")
rows = []
for v, (c, form) in VARIANTS.items():
    if form != "claims":
        continue
    t = fig4 if c == "main" else fig4ac_table(c)[0]
    for reading in ["f", "s"]:
        sub = t[t.reading == reading]
        rows.append({"variant": v, "reading": reading, "R2_average": f"{sub.R2_average.min():.2f} to {sub.R2_average.max():.2f}",
                     "R2_rec_median": f"{sub.R2_rec_median.min():.2f} to {sub.R2_rec_median.max():.2f}",
                     "p99/p1": f"{sub['p99/p1'].min():.3g} to {sub['p99/p1'].max():.3g}", "criterion": fig4ac_verdict(t, reading)})
print(pd.DataFrame(rows).to_string(index=False))
     scale reading measure  recordings  n_values  R2_average  R2_rec_median  R2_rec_min       p1     p99   p99/p1  p99/p1_rec_min      min    max  mu_log10  sigma_log10
1.6-6.4 ms       f      te          25     55190       0.935          0.913       0.371 5.43e-06 0.00631 1.16e+03             200 1.45e-06 0.0209     -3.45        0.751
1.6-6.4 ms       f     nte          25     55190       0.882          0.875       0.331 0.000121  0.0739      610            94.7  7.5e-06   0.21      -1.9        0.625
1.6-6.4 ms       s      te          24     39337       0.939           0.95       0.371 6.33e-06 0.00685 1.08e+03            25.3 1.45e-06 0.0209     -3.28          0.7
1.6-6.4 ms       s     nte          24     39337       0.895          0.914       0.331 0.000183  0.0791      432            3.97  7.5e-06   0.21     -1.69        0.431
 3.5-14 ms       f      te          25    130029       0.957          0.954       0.687 1.41e-05  0.0155  1.1e+03             211 1.98e-06 0.0479     -3.08        0.684
 3.5-14 ms       f     nte          25    130029       0.904          0.916       0.654 0.000172    0.12      695             118 7.57e-06  0.315     -1.73        0.649
 3.5-14 ms       s      te          25     66264        0.96          0.958       0.693 1.75e-05  0.0187 1.07e+03            23.3 1.98e-06 0.0479     -2.86        0.646
 3.5-14 ms       s     nte          25     66264       0.899           0.95       0.655 0.000385   0.136      353            2.73 8.69e-06  0.315     -1.38        0.341

Criterion (each reading): R2 >= 0.9 and p99/p1 >= 100 for both scales and both measures
       variant reading   R2_average R2_rec_median               p99/p1  criterion
          main       f 0.88 to 0.96  0.87 to 0.95      610 to 1.16e+03    not met
          main       s 0.89 to 0.96  0.91 to 0.96      353 to 1.08e+03    not met
   strict ties       f 0.08 to 0.40  0.87 to 0.96 5.28e+03 to 2.93e+05    not met
   strict ties       s 0.13 to 0.71  0.86 to 0.95    1.36e+03 to 1e+05    not met
  past t-1,t-2       f 0.90 to 0.98  0.88 to 0.97      623 to 1.31e+03 reproduced
  past t-1,t-2       s 0.92 to 0.98  0.94 to 0.97      196 to 1.16e+03 reproduced
sub (b) random       f 0.88 to 0.96  0.87 to 0.95      610 to 1.16e+03    not met
sub (b) random       s 0.89 to 0.95  0.87 to 0.95      660 to 1.21e+03    not met
    calibrated       f 0.88 to 0.96  0.85 to 0.95           476 to 806    not met
    calibrated       s 0.92 to 0.97  0.92 to 0.96           195 to 602 reproduced
In [10]:
fig, axes = plt.subplots(2, 4, figsize=(16, 6))
for ax, key in zip(axes.flat, curves):
    centers, pmfs, p = curves[key]
    ax.semilogx(centers, pmfs.mean(0), "k.", ms=3)
    if p is not None:
        ax.semilogx(centers, lognorm_pmf(centers, *p), "r-")
    ax.set_title(" ".join(key), fontsize=9)
plt.tight_layout(); plt.show()
print("Main analysis. Every bin of the 100 log-spaced bins is shown; values span the full range of each panel's x axis.")
No description has been provided for this image
Main analysis. Every bin of the 100 log-spaced bins is shown; values span the full range of each panel's x axis.

Result: partially reproduced, resting on the assumptions of the tie rule and bins t-2 and t-3. The significant TE values span several orders of magnitude: the 99th percentile is 353 to 1160 times the 1st, at both time scales, for raw and normalized TE and under both readings. The log-normal of Eq 21 fits the distribution averaged over recordings with R2 of 0.935 and 0.957 for raw TE (reading f) and 0.882 and 0.904 for normalized TE; under (s) 0.939 and 0.960, and 0.895 and 0.899. Three of the eight fits fall just below the criterion's 0.9, all for normalized TE. With bins t-1 and t-2 every fit reaches 0.90 to 0.98 and the criterion holds under both readings; with the strict tie rule the averaged fits have R2 of 0.08 to 0.71. At the stricter threshold (calibrated) the fits under (s) reach 0.92 to 0.97 and the criterion holds; under (f) one normalized-TE fit stays at 0.88.

fig4bd-heavy-tailed-degree¶

The total degree distributions are heavy-tailed, with many more high-degree neurons than in random networks with the same numbers of neurons and connections.

Random networks place the same number of directed connections uniformly among the same neurons: under (f) 100 random networks per recording, under (s) one per sub-network (50 neurons, 75 connections). The threshold is the 99.9th percentile of the random total degrees of the recording (f) or of all its random sub-networks (s).

In [11]:
def random_degrees(n, e, rng):
    flat = rng.choice(n * (n - 1), e, replace=False)
    s = flat // (n - 1); r = flat % (n - 1); r = r + (r >= s)
    return np.bincount(s, minlength=n), np.bincount(r, minlength=n)

def fig4bd_table(c, rng):
    past, rule = CONFIGS[c][:2]
    deg, rows = {}, []
    for scale in hdn.TIME_SCALES:
        for reading in ["f", "s"]:
            above, n_real, max_real, max_rand, per_rec = 0, 0, 0, 0, []
            for r in recs:
                if reading == "f":
                    sig = NETS[past, scale, r["name"]]["sig"][rule]; n = sig.shape[0]; e = int(sig.sum())
                    ins, outs = [sig.sum(0)], [sig.sum(1)]
                    rt = np.concatenate([np.add(*random_degrees(n, e, rng)) for _ in range(100)])
                else:
                    ins, outs, rt = [], [], []
                    for g, s_e, r_e in RES[c][scale, r["name"]]["subs"]:
                        loc = {v: k for k, v in enumerate(g.tolist())}
                        s_l = np.array([loc[v] for v in s_e.tolist()]); r_l = np.array([loc[v] for v in r_e.tolist()])
                        ins.append(np.bincount(r_l, minlength=len(g))); outs.append(np.bincount(s_l, minlength=len(g)))
                        rt.append(np.add(*random_degrees(len(g), len(s_e), rng)))
                    if not rt:
                        continue
                    rt = np.concatenate(rt)
                ins, outs = np.concatenate(ins), np.concatenate(outs)
                tot = ins + outs
                thr = np.percentile(rt, 99.9)
                above += int((tot > thr).sum()); n_real += len(tot)
                max_real = max(max_real, tot.max()); max_rand = max(max_rand, rt.max())
                per_rec.append({"rec": r["name"], "in": ins, "out": outs, "tot": tot, "rand": rt, "thr": thr})
            deg[scale, reading] = per_rec
            rows.append({"scale": scale, "reading": reading, "recordings": len(per_rec), "neurons_or_slots": n_real,
                         "fraction_above_random_99.9": above / n_real, "ratio_to_0.001": above / n_real / 0.001,
                         "max_real_total": int(max_real), "max_random_total": int(max_rand),
                         "median_threshold": np.median([p["thr"] for p in per_rec])})
    return pd.DataFrame(rows), deg

def fig4bd_verdict(t, reading):
    sub = t[t.reading == reading]
    ok = ((sub["fraction_above_random_99.9"] >= 0.01) & (sub.max_real_total > sub.max_random_total)).all()
    return "reproduced" if bool(ok) else "not met"

rng = np.random.default_rng(41)
DEG = {}
fig4bd, DEG["main"] = fig4bd_table("main", rng)
print(fig4bd.round(4).to_string(index=False))
print("\nCriterion: fraction >= 0.01 and max real > max random, at both scales")
rows = []
for v, (c, form) in VARIANTS.items():
    if form != "claims":
        continue
    if c == "main":
        t = fig4bd
    else:
        t, DEG[c] = fig4bd_table(c, rng)
    for reading in ["f", "s"]:
        sub = t[t.reading == reading]
        rows.append({"variant": v, "reading": reading, "fraction_above": " / ".join(f"{x:.4f}" for x in sub["fraction_above_random_99.9"]),
                     "max_real": " / ".join(str(x) for x in sub.max_real_total), "max_random": " / ".join(str(x) for x in sub.max_random_total),
                     "criterion": fig4bd_verdict(t, reading)})
print(pd.DataFrame(rows).to_string(index=False))
     scale reading  recordings  neurons_or_slots  fraction_above_random_99.9  ratio_to_0.001  max_real_total  max_random_total  median_threshold
1.6-6.4 ms       f          25              7735                      0.1019        101.8746             373                84              19.0
1.6-6.4 ms       s          24            551700                      0.0706         70.6108              53                14               9.0
 3.5-14 ms       f          25              7735                      0.1432        143.2450             517               147              37.0
 3.5-14 ms       s          25            625000                      0.0660         65.9744              52                13               9.0

Criterion: fraction >= 0.01 and max real > max random, at both scales
       variant reading  fraction_above  max_real max_random  criterion
          main       f 0.1019 / 0.1432 373 / 517   84 / 147 reproduced
          main       s 0.0706 / 0.0660   53 / 52    14 / 13 reproduced
   strict ties       f 0.2098 / 0.2111 886 / 929  226 / 163 reproduced
   strict ties       s 0.0578 / 0.0640   47 / 47    13 / 12 reproduced
  past t-1,t-2       f 0.1196 / 0.1801 360 / 511   88 / 167 reproduced
  past t-1,t-2       s 0.0721 / 0.0717   53 / 51    12 / 13 reproduced
sub (b) random       f 0.1021 / 0.1431 373 / 517   87 / 149 reproduced
sub (b) random       s 0.0580 / 0.0563   49 / 52    12 / 12 reproduced
    calibrated       f 0.0923 / 0.1297 353 / 503   69 / 136 reproduced
    calibrated       s 0.0666 / 0.0648   52 / 52    12 / 12 reproduced
In [12]:
fig, axes = plt.subplots(1, 4, figsize=(16, 3.5))
for ax, key in zip(axes, DEG["main"]):
    tot = np.concatenate([p["tot"] for p in DEG["main"][key]]); rt = np.concatenate([p["rand"] for p in DEG["main"][key]])
    bins = np.arange(0, max(tot.max(), rt.max()) + 2)
    ax.loglog(bins[:-1], np.histogram(tot, bins, density=True)[0], "k.", label="real total")
    ax.loglog(bins[:-1], np.histogram(rt, bins, density=True)[0], "r.", label="random total")
    ax.set_title(" ".join(key)); ax.legend(fontsize=7)
plt.tight_layout(); plt.show()
print("Main analysis. Zero-degree neurons and empty bins are not shown on the log axes.")
No description has been provided for this image
Main analysis. Zero-degree neurons and empty bins are not shown on the log axes.

Result: reproduced. In the full networks 10.2% (1.6 to 6.4 ms) and 14.3% (3.5 to 14 ms) of neurons have a total degree above the 99.9th percentile of matched random networks, 102 and 143 times the 0.001 expected; in the sub-networks 7.1% and 6.6%. The largest real total degree is 373 and 517 (full) and 53 and 52 (sub-networks), against 84, 147, 14 and 13 in the random networks. The criterion holds under every variant shown (strict rule, bins t-1 and t-2, random sub-network connections, the stricter threshold).

fig4bd-out-tail-longer¶

The in-degree distribution has a shorter tail than the out-degree distribution, so there are more high out-degree neurons than high in-degree neurons.

In [13]:
def tail_table(deg):
    rows = []
    for (scale, reading), per_rec in deg.items():
        ins = np.concatenate([p["in"] for p in per_rec]); outs = np.concatenate([p["out"] for p in per_rec])
        q_in = np.array([np.percentile(p["in"], 99) for p in per_rec]); q_out = np.array([np.percentile(p["out"], 99) for p in per_rec])
        w = stats.wilcoxon(q_out, q_in, alternative="greater") if np.any(q_out != q_in) else None
        rows.append({"scale": scale, "reading": reading, "p99_out": np.percentile(outs, 99), "p99_in": np.percentile(ins, 99),
                     "max_out": outs.max(), "max_in": ins.max(), "recordings_out_gt_in": int((q_out > q_in).sum()),
                     "recordings_out_lt_in": int((q_out < q_in).sum()), "wilcoxon_p_one_sided": w.pvalue if w else np.nan})
    return pd.DataFrame(rows)

def tail_verdict(t, reading):
    sub = t[t.reading == reading]
    return "reproduced" if bool(((sub.p99_out > sub.p99_in) & (sub.max_out > sub.max_in)).all()) else "not met"

tail = tail_table(DEG["main"])
print(tail.round(4).to_string(index=False))
print("\nCriterion: pooled p99 and max of out-degree above those of in-degree, at both scales")
rows = []
for v, (c, form) in VARIANTS.items():
    if form != "claims":
        continue
    t = tail_table(DEG[c])
    for reading in ["f", "s"]:
        sub = t[t.reading == reading]
        rows.append({"variant": v, "reading": reading, "p99_out/in": " / ".join(f"{a:.3g}-{b:.3g}" for a, b in zip(sub.p99_out, sub.p99_in)),
                     "max_out/in": " / ".join(f"{a}-{b}" for a, b in zip(sub.max_out, sub.max_in)),
                     "wilcoxon_p": " / ".join(f"{x:.2g}" for x in sub.wilcoxon_p_one_sided), "criterion": tail_verdict(t, reading)})
print(pd.DataFrame(rows).to_string(index=False))
     scale reading  p99_out  p99_in  max_out  max_in  recordings_out_gt_in  recordings_out_lt_in  wilcoxon_p_one_sided
1.6-6.4 ms       f    123.0    48.0      322      86                    25                     0                   0.0
1.6-6.4 ms       s     23.0     6.0       47      14                    23                     1                   0.0
 3.5-14 ms       f    209.0    98.0      395     180                    25                     0                   0.0
 3.5-14 ms       s     26.0     6.0       49      14                    25                     0                   0.0

Criterion: pooled p99 and max of out-degree above those of in-degree, at both scales
       variant reading        p99_out/in        max_out/in        wilcoxon_p  criterion
          main       f   123-48 / 209-98  322-86 / 395-180   6.1e-06 / 3e-08 reproduced
          main       s       23-6 / 26-6     47-14 / 49-14     1e-05 / 6e-06 reproduced
   strict ties       f 242-234 / 229-179 446-440 / 449-480  0.0015 / 1.5e-07    not met
   strict ties       s       19-8 / 23-7     44-35 / 45-31 9.6e-05 / 6.1e-06 reproduced
  past t-1,t-2       f  126-57 / 226-120 319-101 / 412-175     3e-07 / 6e-08 reproduced
  past t-1,t-2       s       21-6 / 24-6     47-15 / 47-16 9.8e-06 / 6.1e-06 reproduced
sub (b) random       f   123-48 / 209-98  322-86 / 395-180   6.1e-06 / 3e-08 reproduced
sub (b) random       s       16-6 / 17-6     44-10 / 44-13   1.3e-05 / 6e-06 reproduced
    calibrated       f 107-40 / 190-87.7  306-79 / 371-170   9.1e-06 / 3e-08 reproduced
    calibrated       s       24-6 / 27-6     48-11 / 48-18 1.5e-05 / 6.1e-06 reproduced

Result: reproduced, resting on the tie rule. Pooled over recordings, the 99th percentile of out-degree exceeds that of in-degree at both time scales in the full networks (123 against 48, 209 against 98) and in the sub-networks (23 against 6, 26 against 6), and so does the largest out-degree (322 against 86 and 395 against 180; 47 against 14 and 49 against 14). The per-recording 99th percentile of out-degree is higher in 25 and 25 of 25 recordings (full; one-sided Wilcoxon p = 6.1e-06 and 3e-08) and in 23 and 25 (sub-networks). Both readings now meet the criterion. Under the strict rule the full networks fail it at 3.5 to 14 ms (largest in-degree 480 against out-degree 449); every other variant meets it.

fig5a-in-degree-uncorrelated, fig5b-out-degree-positive¶

fig5a: The correlation between a receiver's in-degree and the synergy (computation) it performs is centered near zero across recordings, with a slight negative skew; computation is independent of in-degree.

fig5b: Most recordings show a positive correlation between a transmitter's out-degree and the synergy computed by its receivers.

Synergy is normalized by H(I_F). Its redundancy term is the claims file's M-PID form (minimum over sources within each state of I_F and I_P); Eq 8 of the version of record (minimum per state of I_F, hdn.pid_from_table) is the variant "PID Eq 8". Under (s) each triple of each sub-network is a data point, with degrees counted inside the sub-network, the 500 sub-networks pooled per recording; under (f) the triples of the full network (sampled, see the table above) with full-network degrees. Each transmitter of a triple is a separate data point for the out-degree. Correlations: (p) Pearson, (r) Spearman.

In [14]:
def triple_data(c, form, scale, name, reading):
    a = RES[c][scale, name]
    sd = a["syn"] if form == "claims" else a["syn8"]
    if reading == "s":
        t = a["sub_triples"]
        syn = np.array([sd[(x[1], x[2], x[3])] for x in t])
        return t[:, 4], syn, np.r_[t[:, 5], t[:, 6]], np.r_[syn, syn]
    t = a["full_triples"]
    syn = np.array([sd[tuple(x)] for x in t.tolist()])
    return a["indeg_f"][t[:, 0]], syn, np.r_[a["outdeg_f"][t[:, 1]], a["outdeg_f"][t[:, 2]]], np.r_[syn, syn]

def corr_table(c, form):
    rows = []
    for scale in hdn.TIME_SCALES:
        for r in recs:
            for reading in ["s", "f"]:
                indeg, syn_in, outdeg, syn_out = triple_data(c, form, scale, r["name"], reading)
                for kind, f in [("p", stats.pearsonr), ("r", stats.spearmanr)]:
                    for panel, x, y in [("in", indeg, syn_in), ("out", outdeg, syn_out)]:
                        ok = len(x) > 2 and np.ptp(x) > 0 and np.ptp(y) > 0
                        cc = f(x, y) if ok else None
                        rows.append({"scale": scale, "recording": r["name"], "reading": reading, "coef": kind, "panel": panel,
                                     "n": len(x), "r": cc[0] if ok else np.nan, "p": cc[1] if ok else np.nan})
    return pd.DataFrame(rows)

def skew_test(r):
    r = r.dropna(); pos, neg = int((r > 0).sum()), int((r < 0).sum()); n = pos + neg
    return {"n": n, "positive": pos, "negative": neg, "median_r": r.median(),
            "P(neg skew this large or larger)": stats.binom.cdf(pos, n, 0.5),
            "P(pos skew this large or larger)": stats.binom.sf(pos - 1, n, 0.5)}

def skew_table(corr):
    rows = []
    for panel in ["in", "out"]:
        for reading in ["s", "f"]:
            for kind in ["p", "r"]:
                for scale in ["both"] + list(hdn.TIME_SCALES):
                    sub = corr[(corr.panel == panel) & (corr.reading == reading) & (corr.coef == kind)]
                    if scale != "both":
                        sub = sub[sub.scale == scale]
                    rows.append({"panel": panel, "reading": reading, "coef": kind, "scale": scale, **skew_test(sub.r)})
    return pd.DataFrame(rows)

def fig5a_verdict(row):
    if row["P(pos skew this large or larger)"] < 0.05:
        return "not reproduced"
    return "partially reproduced" if row["P(neg skew this large or larger)"] < 0.05 else "reproduced"

def fig5b_verdict(row):
    if row.positive > row.n / 2:
        return "reproduced" if row["P(pos skew this large or larger)"] < 0.05 else "partially reproduced"
    return "not reproduced"

CORR, SKEW = {}, {}
for v, (c, form) in VARIANTS.items():
    CORR[v] = corr_table(c, form)
    SKEW[v] = skew_table(CORR[v])
print("Correlations that could not be computed (fewer than 3 points, or one degree or one synergy value), main:",
      int(CORR["main"].r.isna().sum()), "of", len(CORR["main"]))
print(SKEW["main"].to_string(index=False, float_format=lambda v: f"{v:.3g}"))
rows = []
for v, sk in SKEW.items():
    for reading in ["s", "f"]:
        for kind in ["p", "r"]:
            a = sk[(sk.panel == "in") & (sk.reading == reading) & (sk.coef == kind) & (sk.scale == "both")].iloc[0]
            b = sk[(sk.panel == "out") & (sk.reading == reading) & (sk.coef == kind) & (sk.scale == "both")].iloc[0]
            rows.append({"variant": v, "reading": reading, "coef": kind,
                         "in: pos/neg": f"{a.positive}/{a.negative}", "in: median r": round(a.median_r, 3),
                         "in: P neg": f"{a['P(neg skew this large or larger)']:.2g}", "in: P pos": f"{a['P(pos skew this large or larger)']:.2g}",
                         "fig5a": fig5a_verdict(a),
                         "out: pos/neg": f"{b.positive}/{b.negative}", "out: median r": round(b.median_r, 3),
                         "out: P pos": f"{b['P(pos skew this large or larger)']:.2g}", "fig5b": fig5b_verdict(b)})
fig5_var = pd.DataFrame(rows)
print()
print(fig5_var.to_string(index=False))
Correlations that could not be computed (fewer than 3 points, or one degree or one synergy value), main: 4 of 400
panel reading coef      scale  n  positive  negative  median_r  P(neg skew this large or larger)  P(pos skew this large or larger)
   in       s    p       both 49        18        31   -0.0366                            0.0427                             0.978
   in       s    p 1.6-6.4 ms 24         6        18    -0.073                            0.0113                             0.997
   in       s    p  3.5-14 ms 25        12        13  -0.00498                               0.5                             0.655
   in       s    r       both 49        24        25   -0.0139                               0.5                             0.612
   in       s    r 1.6-6.4 ms 24         8        16   -0.0399                            0.0758                             0.968
   in       s    r  3.5-14 ms 25        16         9    0.0143                             0.946                             0.115
   in       f    p       both 50        10        40    -0.137                          1.19e-05                                 1
   in       f    p 1.6-6.4 ms 25         7        18      -0.1                            0.0216                             0.993
   in       f    p  3.5-14 ms 25         3        22    -0.196                          7.83e-05                                 1
   in       f    r       both 50        11        39     -0.12                          4.51e-05                                 1
   in       f    r 1.6-6.4 ms 25         8        17   -0.0941                            0.0539                             0.978
   in       f    r  3.5-14 ms 25         3        22    -0.171                          7.83e-05                                 1
  out       s    p       both 49        42         7     0.118                                 1                          1.81e-07
  out       s    p 1.6-6.4 ms 24        22         2      0.22                                 1                          1.79e-05
  out       s    p  3.5-14 ms 25        20         5    0.0661                                 1                           0.00204
  out       s    r       both 49        44         5     0.127                                 1                           3.8e-09
  out       s    r 1.6-6.4 ms 24        24         0     0.258                                 1                          5.96e-08
  out       s    r  3.5-14 ms 25        20         5    0.0749                                 1                           0.00204
  out       f    p       both 50        47         3     0.192                                 1                          1.85e-11
  out       f    p 1.6-6.4 ms 25        24         1     0.189                                 1                          7.75e-07
  out       f    p  3.5-14 ms 25        23         2     0.194                                 1                          9.72e-06
  out       f    r       both 50        50         0     0.229                                 1                          8.88e-16
  out       f    r 1.6-6.4 ms 25        25         0      0.23                                 1                          2.98e-08
  out       f    r  3.5-14 ms 25        25         0     0.227                                 1                          2.98e-08

       variant reading coef in: pos/neg  in: median r in: P neg in: P pos                fig5a out: pos/neg  out: median r out: P pos                fig5b
          main       s    p       18/31        -0.037     0.043      0.98 partially reproduced         42/7          0.118    1.8e-07           reproduced
          main       s    r       24/25        -0.014       0.5      0.61           reproduced         44/5          0.127    3.8e-09           reproduced
          main       f    p       10/40        -0.137   1.2e-05         1 partially reproduced         47/3          0.192    1.9e-11           reproduced
          main       f    r       11/39        -0.120   4.5e-05         1 partially reproduced         50/0          0.229    8.9e-16           reproduced
   strict ties       s    p       10/40        -0.155   1.2e-05         1 partially reproduced         42/8          0.215    5.8e-07           reproduced
   strict ties       s    r       10/40        -0.120   1.2e-05         1 partially reproduced        38/12          0.169    0.00015           reproduced
   strict ties       f    p        8/42        -0.145   5.8e-07         1 partially reproduced        35/15          0.214     0.0033           reproduced
   strict ties       f    r       21/29        -0.063      0.16       0.9           reproduced        26/24          0.081       0.44 partially reproduced
  past t-1,t-2       s    p       23/27        -0.008      0.34      0.76           reproduced        40/10          0.102    1.2e-05           reproduced
  past t-1,t-2       s    r       27/23         0.003      0.76      0.34           reproduced         43/7          0.136      1e-07           reproduced
  past t-1,t-2       f    p        8/42        -0.099   5.8e-07         1 partially reproduced         47/3          0.216    1.9e-11           reproduced
  past t-1,t-2       f    r       12/38        -0.084   0.00015         1 partially reproduced         50/0          0.232    8.9e-16           reproduced
sub (b) random       s    p        8/41        -0.107   9.8e-07         1 partially reproduced         48/1          0.161    8.9e-14           reproduced
sub (b) random       s    r        8/41        -0.093   9.8e-07         1 partially reproduced         49/0          0.189    1.8e-15           reproduced
sub (b) random       f    p        9/41        -0.146   2.8e-06         1 partially reproduced         47/3          0.194    1.9e-11           reproduced
sub (b) random       f    r       11/39        -0.129   4.5e-05         1 partially reproduced         50/0          0.226    8.9e-16           reproduced
      PID Eq 8       s    p       18/31        -0.038     0.043      0.98 partially reproduced         42/7          0.118    1.8e-07           reproduced
      PID Eq 8       s    r       24/25        -0.013       0.5      0.61           reproduced         44/5          0.128    3.8e-09           reproduced
      PID Eq 8       f    p       10/40        -0.137   1.2e-05         1 partially reproduced         47/3          0.193    1.9e-11           reproduced
      PID Eq 8       f    r       11/39        -0.121   4.5e-05         1 partially reproduced         50/0          0.228    8.9e-16           reproduced
    calibrated       s    p       19/29        -0.026     0.097      0.94           reproduced         42/6          0.105      5e-08           reproduced
    calibrated       s    r       24/24        -0.002      0.56      0.56           reproduced         41/7          0.138    3.1e-07           reproduced
    calibrated       f    p        9/41        -0.149   2.8e-06         1 partially reproduced         46/4          0.192    2.2e-10           reproduced
    calibrated       f    r       10/40        -0.135   1.2e-05         1 partially reproduced         50/0          0.211    8.9e-16           reproduced
In [15]:
corr = CORR["main"]
print("Per-recording correlations, main, reading (s), Pearson, by time scale:")
piv = corr[(corr.reading == "s") & (corr.coef == "p")].pivot_table(index="recording", columns=["panel", "scale"], values="r")
print(piv.round(3).to_string())
fig, axes = plt.subplots(1, 2, figsize=(10, 3.5))
for ax, panel in zip(axes, ["in", "out"]):
    v = corr[(corr.reading == "s") & (corr.coef == "p") & (corr.panel == panel)].r.dropna()
    ax.hist(v, bins=np.linspace(-1, 1, 41)); ax.axvline(0, color="k")
    ax.set_title(f"{panel}-degree vs synergy, (s), Pearson; range {v.min():.2f} to {v.max():.2f}")
plt.tight_layout(); plt.show()
Per-recording correlations, main, reading (s), Pearson, by time scale:
panel             in                  out          
scale     1.6-6.4 ms 3.5-14 ms 1.6-6.4 ms 3.5-14 ms
recording                                          
DataSet1       0.216     0.094     -0.030     0.060
DataSet10      0.124    -0.042      0.218     0.258
DataSet11     -0.083    -0.040      0.302     0.149
DataSet12     -0.086     0.066      0.192     0.039
DataSet13     -0.171    -0.115      0.311     0.144
DataSet14     -0.150     0.006      0.246     0.044
DataSet15     -0.034     0.098      0.112    -0.086
DataSet16     -0.130    -0.014      0.117     0.070
DataSet17      0.116    -0.064      0.163     0.181
DataSet18      0.057     0.284      0.090    -0.220
DataSet19      0.121     0.100      0.060     0.035
DataSet2      -0.113    -0.049      0.099    -0.037
DataSet20     -0.062    -0.114     -0.022     0.038
DataSet21     -0.107    -0.176      0.295     0.227
DataSet22     -0.107    -0.164      0.238     0.189
DataSet23      0.168     0.149      0.075     0.066
DataSet24     -0.019    -0.020      0.049     0.054
DataSet25     -0.072     0.047      0.236     0.111
DataSet3      -0.074     0.174      0.222     0.035
DataSet4      -0.037    -0.247      0.256     0.237
DataSet5         NaN     0.093        NaN    -0.092
DataSet6      -0.142    -0.005      0.293     0.118
DataSet7      -0.090     0.058      0.238    -0.015
DataSet8      -0.208    -0.026      0.330     0.120
DataSet9      -0.065     0.065      0.224     0.165
No description has been provided for this image

Result: partially reproduced, resting on the assumptions of reading (s), Pearson correlations and the tie rule. Under (s, Pearson) 18 of 49 correlations between receiver in-degree and synergy are positive and 31 negative, median r = -0.037, binomial probability of a negative skew this large 0.043: a slight negative skew, significant at 0.05, which the criterion counts as partial (1.6 to 6.4 ms alone 6 of 24 positive, p = 0.011; 3.5 to 14 ms 12 of 25, p = 0.5). Under (s, Spearman) 24 of 49 are positive (p = 0.5), which the criterion counts as reproduced. Under (f) 10 and 11 of 50 are positive (p = 1.2e-05 and 4.5e-05), a significant negative skew. With bins t-1 and t-2 both (s) readings give no significant skew; with random sub-network connections and with the strict rule the skew is significantly negative in seven of eight readings. At the stricter threshold (calibrated) (s) gives 19 of 48 positive under Pearson (p = 0.097) and 24 of 48 under Spearman, both reproduced by the criterion, and (f) a significant negative skew. The redundancy form of Eq 8 gives the same counts.

Result: reproduced, resting on the tie rule. Correlations between transmitter out-degree and synergy are positive in 42 of 49 recordings and time scales under (s, Pearson), median r = 0.118, binomial p = 1.8e-07 (22 of 24 and 20 of 25 at each time scale); 44 of 49 under (s, Spearman), p = 3.8e-09; 47 of 50 and 50 of 50 under (f). Every variant meets the criterion under every reading except the strict rule with (f, Spearman), 26 of 50 positive (p = 0.44), which the criterion counts as partial.

fig5ab-correlations-beyond-null¶

Nearly all the per-recording degree and synergy correlations lie beyond a null of randomized degree and computation pairings, whose correlations sit near zero.

Ten permutations of degree against synergy per correlation (400 null values for 40 correlations in the paper; here 10 for each of the 50).

In [16]:
def beyond_table(c, form, rng):
    rows = []
    for reading in ["s", "f"]:
        for kind, f in [("p", stats.pearsonr), ("r", stats.spearmanr)]:
            for panel in ["in", "out"]:
                real, null = [], []
                for scale in hdn.TIME_SCALES:
                    for r in recs:
                        indeg, syn_in, outdeg, syn_out = triple_data(c, form, scale, r["name"], reading)
                        x, y = (indeg, syn_in) if panel == "in" else (outdeg, syn_out)
                        if len(x) < 3 or np.ptp(x) == 0 or np.ptp(y) == 0:
                            continue
                        real.append(f(x, y)[0])
                        null += [f(rng.permutation(x), y)[0] for _ in range(10)]
                real, null = np.abs(np.array(real)), np.abs(np.array(null))
                thr = np.percentile(null, 99)
                rows.append({"reading": reading, "coef": kind, "panel": panel, "n_corr": len(real), "n_null": len(null),
                             "null_|r|_median": np.median(null), "null_|r|_p99": thr, "fraction_beyond": (real > thr).mean()})
    return pd.DataFrame(rows)

rng = np.random.default_rng(52)
rows = []
for v, (c, form) in VARIANTS.items():
    b = beyond_table(c, form, rng)
    if v == "main":
        print(b.to_string(index=False, float_format=lambda x: f"{x:.3g}"))
        print("\nCriterion: at least 90% beyond the null's 99th percentile in each panel")
    for (reading, kind), sub in b.groupby(["reading", "coef"], sort=False):
        rows.append({"variant": v, "reading": reading, "coef": kind,
                     "fraction_beyond in/out": " / ".join(f"{x:.2f}" for x in sub.fraction_beyond),
                     "null_p99 in/out": " / ".join(f"{x:.3f}" for x in sub["null_|r|_p99"]),
                     "criterion": "reproduced" if bool((sub.fraction_beyond >= 0.9).all()) else "not met"})
print(pd.DataFrame(rows).to_string(index=False))
reading coef panel  n_corr  n_null  null_|r|_median  null_|r|_p99  fraction_beyond
      s    p    in      49     490          0.00335         0.031            0.878
      s    p   out      49     490          0.00239        0.0156             0.98
      s    r    in      49     490          0.00381        0.0567            0.633
      s    r   out      49     490          0.00251        0.0138                1
      f    p    in      50     500           0.0144        0.0861              0.8
      f    p   out      50     500           0.0108        0.0782             0.86
      f    r    in      50     500           0.0145         0.101             0.72
      f    r   out      50     500           0.0105         0.101             0.96

Criterion: at least 90% beyond the null's 99th percentile in each panel
       variant reading coef fraction_beyond in/out null_p99 in/out  criterion
          main       s    p            0.88 / 0.98   0.031 / 0.016    not met
          main       s    r            0.63 / 1.00   0.057 / 0.014    not met
          main       f    p            0.80 / 0.86   0.086 / 0.078    not met
          main       f    r            0.72 / 0.96   0.101 / 0.101    not met
   strict ties       s    p            0.92 / 0.90   0.030 / 0.019 reproduced
   strict ties       s    r            0.94 / 0.94   0.026 / 0.018 reproduced
   strict ties       f    p            0.88 / 0.92   0.047 / 0.035    not met
   strict ties       f    r            0.86 / 0.96   0.044 / 0.034    not met
  past t-1,t-2       s    p            0.82 / 0.86   0.033 / 0.025    not met
  past t-1,t-2       s    r            0.76 / 0.86   0.036 / 0.024    not met
  past t-1,t-2       f    p            0.60 / 0.84   0.083 / 0.074    not met
  past t-1,t-2       f    r            0.64 / 0.98   0.086 / 0.043    not met
sub (b) random       s    p            0.90 / 0.92   0.033 / 0.026    not met
sub (b) random       s    r            0.78 / 0.98   0.046 / 0.025    not met
sub (b) random       f    p            0.66 / 0.86   0.118 / 0.078    not met
sub (b) random       f    r            0.48 / 0.98   0.145 / 0.069    not met
      PID Eq 8       s    p            0.88 / 1.00   0.031 / 0.011    not met
      PID Eq 8       s    r            0.84 / 0.98   0.020 / 0.019    not met
      PID Eq 8       f    p            0.54 / 0.86   0.125 / 0.077    not met
      PID Eq 8       f    r            0.74 / 0.98   0.099 / 0.066    not met
    calibrated       s    p            0.71 / 0.92   0.042 / 0.031    not met
    calibrated       s    r            0.60 / 0.94   0.065 / 0.026    not met
    calibrated       f    p            0.48 / 0.76   0.167 / 0.117    not met
    calibrated       f    r            0.28 / 0.86   0.188 / 0.110    not met

Result: partially reproduced, resting on the assumptions of reading (s), Pearson correlations and the tie rule. The permuted null correlations sit near zero (median absolute value 0.002 to 0.004 under (s), 0.010 to 0.015 under (f)). Under (s, Pearson) 98% of the out-degree correlations and 88% of the in-degree correlations lie beyond the null's 99th percentile (0.016 and 0.031); the in-degree panel misses the criterion's 90%. Under the other readings the in-degree panel has 63% to 80% and the out-degree panel 86% to 100%. Only the strict rule under (s) meets the criterion in both panels (92% and 90%; 94% and 94%). At the stricter threshold the in-degree panel has 28% to 71% and the out-degree panel 76% to 94%.

fig5cd-pooled-trends¶

Pooled over all neuron groups and recordings, synergy shows no trend with receiver in-degree and rises with transmitter out-degree, at both time scales.

In [17]:
def trend_table(c, form):
    rows = []
    for reading in ["s", "f"]:
        for scale in hdn.TIME_SCALES:
            parts = [triple_data(c, form, scale, r["name"], reading) for r in recs]
            for panel in ["in", "out"]:
                x = np.concatenate([p[0] if panel == "in" else p[2] for p in parts])
                y = np.concatenate([p[1] if panel == "in" else p[3] for p in parts])
                d = pd.DataFrame({"deg": x, "syn": y}).groupby("deg").syn.agg(["count", "median"])
                d = d[d["count"] >= 20]
                rho, p = stats.spearmanr(d.index, d["median"]) if len(d) > 2 else (np.nan, np.nan)
                rows.append({"reading": reading, "scale": scale, "panel": panel, "degrees_kept": len(d),
                             "degree_range": f"{d.index.min()} to {d.index.max()}", "groups": int(d["count"].sum()),
                             "median_at_lowest": d["median"].iloc[0], "median_at_highest": d["median"].iloc[-1],
                             "spearman_rho": rho, "p": p})
    return pd.DataFrame(rows)

def trend_verdict(t, reading):
    sub = t[t.reading == reading]
    o, i = sub[sub.panel == "out"], sub[sub.panel == "in"]
    ok = ((o.spearman_rho > 0) & (o.p < 0.05)).all() and not ((i.spearman_rho > 0) & (i.p < 0.05)).any()
    return "reproduced" if bool(ok) else "not met"

rows = []
for v, (c, form) in VARIANTS.items():
    t = trend_table(c, form)
    if v == "main":
        print(t.to_string(index=False, float_format=lambda x: f"{x:.3g}"))
        print("\nCriterion: out-degree rho > 0 with p < 0.05, and in-degree not significantly positive, at both scales")
    for reading in ["s", "f"]:
        sub = t[t.reading == reading]
        o, i = sub[sub.panel == "out"], sub[sub.panel == "in"]
        rows.append({"variant": v, "reading": reading,
                     "out rho (p)": " / ".join(f"{a:.2f} ({b:.2g})" for a, b in zip(o.spearman_rho, o.p)),
                     "in rho (p)": " / ".join(f"{a:.2f} ({b:.2g})" for a, b in zip(i.spearman_rho, i.p)),
                     "criterion": trend_verdict(t, reading)})
print(pd.DataFrame(rows).to_string(index=False))
reading      scale panel  degrees_kept degree_range  groups  median_at_lowest  median_at_highest  spearman_rho        p
      s 1.6-6.4 ms    in            11      2 to 14  796099            0.0165            0.00106        -0.836  0.00133
      s 1.6-6.4 ms   out            47      1 to 47 1592198           0.00833            0.00573        -0.255   0.0831
      s  3.5-14 ms    in            13      2 to 14  895179            0.0243             0.0116        -0.879 7.54e-05
      s  3.5-14 ms   out            49      1 to 49 1790358             0.013             0.0185        -0.198    0.174
      f 1.6-6.4 ms    in            70      2 to 86   55193           0.00338             0.0019        -0.139     0.25
      f 1.6-6.4 ms   out           174     1 to 322  110386           0.00107            0.00445        0.0285    0.709
      f  3.5-14 ms    in           129     2 to 180   69925            0.0028            0.00258       -0.0455    0.609
      f  3.5-14 ms   out           259     1 to 395  139850          0.000946            0.00142         0.158    0.011

Criterion: out-degree rho > 0 with p < 0.05, and in-degree not significantly positive, at both scales
       variant reading                      out rho (p)                        in rho (p) criterion
          main       s     -0.26 (0.083) / -0.20 (0.17)  -0.84 (0.0013) / -0.88 (7.5e-05)   not met
          main       f       0.03 (0.71) / 0.16 (0.011)       -0.14 (0.25) / -0.05 (0.61)   not met
   strict ties       s      0.46 (0.0015) / 0.23 (0.12) -0.89 (2.6e-12) / -0.85 (4.1e-09)   not met
   strict ties       f -0.51 (2.6e-20) / 0.35 (2.3e-09)   -0.51 (1.7e-19) / -0.80 (5e-52)   not met
  past t-1,t-2       s       -0.22 (0.14) / 0.15 (0.32) -0.85 (9.8e-05) / -0.95 (9.4e-08)   not met
  past t-1,t-2       f      -0.04 (0.59) / 0.12 (0.052)     -0.15 (0.18) / -0.24 (0.0032)   not met
sub (b) random       s  -0.78 (6.1e-10) / -0.30 (0.048)     -0.97 (2.2e-05) / 0.06 (0.86)   not met
sub (b) random       f       0.02 (0.78) / 0.13 (0.043)       -0.15 (0.23) / -0.00 (0.96)   not met
      PID Eq 8       s     -0.26 (0.079) / -0.20 (0.18)  -0.84 (0.0013) / -0.88 (7.5e-05)   not met
      PID Eq 8       f      0.03 (0.69) / 0.16 (0.0095)       -0.14 (0.24) / -0.05 (0.55)   not met
    calibrated       s     -0.32 (0.027) / -0.12 (0.41)    -0.68 (0.029) / -0.82 (0.0011)   not met
    calibrated       f        -0.01 (0.89) / 0.07 (0.3)    -0.25 (0.046) / -0.26 (0.0048)   not met

Result: not reproduced. With all triples pooled, the per-degree median synergy does not rise with transmitter out-degree under (s) (Spearman rho = -0.26, p = 0.083, and -0.20, p = 0.17) and rises at only one time scale under (f) (rho = 0.03, p = 0.71, at 1.6 to 6.4 ms; 0.16, p = 0.011, at 3.5 to 14 ms). With receiver in-degree it falls under (s) (rho = -0.84 and -0.88, p = 0.0013 and 7.5e-05) and shows no trend under (f) (rho = -0.14 and -0.05). The in-degree part holds under both readings; the out-degree part fails. No variant meets the criterion.

fig6-information-gain-not-rising¶

The information gained by adding inputs to a neuron, a bound on its highest-order synergy, stays constant or decreases with the number of inputs at both time scales; exponential fits to the medians give small negative exponents, one with a 95% range overlapping zero.

Per recording, time scale and reading, 30 receivers with at least one input are sampled: under (f) neurons with their significant inputs in the full network, under (s) neurons of a sub-network with their inputs inside it. For each n, all combinations of n inputs or 100 sampled ones, whichever is fewer (the paper: every receiver, up to 100 combinations). The variant "sub random" is not run here (its (f) gains equal the main analysis's).

In [18]:
def expo(n, A, k):
    return A * np.exp(k * n)

def gain_table(c):
    rows = []
    for reading in ["f", "s"]:
        for scale in hdn.TIME_SCALES:
            for norm, col in [("u (normalized)", 1), ("v (bits)", 0)]:
                per_n = {}
                for n_in in range(1, hdn.MAX_INPUTS + 1):
                    per_n[n_in] = np.array([v[col] for (sc, nm), a in RES[c].items() if sc == scale
                                            for v in a["gains"][reading].get(n_in, {}).values()])
                for first in [2, 1]:
                    ns = np.array([n for n in range(first, hdn.MAX_INPUTS + 1) if len(per_n[n]) > 0])
                    med = np.array([np.median(per_n[n]) for n in ns])
                    try:
                        p, cov = curve_fit(expo, ns, med, p0=[med[0] * np.exp(0.1 * ns[0]), -0.1], maxfev=20000)
                        se = np.sqrt(cov[1, 1]); tq = stats.t.ppf(0.975, len(ns) - 2)
                        k, lo, hi = p[1], p[1] - tq * se, p[1] + tq * se
                    except (RuntimeError, ValueError):
                        k = lo = hi = np.nan
                    rows.append({"reading": reading, "scale": scale, "norm": norm, "n_from": first,
                                 "neurons_per_n": "/".join(str(len(per_n[n])) for n in range(first, hdn.MAX_INPUTS + 1)),
                                 "medians": " ".join(f"{m:.3g}" for m in med), "k": k, "k_low": lo, "k_high": hi})
    return pd.DataFrame(rows)

def gain_verdict(sub):
    if (sub.k_low > 0).any() or sub.k.isna().any():
        return "not reproduced" if (sub.k_low > 0).any() else "no fit"
    return "reproduced" if bool((sub.k < 0).all()) else "partially reproduced"

rows = []
for v, (c, form) in VARIANTS.items():
    if form != "claims" or not CONFIGS[c][3]:
        continue
    g = gain_table(c)
    if v == "main":
        print(g.to_string(index=False, float_format=lambda x: f"{x:.3g}"))
        print()
    for (reading, norm, first), sub in g.groupby(["reading", "norm", "n_from"], sort=False):
        rows.append({"variant": v, "reading": reading, "norm": norm, "n_from": first,
                     "k (1.6 / 3.5)": " / ".join(f"{x:.3f}" for x in sub.k),
                     "95% interval": " / ".join(f"{a:.3f} to {b:.3f}" for a, b in zip(sub.k_low, sub.k_high)),
                     "criterion": gain_verdict(sub)})
print(pd.DataFrame(rows).to_string(index=False))
reading      scale           norm  n_from           neurons_per_n                                               medians       k    k_low   k_high
      f 1.6-6.4 ms u (normalized)       2     572/497/436/392/350                    0.0139 0.0135 0.0123 0.0114 0.0106 -0.0709  -0.0889  -0.0529
      f 1.6-6.4 ms u (normalized)       1 750/572/497/436/392/350             0.0129 0.0139 0.0135 0.0123 0.0114 0.0106  -0.045  -0.0866 -0.00346
      f 1.6-6.4 ms       v (bits)       2     572/497/436/392/350          0.000307 0.000316 0.000316 0.000321 0.000317 0.00794 -0.00402   0.0199
      f 1.6-6.4 ms       v (bits)       1 750/572/497/436/392/350 0.000227 0.000307 0.000316 0.000316 0.000321 0.000317  0.0445  -0.0198    0.109
      f  3.5-14 ms u (normalized)       2     672/610/561/530/498                    0.0199 0.0178 0.0159 0.0139 0.0128  -0.114   -0.123   -0.104
      f  3.5-14 ms u (normalized)       1 750/672/610/561/530/498             0.0208 0.0199 0.0178 0.0159 0.0139 0.0128  -0.101    -0.12  -0.0818
      f  3.5-14 ms       v (bits)       2     672/610/561/530/498          0.000605 0.000585 0.000525 0.000483 0.000447 -0.0787     -0.1   -0.057
      f  3.5-14 ms       v (bits)       1 750/672/610/561/530/498 0.000636 0.000605 0.000585 0.000525 0.000483 0.000447 -0.0709  -0.0876  -0.0542
      s 1.6-6.4 ms u (normalized)       2       441/237/118/53/19                    0.0237 0.0219 0.0199 0.0184 0.0174   -0.08  -0.0907  -0.0693
      s 1.6-6.4 ms u (normalized)       1   720/441/237/118/53/19             0.0247 0.0237 0.0219 0.0199 0.0184 0.0174 -0.0738  -0.0847   -0.063
      s 1.6-6.4 ms       v (bits)       2       441/237/118/53/19           0.000745 0.00081 0.000814 0.000684 0.000699  -0.028   -0.106   0.0498
      s 1.6-6.4 ms       v (bits)       1   720/441/237/118/53/19  0.000592 0.000745 0.00081 0.000814 0.000684 0.000699  0.0131  -0.0711   0.0973
      s  3.5-14 ms u (normalized)       2       466/243/111/39/12                    0.0395 0.0316 0.0233 0.0185 0.0152  -0.249   -0.278   -0.219
      s  3.5-14 ms u (normalized)       1   750/466/243/111/39/12             0.0467 0.0395 0.0316 0.0233 0.0185 0.0152  -0.228   -0.259   -0.197
      s  3.5-14 ms       v (bits)       2       466/243/111/39/12               0.00152 0.00138 0.0014 0.00124 0.000963 -0.0926   -0.174  -0.0116
      s  3.5-14 ms       v (bits)       1   750/466/243/111/39/12       0.00151 0.00152 0.00138 0.0014 0.00124 0.000963 -0.0725   -0.127  -0.0179

     variant reading           norm  n_from   k (1.6 / 3.5)                        95% interval            criterion
        main       f u (normalized)       2 -0.071 / -0.114 -0.089 to -0.053 / -0.123 to -0.104           reproduced
        main       f u (normalized)       1 -0.045 / -0.101 -0.087 to -0.003 / -0.120 to -0.082           reproduced
        main       f       v (bits)       2  0.008 / -0.079  -0.004 to 0.020 / -0.100 to -0.057 partially reproduced
        main       f       v (bits)       1  0.045 / -0.071  -0.020 to 0.109 / -0.088 to -0.054 partially reproduced
        main       s u (normalized)       2 -0.080 / -0.249 -0.091 to -0.069 / -0.278 to -0.219           reproduced
        main       s u (normalized)       1 -0.074 / -0.228 -0.085 to -0.063 / -0.259 to -0.197           reproduced
        main       s       v (bits)       2 -0.028 / -0.093  -0.106 to 0.050 / -0.174 to -0.012           reproduced
        main       s       v (bits)       1  0.013 / -0.072  -0.071 to 0.097 / -0.127 to -0.018 partially reproduced
 strict ties       f u (normalized)       2 -0.044 / -0.107 -0.075 to -0.013 / -0.124 to -0.089           reproduced
 strict ties       f u (normalized)       1 -0.048 / -0.100 -0.066 to -0.030 / -0.113 to -0.086           reproduced
 strict ties       f       v (bits)       2 -0.053 / -0.108 -0.103 to -0.003 / -0.118 to -0.097           reproduced
 strict ties       f       v (bits)       1 -0.042 / -0.120 -0.075 to -0.010 / -0.137 to -0.102           reproduced
 strict ties       s u (normalized)       2 -0.495 / -0.268  -1.059 to 0.070 / -0.299 to -0.238           reproduced
 strict ties       s u (normalized)       1 -0.300 / -0.231  -0.686 to 0.087 / -0.282 to -0.181           reproduced
 strict ties       s       v (bits)       2 -0.369 / -0.216  -1.186 to 0.449 / -0.365 to -0.067           reproduced
 strict ties       s       v (bits)       1 -0.196 / -0.151  -0.734 to 0.343 / -0.276 to -0.027           reproduced
past t-1,t-2       f u (normalized)       2 -0.055 / -0.106 -0.079 to -0.031 / -0.115 to -0.096           reproduced
past t-1,t-2       f u (normalized)       1 -0.038 / -0.096 -0.068 to -0.009 / -0.111 to -0.082           reproduced
past t-1,t-2       f       v (bits)       2  0.047 / -0.078   0.036 to 0.059 / -0.090 to -0.065       not reproduced
past t-1,t-2       f       v (bits)       1  0.070 / -0.059   0.029 to 0.110 / -0.089 to -0.028       not reproduced
past t-1,t-2       s u (normalized)       2 -0.123 / -0.221 -0.154 to -0.092 / -0.254 to -0.188           reproduced
past t-1,t-2       s u (normalized)       1 -0.102 / -0.224 -0.137 to -0.067 / -0.241 to -0.206           reproduced
past t-1,t-2       s       v (bits)       2  0.030 / -0.113  -0.044 to 0.105 / -0.167 to -0.059 partially reproduced
past t-1,t-2       s       v (bits)       1  0.066 / -0.083  -0.014 to 0.145 / -0.137 to -0.029 partially reproduced
  calibrated       f u (normalized)       2 -0.083 / -0.149 -0.100 to -0.065 / -0.162 to -0.136           reproduced
  calibrated       f u (normalized)       1 -0.066 / -0.138 -0.093 to -0.040 / -0.155 to -0.121           reproduced
  calibrated       f       v (bits)       2  0.009 / -0.068  -0.014 to 0.032 / -0.098 to -0.039 partially reproduced
  calibrated       f       v (bits)       1  0.039 / -0.061  -0.014 to 0.092 / -0.081 to -0.042 partially reproduced
  calibrated       s u (normalized)       2 -0.143 / -0.250 -0.175 to -0.111 / -0.291 to -0.210           reproduced
  calibrated       s u (normalized)       1 -0.118 / -0.229 -0.158 to -0.078 / -0.263 to -0.194           reproduced
  calibrated       s       v (bits)       2 -0.025 / -0.165  -0.194 to 0.144 / -0.317 to -0.014           reproduced
  calibrated       s       v (bits)       1  0.020 / -0.097   -0.110 to 0.150 / -0.235 to 0.041 partially reproduced

Result: reproduced, resting on the assumption that the gain is normalized by H(I_F), as the paper's PID terms are. For the normalized gain the fitted exponent k is negative at both time scales under both network readings and both starting values of n, and no 95% interval lies above zero: under (f), from n = 2, k = -0.071 (-0.089 to -0.053) and -0.114 (-0.123 to -0.104); from n = 1 the interval at 1.6 to 6.4 ms reaches -0.003; under (s) k is -0.074 to -0.249. For the gain in bits under (f) k is positive at 1.6 to 6.4 ms (0.008, interval -0.004 to 0.020, from n = 2), which the criterion counts as partial; under (s) in bits it is reproduced from n = 2 and partial from n = 1. With bins t-1 and t-2 the gain in bits under (f) rises at 1.6 to 6.4 ms with an interval above zero (0.047, 0.036 to 0.059), which would be not reproduced; the normalized gain is reproduced under every variant. The statement's detail that one interval overlaps zero holds only for the gain in bits. Between 350 and 750 receivers contribute per n under (f), and 12 to 750 under (s), from 30 sampled receivers per recording and time scale.

table1-pid-examples¶

On the example distributions of Table 1, the PID multivariate TE finds synergy only in the synergistic and the synergistic and redundant examples; mutual information misses the hidden self interaction, and interaction information misses simultaneous synergy and redundancy and unique information.

The joint distributions are the paper's Table 1 (rows I_F, I_P, J_P, K_P from 0000 to 1111), typed in as printed; each column is renormalized to sum to 1. The PID uses the claims file's M-PID form of the redundancy; the Eq 8 form is shown as a variant.

In [19]:
TABLE1 = {  # p(I_F, I_P, J_P, K_P), rows 0000 ... 1111, as printed in Table 1
    "No Interaction": ["1/16"] * 16,
    "Self Interaction": ["1/8", "1/8", "1/8", "1/8", "0", "0", "0", "0", "0", "0", "0", "0", "1/8", "1/8", "1/8", "1/8"],
    "Hidden Self Interaction": ["1/4", "1/4", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1/4", "1/4"],
    "Single Interaction": ["1/8", "1/8", "0", "0", "1/8", "1/8", "0", "0", "0", "0", "1/8", "1/8", "0", "0", "1/8", "1/8"],
    "Redundant Interaction": ["1/4", "0", "0", "0", "1/4", "0", "0", "0", "0", "0", "0", "1/4", "0", "0", "0", "1/4"],
    "Single and Redundant Interaction": ["0.1964", "0.0536", "0", "0", "0.1964", "0.0536", "0", "0", "0", "0", "0.0536", "0.1964", "0", "0", "0.0536", "0.1964"],
    "Synergistic Interaction": ["1/8", "0", "0", "1/8", "1/8", "0", "0", "1/8", "0", "1/8", "1/8", "0", "0", "1/8", "1/8", "0"],
    "Synergistic and Redundant Interaction": ["0.0548", "0.0548", "0.0548", "0", "0.0548", "0.0548", "0.0548", "0", "0", "0", "0", "0.3357", "0", "0", "0", "0.3357"],
}

def mi(pxy):
    px, py = pxy.sum(1, keepdims=True), pxy.sum(0, keepdims=True)
    m = pxy > 0
    return float((pxy[m] * np.log2(pxy[m] / (px @ py)[m])).sum())

rows = []
for name, col in TABLE1.items():
    p = np.array([eval(v) for v in col], float); p = p / p.sum()
    n = np.zeros((2, 2, 4))
    pf = np.zeros((2, 2, 2))   # p(I_F, J_P, K_P)
    for row in range(16):
        f, q, j, k = (row >> 3) & 1, (row >> 2) & 1, (row >> 1) & 1, row & 1
        n[f, q, j + 2 * k] = p[row] * 1e6
        pf[f, j, k] += p[row]
    syn, red, uJ, uK, teJ, teK, teJK, H, syn8, red8 = hdn.pid_from_table(n)
    mi_j = mi(pf.sum(2))                                  # MI(J_P; I_F)
    mi_jk = mi(pf.sum(0))                                 # MI(J_P; K_P)
    mi_jk_f = sum(pf[f].sum() * mi(pf[f] / pf[f].sum()) for f in range(2) if pf[f].sum() > 0)  # MI(J_P; K_P | I_F)
    for form, (s_, r_) in [("claims", (syn, red)), ("eq8", (syn8, red8))]:
        rows.append({"form": form, "example": name, "TE(J)": teJ, "TE(K)": teK, "TE(JK)": teJK, "redundancy": r_,
                     "unique J": teJ - r_, "unique K": teK - r_, "synergy": s_, "MI(J_P;I_F)": mi_j, "II": mi_jk_f - mi_jk})
t1_all = pd.DataFrame(rows)
tol = 0.001
for form in ["claims", "eq8"]:
    t1 = t1_all[t1_all.form == form].drop(columns="form").set_index("example")
    print(f"=== redundancy form: {form} ===")
    print(t1.round(4).to_string())
    hs, srd, snr = t1.loc["Hidden Self Interaction"], t1.loc["Synergistic and Redundant Interaction"], t1.loc["Single and Redundant Interaction"]
    checks = {
        "synergy > 0.001 exactly in the two synergistic examples":
            set(t1.index[t1.synergy > tol]) == {"Synergistic Interaction", "Synergistic and Redundant Interaction"},
        "hidden self: MI(J_P;I_F) > 0 while TE and every PID term are 0":
            hs["MI(J_P;I_F)"] > tol and all(abs(hs[c]) <= tol for c in ["TE(J)", "TE(K)", "TE(JK)", "redundancy", "unique J", "unique K", "synergy"]),
        "synergistic and redundant: II = 0 while synergy and redundancy are not":
            abs(srd["II"]) <= tol and srd.synergy > tol and srd.redundancy > tol,
        "single and redundant: unique J > 0 and |II| = redundancy":
            snr["unique J"] > tol and abs(abs(snr["II"]) - snr.redundancy) <= tol,
    }
    for k, v in checks.items():
        print(f"  {k}: {v}")
=== redundancy form: claims ===
                                        TE(J)   TE(K)  TE(JK)  redundancy  unique J  unique K  synergy  MI(J_P;I_F)      II
example                                                                                                                    
No Interaction                         0.0000  0.0000  0.0000      0.0000    0.0000       0.0   0.0000       0.0000  0.0000
Self Interaction                       0.0000  0.0000  0.0000      0.0000    0.0000       0.0   0.0000       0.0000  0.0000
Hidden Self Interaction                0.0000  0.0000  0.0000      0.0000    0.0000       0.0   0.0000       1.0000  0.0000
Single Interaction                     1.0000  0.0000  1.0000      0.0000    1.0000       0.0   0.0000       1.0000  0.0000
Redundant Interaction                  1.0000  1.0000  1.0000      1.0000    0.0000       0.0   0.0000       1.0000 -1.0000
Single and Redundant Interaction       1.0000  0.2502  1.0000      0.2502    0.7498       0.0   0.0000       1.0000 -0.2502
Synergistic Interaction                0.0000  0.0000  1.0000      0.0000    0.0000       0.0   1.0000       0.0000  1.0000
Synergistic and Redundant Interaction  0.4567  0.4567  0.9136      0.4567   -0.0000      -0.0   0.4569       0.4567  0.0001
  synergy > 0.001 exactly in the two synergistic examples: True
  hidden self: MI(J_P;I_F) > 0 while TE and every PID term are 0: True
  synergistic and redundant: II = 0 while synergy and redundancy are not: True
  single and redundant: unique J > 0 and |II| = redundancy: True
=== redundancy form: eq8 ===
                                        TE(J)   TE(K)  TE(JK)  redundancy  unique J  unique K  synergy  MI(J_P;I_F)      II
example                                                                                                                    
No Interaction                         0.0000  0.0000  0.0000      0.0000    0.0000       0.0   0.0000       0.0000  0.0000
Self Interaction                       0.0000  0.0000  0.0000      0.0000    0.0000       0.0   0.0000       0.0000  0.0000
Hidden Self Interaction                0.0000  0.0000  0.0000      0.0000    0.0000       0.0   0.0000       1.0000  0.0000
Single Interaction                     1.0000  0.0000  1.0000      0.0000    1.0000       0.0   0.0000       1.0000  0.0000
Redundant Interaction                  1.0000  1.0000  1.0000      1.0000    0.0000       0.0   0.0000       1.0000 -1.0000
Single and Redundant Interaction       1.0000  0.2502  1.0000      0.2502    0.7498       0.0   0.0000       1.0000 -0.2502
Synergistic Interaction                0.0000  0.0000  1.0000      0.0000    0.0000       0.0   1.0000       0.0000  1.0000
Synergistic and Redundant Interaction  0.4567  0.4567  0.9136      0.4567   -0.0000      -0.0   0.4569       0.4567  0.0001
  synergy > 0.001 exactly in the two synergistic examples: True
  hidden self: MI(J_P;I_F) > 0 while TE and every PID term are 0: True
  synergistic and redundant: II = 0 while synergy and redundancy are not: True
  single and redundant: unique J > 0 and |II| = redundancy: True

Result: reproduced. On the distributions of Table 1, synergy is above 0.001 bits only in the synergistic (1.000 bit) and the synergistic and redundant (0.457 bits) examples. In the hidden self interaction MI(J_P; I_F) is 1 bit while TE and every PID term are 0. In the synergistic and redundant example the interaction information is 0.0001 bits while synergy and redundancy are 0.457 bits each. In the single and redundant example the unique information of J is 0.750 bits and the interaction information is -0.250 bits, the size of the redundancy (0.250 bits). The claims file's redundancy form and that of Eq 8 give the same values on every example.

Feedforward model: fig7b, fig7c, fig7d, figs1¶

fig7c: In a two-layer feedforward model, degree-modified and firing-rate-modified Hebbian rewiring rules qualitatively reproduce the degree and synergy correlations of the real data, the degree-modified rule more closely, while a pure Hebbian rule and random wiring do not.

fig7b: The pure Hebbian rule pools connections among the input neurons most correlated with the network-wide signal, the firing-rate-modified rule spreads them to less correlated input neurons, and the degree-modified rule spreads them almost uniformly across the input layer.

fig7d: The pure Hebbian rule gives the highest mutual information between connected neurons, but conditioned on the network-wide binary signal the degree-modified rule gives the highest; it alone raises neuron-to-neuron communication while also reinforcing network-wide correlation.

figs1: With 40 neurons per layer the model gives the same qualitative results, the degree-modified rule again raising neuron-to-neuron communication, though the Hebbian and firing-rate-modified rules give larger conditioned mutual information than in the small model.

The model follows the Methods and Eqs 13 to 24 of the version of record (hdn.py), whose displayed equations read, as transcribed from its JATS XML:

  • Eq 13, p(I) = 1 / (1 + e^(-alpha I + beta)); Eq 14, p(I = 0) = 0.01; Eq 15, p(I = I_con N_Neurons) = 0.5.
  • Eqs 16 and 17, p(b(t) = 0, i) = 0.5 - 0.4 (i - 1)/(N_Neurons - 1) and p(b(t) = 1, i) = 0.5 + 0.4 (i - 1)/(N_Neurons - 1).
  • Eqs 18 and 19, the same for output neuron o with 0.2 in place of 0.4.
  • Eq 20, S(i, o) = A(i, o) + a1 DegIn(o) + a2 DegOut(i) + a3 FR(o) + a4 FR(i).
  • Eq 22, S_Deg(i, o) = A(i, o) + 0.05 DegIn(o) - 1.75 DegOut(i); Eq 23, S_FR(i, o) = A(i, o) + 0.35 FR(o) + 3.1 FR(i); Eq 24, S_Deg,40(i, o) = A(i, o) + 0.16 DegIn(o) - 0.3 DegOut(i).

The PID equations read, for the record: Eq 8, Redundancy = sum over i_F of p(i_F) min over R in {J_P, K_P} of [I_spec(I_F = i_F; R, I_P) - I_spec(I_F = i_F; I_P)], with Eq 9, I_spec(I_F = i_F; R, I_P) = sum over r, i_P of p(r, i_P | i_F) log [p(r, i_P, i_F) / (p(r, i_P) p(i_F))], and Eq 10 the same without r.

Synergy and MI are computed from 2000 fresh runs per model. The real data's reference is the mean and standard deviation of the per-recording correlations (25 recordings, two time scales) of the main analysis, reading (s), Pearson, of which there are 49, since DataSet5 has no sub-network at 1.6 to 6.4 ms; the other readings and variants are shown. Where all output neurons of a model have the same in-degree, its in-degree correlation is undefined; the model means are given over the defined models and, as a check, with the undefined ones set to 0.

In [20]:
MODEL_EVAL_RUNS = 2000
models = {}
t_all = time.time()
for N, readings in [(20, ["kept"]), (40, ["recomputed", "kept"])]:
    for ab in readings:
        alpha, beta = hdn.sigmoid_params(N if ab == "recomputed" else 20)
        for k, rule in enumerate(hdn.RULES[N]):
            rng = np.random.default_rng(700 + 10 * N + k + (5 if ab == "kept" and N == 40 else 0))
            conn = hdn.build_models(N, rule, rng, alpha, beta)
            models[N, ab, rule] = (conn, pd.DataFrame(hdn.model_correlations(conn, rng, alpha, beta, MODEL_EVAL_RUNS)))
print(f"models built and evaluated in {time.time() - t_all:.0f} s")
print("alpha, beta for N = 20:", [round(v, 4) for v in hdn.sigmoid_params(20)], "| recomputed for N = 40:", [round(v, 4) for v in hdn.sigmoid_params(40)])
rows = []
for (N, ab, rule), (conn, d) in models.items():
    rows.append({"N": N, "alpha_beta": ab, "rule": rule, "models": len(d), "connections": int(conn[0].sum()),
                 **{c: d[c].mean() for c in ["in_p", "out_p", "in_r", "out_r", "mi", "mi_given_b", "upper_half_fraction"]},
                 "in_p_sd": d.in_p.std(), "out_p_sd": d.out_p.std(), "nan_in": int(d.in_p.isna().sum()), "nan_out": int(d.out_p.isna().sum())})
mod = pd.DataFrame(rows)
print(mod.to_string(index=False, float_format=lambda v: f"{v:.4g}"))
models built and evaluated in 281 s
alpha, beta for N = 20: [0.023, 4.5951] | recomputed for N = 40: [0.0115, 4.5951]
 N alpha_beta        rule  models  connections     in_p     out_p       in_r     out_r      mi  mi_given_b  upper_half_fraction  in_p_sd  out_p_sd  nan_in  nan_out
20       kept      random     100           80    0.128 -0.008989     0.1268 -0.002676 0.02289    0.002298               0.5019     0.18    0.1095       0        0
20       kept     hebbian     100           80    0.321   0.02223     0.2897  -0.05183  0.0901    0.001676                0.988  0.09368   0.08156       0        0
20       kept      degree     100           80  0.01722    0.1138   -0.00325    0.1295 0.02962    0.001528               0.5054   0.1481    0.0581      56       56
20       kept firing_rate     100           80  -0.0611    0.2803    -0.1081    0.2269 0.07102    0.001664               0.7915   0.1472   0.08239       0        0
40 recomputed      random     100          320  0.07893 -0.006432    0.08132 -0.004064 0.01818    0.001119               0.4989   0.1049   0.07434       0        0
40 recomputed     hebbian     100          320   0.3596   0.08196     0.3366 0.0009662  0.0823   0.0009618               0.9905  0.05432   0.04656       0        0
40 recomputed      degree     100          320  0.03031   0.09685    0.01598    0.1138 0.02461   0.0009405               0.5016  0.09338   0.02639      49       49
40 recomputed firing_rate     100          320 -0.06765    0.3501    -0.1221    0.2771 0.06421   0.0009673               0.7694  0.08339   0.03747       0        0
40       kept      random     100          320  0.09562  -0.00511    0.08048 -0.001574 0.02674    0.002058               0.4981   0.1119   0.08854       0        0
40       kept     hebbian     100          320   0.3256   0.08881     0.2996   0.01632  0.1047    0.001468               0.9993   0.0686   0.04772       0        0
40       kept      degree     100          320 0.003996   0.08148 -0.0007195   0.08111 0.01214   0.0009947               0.5014   0.0467   0.04393      53       53
40       kept firing_rate     100          320  -0.2227    0.3898     -0.245    0.3102 0.06193    0.001458               0.7976   0.0917   0.03294       0        0
In [21]:
def real_ref(v, reading, kind):
    sub = CORR[v][(CORR[v].reading == reading) & (CORR[v].coef == kind)]
    i, o = sub[sub.panel == "in"].r.dropna(), sub[sub.panel == "out"].r.dropna()
    return i.mean(), i.std(), o.mean(), o.std()

def match_table(N, ab, v, reading, kind, nan_zero=False):
    mi_, si, mo, so = real_ref(v, reading, kind)
    rows = []
    for rule in hdn.RULES[N]:
        d = models[N, ab, rule][1]
        xi, xo = d["in_" + kind], d["out_" + kind]
        if nan_zero:
            xi, xo = xi.fillna(0), xo.fillna(0)
        a, b = xi.mean(), xo.mean()
        rows.append({"rule": rule, "mean_in": a, "mean_out": b, "match": abs(a - mi_) <= si and abs(b - mo) <= so,
                     "distance": math.hypot(a - mi_, b - mo)})
    return pd.DataFrame(rows), (mi_, si, mo, so)

def fig7c_ok(t):
    m = t.set_index("rule")
    return bool(m.match["degree"] and m.match["firing_rate"] and not m.match["hebbian"] and not m.match["random"]
                and m.distance["degree"] < m.distance["firing_rate"])

def fig7c_label(t):
    m = t.set_index("rule")
    if fig7c_ok(t):
        return "reproduced"
    qual = bool(m.match["degree"] and m.match["firing_rate"] and not m.match["hebbian"] and not m.match["random"])
    return "match, but firing-rate rule closer" if qual else "not met"

for reading in ["s", "f"]:
    for kind in ["p", "r"]:
        t, ref = match_table(20, "kept", "main", reading, kind)
        print(f"main, reading ({reading}, {kind}): real in {ref[0]:.3f} +- {ref[1]:.3f}, out {ref[2]:.3f} +- {ref[3]:.3f}")
        print(t.round(4).to_string(index=False))
        print("  fig7c criterion:", fig7c_ok(t), "| with undefined in-degree correlations set to 0:",
              fig7c_label(match_table(20, "kept", "main", reading, kind, nan_zero=True)[0]))
rows = []
for v in VARIANTS:
    for reading in ["s", "f"]:
        for kind in ["p", "r"]:
            t, ref = match_table(20, "kept", v, reading, kind)
            m = t.set_index("rule")
            rows.append({"variant": v, "reading": reading, "coef": kind, "real in": f"{ref[0]:.3f} +- {ref[1]:.3f}",
                         "real out": f"{ref[2]:.3f} +- {ref[3]:.3f}", "matching rules": ",".join(m.index[m.match]),
                         "dist degree": round(m.distance["degree"], 3), "dist firing_rate": round(m.distance["firing_rate"], 3),
                         "fig7c": fig7c_label(t)})
print(pd.DataFrame(rows).to_string(index=False))
fig, ax = plt.subplots(figsize=(5, 4))
for rule in hdn.RULES[20]:
    d = models[20, "kept", rule][1]
    ax.plot(d.in_p, d.out_p, ".", alpha=0.3, label=rule)
mi_, si, mo, so = real_ref("main", "s", "p")
ax.errorbar(mi_, mo, xerr=si, yerr=so, color="k", label="real (s, p)")
ax.set_xlabel("in-degree vs synergy r"); ax.set_ylabel("out-degree vs synergy r"); ax.legend(fontsize=7)
plt.show()
d_all = pd.concat([models[20, "kept", r][1] for r in hdn.RULES[20]])
print(f"model correlations range: in {d_all.in_p.min():.3f} to {d_all.in_p.max():.3f}, out {d_all.out_p.min():.3f} to {d_all.out_p.max():.3f}; all within the axes")
main, reading (s, p): real in -0.016 +- 0.117, out 0.127 +- 0.120
       rule  mean_in  mean_out  match  distance
     random   0.1280   -0.0090  False    0.1978
    hebbian   0.3210    0.0222  False    0.3529
     degree   0.0172    0.1138   True    0.0356
firing_rate  -0.0611    0.2803  False    0.1602
  fig7c criterion: False | with undefined in-degree correlations set to 0: not met
main, reading (s, r): real in 0.005 +- 0.120, out 0.147 +- 0.119
       rule  mean_in  mean_out  match  distance
     random   0.1268   -0.0027  False    0.1934
    hebbian   0.2897   -0.0518  False    0.3478
     degree  -0.0033    0.1295   True    0.0194
firing_rate  -0.1081    0.2269   True    0.1379
  fig7c criterion: True | with undefined in-degree correlations set to 0: reproduced
main, reading (f, p): real in -0.120 +- 0.117, out 0.207 +- 0.117
       rule  mean_in  mean_out  match  distance
     random   0.1280   -0.0090  False    0.3287
    hebbian   0.3210    0.0222  False    0.4779
     degree   0.0172    0.1138  False    0.1657
firing_rate  -0.0611    0.2803   True    0.0939
  fig7c criterion: False | with undefined in-degree correlations set to 0: not met
main, reading (f, r): real in -0.109 +- 0.131, out 0.244 +- 0.095
       rule  mean_in  mean_out  match  distance
     random   0.1268   -0.0027  False    0.3411
    hebbian   0.2897   -0.0518  False    0.4963
     degree  -0.0033    0.1295  False    0.1557
firing_rate  -0.1081    0.2269   True    0.0173
  fig7c criterion: False | with undefined in-degree correlations set to 0: not met
       variant reading coef         real in        real out            matching rules  dist degree  dist firing_rate                              fig7c
          main       s    p -0.016 +- 0.117  0.127 +- 0.120                    degree        0.036             0.160                            not met
          main       s    r  0.005 +- 0.120  0.147 +- 0.119        degree,firing_rate        0.019             0.138                         reproduced
          main       f    p -0.120 +- 0.117  0.207 +- 0.117               firing_rate        0.166             0.094                            not met
          main       f    r -0.109 +- 0.131  0.244 +- 0.095               firing_rate        0.156             0.017                            not met
   strict ties       s    p -0.136 +- 0.166  0.193 +- 0.174        degree,firing_rate        0.173             0.115 match, but firing-rate rule closer
   strict ties       s    r -0.130 +- 0.189  0.172 +- 0.197        degree,firing_rate        0.133             0.059 match, but firing-rate rule closer
   strict ties       f    p -0.150 +- 0.146  0.155 +- 0.198               firing_rate        0.172             0.154                            not met
   strict ties       f    r -0.062 +- 0.190 -0.009 +- 0.366 random,degree,firing_rate        0.151             0.241                            not met
  past t-1,t-2       s    p -0.014 +- 0.125  0.109 +- 0.129                    degree        0.032             0.178                            not met
  past t-1,t-2       s    r  0.003 +- 0.117  0.135 +- 0.134        degree,firing_rate        0.008             0.144                         reproduced
  past t-1,t-2       f    p -0.092 +- 0.103  0.206 +- 0.118               firing_rate        0.143             0.081                            not met
  past t-1,t-2       f    r -0.073 +- 0.114  0.241 +- 0.105               firing_rate        0.132             0.037                            not met
sub (b) random       s    p -0.088 +- 0.087  0.160 +- 0.085                                  0.115             0.123                            not met
sub (b) random       s    r -0.082 +- 0.096  0.200 +- 0.082        degree,firing_rate        0.106             0.038 match, but firing-rate rule closer
sub (b) random       f    p -0.119 +- 0.115  0.206 +- 0.115               firing_rate        0.165             0.094                            not met
sub (b) random       f    r -0.108 +- 0.130  0.244 +- 0.094               firing_rate        0.155             0.017                            not met
      PID Eq 8       s    p -0.017 +- 0.117  0.126 +- 0.120                    degree        0.036             0.160                            not met
      PID Eq 8       s    r  0.004 +- 0.120  0.147 +- 0.119        degree,firing_rate        0.019             0.137                         reproduced
      PID Eq 8       f    p -0.120 +- 0.117  0.207 +- 0.117               firing_rate        0.166             0.094                            not met
      PID Eq 8       f    r -0.109 +- 0.131  0.245 +- 0.095               firing_rate        0.156             0.018                            not met
    calibrated       s    p -0.026 +- 0.132  0.114 +- 0.126                    degree        0.044             0.170                            not met
    calibrated       s    r -0.001 +- 0.141  0.128 +- 0.130        degree,firing_rate        0.003             0.146                         reproduced
    calibrated       f    p -0.124 +- 0.132  0.190 +- 0.126               firing_rate        0.160             0.109                            not met
    calibrated       f    r -0.106 +- 0.145  0.219 +- 0.103        degree,firing_rate        0.137             0.008 match, but firing-rate rule closer
No description has been provided for this image
model correlations range: in -0.463 to 0.590, out -0.235 to 0.437; all within the axes

Result: partially reproduced, resting on the assumptions of reading (s), Pearson correlations and the tie rule. Against the real mean and standard deviation (in-degree -0.016 +- 0.117, out-degree 0.127 +- 0.120), the degree-modified models (0.017, 0.114) match and are the nearest (distance 0.036), and the Hebbian (0.321, 0.022) and random (0.128, -0.009) models do not match, as the paper says. The firing-rate-modified models (-0.061, 0.280) do not match: their out-degree correlation is beyond one standard deviation. Under (s, Spearman) the whole criterion holds (degree distance 0.019 against 0.138); under (f) only the firing-rate rule matches. At the stricter threshold the real data give the same verdicts as the main analysis under (s): only the degree rule matches under Pearson, and the whole criterion holds under Spearman. Counting the 56 degree-modified models with undefined in-degree correlations as 0 changes no verdict.

In [22]:
def fig7b_table(N, ab):
    t = pd.DataFrame([{"rule": r, "upper_half_fraction": models[N, ab, r][1].upper_half_fraction.mean(),
                       "sd": models[N, ab, r][1].upper_half_fraction.std()} for r in hdn.RULES[N]])
    m = t.set_index("rule").upper_half_fraction
    ok = bool(m["hebbian"] > m["firing_rate"] > m["degree"] and abs(m["degree"] - 0.5) <= 0.1)
    return t, ok

t, ok = fig7b_table(20, "kept")
print(t.round(4).to_string(index=False)); print("fig7b criterion:", ok)
fig, axes = plt.subplots(1, 4, figsize=(14, 3))
for ax, rule in zip(axes, hdn.RULES[20]):
    im = ax.imshow(models[20, "kept", rule][0].mean(0), vmin=0, vmax=1, cmap="viridis")
    ax.set_title(rule); ax.set_xlabel("output o"); ax.set_ylabel("input i")
plt.colorbar(im, ax=axes); plt.show()
       rule  upper_half_fraction     sd
     random               0.5019 0.0503
    hebbian               0.9880 0.0115
     degree               0.5054 0.0062
firing_rate               0.7915 0.0494
fig7b criterion: True
No description has been provided for this image

Result: reproduced. The fraction of connections leaving the upper half of the input layer is 0.988 for the Hebbian rule, 0.792 for the firing-rate-modified rule and 0.505 for the degree-modified rule (random wiring 0.502), in the order the criterion requires, with the degree-modified rule within 0.5 +- 0.1.

In [23]:
def fig7d_tests(N, ab):
    rules = list(hdn.RULES[N])
    rows = []
    for col in ["mi", "mi_given_b"]:
        for a, b in itertools.combinations(rules, 2):
            x, y = models[N, ab, a][1][col], models[N, ab, b][1][col]
            rows.append({"measure": col, "a": a, "b": b, "mean_a": x.mean(), "mean_b": y.mean(),
                         "p": stats.mannwhitneyu(x, y, alternative="two-sided").pvalue})
    t = pd.DataFrame(rows)
    t["p_fdr"] = stats.false_discovery_control(t.p, method="bh")
    return t

def above(t, N, ab, hi, lo):
    """hi's mean conditioned MI above lo's, at FDR-corrected p < 0.001."""
    c = t[(t.measure == "mi_given_b") & (((t.a == hi) & (t.b == lo)) | ((t.a == lo) & (t.b == hi)))]
    return bool(models[N, ab, hi][1].mi_given_b.mean() > models[N, ab, lo][1].mi_given_b.mean() and c.p_fdr.iloc[0] < 0.001)

def fig7d_ok(N, ab, t):
    means = {r: models[N, ab, r][1][["mi", "mi_given_b"]].mean() for r in hdn.RULES[N]}
    top_u = max(means, key=lambda r: means[r]["mi"]); top_c = max(means, key=lambda r: means[r]["mi_given_b"])
    deg_beats = all(above(t, N, ab, "degree", r) for r in hdn.RULES[N] if r != "degree")
    not_above_random = all(not above(t, N, ab, r, "random") for r in ["hebbian", "firing_rate"])
    return top_u, top_c, deg_beats, not_above_random

t = fig7d_tests(20, "kept")
print(t.to_string(index=False, float_format=lambda v: f"{v:.3g}"))
top_u, top_c, deg_beats, nar = fig7d_ok(20, "kept", t)
print(f"highest unconditioned MI: {top_u}; highest conditioned MI: {top_c}; degree above every other rule at FDR p < 0.001: {deg_beats}; "
      f"Hebbian and firing-rate not significantly above random: {nar}")
print("fig7d criterion:", top_u == "hebbian" and top_c == "degree" and deg_beats and nar)
# first-order bias of the plug-in MI of two binary variables, (2-1)(2-1) / (2 n ln 2) bits
bias_u = 1 / (2 * MODEL_EVAL_RUNS * np.log(2))
bias_c = 1 / (2 * (MODEL_EVAL_RUNS / 2) * np.log(2))
print(f"Plug-in bias, first order: {bias_u:.2e} bits unconditioned, {bias_c:.2e} bits conditioned on b (two halves of {MODEL_EVAL_RUNS // 2} runs);"
      " the same for every rule, since every model uses the same number of runs and binary states.")
print("Conditioned MI minus that bias:", {r: f"{models[20, 'kept', r][1].mi_given_b.mean() - bias_c:.2e}" for r in hdn.RULES[20]})
   measure       a           b  mean_a  mean_b        p    p_fdr
        mi  random     hebbian  0.0229  0.0901 2.56e-34 6.34e-34
        mi  random      degree  0.0229  0.0296 1.46e-23 1.94e-23
        mi  random firing_rate  0.0229   0.071 2.56e-34 6.34e-34
        mi hebbian      degree  0.0901  0.0296 2.56e-34 6.34e-34
        mi hebbian firing_rate  0.0901   0.071 2.64e-34 6.34e-34
        mi  degree firing_rate  0.0296   0.071 2.56e-34 6.34e-34
mi_given_b  random     hebbian  0.0023 0.00168 2.19e-33 3.29e-33
mi_given_b  random      degree  0.0023 0.00153 3.56e-34 7.13e-34
mi_given_b  random firing_rate  0.0023 0.00166 6.48e-34 1.11e-33
mi_given_b hebbian      degree 0.00168 0.00153    4e-10 4.81e-10
mi_given_b hebbian firing_rate 0.00168 0.00166    0.699    0.699
mi_given_b  degree firing_rate 0.00153 0.00166 6.02e-08 6.57e-08
highest unconditioned MI: hebbian; highest conditioned MI: random; degree above every other rule at FDR p < 0.001: False; Hebbian and firing-rate not significantly above random: True
fig7d criterion: False
Plug-in bias, first order: 3.61e-04 bits unconditioned, 7.21e-04 bits conditioned on b (two halves of 1000 runs); the same for every rule, since every model uses the same number of runs and binary states.
Conditioned MI minus that bias: {'random': '1.58e-03', 'hebbian': '9.55e-04', 'degree': '8.07e-04', 'firing_rate': '9.43e-04'}

Result: not reproduced. The Hebbian rule gives the highest unconditioned MI between connected neurons (0.090 bits, against 0.071, 0.030 and 0.023), as the paper says. Conditioned on the binary signal, the random model gives the highest MI (0.00230 bits) and the degree-modified rule the lowest (0.00153; Hebbian 0.00168, firing-rate 0.00166). The degree-modified rule differs from the random, Hebbian and firing-rate rules at FDR p < 0.001 but lies below each, so it is above none. The first-order plug-in bias of the conditioned MI, 7.2e-04 bits, is the same for every rule; with it subtracted the order is unchanged.

In [24]:
rows = []
for ab in ["recomputed", "kept"]:
    print(f"=== N = 40, alpha and beta {ab} ===")
    tb, ok_b = fig7b_table(40, ab)
    print(tb.round(4).to_string(index=False), "| connectivity ordering:", ok_b)
    td = fig7d_tests(40, ab)
    print(td.to_string(index=False, float_format=lambda v: f"{v:.3g}"))
    deg_above = above(td, 40, ab, "degree", "random")
    larger = {r: (models[40, ab, r][1].mi_given_b.mean(), models[20, "kept", r][1].mi_given_b.mean()) for r in ["hebbian", "firing_rate"]}
    print("degree conditioned MI above random (FDR p < 0.001):", deg_above)
    print("conditioned MI, N = 40 against N = 20:", {r: (round(a, 5), round(b, 5)) for r, (a, b) in larger.items()})
    for v in VARIANTS:
        for reading, kind in [("s", "p"), ("s", "r"), ("f", "p"), ("f", "r")]:
            t, ref = match_table(40, ab, v, reading, kind)
            m = t.set_index("rule")
            ok_c = bool(m.match["degree"] and m.match["firing_rate"] and not m.match["hebbian"])
            rows.append({"alpha_beta": ab, "variant": v, "reading": reading, "coef": kind,
                         "mean_in": " ".join(f"{x:.3f}" for x in t.mean_in), "mean_out": " ".join(f"{x:.3f}" for x in t.mean_out),
                         "correlation match": ok_c, "ordering": ok_b, "degree MI above random": deg_above,
                         "Hebbian and FR larger than N=20": all(a > b for a, b in larger.values()),
                         "figs1 criterion": ok_c and ok_b and deg_above and all(a > b for a, b in larger.values())})
print("\nRule order in mean_in and mean_out:", list(hdn.RULES[40]))
print(pd.DataFrame(rows).to_string(index=False))
=== N = 40, alpha and beta recomputed ===
       rule  upper_half_fraction     sd
     random               0.4989 0.0288
    hebbian               0.9905 0.0064
     degree               0.5016 0.0016
firing_rate               0.7694 0.0279 | connectivity ordering: True
   measure       a           b   mean_a   mean_b        p    p_fdr
        mi  random     hebbian   0.0182   0.0823 2.56e-34 6.15e-34
        mi  random      degree   0.0182   0.0246 3.74e-33 6.41e-33
        mi  random firing_rate   0.0182   0.0642 2.56e-34 6.15e-34
        mi hebbian      degree   0.0823   0.0246 2.56e-34 6.15e-34
        mi hebbian firing_rate   0.0823   0.0642 2.56e-34 6.15e-34
        mi  degree firing_rate   0.0246   0.0642 2.56e-34 6.15e-34
mi_given_b  random     hebbian  0.00112 0.000962 2.11e-32 3.16e-32
mi_given_b  random      degree  0.00112 0.000941 3.52e-33 6.41e-33
mi_given_b  random firing_rate  0.00112 0.000967 4.63e-32 6.17e-32
mi_given_b hebbian      degree 0.000962 0.000941  0.00609  0.00665
mi_given_b hebbian firing_rate 0.000962 0.000967    0.363    0.363
mi_given_b  degree firing_rate 0.000941 0.000967   0.0011  0.00132
degree conditioned MI above random (FDR p < 0.001): False
conditioned MI, N = 40 against N = 20: {'hebbian': (np.float64(0.00096), np.float64(0.00168)), 'firing_rate': (np.float64(0.00097), np.float64(0.00166))}
=== N = 40, alpha and beta kept ===
       rule  upper_half_fraction     sd
     random               0.4981 0.0234
    hebbian               0.9993 0.0014
     degree               0.5014 0.0016
firing_rate               0.7976 0.0343 | connectivity ordering: True
   measure       a           b   mean_a   mean_b        p   p_fdr
        mi  random     hebbian   0.0267    0.105 2.56e-34 2.8e-34
        mi  random      degree   0.0267   0.0121 2.56e-34 2.8e-34
        mi  random firing_rate   0.0267   0.0619 2.56e-34 2.8e-34
        mi hebbian      degree    0.105   0.0121 2.56e-34 2.8e-34
        mi hebbian firing_rate    0.105   0.0619 2.56e-34 2.8e-34
        mi  degree firing_rate   0.0121   0.0619 2.56e-34 2.8e-34
mi_given_b  random     hebbian  0.00206  0.00147 2.56e-34 2.8e-34
mi_given_b  random      degree  0.00206 0.000995 2.56e-34 2.8e-34
mi_given_b  random firing_rate  0.00206  0.00146 2.56e-34 2.8e-34
mi_given_b hebbian      degree  0.00147 0.000995 2.56e-34 2.8e-34
mi_given_b hebbian firing_rate  0.00147  0.00146    0.597   0.597
mi_given_b  degree firing_rate 0.000995  0.00146 2.56e-34 2.8e-34
degree conditioned MI above random (FDR p < 0.001): False
conditioned MI, N = 40 against N = 20: {'hebbian': (np.float64(0.00147), np.float64(0.00168)), 'firing_rate': (np.float64(0.00146), np.float64(0.00166))}

Rule order in mean_in and mean_out: ['random', 'hebbian', 'degree', 'firing_rate']
alpha_beta        variant reading coef                   mean_in                 mean_out  correlation match  ordering  degree MI above random  Hebbian and FR larger than N=20  figs1 criterion
recomputed           main       s    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed           main       s    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
recomputed           main       f    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed           main       f    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
recomputed    strict ties       s    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed    strict ties       s    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277               True      True                   False                            False            False
recomputed    strict ties       f    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed    strict ties       f    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277               True      True                   False                            False            False
recomputed   past t-1,t-2       s    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed   past t-1,t-2       s    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
recomputed   past t-1,t-2       f    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed   past t-1,t-2       f    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
recomputed sub (b) random       s    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed sub (b) random       s    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
recomputed sub (b) random       f    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed sub (b) random       f    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
recomputed       PID Eq 8       s    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed       PID Eq 8       s    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
recomputed       PID Eq 8       f    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed       PID Eq 8       f    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
recomputed     calibrated       s    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed     calibrated       s    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
recomputed     calibrated       f    p  0.079 0.360 0.030 -0.068 -0.006 0.082 0.097 0.350              False      True                   False                            False            False
recomputed     calibrated       f    r  0.081 0.337 0.016 -0.122 -0.004 0.001 0.114 0.277              False      True                   False                            False            False
      kept           main       s    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept           main       s    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False
      kept           main       f    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept           main       f    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False
      kept    strict ties       s    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept    strict ties       s    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310               True      True                   False                            False            False
      kept    strict ties       f    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept    strict ties       f    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310               True      True                   False                            False            False
      kept   past t-1,t-2       s    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept   past t-1,t-2       s    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False
      kept   past t-1,t-2       f    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept   past t-1,t-2       f    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False
      kept sub (b) random       s    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept sub (b) random       s    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False
      kept sub (b) random       f    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept sub (b) random       f    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False
      kept       PID Eq 8       s    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept       PID Eq 8       s    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False
      kept       PID Eq 8       f    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept       PID Eq 8       f    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False
      kept     calibrated       s    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept     calibrated       s    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False
      kept     calibrated       f    p  0.096 0.326 0.004 -0.223 -0.005 0.089 0.081 0.390              False      True                   False                            False            False
      kept     calibrated       f    r 0.080 0.300 -0.001 -0.245 -0.002 0.016 0.081 0.310              False      True                   False                            False            False

Result: not reproduced. With 40 neurons per layer the connectivity ordering holds (Hebbian 0.991, firing-rate 0.769, degree 0.502 with alpha and beta recomputed; 0.999, 0.798, 0.501 with them kept). The degree-modified rule's conditioned MI is below the random model's under both readings (0.00094 against 0.00112; 0.00100 against 0.00206), and the Hebbian and firing-rate rules' conditioned MI is smaller than in the 20-neuron model (0.00096 and 0.00097, or 0.00147 and 0.00146, against 0.00168 and 0.00166), not larger. The correlation match fails under every reading of the main analysis. The criterion fails under every reading, variant and choice of alpha and beta.

Summary¶

Claim Outcome
data-recordings reproduced
fig4ac-te-lognormal partially reproduced (assumes the tie rule and bins t-2, t-3)
fig4bd-heavy-tailed-degree reproduced
fig4bd-out-tail-longer reproduced (assumes the tie rule)
fig5a-in-degree-uncorrelated partially reproduced (assumes sub-networks, Pearson, the tie rule)
fig5b-out-degree-positive reproduced (assumes the tie rule)
fig5ab-correlations-beyond-null partially reproduced (assumes sub-networks, Pearson, the tie rule)
fig5cd-pooled-trends not reproduced
fig6-information-gain-not-rising reproduced (assumes the normalized gain)
table1-pid-examples reproduced
fig7b-connectivity-patterns reproduced
fig7c-degree-modified-rule-matches partially reproduced (assumes sub-networks, Pearson, the tie rule)
fig7d-degree-rule-highest-conditioned-mi not reproduced
figs1-larger-model not 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 paper reused TE networks computed for [44]; they are rebuilt here from the deposited spike times with the bins, past states, jitter window and threshold of [44], so they need not be the same networks. A surrogate that ties with the real TE counts as exceeding it; [44]'s text says "larger", which, taken literally, calls a pair significant whenever the jitter cannot change its counts, and gives a false-positive rate of 10.8% on independent trains here. The rule used gives 0.32%, three times the nominal 0.1%, so 8% to 30% of the significant connections of five tested recordings are expected by chance; a stricter threshold (no surrogate at or above the real TE, 0.20%) is shown as a variant. Under it fig5a would be graded reproduced and the fig4ac fits under (s) meet the criterion, while every other grade is the same as in the main analysis. The outcomes rest on the paper's threshold of fewer than 5 of 5000 with ties counted as exceeding. Which two bins form the past state is read from the delay windows both papers state (t-2 and t-3); bins t-1 and t-2, from [44]'s text, are shown as a variant. For pairs whose jitter moves more than 50 relevant spikes the surrogate counts are drawn from a normal distribution with their exact moments; on two recordings this shares 83% to 89% of the connections with the full jitter. Sub-networks with fewer than 75 connections are redrawn, and four recordings give fewer than 500 at 1.6 to 6.4 ms. The redundancy uses the claims file's form, which differs from Eq 8 of the version of record; Eq 8 is shown and changes no outcome. The full-network triples are sampled (3000 per recording and time scale), and the information gain uses 30 receivers per recording, time scale and reading (the paper: all receivers). The variants use 100 sub-networks per recording and 20 combinations per n. The model's synergy is the PID of two input states about the output state in the same run, without the receiver's past, which the model does not have; MI and synergy use 2000 fresh runs per model.

What was found about the data set. The deposit matches the paper's description: 25 recordings, 7735 neurons, all with at least 100 spikes, a mean rate of 2.10 Hz, spike times on the 20 kHz grid. One recording (DataSet19) lasts 48 min, not 60. The first ten recordings have no spikes in their first 8 s. The networks of [44] that the paper analysed are not deposited, so the networks have to be rebuilt.

In [25]:
print(f"Notebook ran in {(time.time() - started) / 60:.1f} min")
Notebook ran in 69.0 min