Skip to content

feat(stdlib): AURA BCI builtins — gaussian_kernel_1d·separable_blur·nearest_template·r2 (handoff f125d45c)#2207

Merged
dancinlife merged 2 commits into
mainfrom
feat/aura-bci-builtins
May 30, 2026
Merged

feat(stdlib): AURA BCI builtins — gaussian_kernel_1d·separable_blur·nearest_template·r2 (handoff f125d45c)#2207
dancinlife merged 2 commits into
mainfrom
feat/aura-bci-builtins

Conversation

@dancinlife
Copy link
Copy Markdown
Contributor

AURA BCI .hexa-native porting primitives (handoff f125d45c)

Implements the 4 numpy-equivalent kernels the anima AURA-* app set needs to drop its // TODO(f125d45c) stubs and compile/run.

Surface (stdlib/aura/bci_kernels.hexa)

fn semantics numpy ref
gaussian_kernel_1d(n, sigma) row-stochastic n×n Gaussian matrix K[i,j]=exp(-(i-j)²/2σ²), each row ÷ its sum (Σ_j K[i,j]=1) K=np.exp(-(i-j)**2/(2σ**2)); K/=K.sum(1,keepdims=True)
separable_blur(x, k, g) separable 2-D blur Y = K·reshape(x,[g,g])·K^T K @ x.reshape(g,g) @ K.T
nearest_template(y, templates, n_t, d) argmin_i ‖y−templates[i]‖² (int index, ties→lowest) int(np.argmin(((T-y)**2).sum(1)))
r2(y, ref, n) coefficient of determination 1 − SS_res/SS_tot 1 - ((y-r)**2).sum()/((r-r.mean())**2).sum()

No new C builtin required

Pure-hexa port over the existing farr handle API (farr_zeros/get/set/free) + self/runtime/math_pure.exp_pure — mirrors the established stdlib/stats/correlation.hexa and stdlib/consciousness/phi_spatial.hexa precedent (stdlib-as-builtin over farr). add_gaussian_noise (RFC 033) and phi_spatial (RFC 036) already existed as builtins; these four close the remaining gap the handoff named.

Verification — 10/10 falsifiers PASS

hexa run stdlib/aura/bci_kernels_test.hexa__HEXA_STDLIB_AURA_BCI_KERNELS__ PASS (verbatim stdout committed at .verdicts/aura-bci-kernels/bci_kernels_test_2026_05_30.txt).

  • F1 gaussian_kernel_1d(5,1.0) every row sums to 1 (max |Δ| = 2.22e-16)
  • F2 gaussian_kernel_1d(3,1.0) center K[1,1] = 0.451863 (numpy 0.45186276187760605, asserted to 1e-9)
  • F3 gaussian_kernel_1d(4,1.5) row-stochastic AND edge-asymmetric (K[0,1] > K[1,0] — design, see note below)
  • F4 separable_blur(const 7.0) == const 7.0 (partition-of-unity)
  • F5 separable_blur(center impulse) center stays max, all ≥ 0
  • F6/F7 nearest_template exact → idx 3 · nearest(y≈[1.1,1.1,1.1]) → idx 1
  • F8 r2(y==ref) == 1.0 · F9 r2 known == 0.8 (exact) · F10 mean-predictor == 0.0

Note on row-normalized Gaussian asymmetry (honest finding)

The first draft of F3 asserted K symmetry — that FAILED, and the self-test caught it. Row-normalized Gaussian K is intentionally asymmetric at the boundary: edge rows sum to less than center rows pre-normalization, so dividing each row by its own sum makes K[0,1] ≠ K[1,0]. This is the standard weighted-average smoothing operator (every output is a proper convex combination of inputs) and matches numpy K/=K.sum(1,keepdims=True). The implementation was correct; the test invariant was wrong and is now fixed to assert the true row-stochastic + edge-asymmetric property. Module doc-comment updated accordingly.

🤖 Generated with Claude Code

dancinlife and others added 2 commits May 30, 2026 17:26
…arest_template·r2 (handoff f125d45c)

Pure-hexa port over the farr handle API (no new C builtin), mirroring
stats/correlation.hexa + consciousness/phi_spatial.hexa. + 10-falsifier
self-test vs hand-computed numpy references.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…mmetric) + CHANGELOG + verdict

Row-normalized Gaussian K is intentionally asymmetric at the boundary
(edge rows sum to less than center rows pre-normalization), so the
original F3 symmetry assertion was a false invariant — the self-test
caught it. F3 now asserts the correct row-stochastic + edge-asymmetric
property. hexa run → 10/10 PASS · __HEXA_STDLIB_AURA_BCI_KERNELS__ PASS.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dancinlife dancinlife merged commit 5ea74ba into main May 30, 2026
1 of 4 checks passed
@dancinlife dancinlife deleted the feat/aura-bci-builtins branch May 30, 2026 08:53
@dancinlife dancinlife restored the feat/aura-bci-builtins branch May 30, 2026 17:37
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