# Natural-image population spectra in a connectome-constrained fly visual system model Mouse V1 responds to natural images with a population variance spectrum λ_n ∝ n^(-α), α ≈ 1, and keeps α ≈ 1 when the images are whitened ([Stringer et al. 2019](https://www.nature.com/articles/s41586-019-1346-5)). This repository asks the same question of [flyvis](https://github.com/TuragaLab/flyvis) ([Lappalainen et al. 2024](https://www.nature.com/articles/s41586-024-07939-3)), a model of the fly optic lobe whose wiring comes from an electron-microscopy connectome: 64 cell types repeated over 721 columns (45,669 graded neurons), with the unknown physiology trained on optic flow. It contains the code and derived results for the fly-model part of a longer write-up. ![main result](figures/out/fly_main.png) ## Findings (MODEL; 50 trained flyvis models) - **Natural images give α near 1 on a rank-matched window.** Every neuron is driven by the same 721 photoreceptor columns, so spectra bend down towards rank 721. On PCs 11 to 100 the whole network gives α = 1.18 (median over 50 models, IQR 1.05 to 1.29); on Stringer's PCs 11 to 500 it gives 1.43 (IQR 1.29 to 1.58). - **Unlike V1, the exponent collapses for whitened images**: every layer drops to α = 0.25 to 0.38 (PCs 11 to 100) in all 50 models, while V1 stays at about 1.03. - **The fly exponent is inherited from the input.** Layer α tracks photoreceptor-input α across natural, whitened, flat, 8-D and 4-D image sets. Layers pass on 76% (T4/T5) to 98% (photoreceptors) of the input's change under whitening; V1 passes on about 0%. - **Through linear filtering.** A small-signal (linearised) copy of model 000 reproduces the full network's exponents within 0.03; an untrained network with connectome wiring collapses under whitening in the same way. - **Measurement caveat.** With mouse-like single-trial SNR (median 0.12), cvPCA on two noisy repeats cannot recover the fly spectra; it does at SNR ≥ 10. - Better motion models have flatter spectra (Spearman ρ = 0.44 between α and task rank; 0.60 for T4/T5). For gratings, smoothing the ReLU (softplus) steepens tuning-curve Fourier tails (median exponent 5.4 to 8.8). ![controls](figures/out/fly_controls.png) ## Contents | path | what | |---|---| | `fly_spectra/fast_sim.py` | Sparse re-implementation of the flyvis dynamics, τ dV/dt = -V + b + Σ w ReLU(V) + x (Euler, dt = 20 ms), with optional softplus and a small-signal mode; `check_dynamics` compares it with `flyvis.Network.simulate` (max abs. error 2.4e-6) | | `fly_spectra/fly_sim.py` | Model loading (trained and untrained), stimulus sets, BoxEye and Gaussian rendering onto the hexagonal eye, layer groups | | `fly_spectra/powerlaw.py` | Stringer et al.'s power-law fit (weighted log-log, PCs 11 to 500) and shuffled cvPCA, ported from their MATLAB code | | `fly_spectra/spectra.py` | Per-type and per-layer spectra, half-sample confidence intervals, noisy-repeat cvPCA | | `scripts/prep_stimuli.py` | Builds the photoreceptor inputs for every stimulus set | | `scripts/run_models.py` | Flashes each image for 500 ms from grey and computes spectra per model (`--models`, `--untrained`, `--linear`, `--act softplus`) | | `scripts/aggregate.py`, `noise_check.py`, `whitening_noise_check.py`, `gratings.py`, `check_dynamics.py` | Ensemble summary and controls | | `scripts/export_figdata.py`, `figures/make_fly_figs.m` | Figure data and MATLAB figures | | `results/` | Per-model results (JSON), summary, controls, figure data | | `resources/mouse_snr_pool.npy` | Per-neuron single-trial SNR of mouse V1 (derived from Stringer et al. 2019 data) used for the noise control | ## Reproducing ```bash pip install -r requirements.txt flyvis download-pretrained --skip_large_files # 50 trained models (see flyvis docs; set FLYVIS_ROOT_DIR) # Stringer et al. 2019 images: figshare 6845348, files images_natimg2800_all.mat, # images_natimg2800_white_all.mat and the per-recording 8-D / 4-D image files -> $FLY_SPECTRA_DATA/stringer2019/ python scripts/check_dynamics.py python scripts/prep_stimuli.py python scripts/run_models.py --models 0,1,2 --conds nat_c68,white_c68 --save_full python scripts/aggregate.py python scripts/export_figdata.py && matlab -batch "cd figures; make_fly_figs" ``` Paths are read from `FLY_SPECTRA_DATA` (default `./data`), `FLY_SPECTRA_RESULTS` (default `./results`) and `FLYVIS_ROOT_DIR`. The 50-model run takes about 4 minutes per model and condition on 4 CPU threads. ## Data and licences Code: GPL-3.0 (`powerlaw.py` ports functions from [MouseLand/stringer-pachitariu-et-al-2018b](https://github.com/MouseLand/stringer-pachitariu-et-al-2018b), GPL-3.0). flyvis is MIT-licensed and is used as a dependency. The Stringer et al. image data (figshare 6845348) are CC BY-NC 4.0 and are not redistributed here; `resources/mouse_snr_pool.npy` and the mouse reference values in `scripts/export_figdata.py` are derived from them. ## Citation Stringer, Pachitariu, Steinmetz, Carandini & Harris (2019) High-dimensional geometry of population responses in visual cortex. *Nature* 571, 361-365. Lappalainen et al. (2024) Connectome-constrained networks predict neural activity across the fly visual system. *Nature* 634, 1132-1140.