/** * limbic_model.ts – LimbicModel: a small, trainable recurrent affect head. * * The limbic model learns the *dynamics* of an agent's affective/motivational * state. Given an experience embedding (produced upstream by the hippocampus * SSM) and the current affective state, it predicts: * • a bounded affect *delta* (how valence/arousal/drives/attention/exploration * should move in response to this experience), and * • a scalar *reward* prediction (how good/bad this experience was). * * Architecture (intentionally tiny — the heavy representation work happens in * the hippocampus; this head just maps representation → affect): * * pre[j] = Σ_i Win[j,i]·x[i] + Σ_k Ws[j,k]·s[k] (hidden pre-activation) * a[j] = sigmoid(A[j]) (per-channel SSM gate) * h'[j] = a[j]·h[j] + (1-a[j])·tanh(pre[j]) (recurrent leak/input) * Δ[k] = tanh( Σ_j Wout[k,j]·h'[j] + b[k] ) (bounded affect delta) * r = Σ_j Wr[j]·h'[j] + br (reward prediction) * * It runs on WebGPU (per-turn `step()` via {@link LIMBIC_AFFECT_WGSL}, and the * AdamW optimiser via the shared WEIGHT_UPDATE_WGSL kernel during training) with * a numerically-identical pure-CPU reference path used when no GPUDevice is * available — the same WebGPU-or-fallback contract the rest of the engine uses. * * Training uses truncated BPTT(1): the recurrent state is carried forward across * a sequence, but each step's gradient treats the incoming hidden state as a * constant. For an affect head this is stable and sufficient — each * (experience, state) → affect pair is close to an independent regression. */ export interface LimbicModelConfig { /** Experience-embedding dimension (input). Default 32. */ inputDim: number; /** Hidden recurrent width. Must be ≤ 64 (the GPU kernel's workgroup size). Default 16. */ hiddenDim: number; /** Affective state dimension. Default {@link LIMBIC_STATE_DIM} (8). */ stateDim: number; /** Deterministic init seed for reproducible cold-start weights. */ seed?: number; /** Weight of the reward-prediction term in the training loss. Default 0.5. */ rewardWeight?: number; } export declare const DEFAULT_LIMBIC_CONFIG: Required>; /** Result of a single forward step. */ export interface LimbicForward { /** Next hidden recurrent state (length hiddenDim). */ hidden: Float32Array; /** Bounded affect delta in (-1, 1) per state dim (length stateDim). */ delta: Float32Array; /** Reward prediction (scalar). */ reward: number; } /** A named trainable parameter tensor (flat row-major Float32Array). */ export interface LimbicParam { name: string; data: Float32Array; numel: number; } /** Fixed default init seed — reproducible byte-identical cold start across machines. */ export declare const DEFAULT_LIMBIC_SEED = 296863214; export declare class LimbicModel { readonly config: Required>; win: Float32Array; ws: Float32Array; aLogit: Float32Array; woutState: Float32Array; boutState: Float32Array; woutReward: Float32Array; boutReward: Float32Array; private gWin; private gWs; private gALogit; private gWoutState; private gBoutState; private gWoutReward; private gBoutReward; constructor(config?: Partial); /** Trainable parameters, in the canonical checkpoint order. */ parameters(): LimbicParam[]; /** Gradient buffers, index-aligned with {@link parameters}. */ gradients(): LimbicParam[]; zeroGrad(): void; /** A fresh zeroed hidden state. */ initHidden(): Float32Array; /** * One forward step (CPU reference). Pure — does not mutate the model or the * inputs. The GPU kernel path produces numerically-identical results. */ forward(x: ArrayLike, hPrev: ArrayLike, sPrev: ArrayLike): LimbicForward; private _forwardCached; /** * Accumulate gradients for one (input, state) → (deltaTarget, rewardTarget) * sample using truncated BPTT(1). Returns the scalar loss for this step and * the next hidden state to carry forward. Call {@link zeroGrad} before a batch * and apply the optimiser after. */ backwardStep(x: ArrayLike, hPrev: ArrayLike, sPrev: ArrayLike, deltaTarget: ArrayLike, rewardTarget: number): { loss: number; hidden: Float32Array; }; /** * Serialise weights to a compact "LMBC" binary. fp16 (v2) halves the size at * ~0.5% precision cost; f32 (v1) is exact. Layout: magic, version, [inputDim, * hiddenDim, stateDim], then params in {@link parameters} order. */ exportWeights(opts?: { fp16?: boolean; }): ArrayBuffer; /** Load weights from an "LMBC" binary. Validates magic + dims. */ loadWeights(buffer: ArrayBuffer): void; } //# sourceMappingURL=limbic_model.d.ts.map