Skip to content

Cap auto-selected EMGFromLFP channels when there are many spike groups - #33

Merged
ryanharvey1 merged 4 commits into
masterfrom
emg-from-lfp-many-spike-groups
Nov 20, 2026
Merged

ryanharvey1 merged 4 commits into
masterfrom
emg-from-lfp-many-spike-groups

Conversation

@ryanharvey1

@ryanharvey1 ryanharvey1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

getEMGFromLFP picks one channel per spike group and correlates every channel pair, so the work grows with the square of the number of spike groups. A layout with 42 spike groups gives 42 channels and 861 pairs, compared with 6-28 pairs for 4-8 groups.

  • New 'maxAutoChannels' option (default 16). With more usable spike groups than that, use that many groups spread evenly over the spike-group list. Recordings with <= 16 usable groups take the unchanged selection path and consume the RNG identically, so they get the same channels. specialChannels are still added on top; inf disables the cap.
  • Replace the per-bin corr() loop with blocked, vectorised Pearson correlations (same formula, NaN for flat windows). Values match the former loop to rounding error (<1e-12 in the regression tests).
  • Record the selection in EMGFromLFP.detectorinfo.
  • Call loadBinary with its actual case so the function runs on Linux.
  • Tests compare layouts with few spike groups against a frozen copy of the former implementation and check the cap on a 42-group layout.

CI: ubuntu-latest moved to Ubuntu 26.04, where setup-matlab@v1 no longer installs or activates MATLAB. The runner is pinned to ubuntu-24.04, setup-matlab is now v2 with release R2025b and the toolboxes the tests need, and MATLAB runs through matlab-actions/run-command@v2 so the CI licence applies.

Checks on a 42-spike-group, 257-channel, 8.2 h recording:

  • With the same channels, the new correlation code matches the old loop to 4e-16, and CellExplorer's ce_EMGFromLFP to 3e-16 (full session, 16 channels) or better (10-min and 1-min windows, 2 to 42 channels).
  • Default run time on the full session goes from about 37 min (extrapolated) to 8.7 min.

getEMGFromLFP picks one channel per spike group and correlates every
channel pair, so the work grows with the square of the number of spike
groups. A layout with 42 spike groups gives 42 channels and 861 pairs,
compared with 6-28 pairs for 4-8 groups.

- New 'maxAutoChannels' option (default 16). With more usable spike
  groups than that, use that many groups spread evenly over the
  spike-group list. Recordings with <= 16 usable groups take the
  unchanged selection path and consume the RNG identically, so they get
  the same channels. specialChannels are still added on top; inf
  disables the cap.
- Replace the per-bin corr() loop with blocked, vectorised Pearson
  correlations (same formula, NaN for flat windows). Values match the
  former loop to rounding error (<1e-12 in the regression tests).
- Record the selection in EMGFromLFP.detectorinfo.
- Call loadBinary with its actual case so the function runs on Linux.
- Tests compare layouts with few spike groups against a frozen copy of
  the former implementation and check the cap on a 42-group layout.
ubuntu-latest now resolves to Ubuntu 26.04, where setup-matlab@v1
installs the latest MATLAB release with an installer that is no longer
supported, and activation fails before any test runs.

- Pin the runner to ubuntu-24.04.
- Use setup-matlab@v2 with a pinned release (R2025b) and the toolboxes
  the tests need (Signal Processing, DSP System, Statistics and Machine
  Learning); v2 installs only MATLAB unless products are listed.
- Update actions/checkout to v4.
With setup-matlab@v2, calling matlab -batch from a shell step finds no
license ("Unable to find a license for MATLAB"). Public repositories are
licensed only through the matlab-actions run steps, so compile the MEX
files and run the tests with matlab-actions/run-command@v2.
LFPfromDat calls gpuDeviceCount (useGPU defaults to true) and its
progress reporter uses parallel.pool.DataQueue, both from Parallel
Computing Toolbox, so test_LFPfromDat errors without it.
@ryanharvey1
ryanharvey1 merged commit 1e2fd92 into master Nov 20, 2026
1 check passed
@ryanharvey1
ryanharvey1 deleted the emg-from-lfp-many-spike-groups branch November 20, 2026 14:28
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