/ proof-of-concept / audio-spike-sorting
Sign in
proof-of-concept / audio-spike-sorting
audio-spike-sorting / src / bench / training.ts
27 lines · 1.0 KBBlameHistoryRaw
1/**
2 * The training payload handed to an algorithm, kept free of any numbl
3 * import so the main thread can assemble it without pulling the whole
4 * interpreter into its bundle; the worker turns it into runtime values.
5 */
6import type { SnippetLibrary } from './types.ts';
8export interface TrainingArrays {
9 names: string[];
10 pre: number;
11 /** Per type: column-major [snipLen x count] snippet matrix. */
12 snips: { data: Float64Array; snipLen: number; count: number }[];
15/** Assemble per-type training matrices from a library and a train split. */
16export function buildTraining(lib: SnippetLibrary, trainIndices: number[][]): TrainingArrays {
17 const snipLen = lib.pre + lib.post;
18 const snips = trainIndices.map((idx) => {
19 const data = new Float64Array(snipLen * idx.length);
20 idx.forEach((si, j) => {
21 const s = lib.snippets[si].samples;
22 for (let i = 0; i < snipLen; i++) data[j * snipLen + i] = s[i] ?? 0;
23 });
24 return { data, snipLen, count: idx.length };
25 });
26 return { names: lib.names, pre: lib.pre, snips };
↑↓ move↵openescclose