Skip to content

Give NEMAR's prompt the ERP low-pass as code - #485

Merged
neuromechanist merged 4 commits into
developfrom
fix/nemar-erp-kernel
Sep 24, 2026
Merged

neuromechanist merged 4 commits into
developfrom
fix/nemar-erp-kernel

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Found in the staging test on test.nemar.org/dataset/xx099906 (develop, 0.8.14.dev16), asking for "an ERP image of sub-01's SiB recording, one panel per condition".

What went wrong

The whole path worked: nemar_get_events with limit: 1, then columns, the event indices written into the code, reads from zarr-test, six code runs in one reply, and a four-condition figure. But the averages were dominated by high-frequency ripple, because the model wrote the prompt's windowed-sinc low-pass as

kernel = np.sinc(np.arange(tap_len) - tap_len // 2) * cutoff

np.sinc of whole numbers is zero everywhere but the center, so that kernel is a single spike: its gain at 50 Hz is 1.0, and nothing was filtered. The prompt said "np.sinc times np.hamming" and left the argument to the model. The figure also had its time axis in samples, and the reply called the result "P300-like" on averages that do not support it.

The change

  • The kernel is in the prompt as code, with the cutoff (np.sinc(2 * 30 / rate * n)) and one sentence saying what happens without it.
  • The ERP image's time axis is in milliseconds (extent from -200 to 800).
  • Deflections before names: the model describes latency and size, and names a component only when the dataset or its paper says the task evokes it.

Test

frontend/test-data-lane.js takes the python block out of the prompt's ERP section and runs it, as written, in real Pyodide at 250 Hz: 101 taps, gain 1.000 at 5 Hz and 0.0007 at 50 Hz, and a 5 Hz plus 50 Hz sine comes out as the 5 Hz sine to within 0.0007, unshifted.

Mutation: replacing the prompt's kernel line with np.sinc(n) * np.hamming(taps), the model's version, fails two checks (gain 1.0 at 50 Hz; residual 0.95).

  • bun frontend/test-data-lane.js: 66 passed
  • mutation fails 2, restored
  • pytest tests/test_assistants/test_nemar_runtime.py tests/test_assistants/test_nemar_mcp_wiring.py tests/test_core: 616 passed
  • ruff check .

Ships in 0.8.14 with the rest of the ERP work (#483).

In a staging run on test.nemar.org/dataset/xx099906 the model wrote np.sinc(n) * np.hamming(taps) from the prose, which is a single spike: its gain at 50 Hz is 1.0, so every ERP image it drew was unfiltered. The prompt now carries the kernel as a python block with the cutoff (np.sinc(2 * 30 / rate * n)), puts the ERP image's time axis in milliseconds, and asks for deflections with latency and size before naming a component.

test-data-lane.js runs that block as the prompt writes it in real Pyodide: 101 taps at 250 Hz, gain 1.000 at 5 Hz and 0.0007 at 50 Hz, and a 5 Hz plus 50 Hz sine comes out as the 5 Hz sine.

Tested: bun frontend/test-data-lane.js 66/66; mutated the prompt to np.sinc(n), 2 checks fail; pytest test_nemar_runtime, test_nemar_mcp_wiring, test_core 616 passed; ruff clean.
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

Name Link
Preview URL https://fix-nemar-erp-kernel-demo.osc.earth
Branch fix/nemar-erp-kernel
Commit 5edb3eb

This preview will be updated automatically when you push new commits.

Review of #485: at 60 Hz the 30 Hz cutoff reaches the Nyquist frequency and the kernel is a spike again, and at 5000 Hz np.convolve with 2001 taps is too slow for a browser. The prompt's filter clamps the cutoff to rate / 4 and convolves by FFT, which equals np.convolve(x, kernel, "same") and takes a channels-by-samples array. The test runs the block at 60, 125, 250, 1000 and 5000 Hz, compares it with np.convolve and row by row, and requires the block to follow the ERP bullet's opening lines.

Tested: bun frontend/test-data-lane.js 93/93; mutations (no clamp, np.sinc(k), slice off by one) fail 2, 6+ and 6+ checks; pytest nemar runtime and wiring pass.
@neuromechanist

Copy link
Copy Markdown
Member Author

Review response

One Sonnet review, no blocking findings. Every point is addressed in 5311f56.

  • No Nyquist guard. At 60 Hz a 30 Hz cutoff sits at the Nyquist frequency and the kernel is a single spike again; below that it amplifies. The cutoff is now min(30.0, rate / 4), and the test runs at 60 Hz (cutoff 15 Hz, gain 0.0014 at 27 Hz). Removing the clamp fails the 60 Hz checks.
  • 2001 taps at 5000 Hz. np.convolve is direct, too slow for a long recording in a browser. The prompt now convolves by FFT (numpy has np.fft, so SciPy is not needed): the same values as np.convolve(x, kernel, "same") to within 5e-15, and it takes a channels-by-samples array, so the "one channel at a time" caveat is gone. 10 minutes at 5000 Hz takes 0.13 s in native numpy.
  • Only 250 Hz exercised. The test runs the block at 60, 125, 250, 1000 and 5000 Hz, and at each rate also checks it against np.convolve and row by row on a two-channel array.
  • No upper bound on the fence search. The block must start within 400 characters of the ERP bullet (it is at 259), so a block moved to a later section fails.
  • Changelog paraphrase. Now says "the dataset or its paper", as the prompt does.

Mutations, each run against the whole suite and restored: no clamp fails 2 checks; np.sinc(k) fails 8; a slice off by one sample fails 10.

  • bun frontend/test-data-lane.js: 93 passed
  • pytest tests/test_assistants/test_nemar_runtime.py tests/test_assistants/test_nemar_mcp_wiring.py: 41 passed

neuromechanist added a commit that referenced this pull request Sep 24, 2026
tests/test_tools/test_hed_validation.py calls hedtools.org in every test but only one class carried a marker (integration), so the unit jobs ran the rest and a slow response failed unrelated PRs: #484 (read operation timed out) and #485 (two validations returned False) on 2026-09-24. A module-level pytestmark = pytest.mark.network leaves them to test.yml's network job, which is continue-on-error.

Tested: -m 'not integration and not llm and not network' deselects all 11; -m network runs all 11, passing against hedtools.org; ruff check and format clean.
@neuromechanist
neuromechanist merged commit b68814a into develop Sep 24, 2026
11 checks passed
@neuromechanist
neuromechanist deleted the fix/nemar-erp-kernel branch September 24, 2026 19:53
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