f_peaks_spike — can local maxima and minima of a scalar field be read out as clean objects?
Working name f_peaks (plain words on purpose: f_cores showed that physics words read as jargon in a video menu). The name is Matt's call (gate D1 below).
Status: 🟡 tier 1 (NumPy) run 2026-11-29, result section below: stop rule 2 triggered on f_vf_ch (see "Where the stop rules stand"); decisions D1 to D6 accepted 2026-11-29; written 2026-11-29 (Claude, offline, at Matt's go: "Start item 4, write the spec"). Nothing run, nothing built. This is item 4 of ideas/cores_next_steps.md, parked as P-cores-sibling-reader in .specify/gates.md; Matt reopened it this session. Format follows ideas/f_defects_spike.md.
The question
f_cores reads one kind of object out of a field: the points where a signed 2-vector field winds. Does the same reader idea work for a scalar field: mark each local maximum (and, as the second channel, each local minimum) as an object, with a clean count, on the scalar fields this library already makes? The cases named in the next-steps note: droplets of f_vf_ch (its phase outlet), and blobs in a scalar made from f_cgl's amplitude. Vorticity of f_vf_fluid is a third candidate (from memory, not looked up; out of v1 until it is).
The risk is known in advance: a bare local-maximum test fires on every ripple, and on every flat top (ties). f_cores was easy because winding is topological, so noise does not create it. A maximum is not, so this spike is mostly about what has to be added to a 3×3 comparison to make it trustworthy, and whether that addition is cheap on the GPU.
What already overlaps (checked 2026-11-29 offline; per CLAUDE.md)
- f_ library (
docs/f-reference/module-inventory.md): nothing finds extrema of a scalar.f_coresfinds windings of a 2-vector;f_vf_seedsplaces marks from a vecfield and takes an external mask;f_vf_choutputs the phase as grey and never reports droplets as objects;f_vf_vorticityadds swirl back to a field, it does not read objects out. - jit.fx (
docs/max-reference/jit_fx.md,jit_fx_vs_ideas.md):an.mean,an.min,an.maxgive GLOBAL 1×1 values only; centroid and regional analysis are listed there as not covered. No local-extremum or blob object. - cv.jit (added 2026-11-29; the original check missed it, found when Matt asked; see
docs/max-reference/cv_jit.md). The installedcv.jitpackage (a third-party dependency, CPU matrices) hascv.jit.label(connected components) withcv.jit.blobs.centroids(a center of mass and area per blob, char matrix, at most 255 blobs) and acv.jit.extremawhose own behavior is undocumented in its help. So a CPU blob route to droplet centers exists. It does not change the NumPy result for the GPU detectors; it is a different module (a blob reader) that Matt may reopen. - Vsynth (
docs/vsynth-reference/module-inventory.md,patterns.md): only audio peak followers (peakamp~) turn up in a search; nothing for image extrema. - Reusable from
f_cores: its downstream stages draw marks from a one-texel (plus, minus) mask in R and G, and its sum chain, readback and js turn a mask into count, bangs and rate. If a peaks detector writes maxima to R and minima to G, those stages should apply unchanged (inferred from the definition's data flow, not tried).
What to find out
- Agreement with a reference. Define the reference object count per field by a method independent of the detector: a connected-component labelling of a superlevel set, one peak per component, swept over a few levels (a persistence-style reference). How often does each candidate detector (below) agree with it, per source and regime? Report missed, invented, and merged objects.
- Noise and ties. How many spurious maxima does a bare strict 3×3 test (with a fixed tie rule) invent on each source? Hypothesis to test, not a finding:
f_vf_ch's phase should be close to flat inside a droplet (Cahn-Hilliard drives the bulk toward ±1), so the interior is a plateau and a bare test either misses droplets or fires on rounding noise. The spike measures this on real states. - What fixes it, and what it costs. Candidates, cheapest first:
- A. strict 3×3 maximum with a half-open tie rule (the same idea as
f_cores' half-open crossing convention) plus a prominence threshold (the peak must beat its eight neighbors by at leastp); - B. a blur at the object scale, then candidate A (a blur module exists in the library; the spike measures how wide);
- C. only if A and B fail: a peak of distance-to-edge for flat-topped blobs. Multi-pass and likely heavy, so it is a stop-and-ask, not part of v1 here.
- A. strict 3×3 maximum with a half-open tie rule (the same idea as
- Count stability. The count outlets drive bangs (
f_coresoutlets 3 and 4). A detector whose count flips by plus or minus one on noise would chatter. Measure, in each regime, the share of steps where the count changes against the share where the reference changes (thef_coresspike did this per step). - Render size. As for
f_cores(input must be at the render size): does the detector run on a bilinearly upsampled field and give the same objects as on the solver grid? Counts and positions. - Both signs. Maxima in one channel, minima in the other: is the minima channel useful on these sources, or empty or redundant (
f_cglamplitude minima are exactlyf_cores' cores, so they duplicate it there)? - Output contract. One inlet, R = the scalar (the gray a module already outputs, such as
f_vf_choutlet 0)? Which encoding range does each source emit, and does clamping (as in the D10 vecfield encode) flatten the very peaks being looked for? Not read yet: the exact range off_vf_choutlet 0 and off_cgl's Amplitude view; readdocs/f-reference/f_vf_ch.mdandf_cgl.mdfirst.
Proposed method (the f_ verification tiers)
- Tier 1, NumPy (offline, no Max, no API calls). Sources:
f_vf_chstates fromtests/modules/vf_ch/vf_ch_mirror.py;f_cglstates fromtests/modules/cgl/cgl_mirror.py(astests/records/spike_defects.pyloaded them). Reuse its periodic-component helper (blobs()intests/records/spike_defects.py) for the reference. Answers questions 1 to 6 and the range half of 7. Script:tests/records/spike_peaks.py, summaries toscratch/experiments/peaks_spike/(gitignored). - Tier 2, bench (Max foreground, Matt's go, announce first), only if tier 1 passes stop rules 1 to 3. One scratch codebox (
tests/records/codebox_peaks_spike.gen): eight neighbor reads, the tie rule, the prominence test; GPU against NumPy on every texel; cost with the amplified method (bench-test-authoring9). Readjit-gen-codeboxfirst. - Tier 3, live look: Matt's. Do the marks sit on the droplets and the blobs, do they stay put frame to frame, and do the bangs chatter or track births and deaths of droplets?
Stop rules (the numbers are my picks, not derived)
- If a bare 3×3 test already agrees at roughly 0.9 precision and 0.9 recall on both sources, no blur or prominence is needed; the finding is that the reader is as cheap as the
f_coresone. - If no cheap candidate (A or B) reaches about 0.9 on
f_vf_ch, stop and say what the droplet object really is (a blob, not a peak), who decides, and that C would be the next idea. No stage is built. - Cost (tier 2 only): a detector pass above about 0.5 ms per frame at the solver grid is too heavy beside a 3 to 4 ms solver (the budget
f_defects_spikeused). - Chatter: if, in a settled regime, the count changes on more than about 10% of steps where the reference does not, the count outlets would be unusable from this detector: marks only, and say so.
- A merge is not a failure: if the shared stages of
f_coresapply unchanged, record that and stop; the module question is gate D2.
Phase 0 gates (Matt decides; Claude's lean in each)
- D1 Name. Lean
f_peaksas a working name. Matt picks before any build; the spike scripts can use it. - D2 Sibling or a mode of
f_cores. Matt's own question on the count was "why isn't this part of cores?", and the answer was to merge. Same question here: the downstream marks and count chain are shared; the input differs (a 2-vector against a scalar). Lean: decide after tier 1, because aSourcemenu (Field winding / Scalar peaks) onf_coresis plausible only if one inlet can carry both, and nothing here says so yet. - D3 Sources in v1. Lean
f_vf_chphase (droplets) first,f_cglamplitude second; vorticity only after it is looked up. - D4 Detector family. Lean A, then B; C not in this spike.
- D5 Tiers. Lean tier 1 now; tier 2 only if the stop rules pass; tier 3 is Matt's.
- D6 Stop rules. Lean as above; Matt may move the 0.9, 0.5 ms and 10% picks.
Decisions
Matt, 2026-11-29 (chat: "Accept all"): D1 to D6 as leaned. Working name f_peaks; D2 (sibling or a mode of f_cores) stays open until tier 1 reports; sources f_vf_ch phase first, f_cgl amplitude second; detector A then B; tier 1 NumPy next, tier 2 only if stop rules 1 to 3 pass; stop-rule numbers as written.
Result, NumPy tier (run 2026-11-29; Claude, offline, NumPy, no Max, no bench, no API calls)
What ran. tests/records/spike_peaks.py (uv run --no-project --with numpy python3 tests/records/spike_peaks.py, about 150 s; log and summary.json in scratch/experiments/peaks_spike/, gitignored). Detectors: A = strict 3×3 maximum, half-open tie rule (strict against W, NW, N, NE; ≥ against E, SE, S, SW), plus a prominence p over the largest of the 8 neighbors; B = periodic Gaussian blur of σ texels, then A. C (distance to edge) was not run. Reference: periodic 4-connected components of the superlevel set, one peak per component, three levels (f_vf_ch w > 0.5 / 0.75 / 0.9; amplitude maxima > 0.5 / 0.8 / 0.95; minima < 0.1 / 0.2 / 0.4). Scoring: precision = components holding a peak / detected peaks, recall = components holding a peak / components. Numbers below are pooled over five states per config unless noted.
Sources. f_vf_ch mirror (module defaults, no flow, except STIR) read as outlet 0, w = clamp((φ+1)/2, 0, 1): D1 (fill −0.55, coarsen 0.3, frames 100 to 600), D2 (fill −0.4, coarsen 0.6, same frames), LAB (fill 0, coarsen 0.6), STIR (fill −0.4, a synthetic steady cellular flow in A and B, not a real f_vf_fluid pair), and E2 (fill −0.4, coarsen 0.3, frames 40 to 100, the only config with many droplets: 48 components pooled). f_cgl states from tests/records/spike_defects.py (PT, DT, STAB, FRZ, 10 states each), read as the Amplitude view clamp(|A| e^(dt/2), 0, 1). Limits of the sample. D1, D2, LAB and STIR coarsen to 1 to 3 big objects per state (16 to 17 components pooled for D2 and STIR, 5 to 6 for D1 and LAB), so their precision figures rest on few objects. E1 (fill −0.55, frames 40 to 100) had no droplet above w = 0.75 yet (reference 0), so it scores nothing. The flow in STIR is synthetic. Droplet size is not controlled, which turned out to matter (below).
Q1 and Q3: agreement, and what fixes it (f_vf_ch, maxima of w, level 0.75)
| Config | components | bare A (p 0): detected, precision, recall | B σ3: precision | B σ6: precision | recall |
|---|---|---|---|---|---|
| E2 (many small droplets) | 48 | 122, 0.39, 1.00 | 0.84 | 0.92 (52 detected) | 1.00 |
| D2 | 16 | 89, 0.18, 1.00 | 0.29 | 0.39 | 1.00 |
| STIR | 17 | 89, 0.19, 1.00 | 0.42 | 0.52 | 1.00 |
| D1 | 5 | 42, 0.12, 1.00 | 0.16 | 0.19 | 1.00 |
| LAB | 6 | 122, 0.05, 1.00 | 0.05 | 0.05 | 1.00 |
- Bare test: recall 1.0, precision 0.05 to 0.39. Every droplet gets a peak, and most of the peaks are extra ones on the same droplet (E2: 71 extra of 122; LAB: 116 of 122), plus a few outside any droplet (E2: 3). Missed and merged are 0 in every row; the failure is invention and duplication, not loss.
- A with prominence p (the "what fixes it" candidate A): does not work. Any p ≥ 1e-5 drops recall to 0.08 or below on E2 (p 1e-6: 7 peaks for 48 droplets), because a droplet top is flatter than the threshold. Prominence kills the real peaks along with the noise.
- B (blur, then the tie rule, p 0) works only where σ is below the droplet radius. On E2 the precision climbs with σ (σ1 0.05, σ2 0.64, σ3 0.84, σ4 0.89, σ6 0.92, recall 1.0 throughout; the E2 rows at level 0.5 and 0.9 give 0.94 and 0.90 at σ6). On D1, D2, STIR and LAB the droplets and labyrinth arms are larger than σ6, the blurred top is still a plateau, and precision stays 0.05 to 0.52. So B needs a σ matched to the droplet radius, which drifts as coarsening runs, and the object scale is not a number the module has (inferred; a σ above 6 was not run).
- Level dependence of the reference is small here (E2: 49, 48, 47 components at the three levels), and "merged" is 0 or ≤ 4 everywhere: the reference is stable, so the disagreement is in the detector, not the level choice.
Q2: noise and ties, and the flat-phase hypothesis
Supported, with a caveat. Inside droplets (w > 0.9), 44% (E2, STIR) to 78% (LAB) of the texels are exactly tied with a neighbor at w = 1.0, because φ overshoots to 1.01 to 1.07 and the outlet clamps it (max φ: D1 1.0713, D2 1.0291, LAB 1.0134, STIR 1.0304, E2 1.0689). The half-open rule turns each tied plateau into one or more peaks (clamped outlet: 122 bare peaks over E2's five states against 48 droplets; the unclamped (φ+1)/2 gives 53). Even without the clamp the interior is not clean: 49 of 53 unclamped peaks are inside droplets, i.e. rounding-level wiggle on the plateau (D2: 38 bare peaks unclamped for 16 droplets; LAB: 21 for 6). The std of φ inside w > 0.9 (0.04 to 0.07) includes the interface tails, so it is not a measure of flatness by itself; the tie fraction is the cleaner evidence. (The module doc says "observed |φ| ≤ 1.03"; here D1 and E2 reach 1.07. Cause not examined; the doc line is not changed.)
Q4: count stability per step (last 150 steps)
Share of steps where the count changes, with the reference (components of w > 0.75) holding still in nearly all of them:
| Config | reference changes | bare A | B σ6 |
|---|---|---|---|
| E2 | 4 of 149 | 95 (64%) | 9 (6%) |
| STIR | 1 | 67 (45%) | selected-by-F1 detector found 0 peaks; not a usable row |
| D2 | 0 | 10 (7%) | 36 (24%) |
| LAB | 0 | 9 (6%) | not recorded here (see summary.json) |
The bare count chatters on E2 and STIR (up to 64% of steps). B at σ6 holds it to 6% on E2 but 24% on D2 (its blurred plateau flickers). Stop rule 4 (10%) is met only by B on E2, the favorable case. f_cgl minima: in DT the reference itself changes on 137 of 149 steps (defect turbulence), and bare minima change on 137, so the count tracks the field; in STAB the reference changes on 21 steps and bare minima on 113 (97 while the reference holds still), which is the ripple minima outside the cores (below).
Q5: render size
Bilinear upsample ×4 to 1024². Bare A on E2: 28 solver peaks become 64 render peaks (every solver peak is found, but 26 render peaks have no solver peak nearby); D2: 15 to 49. B with σ scaled ×4 (σ6 → 24 px) on E2: 10 solver peaks, 10 render peaks, all matched; on D2: 8 solver, 100 render (a big plateau again). f_cgl DT minima, bare: 410 solver, 636 render (408 found); B σ1 (scaled): 368 vs 367, 357 found. Detection at the solver grid, not on the upsampled texture, is the safe place, and a scaled blur keeps the objects; a prominence threshold would have to be divided by the scale squared (inferred from the p_over_scale2 rows, which found no peaks at all on f_vf_ch).
Q6: both signs
f_vf_ch minima of w are the continuous background in the droplet configs (E2: 5 sublevel components for 5 states, bare minima 68): not objects unless fill is near 0 and both phases form droplets (LAB: a labyrinth, no separate objects). f_cgl amplitude minima are the cores: with a level gate (value below τ), bare minima equal the winding cores: STAB 746 reference components at τ 0.4, 746 matched, 0 extra; FRZ 251 at τ 0.2, 248 matched; DT 1591 of 1628 at τ 0.4 with 678 extra (merged cores, 138 merged). Without a level gate they are swamped: STAB bare minima 3544 against 746 cores (2798 of them with |A| > 0.4), because |A| ripples around 1 outside the cores. So on f_cgl the minima channel duplicates f_cores (as predicted) and needs a level, not a prominence (p 1e-4 changed 3544 to 3183). Amplitude maxima are not objects: the superlevel set is one connected sea (1 component per state in STAB, 10 states; 69 in DT), and bare maxima are ripples (3399 in STAB, 3944 in DT).
Q7: output encoding
f_vf_choutlet 0 isw = clamp((φ+1)/2, 0, 1); φ reaches 1.07, so the top of every droplet sits at exactly 1.0 (44 to 78% of the interior). The clamp flattens the peaks and turns a smooth top into a tie plateau. Reading φ before the clamp would still leave rounding-level wiggle (21 to 53 peaks in the unclamped runs).f_cglAmplitude view isclamp(|A| e^(dt/2), 0, 1)(dt = 0.1: gain 1.051): 100% of texels clamp in PT (raw range 1.016 to 1.101, so bare maxima: 0 detected, all tied; unclamped: 1287 ripple maxima over 10 states), 21 to 28% in DT, STAB, FRZ. The clamp discards exactly the information a maxima reader would use; the cores (minima, near 0) are not clipped.
Where the stop rules stand
- Bare 3×3 good enough (about 0.9 / 0.9)? No.
f_vf_ch: recall 1.0, precision 0.05 to 0.39.f_cglminima with a level gate: yes, but that isf_cores' case. - No cheap candidate reaches about 0.9 on
f_vf_ch: TRIGGERED, with one exception. A with prominence fails (recall ≤ 0.08). B reaches 0.92 precision at σ6 on small droplets (E2) and 0.05 to 0.52 on larger droplets and labyrinths. What the droplet object is: a flat-topped blob (the outlet clamps its top into a plateau), not a peak. The next idea would be candidate C (a peak of distance-to-edge, or a threshold plus a blob count); that is a multi-pass design and needs Matt's decision before any further work. No stage is built. - Cost: not measured (tier 2 only; not run).
- Chatter (10%): bare fails on E2 (64%) and STIR (45%); B σ6 passes on E2 (6%) and fails on D2 (24%). Not met in general; counts from this family would be marks-only, per the rule.
- Merge not a failure: the downstream marks and count chain of
f_coresshould apply to a peaks mask unchanged (inferred, not tried); but since rule 2 triggered, nothing is built on that.
Recommendation on D2 (INFERENCE, not measured)
Do not build a peaks detector from candidates A or B. If Matt wants droplets as objects, the cheapest next step is candidate C, a threshold on w (the level gate that worked for minima on f_cgl) followed by a blob count, so the object is a thresholded region rather than a local extremum; that is a design question, not an offline measurement yet. If a scalar reader is built later, I lean sibling module (or a front end that writes the same R = plus, G = minus mask), not a mode of f_cores: its inlet is a scalar grey (f_vf_ch gives R = G = B) while f_cores expects a 2-vector with B = 0.5, one inlet cannot tell the two apart safely, and the scalar reader needs its own threshold and scale dials. The f_cgl amplitude case needs no new module: f_cores already marks the same objects. This is my inference from one NumPy run and a small droplet sample.
Not tested: the GPU, any cost, a real f_vf_fluid pair as flow, droplet sizes between E2's and D1's, σ above 6, candidate C, a live look, vorticity.
Result, candidate C (run 2026-11-29; Claude, offline, NumPy, at Matt's go "Spike candidate C")
What ran. tests/records/spike_peaks_c.py (about 115 s; summary_c.json and run_c.log in scratch/experiments/peaks_spike/, gitignored). Same states and reference as the tier above (f_vf_ch, w = outlet 0; reference = components of w > tau, so the only question is one peak per region). Detector C: mask = w > tau; depth = repeated erosion (8-neighbor "d8" or 4-neighbor "d4"; the number of erosion passes is the GPU pass count); optional blur of the depth (σ); then the half-open 3×3 maximum, inside the mask, with prominence p in depth units. Level tau 0.75 below (0.5 is in the log). Pooled over five states per config.
Agreement (tau 0.75, p 0, precision / recall; recall is 1.0 in every row, missed 0):
| Config (components) | bare depth peaks (d8, σ0) | d8, σ2 | d4, σ2 | erosion passes (max) |
|---|---|---|---|---|
| E2 (48, small droplets) | 0.16 | 0.94 | 0.91 | 18 (d8), 25 (d4) |
| D2 (16) | 0.09 | 0.94 | 1.00 | 40, 57 |
| D1 (5) | 0.08 | 1.00 | 1.00 | 41, 58 |
| STIR (17) | 0.09 | 0.57 | 0.59 | 30, 50 |
| LAB (6, labyrinth) | 0.03 | 0.50 | 0.75 | 63, 97 |
- Compared with the blur-only candidate B (E2 0.92; D2 0.39; STIR 0.52; D1 0.19; LAB 0.05), C reaches about 0.9 or better on E2, D2 and D1, the three configs with compact droplets. The depth of a blob has one clear maximum where a clamped plateau has none, so a modest σ (1 to 2 texels) is enough, and it does not need to track the droplet radius. On STIR (droplets pulled into elongated shapes by the flow) and LAB (arms of a labyrinth) it does not reach 0.9: a long arm has a ridge of depth, with several maxima. (Few objects in D1, D2, LAB; the same sample caveat as above.)
- Prominence p 0.5 in depth units fails (it removes the real peaks: recall 0 to 0.33). Use the blur, not p.
- Bare depth peaks (σ0) are as noisy as the bare test (precision 0.03 to 0.16; integer depths tie).
Cost: the structural problem (inferred, not measured on the GPU). The erosion is iterative: 18 to 97 passes at the deepest state here, and the pass count grows with the biggest droplet's radius (D1 and LAB are the deepest). Each pass is a stage; the detector plan's budget (stop rule 3, about 0.5 ms per detector) has no room for tens of stages beside a 3 to 4 ms solver. A log-pass distance transform (jump flooding) was not tried; it was not measured here either.
Chatter (stop rule 4), per step over the last 150 steps, while the reference holds still:
| Config (reference changes) | d8 σ2 | d4 σ1 | d4 σ2 |
|---|---|---|---|
| E2 (4 of 149) | 33% | 70% | 36% |
| STIR (1) | 83% | 82% | 55% |
| D2 (0) | 0% | 0% | 0% |
| LAB (0) | 5% | 2% | 0% |
So the count is steady only where droplets are large and round (D2, LAB for d4 σ2); in E2 and STIR it changes on a third to four fifths of the steps, well above 10%, because an extra peak appears and disappears on a ridge or a thin neck.
Where C leaves the stop rules. Rule 2 (accuracy about 0.9): met on compact droplets (E2, D2, D1), not on elongated shapes (STIR, LAB). Rule 3 (cost): very likely failed by the pass count (inferred). Rule 4 (chatter): failed on E2 and STIR. So C reads droplets better than A or B but is multi-pass and its count still chatters; it is not a cheap detector. Not tested: render size, both signs, tau 0.9, a log-pass transform.
Untested lead (INFERENCE, not run). If what the patch needs is the number of droplets rather than marks at their centers, the count of a thresholded region can be read locally in one pass (each 2×2 pattern of the mask contributes to the Euler number: components minus holes), which would sum through f_cores' existing count chain; the reference here already shows the components are stable per step (0 to 4 changes in 149) while peak counts are not. It would count rings as zero, so it fits droplet regimes, not labyrinths. This is a different reader (count, not marks) and would need its own short NumPy check before anyone builds it.
Matt, 2026-11-29 (chat: "Park it, close D2"): the spike is parked and D2 is CLOSED as not applicable (no module is being built, so sibling-or-mode of f_cores is not asked; reopen it only if the row is reopened).
Gate
P-cores-sibling-reader in .specify/gates.md is the parent row: reopened by Matt 2026-11-29; its tripwire (items 2 and 3 done) is also met. After the spike, the row either becomes a module spec (a new gates row for D1 and D2) or closes on stop rule 2.
Related
cores_next_steps.md, field_object_bridge.md, f_defects_spike.md (the format this follows), docs/f-reference/f_cores.md, docs/f-reference/f_vf_ch.md, docs/f-reference/f_cgl.md, docs/max-reference/jit_fx.md.