Skip to content

Ship precomputed response normalization constants - #24

Merged
lappalainenj merged 1 commit into
mainfrom
precomputed-response-norms
Aug 6, 2026
Merged

Ship precomputed response normalization constants#24
lappalainenj merged 1 commit into
mainfrom
precomputed-response-norms

Conversation

@lappalainenj

Copy link
Copy Markdown
Contributor

Computing a model's response normalization constant requires simulating ~30 minutes of naturalistic stimuli, which has to be done for every model of an ensemble before figures that normalize responses can be drawn. That is infeasible on a laptop and made the paper figures effectively unreproducible outside a cluster, even though the constants themselves are only a handful of floats per model.

Store them instead:

  • Constants for the released ensemble ship with the package in flyvis/data/responses_norm.h5 (57 kB) and are loaded silently.
  • Constants computed for any other ensemble are written to <ensemble_dir>/responses_norm.h5, so a custom ensemble pays the cost once.
  • Ensemble.responses_norm resolves both before falling back to simulating.

Constants are keyed by model name and validated against the SHA256 of the checkpoint their responses were computed from, so the order of an ensemble is irrelevant and a checkpoint retrained in place -- or an unrelated ensemble trained into a directory of the same name -- is recomputed rather than silently normalized with foreign constants. The values are bit-identical to what the previous inline implementation computed.

Add flyvis responses-norm to compute and store the constants of an ensemble.

Also add examples/figure_04_top_models.py, which reproduces figure 4a,b for the models with the lowest task error rather than the task-optimal cluster, plus the plotting support it needs: angular_tuning returns the unnormalized tuning, plot_angular_tuning gains model_reduction to reduce across models with e.g. the median and normalize_by to put several curves on a shared scale.

Computing a model's response normalization constant requires simulating ~30
minutes of naturalistic stimuli, which has to be done for every model of an
ensemble before figures that normalize responses can be drawn. That is
infeasible on a laptop and made the paper figures effectively unreproducible
outside a cluster, even though the constants themselves are only a handful of
floats per model.

Store them instead:

- Constants for the released ensemble ship with the package in
  flyvis/data/responses_norm.h5 (57 kB) and are loaded silently.
- Constants computed for any other ensemble are written to
  <ensemble_dir>/responses_norm.h5, so a custom ensemble pays the cost once.
- Ensemble.responses_norm resolves both before falling back to simulating.

Constants are keyed by model name and validated against the SHA256 of the
checkpoint their responses were computed from, so the order of an ensemble is
irrelevant and a checkpoint retrained in place -- or an unrelated ensemble
trained into a directory of the same name -- is recomputed rather than
silently normalized with foreign constants. The values are bit-identical to
what the previous inline implementation computed.

Add `flyvis responses-norm` to compute and store the constants of an ensemble.

Also add examples/figure_04_top_models.py, which reproduces figure 4a,b for
the models with the lowest task error rather than the task-optimal cluster,
plus the plotting support it needs: `angular_tuning` returns the unnormalized
tuning, `plot_angular_tuning` gains `model_reduction` to reduce across models
with e.g. the median and `normalize_by` to put several curves on a shared
scale.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@lappalainenj
lappalainenj merged commit 6fde329 into main Aug 6, 2026
4 checks passed
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.76684% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.68%. Comparing base (b0b3365) to head (e44dfdc).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
flyvis/analysis/response_norms.py 67.06% 55 Missing ⚠️
flyvis/analysis/moving_bar_responses.py 14.28% 12 Missing ⚠️
flyvis/network/ensemble.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
+ Coverage   38.07%   38.68%   +0.61%     
==========================================
  Files          74       75       +1     
  Lines        9574     9738     +164     
==========================================
+ Hits         3645     3767     +122     
- Misses       5929     5971      +42     
Flag Coverage Δ
unittests 38.68% <64.76%> (+0.61%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant