OSCR

Energy-efficient information processing and eligibility-trace plasticity in the Drosophila optic lobe connectome.

Code ↔ Paper

14 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 14 matches
  1. [1] § Results › Part B Structural information: type symmetries compress the connectome; spatial extensions require conservative treatment ↔ partB_pubready_package/partB_pubready/scripts/compute_heldout_nll.py, lines 1–30 · score 0.92 · Poisson NLL diagnostics, exact dyad split, sample dyad, distance binned, coordinate shuffled, structural model
  2. [2] § Results › Part E Eligibility-trace learning robustly aligns wiring geometry under cost constraints and outperforms REINFORCE under compute-matched budgets ↔ partE_pubready_package/partE_pubready/scripts/make_partE_patch_motif_generalization.py, lines 1–32 · score 0.88 · motif fingerprint space, multi patch motif, geometry alignment, biological patch, representative patch, learned graphs
  3. [3] § Results › Part C Functional information: decoder-based bounds show decodable signal that vanishes under null controls ↔ partC_pubready_package/partC_pubready_pkg/scripts/make_partC_decoder_sensitivity.py, lines 173–204 · score 0.87 · matched split sensitivity, alternative low capacity, claim narrow, activity tensors, archived raw, ConnShuffle
  4. [4] § Results › Part E Eligibility-trace learning robustly aligns wiring geometry under cost constraints and outperforms REINFORCE under compute-matched budgets ↔ partE_pubready_package/partE_pubready/scripts/make_partE_figures.py, lines 639–660 · score 0.66 · eligibility trace learning, forward pass budget, scale robustness, fairness, win, rank
  5. [5] § Methods › Learning rules and benchmarking ↔ partE_pubready_package/partE_pubready/scripts/make_partE_patch_motif_generalization.py, lines 1–32 · score 0.66 · multi patch motif, representative patch motif, fingerprints
  6. [6] § Methods › Learning rules and benchmarking ↔ partE_pubready_package/partE_pubready/scripts/make_partE_figures.py, lines 639–660 · score 0.65 · stochastic perturbation, Eligibility trace learning, gradient, baseline, prop, REINFORCE
  7. [7] § Results › Part C Functional information: decoder-based bounds show decodable signal that vanishes under null controls ↔ partC_pubready_package/partC_pubready_pkg/scripts/make_partC_decoder_sensitivity.py, lines 173–204 · score 0.60 · decoder family, real graph supports, zero lower bound, disappears, reproducible, regime
  8. [8] § Methods › Dynamical model and information bounds ↔ partD_pubready_package/scripts/local_decoding.py, lines 19–58 · score 0.59 · cross entropy, local decoding, lower bounds, classifier, population, shuffling
  9. [9] § Results › Part D Energetic accounting reveals higher bits-per-energy in the real connectome than in matched null networks ↔ partD_pubready_package/scripts/plot_partD_pubready.py, lines 232–295 · score 0.58 · Null_Strength, Null_Conn, energy efficiency, global, bits
  10. [10] § Results › Part C Functional information: decoder-based bounds show decodable signal that vanishes under null controls ↔ partC_pubready_package/partC_pubready_pkg/scripts/partC_metrics_utils.py, lines 1–35 · score 0.58 · cross entropy, mutual information, definition, clip, intentionally, stimulus
  11. [11] § Methods › Structural models and MDL ↔ partB_pubready_package/partB_pubready/scripts/plot_partB_pubready.py, lines 135–211 · score 0.57 · log likelihood, BIC, M0, M2, SBM, penalty
  12. [12] § Results › Part C Functional information: decoder-based bounds show decodable signal that vanishes under null controls ↔ partC_pubready_package/partC_pubready_pkg/scripts/plot_partC_pubready.py, lines 81–159 · score 0.55 · ConnShuffle, LabelShuffle, Global decoding, information lower bounds, accuracy, Decoder
  13. [13] § Results › Part C Functional information: decoder-based bounds show decodable signal that vanishes under null controls ↔ partC_pubready_package/partC_pubready_pkg/scripts/make_partC_report.py, lines 25–105 · score 0.55 · ConnShuffle, LabelShuffle, Global decoding, accuracy, tiles, lower bounds
  14. [14] § Results › Part A Data integrity and retinotopic coverage set the constraints for inference ↔ partA_figures_package/partA_figures/scripts/fig_t4t5_subtypes.py, lines 71–216 · score 0.51 · retinotopy coordinates, weight distributions, population, synapse, cell, neurons

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Python · 574 lines · 23 KB · no license · 2 matches

  1. #!/usr/bin/env python3
  2. """Multi-patch motif generalization analysis for Part E.
  3. This script extends the representative-patch motif proxy by rerunning a small
  4. set of spatially distinct patches with the same lightweight Part E update rules,
  5. then comparing each learned graph to its own biological patch baseline in both
  6. geometry-alignment space and motif-fingerprint space.
  7. """
  8. from __future__ import annotations
  9. import argparse
  10. import sys
  11. from pathlib import Path
  12. import matplotlib.pyplot as plt
  13. import networkx as nx
  14. import numpy as np
  15. import pandas as pd
  16. import scipy.sparse as sp
  17. from scipy.stats import spearmanr
  18. RULE_ORDER = ["EProp", "RewardHebb", "REINFORCE", "Oja"]
  19. RULE_COLORS = {
  20. "EProp": "#0072B2",
  21. "RewardHebb": "#D55E00",
  22. "REINFORCE": "#009E73",
  23. "Oja": "#7A7A7A",
  24. "BioInit": "#111111",
  25. }
  26. FOCAL_TRIADS = ["201", "120U", "300", "021C"]
  27. def import_metrics(raw_root: Path):
  28. sys.path.insert(0, str(raw_root))
  29. from opticflow_partE import metrics # type: ignore
  30. return metrics
  31. def load_inputs(raw_root: Path):
  32. ret_typed = pd.read_parquet(
  33. raw_root / "outputs" / "audit" / "retinotopy_typed.parquet",
  34. columns=["body_id", "mean_u", "mean_v"],
  35. )
  36. nodes = pd.read_parquet(
  37. raw_root / "outputs" / "full_opticlobe_dataset" / "nodes.parquet",
  38. columns=["body_id", "type"],
  39. )
  40. edges = pd.read_parquet(
  41. raw_root / "outputs" / "full_opticlobe_dataset" / "edges.parquet",
  42. columns=["pre_id", "post_id", "weight"],
  43. )
  44. return ret_typed, nodes, edges
  45. def select_patches(ret_typed: pd.DataFrame, num_patches: int, patch_size: int, seed: int) -> list[np.ndarray]:
  46. rng = np.random.default_rng(seed)
  47. all_valid_ids = ret_typed["body_id"].to_numpy()
  48. available_mask = np.ones(len(all_valid_ids), dtype=bool)
  49. node_coords = ret_typed[["mean_u", "mean_v"]].to_numpy(dtype=float)
  50. patches = []
  51. attempts = 0
  52. while len(patches) < num_patches and attempts < 500:
  53. attempts += 1
  54. avail_indices = np.where(available_mask)[0]
  55. if len(avail_indices) < patch_size:
  56. break
  57. center_idx = int(rng.choice(avail_indices))
  58. center = node_coords[center_idx]
  59. dists = np.linalg.norm(node_coords[avail_indices] - center, axis=1)
  60. nearest_local = np.argsort(dists)[:patch_size]
  61. patch_indices = avail_indices[nearest_local]
  62. patches.append(all_valid_ids[patch_indices].copy())
  63. available_mask[patch_indices] = False
  64. return patches
  65. def build_patch_graph(
  66. patch_ids: np.ndarray, ret_typed: pd.DataFrame, nodes: pd.DataFrame, edges: pd.DataFrame
  67. ):
  68. patch_nodes = nodes[nodes["body_id"].isin(patch_ids)].reset_index(drop=True)
  69. patch_nodes = patch_nodes.merge(ret_typed, on="body_id", how="left")
  70. uid_map = {uid: i for i, uid in enumerate(patch_nodes["body_id"].to_numpy())}
  71. patch_edges = edges[edges["pre_id"].isin(uid_map) & edges["post_id"].isin(uid_map)].copy()
  72. rows = patch_edges["pre_id"].map(uid_map).to_numpy(dtype=np.int64)
  73. cols = patch_edges["post_id"].map(uid_map).to_numpy(dtype=np.int64)
  74. weights = patch_edges["weight"].fillna(1.0).to_numpy(dtype=float)
  75. adj_init = sp.csr_matrix((np.full(len(rows), 0.1, dtype=float), (rows, cols)), shape=(len(patch_nodes), len(patch_nodes)))
  76. conn = sp.csr_matrix((weights, (rows, cols)), shape=(len(patch_nodes), len(patch_nodes)))
  77. coords = patch_nodes[["mean_u", "mean_v"]].to_numpy(dtype=float)
  78. r_idx, c_idx = adj_init.nonzero()
  79. d_flat = np.linalg.norm(coords[r_idx] - coords[c_idx], axis=1)
  80. return patch_nodes, adj_init, conn, d_flat, r_idx, c_idx
  81. def compute_geometry_metrics(W_csr: sp.csr_matrix, d_flat: np.ndarray) -> tuple[float, float]:
  82. weights = np.abs(W_csr.data)
  83. if len(weights) == 0:
  84. return 0.0, 0.0
  85. rho = float(np.corrcoef(weights, d_flat)[0, 1]) if len(weights) > 1 else 0.0
  86. q95_w = np.percentile(weights, 95)
  87. q25_d = np.percentile(d_flat, 25)
  88. strong = weights >= q95_w
  89. short = d_flat <= q25_d
  90. short_share = float(np.sum(weights[strong & short]) / (np.sum(weights[strong]) + 1e-9))
  91. return rho, short_share
  92. def compute_ew_norm(W_csr: sp.csr_matrix, d_flat: np.ndarray, mean_d_norm: float) -> float:
  93. weights = np.abs(W_csr.data)
  94. if len(weights) == 0:
  95. return 0.0
  96. total_w = np.sum(weights) + 1e-9
  97. return float((np.sum(weights * d_flat) / total_w) / max(mean_d_norm, 1e-9))
  98. def compute_mean_pair_distance(coords: np.ndarray, seed: int, n_sample: int = 5000) -> float:
  99. rng = np.random.default_rng(seed)
  100. idx_a = rng.integers(0, len(coords), size=n_sample)
  101. idx_b = rng.integers(0, len(coords), size=n_sample)
  102. mean_d = float(np.mean(np.linalg.norm(coords[idx_a] - coords[idx_b], axis=1)))
  103. return mean_d if mean_d > 1e-6 else 1.0
  104. def aggregate_type_graph(W: sp.csr_matrix, patch_nodes: pd.DataFrame) -> pd.DataFrame:
  105. W = W.copy()
  106. W.eliminate_zeros()
  107. coo = W.tocoo()
  108. return (
  109. pd.DataFrame(
  110. {
  111. "pre_type": patch_nodes.iloc[coo.row]["type"].to_numpy(),
  112. "post_type": patch_nodes.iloc[coo.col]["type"].to_numpy(),
  113. "weight_sum": coo.data.astype(float),
  114. }
  115. )
  116. .groupby(["pre_type", "post_type"], as_index=False)["weight_sum"]
  117. .sum()
  118. )
  119. def density_matched_graph(type_df: pd.DataFrame, top_frac: float) -> nx.DiGraph:
  120. sub = type_df[type_df["pre_type"] != type_df["post_type"]].copy()
  121. if sub.empty:
  122. return nx.DiGraph()
  123. k = max(1, int(np.ceil(len(sub) * top_frac)))
  124. sub = sub.nlargest(k, "weight_sum")
  125. g = nx.DiGraph()
  126. for row in sub.itertuples(index=False):
  127. g.add_edge(str(row.pre_type), str(row.post_type), weight=float(row.weight_sum))
  128. return g
  129. def reciprocal_fraction(g: nx.DiGraph) -> float:
  130. if g.number_of_edges() == 0:
  131. return float("nan")
  132. pairs = {tuple(sorted((u, v))) for u, v in g.edges()}
  133. reciprocal = sum(1 for u, v in pairs if g.has_edge(u, v) and g.has_edge(v, u))
  134. return float(reciprocal / max(len(pairs), 1))
  135. def motif_zscores(g: nx.DiGraph, n_nulls: int, seed_base: int) -> dict[str, float]:
  136. real = nx.triadic_census(g)
  137. out = {}
  138. for triad in FOCAL_TRIADS:
  139. vals = []
  140. for i in range(n_nulls):
  141. h = g.copy()
  142. if h.number_of_edges() >= 4:
  143. try:
  144. nswap = min(5 * h.number_of_edges(), 10000)
  145. nx.algorithms.swap.directed_edge_swap(
  146. h, nswap=nswap, max_tries=max(20 * nswap, 1000), seed=seed_base + i
  147. )
  148. except Exception:
  149. pass
  150. vals.append(float(nx.triadic_census(h)[triad]))
  151. mu = float(np.mean(vals))
  152. sd = float(np.std(vals))
  153. out[triad] = (float(real[triad]) - mu) / sd if sd > 0 else float("nan")
  154. return out
  155. def run_rule(
  156. rule: str,
  157. seed: int,
  158. adj: sp.csr_matrix,
  159. d_flat: np.ndarray,
  160. r_idx: np.ndarray,
  161. c_idx: np.ndarray,
  162. metrics,
  163. lam: float = 0.01,
  164. gam: float = 1.0,
  165. n_steps: int = 200,
  166. n_classes: int = 8,
  167. ):
  168. rng = np.random.default_rng(seed)
  169. angles = np.linspace(0, 2 * np.pi, n_classes, endpoint=False)
  170. N = adj.shape[0]
  171. batch_size = 64
  172. W = adj.copy().astype(float)
  173. W_readout = np.zeros((N, n_classes), dtype=float)
  174. lr_plas = 1e-4 if rule == "Oja" else 1e-3
  175. lr_read = 0.01
  176. sigma = 0.001
  177. R_avg = 0.0
  178. e_trace = np.zeros_like(W.data)
  179. alpha = 0.9
  180. node_prefs = rng.random(N) * 2 * np.pi
  181. def fwd(W_c, r):
  182. W_d = W_c.toarray() if sp.issparse(W_c) else W_c
  183. res = r.dot(W_d)
  184. np.maximum(res, 0, out=res)
  185. return res
  186. trace_rows = []
  187. total_forwards = 0
  188. for t in range(n_steps):
  189. target_cls = rng.integers(0, n_classes, size=batch_size)
  190. delta = node_prefs[None, :] - angles[target_cls][:, None]
  191. r_in = np.maximum(np.cos(delta), 0)
  192. if rule == "REINFORCE":
  193. noise = rng.normal(0, sigma, size=W.data.shape)
  194. W_base = W.copy()
  195. W.data = W_base.data + noise
  196. np.maximum(W.data, 0, out=W.data)
  197. rp = fwd(W, r_in)
  198. Ep = np.mean(np.sum(rp, axis=1)) + gam * np.sum(W.data * d_flat)
  199. lp = rp @ W_readout
  200. probs_p = np.exp(lp - np.max(lp, axis=1, keepdims=True))
  201. probs_p /= np.sum(probs_p, axis=1, keepdims=True)
  202. mip = metrics.compute_mi_lb_bits(
  203. np.mean(-np.log2(np.clip(probs_p[np.arange(batch_size), target_cls], 1e-9, 1.0))),
  204. n_classes,
  205. verify=False,
  206. )
  207. Jp = metrics.compute_objective_j(mip, Ep, lam)
  208. W.data = W_base.data - noise
  209. np.maximum(W.data, 0, out=W.data)
  210. rn = fwd(W, r_in)
  211. En = np.mean(np.sum(rn, axis=1)) + gam * np.sum(W.data * d_flat)
  212. ln = rn @ W_readout
  213. probs_n = np.exp(ln - np.max(ln, axis=1, keepdims=True))
  214. probs_n /= np.sum(probs_n, axis=1, keepdims=True)
  215. min_ = metrics.compute_mi_lb_bits(
  216. np.mean(-np.log2(np.clip(probs_n[np.arange(batch_size), target_cls], 1e-9, 1.0))),
  217. n_classes,
  218. verify=False,
  219. )
  220. Jn = metrics.compute_objective_j(min_, En, lam)
  221. grad = (Jp - Jn) / (2 * sigma) * noise
  222. W.data = W_base.data + lr_plas * grad
  223. np.maximum(W.data, 0, out=W.data)
  224. r_out = fwd(W, r_in)
  225. total_forwards += 3
  226. else:
  227. r_out = fwd(W, r_in)
  228. total_forwards += 1
  229. E_tot = np.mean(np.sum(r_out, axis=1)) + gam * np.sum(W.data * d_flat)
  230. logits = r_out @ W_readout
  231. probs = np.exp(logits - np.max(logits, axis=1, keepdims=True))
  232. probs /= np.sum(probs, axis=1, keepdims=True)
  233. ce = np.mean(-np.log2(np.clip(probs[np.arange(batch_size), target_cls], 1e-9, 1.0)))
  234. mi = float(metrics.compute_mi_lb_bits(ce, n_classes, verify=False))
  235. J = float(metrics.compute_objective_j(mi, E_tot, lam))
  236. rp_ = r_in[:, r_idx]
  237. rc_ = r_out[:, c_idx]
  238. hebb = np.mean(rc_ * rp_, axis=0)
  239. if rule == "Oja":
  240. W.data += lr_plas * (hebb - np.mean(rc_**2, axis=0) * W.data)
  241. elif rule == "RewardHebb":
  242. W.data += lr_plas * (J - R_avg) * hebb
  243. R_avg = 0.9 * R_avg + 0.1 * J
  244. elif rule == "EProp":
  245. e_trace = alpha * e_trace + hebb
  246. W.data += lr_plas * (J - R_avg) * e_trace
  247. R_avg = 0.9 * R_avg + 0.1 * J
  248. np.maximum(W.data, 0, out=W.data)
  249. dprob = probs.copy()
  250. dprob[np.arange(batch_size), target_cls] -= 1
  251. W_readout -= lr_read * (r_out.T @ dprob) / batch_size
  252. trace_rows.append(
  253. {
  254. "epoch": t,
  255. "rule": rule,
  256. "seed": seed,
  257. "J": J,
  258. "MI_lb": mi,
  259. "E_total": float(E_tot),
  260. "total_forwards": total_forwards,
  261. }
  262. )
  263. return W.copy(), pd.DataFrame(trace_rows)
  264. def compute_d3z(df_rows: pd.DataFrame, df_bio: pd.DataFrame) -> pd.Series:
  265. metrics_base = ["Ew_norm", "Rho", "ShortShare"]
  266. vec_stats = {}
  267. for m in metrics_base:
  268. pool = np.concatenate([df_rows[m].to_numpy(dtype=float), df_bio[m].to_numpy(dtype=float)])
  269. vec_stats[m] = (float(np.mean(pool)), float(np.std(pool)))
  270. dvals = []
  271. for row in df_rows.itertuples(index=False):
  272. dist_sq = 0.0
  273. bio = df_bio[df_bio["patch_idx"] == row.patch_idx].iloc[0]
  274. for m in metrics_base:
  275. mean, std = vec_stats[m]
  276. std = std if std > 1e-9 else 1.0
  277. z_rule = (getattr(row, m) - mean) / std
  278. z_bio = (bio[m] - mean) / std
  279. dist_sq += (z_rule - z_bio) ** 2
  280. dvals.append(np.sqrt(dist_sq))
  281. return pd.Series(dvals, index=df_rows.index, dtype=float)
  282. def compute_motif_distance(df_rows: pd.DataFrame, df_bio: pd.DataFrame) -> pd.Series:
  283. motif_cols = ["reciprocal_fraction"] + [f"{triad}_z" for triad in FOCAL_TRIADS]
  284. vec_stats = {}
  285. for m in motif_cols:
  286. pool = np.concatenate([df_rows[m].to_numpy(dtype=float), df_bio[m].to_numpy(dtype=float)])
  287. finite = pool[np.isfinite(pool)]
  288. mean = float(np.mean(finite)) if len(finite) else 0.0
  289. std = float(np.std(finite)) if len(finite) else 1.0
  290. vec_stats[m] = (mean, std if std > 1e-9 else 1.0)
  291. dvals = []
  292. for _, row in df_rows.iterrows():
  293. bio = df_bio[df_bio["patch_idx"] == row["patch_idx"]].iloc[0]
  294. dist_sq = 0.0
  295. for m in motif_cols:
  296. mean, std = vec_stats[m]
  297. row_v = row[m]
  298. bio_v = bio[m]
  299. if not np.isfinite(row_v) or not np.isfinite(bio_v):
  300. continue
  301. dist_sq += (((row_v - mean) / std) - ((bio_v - mean) / std)) ** 2
  302. dvals.append(np.sqrt(dist_sq))
  303. return pd.Series(dvals, index=df_rows.index, dtype=float)
  304. def make_figure(
  305. learned: pd.DataFrame,
  306. summary: pd.DataFrame,
  307. corr_rho: float,
  308. corr_p: float,
  309. out_pdf: Path,
  310. out_png: Path,
  311. ) -> None:
  312. fig, axes = plt.subplots(1, 3, figsize=(15.2, 5.2), layout="constrained")
  313. ax = axes[0]
  314. order = RULE_ORDER
  315. xpos = np.arange(len(order))
  316. vals = [summary.loc[summary["rule"] == r, "motif_dist_median"].iloc[0] for r in order]
  317. lo = [summary.loc[summary["rule"] == r, "motif_dist_min"].iloc[0] for r in order]
  318. hi = [summary.loc[summary["rule"] == r, "motif_dist_max"].iloc[0] for r in order]
  319. ax.bar(xpos, vals, color=[RULE_COLORS[r] for r in order], edgecolor="black", linewidth=0.8)
  320. ax.errorbar(xpos, vals, yerr=[np.array(vals) - np.array(lo), np.array(hi) - np.array(vals)], fmt="none", ecolor="black", capsize=3)
  321. ax.set_xticks(xpos, order, rotation=20, ha="right")
  322. ax.set_ylabel("Motif-fingerprint distance to patch connectome")
  323. ax.set_title("Lower is closer to the biological patch")
  324. ax.grid(axis="y", alpha=0.25)
  325. ax = axes[1]
  326. heat = summary.set_index("rule")[["reciprocal_fraction_median"] + [f"{triad}_z_median" for triad in FOCAL_TRIADS]].reindex(order)
  327. finite = heat.to_numpy()[np.isfinite(heat.to_numpy())]
  328. vmax = 2.0 if finite.size == 0 else float(np.nanpercentile(np.abs(finite), 95))
  329. im = ax.imshow(heat.to_numpy(), aspect="auto", cmap="coolwarm", vmin=-vmax, vmax=vmax)
  330. ax.set_xticks(np.arange(1 + len(FOCAL_TRIADS)), ["recip"] + FOCAL_TRIADS)
  331. ax.set_yticks(np.arange(len(order)), order)
  332. ax.set_title("Median motif fingerprint across patches")
  333. for i in range(len(order)):
  334. for j in range(1 + len(FOCAL_TRIADS)):
  335. val = heat.iloc[i, j]
  336. text = "nan" if not np.isfinite(val) else f"{val:.2f}"
  337. ax.text(j, i, text, ha="center", va="center", fontsize=8)
  338. cbar = fig.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
  339. cbar.set_label("Metric value")
  340. ax = axes[2]
  341. for rule in order:
  342. sub = learned[learned["rule"] == rule]
  343. ax.scatter(
  344. sub["D_3z"],
  345. sub["motif_dist_to_bio"],
  346. label=rule,
  347. color=RULE_COLORS[rule],
  348. s=55,
  349. alpha=0.85,
  350. edgecolor="black",
  351. linewidth=0.4,
  352. )
  353. ax.set_xlabel("Geometry alignment distance $D_{3z}$")
  354. ax.set_ylabel("Motif-fingerprint distance to patch connectome")
  355. ax.set_title(f"Across learned graphs: Spearman $\\rho={corr_rho:.2f}$, $p={corr_p:.3f}$")
  356. ax.grid(alpha=0.25)
  357. ax.legend(frameon=False, fontsize=9, loc="lower center", bbox_to_anchor=(0.5, -0.30), ncol=2)
  358. fig.suptitle("Multi-patch motif generalization of learned Part E connectomes", fontsize=13)
  359. fig.savefig(out_pdf, bbox_inches="tight")
  360. fig.savefig(out_png, dpi=600, bbox_inches="tight")
  361. plt.close(fig)
  362. def write_report(
  363. summary: pd.DataFrame,
  364. learned: pd.DataFrame,
  365. corr_rho: float,
  366. corr_p: float,
  367. out_md: Path,
  368. ) -> None:
  369. lines = []
  370. lines.append("# Part E Multi-patch Motif Generalization\n\n")
  371. lines.append("- Source: deterministic rerun of spatially distinct 1000-node patches using the archived patch-generalization regime (`lambda=0.01`, `gamma=1.0`, 8-way motion task).\n")
  372. lines.append("- For each patch we compared learned motif fingerprints to the corresponding biological patch graph after type-level aggregation and density matching.\n")
  373. lines.append(f"- Across learned graphs, motif distance and geometry-alignment distance are related with Spearman rho = {corr_rho:.2f} (p = {corr_p:.3g}).\n\n")
  374. lines.append("| Rule | Patches | Median motif distance | Median D_3z | Median reciprocity |\n")
  375. lines.append("|---|---:|---:|---:|---:|\n")
  376. for row in summary.itertuples(index=False):
  377. lines.append(
  378. f"| {row.rule} | {row.n_patches} | {row.motif_dist_median:.3f} | "
  379. f"{row.D_3z_median:.3f} | {row.reciprocal_fraction_median:.3f} |\n"
  380. )
  381. lines.append("\n")
  382. motif_wins = learned.pivot(index="patch_idx", columns="rule", values="motif_dist_to_bio").idxmin(axis=1).value_counts()
  383. geom_wins = learned.pivot(index="patch_idx", columns="rule", values="D_3z").idxmin(axis=1).value_counts()
  384. lines.append("Interpretation:\n")
  385. lines.append("- This analysis moves beyond a single representative patch: each rule is evaluated across multiple spatially distinct patches against its own biological motif baseline.\n")
  386. lines.append("- Lower motif distance means the learned graph stays closer to the biological patch in combined reciprocity and triad-enrichment space.\n")
  387. lines.append(
  388. f"- Geometry alignment and motif similarity partly dissociate in this rerun: EProp gives the lowest $D_{{3z}}$ on all {learned['patch_idx'].nunique()} patches, "
  389. f"whereas the motif-fingerprint winner is REINFORCE on {int(motif_wins.get('REINFORCE', 0))} patches, RewardHebb on {int(motif_wins.get('RewardHebb', 0))}, and EProp on {int(motif_wins.get('EProp', 0))}.\n"
  390. )
  391. lines.append("- The weak overall D_3z-to-motif correlation shows that motif resemblance is an additional descriptor of learned solutions rather than a simple restatement of the geometry-alignment score.\n")
  392. lines.append("- The analysis is still type-level rather than cell-level, but it is no longer confined to one patch.\n")
  393. out_md.write_text("".join(lines))
  394. def main() -> None:
  395. ap = argparse.ArgumentParser()
  396. ap.add_argument("--raw_root", required=True)
  397. ap.add_argument("--fig_dir", required=True)
  398. ap.add_argument("--table_dir", required=True)
  399. ap.add_argument("--report_dir", required=True)
  400. ap.add_argument("--n_patches", type=int, default=5)
  401. ap.add_argument("--patch_size", type=int, default=1000)
  402. ap.add_argument("--top_frac", type=float, default=0.2)
  403. ap.add_argument("--n_nulls", type=int, default=10)
  404. ap.add_argument("--seed", type=int, default=42)
  405. args = ap.parse_args()
  406. raw_root = Path(args.raw_root).expanduser().resolve()
  407. fig_dir = Path(args.fig_dir).expanduser().resolve()
  408. table_dir = Path(args.table_dir).expanduser().resolve()
  409. report_dir = Path(args.report_dir).expanduser().resolve()
  410. for d in [fig_dir / "pdf", fig_dir / "png", table_dir, report_dir]:
  411. d.mkdir(parents=True, exist_ok=True)
  412. metrics = import_metrics(raw_root)
  413. ret_typed, nodes, edges = load_inputs(raw_root)
  414. patches = select_patches(ret_typed, args.n_patches, args.patch_size, args.seed)
  415. if not patches:
  416. raise RuntimeError("No patches selected for motif generalization analysis")
  417. learned_rows = []
  418. bio_rows = []
  419. trace_rows = []
  420. for patch_idx, patch_ids in enumerate(patches):
  421. patch_nodes, adj_init, conn, d_flat, r_idx, c_idx = build_patch_graph(patch_ids, ret_typed, nodes, edges)
  422. coords = patch_nodes[["mean_u", "mean_v"]].to_numpy(dtype=float)
  423. mean_d = compute_mean_pair_distance(coords, seed=args.seed + patch_idx)
  424. bio_type = aggregate_type_graph(conn.copy(), patch_nodes)
  425. bio_graph = density_matched_graph(bio_type, args.top_frac)
  426. bio_z = motif_zscores(bio_graph, args.n_nulls, seed_base=1000 + 100 * patch_idx)
  427. bio_rho, bio_short = compute_geometry_metrics(conn, d_flat)
  428. bio_rows.append(
  429. {
  430. "patch_idx": patch_idx,
  431. "rule": "BioInit",
  432. "Ew_norm": compute_ew_norm(conn, d_flat, mean_d),
  433. "Rho": bio_rho,
  434. "ShortShare": bio_short,
  435. "reciprocal_fraction": reciprocal_fraction(bio_graph),
  436. **{f"{triad}_z": bio_z[triad] for triad in FOCAL_TRIADS},
  437. }
  438. )
  439. for rule in RULE_ORDER:
  440. seed = args.seed + 1000 * patch_idx
  441. W_final, trace_df = run_rule(rule, seed, adj_init, d_flat, r_idx, c_idx, metrics)
  442. trace_df["patch_idx"] = patch_idx
  443. trace_rows.append(trace_df)
  444. sp.save_npz(table_dir / f"patch{patch_idx}_{rule}_final_weights.npz", W_final)
  445. type_df = aggregate_type_graph(W_final, patch_nodes)
  446. type_df.to_csv(table_dir / f"patch{patch_idx}_{rule}_type_graph.csv", index=False)
  447. g = density_matched_graph(type_df, args.top_frac)
  448. z = motif_zscores(g, args.n_nulls, seed_base=2000 + 1000 * patch_idx + 100 * RULE_ORDER.index(rule))
  449. rho, short = compute_geometry_metrics(W_final, d_flat)
  450. learned_rows.append(
  451. {
  452. "patch_idx": patch_idx,
  453. "rule": rule,
  454. "Ew_norm": compute_ew_norm(W_final, d_flat, mean_d),
  455. "Rho": rho,
  456. "ShortShare": short,
  457. "reciprocal_fraction": reciprocal_fraction(g),
  458. **{f"{triad}_z": z[triad] for triad in FOCAL_TRIADS},
  459. }
  460. )
  461. print(f"[OK] patch {patch_idx} rule {rule}")
  462. learned = pd.DataFrame(learned_rows)
  463. bio = pd.DataFrame(bio_rows)
  464. learned["D_3z"] = compute_d3z(learned, bio)
  465. learned["motif_dist_to_bio"] = compute_motif_distance(learned, bio)
  466. corr = spearmanr(learned["D_3z"], learned["motif_dist_to_bio"], nan_policy="omit")
  467. corr_rho = float(corr.statistic) if np.isfinite(corr.statistic) else float("nan")
  468. corr_p = float(corr.pvalue) if np.isfinite(corr.pvalue) else float("nan")
  469. summary = (
  470. learned.groupby("rule", as_index=False)
  471. .agg(
  472. n_patches=("patch_idx", "nunique"),
  473. motif_dist_median=("motif_dist_to_bio", "median"),
  474. motif_dist_min=("motif_dist_to_bio", "min"),
  475. motif_dist_max=("motif_dist_to_bio", "max"),
  476. D_3z_median=("D_3z", "median"),
  477. reciprocal_fraction_median=("reciprocal_fraction", "median"),
  478. **{f"{triad}_z_median": (f"{triad}_z", "median") for triad in FOCAL_TRIADS},
  479. )
  480. .reset_index(drop=True)
  481. )
  482. learned.to_csv(table_dir / "patch_motif_generalization_rows.csv", index=False)
  483. bio.to_csv(table_dir / "patch_motif_bio_rows.csv", index=False)
  484. summary.to_csv(table_dir / "patch_motif_generalization_summary.csv", index=False)
  485. pd.concat(trace_rows, ignore_index=True).to_csv(table_dir / "patch_motif_generalization_traces.csv", index=False)
  486. make_figure(
  487. learned,
  488. summary,
  489. corr_rho,
  490. corr_p,
  491. fig_dir / "pdf" / "FigE9_MotifGeneralization.pdf",
  492. fig_dir / "png" / "FigE9_MotifGeneralization.png",
  493. )
  494. write_report(summary, learned, corr_rho, corr_p, report_dir / "partE_patch_motif_generalization_report.md")
  495. print("[OK] wrote multi-patch motif generalization outputs and FigE9")
  496. if __name__ == "__main__":
  497. main()

make_partE_patch_motif_generalization.py at commit 19bcd7d, no license · at the source

Overview

Authors: Nalin Dhiman1, Siddharth Panwar1
  1. School of Computing and Electrical Engineering, Indian Institute of Technology Mandi,Mandi, India
Journal: Scientific reports, volume 16, issue 1, article 22754
Dates: received 12 March 2026; accepted 4 May 2026; published online 19 May 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41598-026-52140-3 · PMID 42156870 · PMCID PMC13385933 · OpenAlex W7161631646
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: drosophila (organism), cellular / molecular (subfield)
Methods: Machine learning
Keywords: Computational biology and bioinformatics, Neuroscience, Physics
MeSH: Connectome*, Drosophila*, Drosophila melanogaster*, Energy Metabolism*, Neuronal Plasticity*, Optic Lobe, Nonmammalian*, Animals (* major topic)
Topic: Neural Networks and Reservoir Computing (Artificial Intelligence, Computer Science), according to OpenAlex
Citations: not cited yet (Europe PMC); 22 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above, with 14 matches between paragraphs and lines of code.

nalin-dhiman/Energy-efficient-information-processing-and-eligibility

License: none: the authors keep all their rights
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Commit: 19bcd7d83a044f90ad691bff5bfe1df636b7150a, 26 May 2026
Languages: Python (33)
Size: 267 files, 33 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README, environment (partA_figures_package/partA_figures/REQUIREMENTS.txt, partD_pubready_package/scripts/requirements_partD.txt, partB_pubready_package/partB_pubready/scripts/requirements.txt, partE_pubready_package/partE_pubready/scripts/requirements.txt)
Not found: license file, CITATION.cff, tests, continuous integration, documentation
Tools: NumPy (27 files), pandas (20 files), Matplotlib (14 files), SciPy (7 files), scikit-learn (4 files), NetworkX (2 files), PyTorch (2 files), seaborn (1 file)
Availability: 1 check, the latest on 28 September 2026: the link answers
  • 28 September 2026: the link answers
34 files

Code availability statement

The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41598-026-52140-3.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 33 scripts, each with its path and the digest of its content;
  • 14 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data availability statement

The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

  • no repository, dataset or request procedure was recognized in it

Read it in the paper: doi.org/10.1038/s41598-026-52140-3.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 28 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 2 authors, 3 keywords, 7 MeSH terms, 17 references.

Cite

This paper

Dhiman, N., & Panwar, S. (2026). Energy-efficient information processing and eligibility-trace plasticity in the Drosophila optic lobe connectome. Scientific reports, 16(1), 22754. https://doi.org/10.1038/s41598-026-52140-3

BibTeX

@article{dhiman2026energy,
author = {Dhiman, Nalin and Panwar, Siddharth},
title = {{Energy-efficient information processing and eligibility-trace plasticity in the Drosophila optic lobe connectome}},
journal = {Scientific reports},
year = {2026},
month = may,
volume = {16},
number = {1},
pages = {22754},
publisher = {Nature Publishing Group},
issn = {2045-2322},
doi = {10.1038/s41598-026-52140-3},
url = {https://doi.org/10.1038/s41598-026-52140-3},
pmid = {42156870},
pmcid = {PMC13385933}
}

RIS

TY - JOUR
AU - Dhiman, Nalin
AU - Panwar, Siddharth
TI - Energy-efficient information processing and eligibility-trace plasticity in the Drosophila optic lobe connectome
T2 - Scientific reports
J2 - Sci Rep
PY - 2026
DA - 2026/05/19
VL - 16
IS - 1
SP - 22754
SN - 2045-2322
PB - Nature Publishing Group
DO - 10.1038/s41598-026-52140-3
UR - https://doi.org/10.1038/s41598-026-52140-3
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41598-026-52140-3",
"type": "article-journal",
"title": "Energy-efficient information processing and eligibility-trace plasticity in the Drosophila optic lobe connectome",
"container-title": "Scientific reports",
"author": [
{
"family": "Dhiman",
"given": "Nalin"
},
{
"family": "Panwar",
"given": "Siddharth"
}
],
"container-title-short": "Sci Rep",
"volume": "16",
"issue": "1",
"page": "22754",
"DOI": "10.1038/s41598-026-52140-3",
"PMID": "42156870",
"PMCID": "PMC13385933",
"ISSN": "2045-2322",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41598-026-52140-3",
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
19
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41586-026-10735-w [code]
Distributed control circuits across a brain-and-cord connectome.
Journal: Nature
In common: NetworkX, PyTorch, seaborn, 5 other tools, drosophila, 2 references
[2] doi:10.3389/fnsys.2026.1822122 [code]
Convergence-divergence circuits for multimodal integration of innate and learned opponent valences.
Journal: Frontiers in systems neuroscience
In common: NetworkX, PyTorch, seaborn, 5 other tools, 2 references
[3] doi:10.1371/journal.pone.0348005 [code]
THOI: An efficient and accessible library for computing higher-order interactions enhanced by batch-processing.
Journal: PloS one
In common: NetworkX, PyTorch, seaborn, 5 other tools, 1 reference
[4] doi:10.1038/s41467-026-72152-x [code]
Centralized brain networks controlling antennal grooming coordination.
Journal: Nature communications
In common: NetworkX, seaborn, scikit-learn, 4 other tools, drosophila, 1 reference
[5] doi:10.1073/pnas.2531706123 [code]
Metabolism-weighted brain connectome reveals synaptic integration and vulnerability to neurodegeneration.
Journal: Proceedings of the National Academy of Sciences of the United States of America
In common: NetworkX, seaborn, scikit-learn, 4 other tools, cellular / molecular, 1 reference
[6] doi:10.1038/s42003-026-10957-8 [code]
Brain defence by the extracellular matrix protein Cochlin.
Journal: Communications biology
In common: NetworkX, PyTorch, seaborn, 5 other tools, cellular / molecular
[7] doi:10.1038/s41467-026-76841-5 [code]
Stable clique membership in male mouse societies requires oxytocin-enabled social sensory states.
Journal: Nature communications
In common: NetworkX, PyTorch, seaborn, 5 other tools, cellular / molecular
[8] doi:10.1186/s12864-026-12965-8 [code]
Systematic evaluation of single-cell foundation model interpretability: attention-derived edge scores add no incremental value over gene-level features for perturbation-target prediction.
Journal: BMC genomics
In common: NetworkX, PyTorch, seaborn, 5 other tools, cellular / molecular
[9] doi:10.1038/s41467-026-71759-4 [code]
CellNiche represents cellular microenvironments in atlas-scale spatial omics data with contrastive learning.
Journal: Nature communications
In common: NetworkX, PyTorch, seaborn, 5 other tools, cellular / molecular
[10] doi:10.1101/gr.281350.125 [code]
High-fidelity bidirectional translation between single-cell transcriptomes and DNA methylomes with scBOND.
Journal: Genome research
In common: NetworkX, PyTorch, seaborn, 5 other tools, cellular / molecular

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.