From musical patterns to biological locomotion —
a NAML pipeline: RSVD · K-means ·
Pearson · Least Squares
Vahid Ghayoomie · wormuse / PyANNOW · May 2026
OpenWorm Foundation
(Delaware non-profit, 2014 – present)
Led ChannelWorm — Python platform for ion-channel modeling in
C. elegans: patch-clamp data curation, HH fitting, API + validation suite.
chModeler (2018 – present) — ion-channel "supermodel" + ML predictor for kinetics from amino-acid sequences (~270 channels, Xenopus oocyte dataset).
B.Sc. IT Engineering · M.Sc. studies in Biology & Mechatronics ·
Currently: M.Sc. HPC Engineering @ PoliMi
(CUDA, OpenMP, NAML, NLA, NMPDE).
Industrial: Big Data @ Sadad/Melli Bank (2015–18); co-founder Neursal (2022–23).
vahidghayoomi@gmail.com · github.com/vahidgh · github.com/VahidGh
The problem with v1:
HH simulation reaches a fixed-point attractor —
the worm locks into one muscle pattern, making raw muscle data useless for
varied visualization.
v2 inversion:
Instead of Worm→Music, we ask:
Music → Patterns → Worm Dance
Extract recurring patterns from Chopin,
drive the worm's 96 muscles from music.
Two matrices — a piano and a worm — connected by linear algebra
P = 56 unique pitches (MIDI bins)
T = 11 711 time frames at 20 ms resolution
Duration: 234 s · BPM: 69
Density: ~9% active
MIDI note-on/off events → binary presence. Velocity and duration encoded separately. This is the pitch × time representation standard in music information retrieval (MIR).
DL/DR fire in-phase (dorsal body-wave).
VL/VR fire 180° anti-phase (ventral).
Bilateral pairs have 0.05 rad lateral offset.
Body-wave travels head→tail within each quadrant.
Finding the best musical basis — the same theorem that compresses images
$U_k \in \mathbb{R}^{56 \times k}$ — pitch profiles:
which pitches co-activate in each pattern
$\sigma_i$ — pattern energy:
$\sigma_i^2 / \|\sigma\|^2$ = fraction of musical variance
$V_k \in \mathbb{R}^{T \times k}$ — temporal envelopes:
when each pattern is active
In Lab01 we compressed images by keeping the top-k singular values.
Here we compress a musical score the same way.
The k=12 most energetic patterns
explain 90% of the piano-roll's Frobenius energy.
Each pattern $U_k[:,i]$ is a pitch chord;
$V_k[:,i]$ is its rhythmic envelope.
Larger $\sigma_i$ = more musical energy.
$\sigma_1$ alone captures ~42% of variance
(the nocturne's repeating motif).
k=12 chosen by 90% cumulative variance threshold
Discovering recurring musical states from temporal modes
$a(i)$ = mean intra-cluster distance · $b(i)$ = nearest-cluster distance
$s \to 1$: tight, well-separated clusters → good K
$s \to 0$: frames on cluster boundaries → ambiguous
$s \to -1$: misclassified → bad K
8 clusters capture the main harmonic transitions of the nocturne: opening motif, bridge, development, recapitulation… Matches human perception of phrase structure.
Peak silhouette at K=8 — 8 musical patterns
Which Chopin patterns make the worm's nervous system resonate?
$\text{excitability}(i) = \max_j |r_{ij}|$
Pearson r is scale-invariant — it measures shape correlation, not amplitude. The worm's neural oscillations may have different amplitude from Chopin's temporal modes but the same rhythmic structure.
$Z_\text{worm} \in \mathbb{R}^{T_p \times k_w}$ — worm neural scores
$V_\text{mus} \in \mathbb{R}^{T_p \times 96}$ — muscle modes
$W_{nm} \in \mathbb{R}^{k_w \times 96}$ — neural→muscle map
Each column of $W_{nm}$ tells us how neural modes linearly combine to activate one muscle. This is the biological motor program encoded as a matrix.
# step2_clustering/motor_primitives.py
W_nm = np.linalg.lstsq(Z_worm_p, V_mus_p, rcond=None)[0]
pose = {j: (Z_worm_p[labels==j].mean(0) @ W_nm)
for j in range(K)}
From piano patterns to body waves — watch it happen on the right →
Mode 0 — amplitude: scales overall muscle contraction
Mode 1 — body-wave phase: $\phi(s) = \phi_0 + s \cdot 2\pi/24$
Mode 2 — D/V bias: dorsal vs ventral imbalance
Mode 3 — L/R offset: lateral turning signal
$\phi_q \in \{0, \pi, \epsilon, \pi+\epsilon\}$ for DL/VL/DR/VR quadrants
Wave travels head→tail as $s$ increases from 0 to 23.
headDL = mean(DL[s=0..7]) — dorsal-left head
headDR = mean(DR[s=0..7]) — dorsal-right head
Both dorsal → no D/V cancellation.
Bilateral offset $\varepsilon=0.05$ rad preserved → real L/R signal.
Body-wave from piano temporal modes. Color = current pattern (P1–P8). Trail = locomotion history (FORWARD / TURN / HALT).
302-neuron connectome compressed to 6 MN classes (DA/DB/VA/VB/DD/VD). Connections visible at resting activation. CMD nodes: AVA/AVD/AVB/PVC.
Pattern ID bar at bottom. Each color segment = one K-means musical state. Pattern transitions align with harmonic changes in the nocturne.
8 circular pattern indicators. Active pattern glows and shows excitability score. Pattern 3 most excitable (r≈0.88).
| Method | NAML reference | Applied to |
|---|---|---|
| RSVD (Halko 2011) | L06–L09 · Lab01 | Extract top-k musical basis from piano-roll M |
| Eckart-Young theorem | L06 · core theorem | Guarantees RSVD is optimal rank-k approximation |
| PCA equivalence | L08–L10 · Lab02 | V_k rows = PCA coordinates of time frames |
| K-means | L10 · Lab02 / Lab05 | Cluster T frames in V_k space → 8 musical states |
| Silhouette score | Lab02 / AppStat | Data-driven choice of K* = 8 |
| Least squares / pseudoinverse | L07 · L09 · Lab03 | Neural scores → 96-muscle activation (W_nm) |
| Pearson correlation | Lab02 / AppStat | Rank patterns by biological excitability |
Replace synthetic HH with actual patch-clamp data from chModeler (~270 channels, Xenopus oocytes). Can the ML predictor recover Chopin-correlated kinetics?
Use a Physics-Informed Neural Network (NAML L27) to replace the HH ODE solver. Loss = data residual + HH PDE residual. Faster inference, differentiable w.r.t. channel parameters.
Music → worm → sensor signal → modify music. The worm's movement generates a new piano-roll → re-run the RSVD pipeline → update dance. Biological feedback as an artistic medium.
Replace K-means with kernel K-means (L12-13) for non-linear musical clusters. Replace lstsq with Tikhonov regularization when W_nm is ill-conditioned.
Code + notebook:
github.com/vahidgh/wormuse · PyANNOW/notebooks/06_chopin_patterns_worm_dance_v2.ipynb
vahidghayoomi@gmail.com