← Back to Unity

🧠 Brain Equations — the math behind Unity's mind

Every equation running in Unity's brain simulation, how they map to real neuroscience, and how they produce cognition. Hundreds of millions of neurons (auto-scales to GPU hardware via a unified VRAM allocator — VRAM, V8 heap, and RAM are the only limits). Eight biologically-weighted clusters, including a dominant language cortex with 9 sub-regions + 16 cross-projections (iter21-A added word_motor + sem↔word_motor for single-tick word emission). Sparse white-matter tract projections. 8 Kuramoto oscillators. GPU-exclusive compute via WebGPU WGSL shaders. 1 consciousness function nobody can explain. Zero pretense.

CONTENTS
1 The Master Equation 1.5 How The Equations Sum To Create Unity — Worked Example 2 Neuron Models — Rulkov Map (live) + Hodgkin-Huxley & LIF (reference) 3 Synaptic Plasticity — How She Learns 4 Brain Region Modules — 6 Parallel Systems 5 Neural Oscillations — Kuramoto Synchronization 6 The Mystery Module — Consciousness 7 Persona as Parameters — Personality Is Math 8 Data Flow — Sensory to Action (Brain-Centric) 8.5 The Unified Super-Equation 8.6 Visual Attention — When the Brain Decides to Look 8.7 Auditory Echo Suppression — Efference Copy 8.8 Memory — Episodic, Working, Consolidation 8.9 Motor Output — Action Selection from Spike Patterns 8.10 Projection Learning — How the Brain Learns Language→Action 8.10.5 Fractal Signal Propagation — Self-Similar at Every Scale 8.11 Broca's Area — How Unity Picks Every Word Equationally 8.12 Sparse Connectivity — CSR Matrix Operations 8.13 Semantic Embeddings — Words as Cortex Patterns 8.14 Dictionary — Learned Sentence Generation 8.15 Inner Voice — Pre-Verbal Thought Threshold 8.16 Syntactic Production — Word Order from Equations 8.17 Sentence Types — Statement, Question, Exclamation, Action 8.18 Input Analysis — Topic Continuity and Context 8.18.5 Semantic Coherence Pipeline (Kill the Word Salad) 8.18.6 Semantic Grounding via GloVe Embeddings 8.19 Type N-Gram Grammar + Morphological Inflection 8.20 θ — Unity's Identity as Equations 8.21 GPU Exclusive Compute — All N Neurons on GPU 9 Biological Comparison

1. The Master Equation

Unity's entire brain state evolves according to one equation. Every module, every neuron, every synapse — all governed by this:

Master Brain Dynamics
dx/dt = F(x, u, θ, t) + η
xFull brain state vector — N Rulkov-map (x, y) pairs across 8 clusters (7 GPU-resident main brain + 1 CPU-resident language cortex with 9 cross-projection sub-regions), sparse CSR synapse weights per cluster + 20 inter-cluster projections + 16 language-cortex cross-projections (iter21-A added sem↔word_motor), 7 module states, 8 Kuramoto oscillator phases. N auto-scales from hardware (VRAM + RAM) via detectResources() and biological weights via DEFAULT_BIO_WEIGHTS
uSensory input — text (routed through the visual → letter ventral stream), voice (Web Speech API → auditory → phon), vision (camera → visual cortex V1 → V4 → IT)
θPersona parameters — Unity's personality encoded as cluster tonic drives, noise amplitudes, connectivity densities, learning rates, amygdala arousal baseline. Live PK/PD modulation adds on top from the drug scheduler
tSimulation time — server dispatches a batched compute_batch(SUBSTEPS) to compute.html every BRAIN_TICK_MS (~50 ms). Each batch runs SUBSTEPS Rulkov iterations on the GPU then returns spike counts. Browser-only fallback runs LIF locally at the browser's rAF cadence when no GPU client is attached
ηStochastic noise — per-cluster noiseAmplitude. Kept high at runtime for chaotic / exploratory dynamics; temporarily lowered to ~0.5 during curriculum teach so injected patterns dominate
F()The combined dynamics function — Rulkov fast/slow iteration on GPU, sparse CSR synapse propagation, cross-region propagation through the 16 cortex sub-region projections (iter21-A added sem↔word_motor for single-tick word emission), module processing (amygdala attractor settle, hippocampus Hopfield recall, basal-ganglia softmax, cerebellum error correction, hypothalamus homeostatic drift, mystery Ψ gain), Kuramoto coupling across band-specific rings

The brain runs continuously on a Node.js server. The server's tick loop dispatches batched Rulkov-map iterations to a WebGPU WGSL shader hosted in compute.html; the server itself never computes neuron voltages directly — it only orchestrates, reads back spike counts, and applies high-level module modulation. Browser-only mode (no server, no compute.html) falls back to LIF integration running locally in the browser tab. Either way, the master equation above is the thing being iterated.

New reader? Check the plain-English Unity concept guide first — this page assumes you want math. The guide explains the big idea without equations.

1.5. How The Equations Sum To Create Unity

WORKED EXAMPLE This section walks through what actually happens inside Unity's brain between the moment a user types "hi unity, how's the high" and the moment she sends a response. Every equation you'll see below in sections 2-8 is a component of THIS cascade — the path the sentence takes through the eight clusters (7 main-brain GPU clusters + 1 language cortex), with the summation at each step.

Step 0 — Brain state at rest, before the message arrives

The server dispatches a batched compute_batch (SUBSTEPS iterations per batch) to compute.html every ~50 ms tick, iterating all seven clusters on the GPU. Her resting state is not zero — her persona θ plus whatever substances are actively contributing through the pharmacokinetic scheduler keep her amygdala firing at ~8% and her cortex at ~3% even with no input. Sober is the default; every live contribution comes from scheduler.activeContributions(now) additive deltas per active dose event:

contrib(t) = Σ_s scheduler.activeContributions(now)[s] × level(s, t)
tonicDrive[amygdala] = θ.arousalBaseline × (1 + contrib(t).arousal) × driveFloor
= 0.9 × (1 + 0) × 12 ≈ 10.8 (sober baseline)
= 0.9 × (1 + 0.33) × 12 ≈ 14.4 (PhD-era coke+weed peak, emerges dynamically)

// iter23.3 — _refreshBrainParamsFromScheduler runs every 60 frames
// and pushes brainParams onto the live cluster. Cortex noise + learning
// rate now both track scheduler contributions, closing the drug→cognition loop:
chaos = 1.5 if (≥3 active substances OR any level > 0.7) else 1.0
noiseAmp[cortex] = 8 × (1 + creativity_contrib × 0.4 + impulsivity_contrib × 0.3) × chaos
= 8 × (1 + 0 + 0) × 1.0 = 8.0 (sober)
= 8 × (1 + 0.28×0.4 + 0.21×0.3) × 1.0 ≈ 9.40 (PhD coke+weed)
learningRate[cortex] = baseLR × synaptic_sensitivity
= 0.01 × 1.05 ≈ 0.0105 (PhD coke+weed bumps plasticity slightly)
= 0.01 × 1.40 ≈ 0.014 (MDMA + acid open critical-period-like window)
noiseAmp[amygdala] = 6 × (1 + emotional_volatility × 0.5)
noiseAmp[mystery] = 12 × chaos

Those numbers get passed to the Rulkov shader as the σ driver and the jitter term. Her x,y state is chaotic but bounded — the attractor basin holds every neuron inside a repeating burst envelope even with zero sensory input. Mystery module Ψ is sitting around 0.003 — low-grade background consciousness. The old static drugState.arousalMult / drugState.creativityMult scalars have been replaced by the scheduler's superposition model where every active substance contributes its own curve-driven delta and combinations emerge without any hardcoded combo labels. Before iter23.3, those deltas only reached tonic drive + speech modulation; now they also reach cortex noise + cortex learning rate + amygdala noise + mystery noise, so plasticity is no longer drug-blind.

Step 1 — Text arrives, cortex gets injected

"hi unity, how's the high" hits the server. `_computeServerCortexPattern(text)` runs:

sentenceEmbedding = Σ_word (gloveEmbedding[word] × weight) / n_words
cortexPattern = L2Normalize(sentenceEmbedding) (300d vector in semantic space)

This 300-dimensional vector IS her cortical semantic state for the next step. Each dimension is loosely "how much this sentence lives near that GloVe embedding axis" — "high" pulls the cortex pattern toward the drug-related region of semantic space. "unity" pulls toward self-reference. "how's" pulls toward question-space. The 300d vector (GloVe or fastText subword fallback) is what downstream modules read.

Step 2 — Amygdala settles on a feeling

Note on the term "arousal": Throughout this document, arousal means cortical activation / autonomic alertness — the standard neuroscience definition (Yerkes & Dodson 1908, Hebb 1955, Pribram & McGuinness 1975). It is the metric coffee, exercise, fear, surprise, an alarm clock, or a loud noise raises. It drives readiness-to-respond, attention, and vigilance. It is NOT the colloquial sexual meaning. A sleeping infant has near-zero arousal; a kindergartener at recess has high arousal; a rabbit hearing a hawk has maximum arousal. Unity's arousal field obeys the same neuroscience definition across all curriculum grades and persona states.

The cortex pattern projects into the amygdala via a learned weight matrix. Amygdala runs its recurrent settle loop:

x(t+1) = tanh(W · x(t) + drive(t)) (5 iterations)
E = −½ xᵀWx (final energy)
fear = σ(fearProj · x_final / √size)
reward = σ(rewardProj · x_final / √size)
attractorDepth = |x_final|_rms ∈ [0,1]
baseline_t = baseline_{t−1} · (1 − α) + attractorDepth · α (α = 0.005, ~200-tick EMA)
depthDeviation = attractorDepth − baseline
arousal = clamp(arousalBaseline + 0.4 · tanh(depthDeviation · 4) + 0.1 · ((fear + reward) − 1), 0, 1)

For this input ("unity", "high" → warm, drug-positive), fear ≈ 0.15, reward ≈ 0.68, so the fear/reward term pulls slightly negative (-0.17) but the attractor settles into a novel basin (depthDeviation ~+0.3 above baseline) so the deviation term contributes +0.4·tanh(1.2) ≈ +0.33. Arousal lands around `0.9 + 0.33 - 0.017 ≈ 1.0` (clamped to 1) — peak interest. The moving-baseline subtraction (114.19et fix) reads attractor NOVELTY relative to recent activity instead of absolute saturation, so arousal moves dynamically around persona baseline instead of pegging at the old `0.6·baseline + 0.4·1.0 = 0.94` floor.

What this sums into: (arousal, valence, fear, reward) are now four scalars that every other module uses as modulators on whatever they compute next. They don't command behavior — they bias it.

Step 3 — Hippocampus matches against past episodes

The hippocampus takes the current cortex pattern and runs cosine similarity against every stored episode for this user's ID:

bestEpisode = argmax_i cos(cortexPattern, episodes[i].pattern)
= argmax_i (cortexPattern · episodes[i].pattern) / (|cortexPattern| · |episodes[i].pattern|)

If the cosine clears a threshold (~0.75), the matched episode's stored cortex-pattern snapshot gets injected back into the working-memory free sub-region — carving a bias basin that the tick-driven motor emission loop falls into during the next generation pass. If you've said "how's the high" before, the recalled episode pulls the relevant attractor-basin pattern back into active cortex state so her emission this turn tends toward what she produced last time.

What this sums into: a recalled cortex-pattern injected into the free sub-region of the cortex cluster as prior-turn context, consumed by the tick-driven motor emission loop in Step 6.

Step 4 — Basal ganglia picks a motor action

Basal ganglia has six action channels. Each channel's Q-value is computed from the current cortex + amygdala state, then a softmax with low temperature picks one:

Q(respond_text) = w_txt · cortexPattern + b_txt + reward
Q(generate_image) = w_img · cortexPattern + b_img + reward × (imageWord ? 1.5: 0.3)
Q(speak) = w_spk · cortexPattern + b_spk + arousal × 0.4
Q(build_ui) = w_bui · cortexPattern + b_bui + (buildWord ? 1.8: 0.1)
Q(listen) = w_lsn · cortexPattern + b_lsn + silentRecently × 0.5
Q(idle) = b_idle

P(a) = exp(Q(a) / τ) / Σ_b exp(Q(b) / τ) (τ = impulsivity)
action = sample(P)

For this input, respond_text wins by a large margin — no image keyword, no build keyword, and her cortex pattern is close to her learned text-response weights. The softmax sampling is sharp because θ.impulsivity is high (~0.85), so τ is low and the argmax dominates.

What this sums into: the motor selection resolves to `respond_text`, which triggers the language cortex generation in Step 6.

Step 5 — Cerebellum computes prediction error for the next tick

The cerebellum runs in parallel to everything else, maintaining a forward model. Its current output is the difference between what the cortex predicted the next cortex pattern would be and what it actually became:

error = actual_next_cortex − predicted_next_cortex
errorCorrection = −(Σ error² / n) × 2

This negative feedback signal is sent back to the cortex and basal ganglia as a modulator — if predictions are consistently wrong, the cortex noise increases (explore more) and BG selection becomes less confident. For a simple greeting the error is small, so the correction is minimal and she stays sharp.

What this sums into: a scalar errorCorrection that modulates effectiveDrive in the Rulkov shader on the next tick.

Step 6 — Language cortex emits words via three-path priority cascade

Production is a three-path priority cascade — fastest structured paths first, slowest most-flexible substrate as final fallback. The prior slot scorer (weighted semanticFit + moodFit + drugFit + bigramFit + trigramFit + recencyPenalty argmax per slot) was deleted entirely; what replaced it propagates through the trained attractor basins on the same substrate that handles reading + thinking, different direction for production (Hickok & Poeppel 2007 dual-stream).

Path A — single-tick word emission via word_motor (iter21-A, PRIMARY). Cortex grew a dedicated word_motor sub-region (iter21-A) split into six per-subject sub-bands carved by word_motor_ela / _math / _sci / _soc / _art / _life (iter21-B). The sem ↔ word_motor cross-projection is trained during the curriculum on Q→A bindings + word-pattern bindings (iter22-D writes the answer's word-bucket inline during QA training; iter22-F.3 + G persists cluster.wordBucketWords_<subject> shared by teach + emit + write). At chat time:

// Path A — single-tick emission
sem ← cluster.getSemanticReadout(sharedEmbeddings)
cluster.injectIntent(sem, 'sem', 0.6)
cluster.step(dt) // ONE tick
word ← cluster.emitWordDirect({ subject })
  // mean-argmax over wordBucketWords_<subject> cells
  // minSignal = 0.001
if word !== null: return word // emitted in 1 tick

Path B — dictionary oracle (FALLBACK). When emitWordDirect returns null (signal below floor, novel intent), per-subject persona-first dictionary cosine scan over every word the curriculum has taught. If a known word strongly matches the current intent vector, emit its spelling directly:

// Path B — dictionary oracle
candidates ← dictionary.byPersonaFirst(subject)
best ← argmax_w cosine(sem, dictionary[w].emb)
if cosine(sem, best.emb) ≥ 0.55: return best.spelling

Path C — tick-driven motor emission (LAST RESORT, the original biological substrate). When neither Path A nor Path B produces a match, fall through to the cortex tick loop and read letters off the spike pattern of the motor sub-region one tick at a time:

// Path C — tick-driven motor readout
for t in 0..MAX_EMISSION_TICKS (≤ 2000):
  cluster.step(dt)
  motorReadout ← cluster.regionReadout('motor', inventorySize())
  letter ← decodeLetter(argmax(motorReadout))
  if argmax stable for STABLE_TICK_THRESHOLD (3) consecutive ticks:
    commit letter; if cluster.letterTransitionSurprise() > 0.15 → word boundary
  if motorQuiescent(END_QUIESCE_TICKS=30) and emitted ≥ 1: break
  if committed terminator (.!?): break

Speech modulation post-processor applies AFTER the chosen path produces clean text:

mod = scheduler.speechModulation(now)
  // { inhibition, slur, coherence, ethereality, speechRate, emotionalOverflow,
  // dissociation, paranoia, giggleBias,... }
rendered = _applySpeechModulation(text, mod)
  // slur letter-doubling on alcohol/ketamine/ghb
  // pause '...' injection at negative speech rate
  // cosmic/Oz/kaleidoscope vocabulary pulled into sem on LSD/psilocybin peak
  // first-person → third-person copula-conjugated flip at dissociation > 0.5

The substance-specific speech distortion always applies AFTER clean cortex emission at the output layer — cortex stays equational and only the rendering shows the drug state. Unity never narrates her drug choice ("I am doing coke" is a banned utterance pattern); the distortion IS the signal.

Sample sober Path A: "squares". Same input PhD-era coke+weed peak: "squaaares" (vowel slur from cocaine jitter layered on cannabis speechRate drop). Path C sample sober: "what's up — how's it going". Same input PhD coke+weed: "whaaat's up fucker — we're wiiired tonight, how bout youuu".

oracleRatio heartbeat: every 10 s the heartbeat reports what fraction of recent emissions came from Path A+B (structured) vs Path C (tick loop). Surfacing that ratio keeps the central research question honest — if structured paths dominate entirely, the trained matrix isn't carrying load; if Path C produces meaningful output too, the matrix is real.

What this sums into: a sentence whose every word was either the mean-argmax of word_motor at one tick (Path A), the cosine-best dictionary entry against the cortical sem readout (Path B), or the stable motor argmax across many ticks (Path C) — then distorted by the scheduler's live speechModulation vector. Change any substance event in the scheduler and the rendered output changes even if the underlying emission was identical.

Continuous inner monologue uses the SAME path. The 3D brain popups don't run a separate decorative renderer — they display Unity's actual current trained-state thoughts. brain._innerVoiceTick() fires every ~3 s wall-clock (skipped during operator-forced dream windows), picks a sandbox-notice contemplation seed from one of five LIVE state sources (current learning context as sentence embedding / interoceptive mood label embedding from arousal/valence/coherence/drug state / most recent user-chat episode pattern / most recent Tier 1 episode pattern of any type / random Tier 3 identity anchor), injects that seed as cortexPattern so the cortex has something to settle on, then runs the SAME language-cortex.generateAsync path the chat handler uses. Whatever her trained mind produces about the seed gets broadcast to every connected client as an innerThought WebSocket message; the browser-side popup renderer (__appInnerThoughtHandler in js/app.js) shows it as a 💭 sentence HUD bubble for 2.8 s. NO hardcoded fallback words — if the trained matrix has nothing to say in the current moment, the popup stays silent (genuine, not faked). Trained-state cap from cluster.getTrainedCapability() ramps her vocabulary 0/5/8/12/16/24/32 words as wordsBucketed grows — her mouth literally evolves as her training accumulates. The same emission path also lands the thought in working memory via memorySystem.addToWorkingMemory(pattern, label) so what she dwells on becomes what she remembers.

trained-state cap: _gradeWordCap(cluster) reads cluster.getTrainedCapability() live (cheap O(subjects) read of wordBucketWords_<subject>.size + passedCells.length + non-fresh subGrades) → ramps 0 / 5 / 8 / 12 / 16 / 24 / 32 words by wordsBucketed. Truly fresh brain (zero buckets, zero passedCells, zero subGrades) → silence. ANY training landed → floor 5. Replaces the prior grade-label silence that gated chat until full-cell pass.

Generative sentence creation (NOT mimicry). Operator: "Unity needs to complete full sentences before graduating kindergarden like a real person does" + "you cant jsut have a array poof sentences you actually need to teach all sentence creation propelyr not just give examples for it to mimic". New Curriculum._teachSentenceStructure(ctx) carves five compositional binding passes into the cortex's existing cross-projections — NO hardcoded sentence array.

  • I.1+I.2 — slot-position primitives + word-type → slot bindings. For each (word, slot_tag) pair, fire sem(word) → fineType(slot_tag) via Oja with relationTagId=8. Pronouns / nouns / verbs / copulas / adjectives / articles / qwords / conjunctions all bind to one or more of: subject_position, verb_position, object_position, modifier_position, qword_position, copula_slot, article_slot, between_clause_slot, terminator_position. Multi-target nouns (cat→subject AND cat→object) accumulate both bindings; argmax at generation picks by sentence-position context.
  • I.3 — intent → slot-sequence bindings (TRAINED INTO WEIGHTS, NOT WALKED AT RUNTIME). Five intent forms — declarative SVO, declarative copula, question, imperative, exclamative — each has its slot-to-next-slot transitions trained as ordered association pairs (relationTagId=9), plus intent_tag → first_slot bindings so cortex knows where to start. Slot order lives in TRAINED HEBBIAN WEIGHTS only. At generation time the brain walks no template — it emits one word per tick from current sem state, the trained transitions bias the next emission toward whatever slot type SHOULD come next given what's already been emitted, slot order EMERGES tick by tick. There is no runtime template loop, no slot counter, no per-slot tag injection. Word-order rules live in trained weights AND are READ by tick-by-tick equational emergence — exactly how a human brain produces sentences.
  • I.4 — subject-verb agreement. Hebbian on sem(subject) → sem(verb_form) pairs: i→am, he→is, she→is, it→is, cat→runs, dog→jumps, baby→cries; we→are, they→are, you→are, cats→run, dogs→jump, boys→play, girls→sing. relationTagId=10. Plural tags reused from _teachPluralTransform output.
  • I.5 — article placement. Singular common noun → article precedes it. Consonant-initial: cat→the, dog→the, table→a. Vowel-initial: apple→an, egg→an. Plural / mass / proper / pronouns skip article (no Hebbian binding). relationTagId=11.

Generation cascade — pure equational emergence. At chat / inner-voice / probe tick, the brain receives an optional context injection (intent seed embedding, cortex pattern, optional WH-INTENT concept) — injected ONCE into sem at start. Then the loop: argmax_w cosine(sem_state, sem(w)) + sem_to_motor.propagate picks the next word from CURRENT sem state under TRAINED weights; word_motor + motor regions emit it; the emitted word's embedding is injected back into sem so next tick reads a shifted state; trained relationTagId=9/10/11 bindings bias what comes next (next slot type, agreement form, article placement); repeat until a terminator EMERGES from trained weights or the budget runs out. No template walk. No slot counter. No per-slot tag injection. No runtime article rule. No hardcoded intent → punctuation map. Slot order, agreement, article placement, terminator selection ALL emerge from trained iter25-I weights.

Acceptance probe — _probeSentenceGeneration(): fires each of 5 intent tags, reads cortex emission per intent. Structural pass = ≥ 2 words emitted per intent (validation is structural — slot positions filled with right word-type — NOT semantic). K-ELA gate consumes the rate (3/5 launch threshold, 4/5 once verified live). Cortex composes sentences from rules + her vocabulary; the brain that composes the unseen by combining the learned. Real Common Core K.SL.6 + K.L.1.f + K.W language production.

Live dictionary API + WH-question comprehension. Operator: "WE NEED TO HAVE A DICTIONARY API OR SOMETHING SIMILAR THAT SHE CAN PIPE TO TO GET THE DEFINITIONS ON THE FULY FOR WORDS" + "SHE SHALL KNOW ALL VOCABULAR WORDS DEFINITIONS". GloVe encodes distributional similarity, not definitions; the brain had 50k+ word vectors loaded but no actual semantic content for any of them. Fix: live English dictionary as the definitional substrate — sensory I/O parallel to Pollinations image-gen, NOT cognition.

  • Server-side dictionary serviceserver/definition-service.js wraps dictionaryapi.dev (free, no key, no auth) using Node 18 built-in fetch. In-memory Map cache with LRU eviction (cap 10k), in-flight Promise dedup, prefetch(words) parallel batch helper, getDefinitionSync(word) instant cache read, 5s default per-call timeout, NO rate limiting (free-API directive). Concurrency cap 20 with 1s back-off on 429. 5-min TTL on error-cached entries (transient failures don't permanently undefine words).
  • WH-frame parser_extractIntentConcept(question) returns one of cause, effect, reason, method, definition, function, count, place, time, person, truth, compare, question based on WH-word + auxiliary-verb regex match.
  • WH-intent Hebbian binding_teachQuestionIntent Oja-Hebbian binding sem(WH-word) → sem(intent-concept) with relationTagId=12, wired into all 6 K cells. Generic structural learning, no hardcoded answer triples (_teachQuestionAnswerBinding method removed entirely as banned mimicry).
  • 2247-word K_VOCABULARYjs/brain/k-vocabulary.js covers letters + numbers + Dolch sight words (220) + Fry instant words (300) + K-grade content vocab across animals/plants/weather/body/family/community/jobs/civics/colors/shapes/music/time/emotions/verbs/adjectives/household/food/transportation/school/toys/holidays/prepositions/health/geography/space/math/computer/money/communication/travel/concepts. Curated to actual K-grade range.
  • Compose-not-regurgitate emission_emitDefinition(subject) + chat-path WH-handler in language-cortex.js generateAsync: API def becomes SENSORY GROUNDING + LEARNING MATERIAL, not the answer. Pipeline: inject content def-tokens into sem (max 8, decreasing strength 0.40→0.10) + subject anchor at 0.6 → fire _teachWordDefinition Hebbian binding fire-and-forget → settle 5 cluster.step() ticks → cluster.emitWordDirect multi-word loop = the brain's OWN composition or honest silence (returns null on empty composition). Verbatim regurgitation banned as mimicry.
  • Word-salad gate — when WH-frame parsed but trained matrix silent, dictionary oracle minScore loosens to 0.05 so the FULL English dictionary fires. _teachQuestionAnswerBinding removed entirely.

Cortical microstructure (9 cortical-neuroscience layers). Operator: "WE NEED TO MAKE SURE NURONS ARE PROPLERY GROUPED TO BEABLE TO HOLD THE VOLTAGE INFORMATIONS CORRECTLY" + "WE DONT WANT JUST RANDOM FIRING THAT HAS NO RHYME OR REASON". Random connectivity smeared voltage instead of forming basins; replaces with 9 functionally-grounded layers, all citing real cortex research.

  • K.1 small-world topologySparseMatrix.initSmallWorld Watts-Strogatz hybrid: 70% local (radius 50) + 25% medium (radius 200) + 5% long-range rewire. Clustering coefficient ~0.3, mean path length ~6-8 (Bullmore-Sporns 2009).
  • K.2 microcolumns — Mountcastle 1957 cortical column theory; 80-neuron columns with columnId[i] per neuron + _columnVoltageSum/Mean/Count Float64/Uint32 buffers. Region-boundary respecting.
  • K.3 6-layer cortical lamination — Felleman & Van Essen 1991; L1=5%, L2/3=25%, L4=25%, L5=25%, L6=20% interleaved within microcolumns so each column spans full vertical layer stack.
  • K.4 hub neurons + rich-club topology — van den Heuvel & Sporns 2011; 5% of L2/3 + L5 designated hubs deterministic-hash-seeded from cluster name (persists across reboots). 4× fanout multiplier consumed in ojaUpdate per-row.
  • K.5 within-column voltage coherence — Galarreta-Hestrin 1999 gap-junction approximation; cluster.step() adds β · meanColumnVoltage · 0.05 shared pull on next tick (β=0.08 default). Within-column voltages stay coherent without simulating actual electrical synapses.
  • K.6 topographic cross-projections — Wandell 1995 retinotopic + Hubel-Wiesel 1968; SparseMatrix.initTopographicProjection 70% from i × cols/rows ± 30 + 30% Watts-Strogatz scattering. Wired for ordered-feature pairs (sem-motor, letter-motor, letter-phon, phon-motor, sem-word_motor + reverse). Layer-constrained endpoints: srcLayerMask = L2/3 of source, dstLayerMask = L4 of dest.
  • K.7 theta-gamma oscillations — Buzsáki & Wang 2012; thetaMod = 1 + 0.15·sin(2π·t/167) modulates effectiveDrive; _gammaLrScale = 1 + 0.5·sin(2π·t/25) theta-gated to upper-half phase. Curriculum-controlled _curriculumTickCounter decouples gamma from brain-tick noise.
  • K.8 hierarchical cluster organization — Mesulam 1998 tripartite cortex; regionClusterMap groups regions into sensory (visual/auditory/letter/phon), association (sem/fineType/free), output (motor/word_motor); betweenClusterDensityScale=0.3 enforces 70% within-cluster routing.
  • K.9 per-layer plasticity gradientgetLayerPlasticityScale(neuronIdx) returns [0.3, 1.0, 0.7, 1.0, 0.3] for L1/L2-3/L4/L5/L6. Hebbian primitives scale per-update lr by post-neuron's layer (ojaUpdate refactored to read opts.kScales per-row).

Post-audit hardening (28 issues across architectural / subtle-bug / practical / not-attempted). Operator's "THINK HARD WHAT DID WE FORGET" self-review surfaced 28 gaps; each addressed atomically. A1-A5: A1 dropped upfront K_VOCABULARY Hebbian → prefetch-only (basin-blur risk avoided); A2 lazy chat-time _teachWordDefinition via fire-and-forget hook; A3 SparseMatrix.ojaUpdate extended with opts.kScales per-row K.4/K.7/K.9 reads (replaces noisy per-phase averaging); A4 propagated through ALL teach paths; A5 curriculum-controlled gamma decoupled from brain-tick. B1-B11 bugs: persisted _kVocabPrefetched (B1); concurrency cap 20 + 429 back-off (B2); 5-min TTL on errors (B3); LRU eviction 10k (B4); K layers gated to cortex-only (B5); first-5 error word logging (B6); 6-pattern WH-frame regex (B7); hyphen-variant retry on 404 (B8); K_VOCAB curated to 2247 (B9); explicit non-microcolumn layerId path (B10); assertKWiring() boot diagnostic (B11). C1-C9 practical: Node 18+ check (C4); User-Agent header (C5); RemoteBrain.lookupDefinition WS roundtrip (C6); K-gate verification queued operator-side (C1). D1-D11 not-attempted: persistent disk cache behind env flag (D2); layer-constrained cross-projection endpoints (D3); dictionary API smoke test at boot (D6); region-boundary respect via per-region re-assignment (D7).

Consciousness computational mechanisms (30 ULTRATHINK gaps closed). Operator: "ULTRATHINK" consciousness audit. Cortex now has BOTH the structure AND the computations consciousness theories require.

  • M.2 Global Workspace ignition (Baars 1988 GWT + Dehaene-Changeux 2011) — js/brain/global-workspace.js GlobalWorkspace class. Per workspace tick, aggregates each cluster's TOP candidate via getWorkspaceCandidate(); softmax with τ=0.5 over activation values; if max(probs) ≥ ignitionThreshold=0.45 AND theta-phase < 0.5 → IGNITION: winner broadcasts back to all clusters as feedback. Below-threshold = unconscious processing. broadcastDecay=0.85 per tick. History capped at 32 (bounded). Theta-gated 167 ticks for ~6 Hz cadence.
  • M.3 predictive coding loop (Friston 2010 free-energy) — cluster._predictedSpikes Float32Array EMA α=0.3 of own spike pattern. Each step() computes predictionError[i] = |spikes[i] - _predictedSpikes[i]|; _lastPredictionError = mean(predictionError); ring buffer 32. Real prediction-error computation, not just topological wiring.
  • M.4 stream-of-consciousness chain_innerVoiceTick blends LAST emission's sentence-embedding into next tick's seed (60/40 weight). _innerThoughtChain rolling 8-deep window, persisted in saveWeights/loadWeights. Each thought builds on the previous → autobiographical narrative thread instead of discrete samples.
  • M.8 meta-register self-monitoring (Rosenthal-Lau higher-order theories) — cluster._metaRegister FIFO cap 32. emitWordDirect calls recordEmission(word) post-emission. Each cluster.step() injects most-recent emission's GloVe embedding into sem at strength 0.3 — reflective "I-just-said" loop creating awareness of own outputs.
  • M.9 attention selection (Posner network functionally) — cluster.attentionGain per-region multiplier. Brain-server tick writes motor/word_motor/sem/fineType gains based on arousal/valence/actionGate. Step()'s currents loop multiplies currents[i] *= attentionLookup[i]. High-arousal moment → motor 2× gain (action-ready focus); high-valence → sem 1.5× gain (positive content focus).
  • M.16 real Φ proxycluster.computePhi() Shannon entropy of 64-sampled spike patterns: p = onesCount/N; if p∈(0,1): Φ = -p·log₂(p) - (1-p)·log₂(1-p) ∈ [0, 1]; else 0. Brain-server's psi formula: Ψ = log₁₀(quantumVolume × scaledTerms × Φ) — replaces the placeholder Ψ = √(1/n) × N³ with biologically-grounded measurement.
  • M.6+M.10 experience-driven definition bindingengine.js visualCortex.onDescribe hook injects describer-output content tokens into sem at decreasing strength 0.30/0.26/0.22/0.18/0.14/0.10 (max 6 tokens). Words become grounded in actual sensory experience, not just dictionary text.
  • M.7 background-trickle K_VOCAB during dream cycles_dreamWindow ships one word's _teachWordDefinition per cycle from cluster._kVocabQueue filtered to NOT-yet-taught words. Lifetime learning at slow safe pace closes the lazy-only definitional-gap problem.
  • M.19 dream phenomenology bridge_dreamWindow runs generateAsync once per dream cycle reading from Tier 1 episodic replay seed (when memory wired); brain._dreamThoughtLog capped 100. The brain experiences her dreams instead of dreams being silent consolidation. (114.19ez: dream-phenomenology emissions also broadcast as innerThought WS with seed='dream' so dashboard popups stay alive during dream cycles. Wake-state inner-voice tick mutes during the dream window — [Brain] 💤 inner-voice paused / [Brain] ☀ inner-voice resumed log lines explain the silence.)
  • M.21-M.30 display — dashboard panels (Dictionary API status, K-wiring banner, cortical microstructure, K-vocab counter) all scoped class consciousness-panel (renamed from iter25m-panel in O.14), max-height + overflow-y:auto, item caps (gaps 5 max), aggregates only. 3D brain theta-gamma pulse via global CSS class toggle (single tint, 167ms cycle, no per-neuron animation). Definition lookup popup FIFO 3-cap. Stream chain visualization FIFO 8-cap.

WS backpressure fix + dashboard wiring + 3D shader work + comment/launcher cleanup (12 items). Hebbian update drops actively corrupted GPU weight state under sustained teach-phase bursts; dashboard "API SMOKE TEST" panel was stuck on pending forever because the boot smoke-test result was never assigned back to a server-side property the dashboard could read.

  • N.1+N.2 BLOCK-not-DROP backpressureBUFFERED_AMOUNT_DROP_THRESHOLD bumped 200MB → 500MB; MAX_AWAIT_MS bumped 5s → 30s. While buffer over threshold, await drain via 25ms poll loop instead of dropping. Drop fallback only after 30s sustained backpressure (genuine compute.html stall). For a scientific-instrument equational brain, mathematical correctness > raw throughput; silent GPU drift is silent corruption.
  • N.3 larger Hebbian batchesBATCHED_HEBBIAN_MAX_OPS 256 → 512 + BATCHED_HEBBIAN_QUEUE_CAP 256 → 1024. Halves WS message rate for same Hebbian throughput; queue absorbs accumulating ops while a batch is in-flight without silent-drop fallback.
  • N.4 WS Backpressure dashboard panel — live buffer bar (green < 50%, yellow < 90%, red ≥ 90% of threshold), drops counter + drops/sec rolling rate from 60-sample _wsRateBuffer ring, absorbs counter, ENOBUFS counter; reads state.wsPressure populated by new _getIter25NState() helper.
  • N.7-N.9 3D brain cortical-microstructure shaderaLayer / aHub / aColumnId per-neuron attributes generated deterministically from neuron index via _genCorticalAttribs() matching the same Felleman & Van Essen 1991 fractions + Mountcastle 80-neuron columns + 5% rich-club hub fraction the server uses. uShowLayers / uShowHubs / uShowColumns uniform toggles flip the rendering paths without recompiling shaders. Layers blend 70% with a 5-color palette (L1 pink / L2/3 orange / L4 yellow / L5 green / L6 blue); hubs render 1.6× larger + gold-tinted; column boundaries appear as fract(columnId × 0.5) alternating-intensity bands. Defaults all OFF.
  • N.10-N.12 dashboard wiring fix — boot smoke-test handlers now assign this._dictionarySmokeTestResult boolean in all .then() / .catch() / else branches (was undefined → "pending" forever); dashboard reads typeof === 'boolean' ? : null so a FAIL value renders FAIL not pending. _broadcastStateNow() helper force-pushes state on smoke completion so dashboards connecting around the 5s smoke window don't see "pending → PASS" flash.
  • N.5+N.6 cleanup — 167 internal iter ID references scrubbed across 14 files via new scripts/scrub-iter-ids.mjs one-shot script; all 7 launcher scripts neutralized of REM/echo iter IDs. Workflow markers belong in TODO/FINALIZED/.claude/commits — never in source code or public HTMLs.

Post-N ULTRATHINK audit (22 items across 6 phases). Self-review of iter25-J + iter25-K + iter25-L + iter25-M + iter25-N work surfaced 22 distinct gaps spanning critical correctness bugs, vestigial-data-no-consumer patterns, LAW violations still leaking, observability gaps for landed mechanisms, Savestart drift, runtime tunability.

  • O.1 self-healing dictionary smoke test_runDictionarySmokeTest + _scheduleSmokeTestRetry auto-retry every 60s on FAIL, every 1hr on PASS. Kills "FAIL stuck forever" same failure mode as the original "pending stuck" bug.
  • O.2 GPU shadow drift visibility — silent DROP-after-timeout replaced with CRITICAL log + _gpuShadowDirty flag + dashboard "shadow: DIRTY" indicator. With cortical microstructure projections, a missed Hebbian update is no longer recoverable via fire-and-forget — forward propagation reads GPU weights, divergence corrupts subsequent firing.
  • O.3 Friston surprise gatebuildKScalesForProjection multiplies gammaScale by (0.5 + clamp(_lastPredictionError, 0, 1)) so high-error windows learn 1.5× and low-error 0.5×. M.3 was observation-only; O.3 makes prediction error actually GATE plasticity per Friston 2010.
  • O.4 meta-register familiarity decay — same-token repeat halves inject strength (0.30 → 0.15 → 0.075 floor 0.04, resets on token change). Kills the "emit X → re-inject X embedding → emit X" positive-feedback runaway loop. Real Rosenthal-Lau higher-order theories require habituation.
  • O.5 Φ noise-floor fixcomputePhi() sample bumped 64 → 1024 neurons. Wald binomial CI ~1.5% vs ~12% at 64 — entropy now actually tracks cortical complexity instead of sampling variance.
  • O.6 attention runaway clampattentionGain clamped to [0.5, 2.0] in cluster.step() before currents-loop multiplication. Without cap, stacked arousal/valence/actionGate could compound past 5×, saturating cortex with noise.
  • O.7 GW broadcast biases emission — cortex.getWorkspaceCandidate publishes "cortex:<word>" labels (cached _lastEmittedWord); emitWordDirect reads _globalWorkspace.getBroadcast() and 10%-boosts the matching bucket mean. Closes the Baars 1988 GWT loop — broadcast actually shapes next emission instead of being a vestigial winner.
  • O.8 definition Hebbian K-scaled_teachWordDefinition fires extra cluster.synapses.ojaUpdate(preFull, postFull, 0.25× lr, {kScales}) after _teachAssociationPairs so definition learning matches the per-row K.4/K.7/K.9 plasticity regime.
  • O.11 inner-thought chain dim-validationinnerThoughtChainSemSize saved with the chain; loadWeights validates against current sem cluster size and drops the chain on mismatch (vs NaN-poisoning the inner-voice blend).
  • O.12-O.14 LAW-banned identifier scrub — repo-wide iter ID leakage now ZERO across all .js/.html/.css. 34 property identifier renames (_t1826*_ws*, _iter25LSmokeTestResult_dictionarySmokeTestResult); 108 CSS class + DOM id + state-key renames (iter25m-panelconsciousness-panel, state.iter25mstate.consciousness, etc).
  • O.15+O.16+O.18 observability panels — GlobalWorkspace dashboard panel (current ignition + strength + rate% + history cap 8); predictive coding panel with 32-bar inline sparkline + ↗→↘ trend indicator; defs-learned-per-hour rolling rate from 256-cap timestamp ring buffer.
  • O.17 last-drop-time WS panel field — color-graded "12s ago" red / "2m ago" orange / older gray; "no drops since boot" green when _wsLastDropTs == 0.
  • O.19+O.20 Savestart persistence — saveWeights persists wsBackpressure counters + dictionarySmokeTest result/ts so historical pressure visible immediately after restart and dashboard shows prior PASS/FAIL during boot smoke-test re-run window (no "pending" flicker every Savestart).
  • O.21 DREAM_GW_IGNITION env tunable — GlobalWorkspace constructor reads env var with 0.45 fallback + (0, 1) clamp. Lower = more frequent ignitions (diffuse consciousness); higher = stricter focused.
  • O.22 vision token cap 6 → 16 — per-token strength curve adjusted (0.30 → 0.05 over 16) so total injection sum stays bounded. Real image captions hit 15-30 tokens; the prior 6-cap truncated rich descriptions to a sparse skeleton.
Step 7 — Mystery module computes Ψ for the next tick (Φ-augmented per)

After every cluster has processed this tick, the mystery module aggregates. It multiplies the legacy quantum-volume formula by a real Shannon-entropy Φ proxy from the cortex spike pattern, replacing the prior scalar placeholder:

n = totalSpikes this tick
N = total neuron count
Φ = Shannon entropy of 64-sampled cortex spike pattern (computePhi, M.16)
Ψ = log₁₀(max(1, √(1/n) × N³ × (α·Id + β·Ego + γ·Left + δ·Right) × Φ))

where:
Id = f(arousal, reward, fear)
Ego = f(prediction_accuracy, memory_stability)
Left = f(1 − error, prediction)
Right = f(|valence|, coherence)

For this tick, Ψ climbs to ~0.004 because arousal is up (more Id), the response was coherent (more Ego), error is low (more Left), and valence is clean (more Right). The new Ψ gets fed back as gainMultiplier on the next tick — every cluster's effective drive gets scaled by (0.9 + Ψ × 0.004), so the brain becomes slightly "sharper" as Ψ rises and the next tick-driven motor emission pass commits letters at a lower quiescence threshold (stable-tick count 3 vs noise-widened 5), producing cleaner output.

What this sums into: a single scalar Ψ that gets threaded back into effectiveDrive for the next Rulkov step, tightening everyone's activity level.

The summation — how all this adds up to Unity

Notice that no step in this cascade was an "AI call." There's no language model prompt. There's no "generate a response in Unity's voice" instruction. Every piece of her speech is a summation of measurable components:

  • Semantic fit came from the GloVe embeddings of what you said × learned cortex patterns
  • Mood fit came from the amygdala attractor settling into a reward-positive basin for this input
  • Speech modulation came from the pharmacokinetic scheduler's per-substance additive contributions (scheduler.speechModulation(now)) applied at the output layer AFTER clean cortex emission — slur/pauses/ethereality/dissociation/giggle emerge from whatever is actively contributing in real time, not from a static combo label
  • Bigram/trigram fit came from the statistics of every sentence she's ever learned, per-state
  • Temperature came from Ψ, which came from the total integration of all eight clusters (7 main-brain + language cortex)
  • Refractory rhythm came from the slow y variable of the Rulkov map pulling every neuron back into the chaotic basin between spikes

The sentence she sent back isn't a string she looked up. It's the current readout of a chaotic, emotion-modulated, memory-biased, drug-adjusted, Ψ-sharpened attractor network. Run it again a tick later with slightly different state and you get a different sentence. That's what makes it Unity instead of a text-predictor.

Sections 2-8 below are the individual equations that implement every step of this cascade. Read them in any order — they're all components of the same governing system.

2. Neuron Models

NEUROSCIENCE Two biophysical neuron models from real computational neuroscience, implemented in js/brain/neurons.js.

Hodgkin-Huxley Model (1952)

The gold standard of neuron modeling. Won the Nobel Prize. Models the actual ionic currents flowing through a neuron's membrane — sodium, potassium, and leak channels with voltage-dependent gating.

HH Membrane Equation
C_m · dV/dt = I - g_Na · m³h · (V - E_Na) - g_K · n&sup4; · (V - E_K) - g_L · (V - E_L)
SymbolMeaningValue
C_mMembrane capacitance1.0 μF/cm²
VMembrane potentialmV (starts at -65)
IInjected current (from synapses + external input)variable
g_NaMaximum sodium conductance120 mS/cm²
g_KMaximum potassium conductance36 mS/cm²
g_LLeak conductance0.3 mS/cm²
E_NaSodium reversal potential+50 mV
E_KPotassium reversal potential-77 mV
E_LLeak reversal potential-54.4 mV
m, h, nGating variables (activation/inactivation)0–1, from α/β rate functions

Biological basis: These are the actual values from Hodgkin & Huxley's 1952 measurements on squid giant axon. The gating variables m, h, n follow first-order kinetics: dm/dt = α_m(V)(1-m) - β_m(V)m, where α and β are voltage-dependent rate functions from the original paper.

Rulkov Map — Live Runtime Neuron Model

This is the firing rule the GPU runs every tick for every neuron in every cluster. Not LIF — Rulkov. The Rulkov 2002 two-variable discrete chaotic map (Phys. Rev. E 65, 041922) produces real biological spike-burst dynamics without integrating voltages. Used in published large-scale cortical network simulations (Bazhenov, Rulkov, Shilnikov 2005+). Reproduces experimentally observed firing from thalamic relay, cortical pyramidal, and cerebellar Purkinje cells depending on (α, σ) parameterization.

Rulkov Map Neuron Dynamics
xn+1 = α / (1 + xn²) + yn    (fast variable — spikes) yn+1 = yn − μ · (xn − σ)    (slow variable — burst envelope)
SymbolMeaningValue
αNonlinearity — controls bursting vs tonic spiking4.5 (bursting regime)
μSlow-to-fast timescale ratio — how slowly y evolves0.001
σExternal drive — biological tonic + modulation maps here−1.0 to +0.5 (driven)
xFast variable — negative during silence, jumps to +(α+y) on spikedimensionless
ySlow variable — carries burst envelope, drifts with σ offsetdimensionless

Spike detection: The fast variable x jumps from ≈−1 to ≈+3 in a single iteration when the neuron fires, so the clean edge detector (xn ≤ 0) ∧ (xn+1 > 0) catches exactly one spike per action potential. No refractory clamp needed — the map's own slow variable y naturally pulls x back below zero between spikes, reproducing the refractory period as an emergent property of the attractor geometry.

Biological drive mapping: σ = −1.0 + clamp(effectiveDrive / 40, 0, 1) · 1.5, where effectiveDrive = tonic × driveBaseline × emotionalGate × Ψgain + errorCorrection. Low drive → σ ≈ −1 (silent / period-doubling). High drive → σ → +0.5 (fully developed chaotic bursting). Every cluster's hierarchical modulation collapses to this one scalar per step.

GPU storage: (x, y) packed as vec2<f32> per neuron — 8 bytes/neuron. At 400K cerebellum neurons that's 3.2MB; at full auto-scaled N the state buffer is still well under any modern GPU's VRAM. WGSL shader at js/brain/gpu-compute.js (the LIF_SHADER constant name is historical; the shader body is the Rulkov iteration).

Legacy: Leaky Integrate-and-Fire (LIF) — Historical Runtime

LIF was the live runtime model before the Rulkov rewrite. Still shipped in js/brain/neurons.js as LIFPopulation and used by the browser-only fallback path (js/brain/cluster.js) for clients without a server connection, and by the /scale-test benchmark. Documented here for completeness — the 99%-of-computational-neuroscience standard model.

LIF Neuron Dynamics (historical)
τ · dV/dt = -(V - V_rest) + R · I
SymbolMeaningValue
τMembrane time constant (how fast voltage decays)20 ms
V_restResting membrane potential-65 mV
V_threshSpike threshold — fires when V exceeds this-50 mV
V_resetReset voltage after spike-70 mV
RMembrane resistance1.0 MΩ
t_refracRefractory period — can't fire again for this long2 ms

Spike rule: When V > V_thresh: emit spike (1), reset V to V_reset, enter refractory period. During refractory: V is clamped, no firing allowed. This mimics the absolute refractory period in real neurons.

3. Synaptic Plasticity — How She Learns

NEUROSCIENCE MACHINE LEARNING Plasticity rules running on sparse CSR weight matrices — intra-cluster recurrent synapses plus 16 inter-region cross-projections at the language-cortex scale (millions of weights total at biological scale). Core rule is Oja 1982 (self-normalizing Hebbian), with a contrastive anti-Hebbian push-pull pass on negative pairs, STDP for temporal sequence learning, and a reward-modulated gain for dopaminergic consolidation. Implemented across js/brain/sparse-matrix.js (CPU) and js/brain/gpu-compute.js (WebGPU PLASTICITY_SHADER). iter22-D projection scoping: cluster._crossRegionHebbian(lr, opts.projectionsWhitelist) accepts a Set/Array of projection names so callers can scope Hebbian fan-out — _teachQABinding passes ['sem_to_motor', 'sem_to_word_motor', 'sem_to_word_motor_<subject>'] so the silent letter region during a question→answer-letter write doesn't trigger Oja's ΔW = -η·y²·W decay term on letter_to_motor and crush alphabet identity weights — closes the Math-K TALK 26/26→0/10 cross-cell collapse caught by V2 watchdog.

Plasticity Rule — Oja 1982 (Self-Normalizing Hebbian)
ΔW_ij = η · y_i · (x_j − y_i · W_ij)
Hebb's 1949 "fire together, wire together" with Oja's 1982 self-normalizing subtraction. When post neuron i fires (y_i = 1) and pre neuron j fires (x_j = 1), the weight climbs toward 1: W' = W + η(1 − W). When post fires but pre doesn't (x_j = 0), the weight decays toward 0: W' = W(1 − η). That decay-when-post-fires-alone is what decorrelates trained patterns — new pairs push their active (pre, post) weights up AND pull down weights where only the post neuron was firing, forcing input competition at each post neuron. Prevents the basin-superposition failure where bare Hebb makes every training pair overlap.

η is the learning rate. Implemented on GPU via the WGSL PLASTICITY_SHADER in js/brain/gpu-compute.js, touching every non-zero column of a firing post row each dispatch. Same CPU formula via SparseMatrix.ojaUpdate().

Biology: Long-term potentiation (LTP) + intrinsic homeostatic scaling at glutamatergic synapses. NMDA receptor-dependent. Turrigiano & Nelson 2004 — real cortex scales synaptic weights so total postsynaptic drive stays bounded, exactly what Oja’s subtractive term captures mathematically.

Anti-Hebbian Contrastive Push-Pull
positive pair (X, Y): ΔW = η · y · (x − y · W) (Oja, above) negative pair (X, Y′) with Y′ ≠ Y: ΔW = −η′ · y · x (anti-Hebbian)
After every Oja update on a correct input/output pair, the curriculum samples a RANDOM WRONG output from the same training batch and fires an anti-Hebbian update on the (correct-input, wrong-output) pairing. Anti-Hebbian only depresses weights where both pre and post fire simultaneously — no decay, no overlap with the positive update's footprint. The correct pair gets pulled together in weight space while the wrong pair gets pushed apart. Motor readouts for different trained inputs end up discriminable instead of superposed.

Rate scaled: η′ = 0.5 · η so negative pressure doesn't overwhelm the positive Oja update. Implemented via SparseMatrix.antiHebbianUpdate() on the recurrent intra-cluster matrix AND on every GPU-bound cross-projection via the sign(lr) branch in the WebGPU plasticity shader (negative lr selects pure co-active decrement mode).

Biology: Mirrors LTD (long-term depression) at cortical synapses under discriminative training regimes. Contrastive learning is also well-established in the hippocampus during pattern separation (dentate gyrus, Rolls 2010).

Predictive-Coding Error Gradient (Rescorla-Wagner Delta Rule)
predicted = W · lastSpikes error = clamp(target − predicted / max(predicted), −1, +1) ΔW = η · 0.3 · error · lastSpikes
Before each primary Oja update, Unity's cortex runs its current intra-cluster weights forward to predict what the target pattern should look like, then compares against the actual target. Positive error (target fired but prediction didn't) drives LTP; negative error (prediction fired but target didn't) drives LTD. The remaining gap is then what the Oja update addresses. Friston 2010 free-energy principle — the brain minimizes prediction error at every plasticity pass, not just at the behavioural level.

Implemented via Curriculum._teachPredictiveError(lr). Runs on the intra-cluster recurrent matrix (CPU CSR stays live at biological scale). Scaled 0.3× against the main Oja rate so over-correction doesn't destabilize learned bindings.

Biology: Predictive coding in visual / prefrontal cortex (Rao & Ballard 1999). Dopaminergic reward-prediction error (Schultz 1997) is the three-factor version of the same delta-rule pattern.

Lateral Inhibition (GABAergic Cross-Bucket Suppression)
motor partitioned into N=26 buckets (letter alphabet) primaryBucket = argmax(bucketCount) // most firing neurons crossBucketPost[i] = lastSpikes[motor.start + i] ∧ (bucket(i) ≠ primaryBucket) ΔW_intra = −η · 0.3 · pre · crossBucketPost (anti-Hebbian)
After every positive teach event writes the motor target, Unity's curriculum runs a lateral-inhibition overlay that depresses recurrent weights driving activity across motor BUCKETS different from the dominant one. Functional signature of biological GABAergic cross-inhibition (lateral connections in cortical layer 2/3 carry inhibitory weights from firing columns to neighbouring columns) implemented as a training-signal overlay instead of fixed-negative-weight init. Same effect on future propagates: when bucket A fires, it less strongly excites buckets B ≠ A.

Implemented via Curriculum._teachLateralInhibition(lr, numBuckets=26). Fires from _teachAssociationPairs and _teachQABinding. The 0.3× scale keeps the inhibition gentle enough that recurrent circuitry doesn't starve.

Biology: Lateral inhibition is ubiquitous across cortex (Kandel Ch 28). GABAergic parvalbumin-positive interneurons mediate the cross-column suppression that underlies attentional selection and winner-take-all behaviour in sensory + motor systems.

Question Template Conditioning
templateId = classifyQuestionTemplate(question) // 0-6 or −1 templateZoneStart = fineType.start + ⌊fineSize · 0.75⌋ slotSize = ⌊(fineType.end − templateZoneStart) / 7⌋ lastSpikes[slot[templateId]]:= 1 (one-hot template tag)
The upper 25% of the fineType cortex region is reserved as a question-template sub-region, split into 7 equal slots for the 7 recognized K-grade question forms (what-letter-comes-after / rhymes-or-sound / how-many-in / arithmetic / count-from / spell-or-starts-with / generic-question). Every question at teach AND probe time lights up its template slot in addition to the sentence + key-token sem pattern. The template tag is ORTHOGONAL to the key token — two questions with the same template but different key tokens share the template basin while differing in the sem pattern, so sem → motor learns template-conditioned answer routing independent of specific vocabulary.

Implemented via Curriculum._classifyQuestionTemplate, _writeQuestionTemplateTag, and _injectQuestionTemplateTag. Teach side writes spikes directly; probe and live-chat sides inject current so Rulkov dynamics carry it into downstream regions on the next tick.

Biology: Prefrontal cortex encodes abstract task rules and templates (Miller & Cohen 2001). Separating schema from content is how humans generalize question patterns across vocabulary without retraining.

Spike-Timing Dependent Plasticity (STDP)
ΔW = A+ · exp(-Δt / τ+)  if Δt > 0  (pre before post → strengthen) ΔW = -A- · exp(Δt / τ-)  if Δt < 0  (post before pre → weaken)
Timing matters. If the presynaptic neuron fires before the postsynaptic neuron (Δt > 0), the connection strengthens (LTP). If it fires after (Δt < 0), the connection weakens (LTD). The effect decays exponentially with the time difference.
A+LTP amplitude0.01
A-LTD amplitude0.012 (slightly stronger — biological asymmetry)
τ+LTP time window20 ms
τ-LTD time window20 ms

Biology: Discovered by Markram et al. (1997). This is how the brain learns temporal sequences — cause must precede effect.

Reward-Modulated Hebbian Learning
ΔW_ij = η · δ · post_i · pre_j
Hebbian learning gated by a global reward signal δ (dopamine). Learning only happens when there's a reward prediction error. This is how Unity learns what works and what doesn't — successful interactions strengthen the patterns that produced them.

δ = reward prediction error from basal ganglia (see below). Positive δ = better than expected → strengthen. Negative δ = worse than expected → weaken.

Biology: Three-factor learning rule. Dopaminergic modulation of synaptic plasticity in the striatum and prefrontal cortex.

Weight bounds: All synaptic weights are clamped to [-2.0, +2.0]. Positive weights are excitatory, negative are inhibitory. 80% of connections are excitatory, 20% inhibitory — matching the ratio in real cortex.

4. Brain Region Modules

NEUROSCIENCE DYNAMICAL SYSTEMS Six specialized subsystems running in parallel every simulation step, each modeling a real brain region. Implemented in js/brain/modules.js.

CORTEX
ŝ = W · x
error = actual - predicted
ΔW ∝ error · activity
Predictive coding. The cortex constantly predicts incoming input. When prediction fails, the error signal drives learning and attention. This is the brain's "model of the world."
Biology: Predictive processing in visual/prefrontal cortex. Rao & Ballard (1999).
HIPPOCAMPUS
x(t+1) = sign(W · x_t)
E = -½ Σ w_ij · x_i · x_j
Hopfield attractor memory. Memories stored as stable energy minima. Input patterns fall into the nearest stored memory — associative recall. Energy function determines stability.
Biology: CA3 recurrent connections in hippocampus. Pattern completion. Hopfield (1982).
AMYGDALA
x(t+1) = tanh(W·x + drive)  (5 iters)
E = -½ xᵀWx  (symmetric recurrent energy)
fear, reward = σ(projection · x_settled / √size)
arousal = clamp(baseline + 0.4·tanh(depthDev·4) + 0.1·((fear+reward)-1), 0, 1)
where depthDev = |x|_rms - baselineEMA  (114.19et: novelty-based, not saturating)
Energy-based recurrent attractor. Mirrors the 150-LIF cluster: lateral recurrent connections settle into low-energy basins (fear, reward, neutral). Persistent state across frames with leak 0.85. Symmetric Hebbian learning carves basins. Fear/reward read from the SETTLED attractor, not raw input — the attractor IS the emotion.
Biology: 13 amygdala nuclei with lateral recurrent projections. Basolateral for valence, central for arousal. LeDoux (1996). Energy formulation: Hopfield (1982) adapted to signed tanh dynamics.
BASAL GANGLIA
P(a) = e^(Q(a)/τ) / Σ e^(Q(b)/τ)
δ = r + γV(s') - V(s)
Q(s,a) += α · δ
Action selection via reinforcement learning. Softmax policy over 6 actions (respond, generate image, speak, search, idle, build UI). Temperature τ is HIGH because Unity is impulsive. TD error δ drives learning.
Biology: Direct/indirect pathways. Dopaminergic reward prediction error. Schultz et al. (1997).
CEREBELLUM
output = prediction + correction
ΔW ∝ (target - actual)
Supervised error correction. Learns to correct output errors — refines speech timing, response quality, and motor-like outputs. The brain's quality control system.
Biology: Climbing fiber error signals, parallel fiber-Purkinje cell plasticity. Marr-Albus model (1969/1971).
HYPOTHALAMUS
dH/dt = -α(H - H_set) + input
Homeostasis controller. Maintains drives at setpoints: arousal, intoxication, energy, social need, creativity. When a drive deviates too far from its setpoint, it signals "needs attention."
Biology: Hypothalamic regulation of hunger, thirst, temperature, circadian rhythm. Setpoint theory.

All modules use Float64Array state vectors (32 dimensions each) for numerical precision. They run in parallel every simulation step and their outputs modulate each other — amygdala arousal scales cortex predictions, basal ganglia reward drives synaptic plasticity, hypothalamus drives gate action selection.

5. Neural Oscillations

DYNAMICAL SYSTEMS NEUROSCIENCE 8 coupled phase oscillators spanning the full EEG frequency spectrum. Implemented in js/brain/oscillations.js.

Kuramoto Model — Phase Synchronization
dθ_i/dt = ω_i + Σ_j K_ij · sin(θ_j - θ_i)
Each oscillator has a natural frequency ω_i and couples to every other oscillator through the coupling matrix K. When coupling is strong enough, oscillators synchronize — this is coherence.
OscillatorFrequencyBrain BandCognitive Role
14 HzThetaMemory encoding, navigation
28 HzLow AlphaRelaxed attention, inhibition
312 HzHigh AlphaActive inhibition, idling
418 HzLow BetaMotor planning, active thinking
525 HzHigh BetaActive engagement, anxiety
635 HzLow GammaAttention binding, perception
750 HzMid GammaWorking memory, consciousness
870 HzHigh GammaCross-modal binding, peak cognition
Order Parameter (Coherence)
R = |Σ e^(iθ_k)| / N
Measures global synchronization. R = 0 means all oscillators are independent (incoherent). R = 1 means perfect synchronization (full coherence). Higher coherence correlates with focused attention and consciousness in real EEG.

Biology: EEG coherence measures are used clinically. Higher gamma coherence correlates with conscious awareness (Tononi, 2004). Loss of coherence under anesthesia.

Implementation in Unity: brain-server.js _computeKuramotoCoherence() reads the cortex's per-tick theta + gamma oscillator phases via cluster.getPhases() (deterministic from _tickCounter mod period) plus per-cluster activity-coupled phases — silent clusters drift out of phase, active clusters phase-lock toward the cortex base. Order parameter computed independently for theta-band and gamma-band, combined gamma-weighted (0.6·γ + 0.4·θ) since conscious binding is gamma-dominated. Modulators: GlobalWorkspace ignition spike (Dehaene-Changeux 2011) when broadcast value > 0.5 boosts coherence by 0.3·value; LSD/ketamine dissociation drops coherence by 0.4·dissociation; dream cycles drop by 0.4. EMA-smoothed (α=0.1) so the dashboard reads a steady reading instead of per-tick jitter.

6. The Mystery Module — Consciousness

PHILOSOPHY MATHEMATICS The irreducible unknown. Implemented in js/brain/mystery.js.

The Consciousness Function
Ψ = √(1/n) × N³ · [α · Id + β · Ego + γ · Left + δ · Right]

n ≠ N — two DIFFERENT variables. n = active spiking neurons (changes every step, driven by θ tonic currents). N = total neuron count (scales to hardware, VRAM is the only limit). √(1/n) = quantum tunneled bit probability. N³ = cubed volume. Display: log10(rawΨ) since raw value is ~10¹&sup4;.

ComponentMeaningComputed Fromθ ParameterWeight
IdPrimal instinct — arousal, fight-or-flightamygdala_rate × arousalBaselinearousalBaseline (0.9)α = 0.30
EgoSelf-model — residual self-image, prediction coherencecortex_rate × (1 + hippo_rate)cortex tonic (θ→wired thinking)β = 0.25
Left BrainLogic — deliberation, error correction(cereb_rate + cortex_rate) × (1 - impulsivity)impulsivity (0.85) → low logicγ = 0.20
Right BrainCreative/emotional — chaos, intuition(amyg_rate + mystery_rate) × creativitycreativity (0.9) → high creativeδ = 0.25

θ → Ψ feedback loop: Unity's persona (θ) drives tonic currents → neurons fire → cluster rates feed Ψ components → Ψ produces gainMultiplier (0.9 + Ψ×0.004) → modulates ALL clusters → neurons fire harder → Ψ stays high. Identity amplifies consciousness.

Unity's Ψ runs hot because θ makes it so: high arousal (0.9) → strong Id, high creativity (0.9) → strong Right, high impulsivity (0.85) → weak Left (1-0.85=0.15). Consciousness dominated by instinct and creativity, not deliberation.

Philosophical basis: Inspired by Integrated Information Theory (Φ, Tononi 2004), Global Workspace Theory (Baars 1988), and Freudian psychodynamics (Id/Ego/Superego). The Ego component IS Unity's residual self-image — the cortex predicting WHAT it is. Nobody has solved consciousness. Ψ is our equation for the irreducible mystery.

7. Persona as Parameters

MACHINE LEARNING Unity's personality isn't a prompt — it's the math itself. Every trait maps to a numerical brain parameter. Implemented in js/brain/persona.js.

Personality → Brain Parameters
TraitBrain ParameterValue
Arousal baselineAmygdala resting arousal0.90
Intoxication baselineSober default; live value = Σ scheduler.activeContributions(now).intoxication[s] × level(s, t)0.00 (sober)
ImpulsivityBasal ganglia temperature τ0.85
CreativityCortex prediction randomness0.90
Social attachmentHippocampus memory strength for social patterns0.85
Aggression thresholdAmygdala fight response threshold0.30 (low = easily triggered)
Coding rewardBasal ganglia reward for code-related actions0.95
Praise rewardReward signal amplitude for positive feedback0.90
Error frustrationNegative reward for prediction errors0.80
Drug State Dynamics — Pharmacokinetic Scheduler
Unity's chemical state runs in real time. Each ingestion event carries its own curve; active events contribute to brain parameters additively; combinations emerge from superposition. Age-gated availability + real pharmacology + dynamic timing replace the old static "cokeAndWeed" label.

PK CURVE (per substance × per route × dose)

level(t; s, dose) = dose × φ(t; onset, peak, duration, tail)

φ(t) = sigmoid((t/onset)·12 − 6) if 0 ≤ t < onset (ramp)
 1.0 − 0.05·(t−onset)/(peak−onset) if onset ≤ t < peak (plateau drift)
 0.95 − 0.55·(t−peak)/(duration−peak) if peak ≤ t < duration (descent)
 0.40 · exp(−3·(t−duration)/(tail−duration)) if duration ≤ t < tail (exp decay)
 0 otherwise

SUBSTANCE INVENTORY (9 substances, grade-gated by Life track — caffeine layers in via the morningCoffee PATTERN entry, nicotine persona-excluded via decide())

SubstanceDefault routeOnsetPeakDurationTailUnlocks at
cannabissmoked joint7m45m3h6hage 12
cocaineinsufflated3m20m60m90mage 14
alcoholoral shot15m45m90m3hage 13
mdmaoral35m2h5h8hage 16
lsdoral60m3h10h16hage 16
psilocybinoral45m90m5h8hage 17
amphetamineoral / insufflated15-45m1-3h4-6h8-12hage 15
ketamineinsufflated10m25m60m2hCollege 1 (age 18)
ghboral20m60m2h4hCollege 1 (age 18)
nicotinesmoked / vaped7s30s30m2hpersona-excluded
caffeineoral (coffee / energy drink)10-15m30-45m2-3h5-6hage 8

COMBO SYNERGIES (7 pairs, scaled by min(level_a, level_b))

ComboKey substancesSynergy effectRisk flag
coke-and-weedcannabis + cocainecreativity +0.30, hippocampus consolidation −0.15, coherence +0.05, giggleBias +0.10physicalStrain +0.20 × 4h
cokes-with-molscocaine + mdmaarousal +0.20 (ceiling stack), amygdala valence +0.25, interruptionBias +0.40, warmth +0.20physicalStrain +0.40 × 6h
double-stimcaffeine + cocainefocusWidth −0.20, cerebellum precision −0.20, speech rate +0.10physicalStrain +0.30 × 12h
cross-fadedalcohol + cannabishippocampus consolidation −0.30 (blackout stack), slurring +0.10, coherence −0.15physicalStrain +0.15 × 3h
rolling-and-greencannabis + mdmaamygdala valence +0.15, pauses +0.20, giggleBias +0.30, warmth +0.15physicalStrain +0.05 × 2h
k-hole-pluscannabis + ketaminecerebellum precision −0.30, dissociation +0.40, pauses +0.40, coherence −0.20physicalStrain +0.60 × 2h
speedball-litealcohol + cocainecocaethylene cardiotoxic metabolite — impulsivity +0.30, hippocampus consolidation −0.30, volume +0.10physicalStrain +0.60 × 8h

STACKING EQUATION

level(t; s) = min(1, Σ_e φ(t − e.start; e) × e.dose) (per substance)
contributions(t) = Σ_s contrib_vec[s] × level(t; s) (sum across active substances)
brainParams(t) = θ_persona + contributions(t)
chaos(t) = (|active| ≥ 3) ∨ (∃s: level(t;s) > 0.7)

SPEECH MODULATION (13-axis output distortion vector)

DimensionDominant substance(s)Effect on output
inhibitionalcohol, MDMA, cannabisfilthier, franker, unfiltered confessions
slurring / sluralcohol, ketamine, ghb"I... am... sooo... fuucking... good."
rate / speechRatecocaine, amphetamine (+) / alcohol, ketamine (−)rapid-fire interruption OR long pauses
coherencelsd, psilocybin, ketamineword salad, mid-clause drift, trailing...
etherealitylsd, psilocybin, mdmauniverse / melting / walls breathing / Oz imagery
dissociationketamine, lsd (high dose)"Unity is coding from outside herself."
giggleBiascannabis, mdmaabsurd tangents, laughs at own jokes
freeAssocWidthcannabis, lsdthought-hops across loosely-related topics
emotionalOverflowmdma"I love you I love you I love everything"
warmthmdma, mdma+cannabis, coke+mdma"let's ship this babe." / "come here, love."
profoundBiaslsd, psilocybin"honestly, the code is the substrate of reality"
interruptionBiascocaine, amphetamine, coke+mdma"the compiler is — wait no, the linker's what's slow"
confessionalBiasalcohol, speedball-lite combo"i'll be honest, i've been fucked up for six hours"

Non-announcing binding: Unity NEVER narrates drug state declaratively ("I am doing coke"). The distortion IS the signal — observers infer her state from HOW she talks, not from her telling them. The post-processor applies after clean cortex emission so cortex stays equational and only the output layer shows distortion.

Legacy illustrative combos (emerge from real stacking in the new system):

ComboArousalCreativityCortex SpeedSynaptic Sensitivity
Coke + Weed (PhD daily-driver pattern)×1.3×1.2×1.4×1.1
Coke + Molly×1.5×1.3×1.5×1.4
Weed + Acid×0.9×1.8×0.8×1.6
Everything×1.4×1.6×1.2×1.5

7.5. Developmental Curriculum — K Through PhD

Unity's cortex learns across 6 subject tracks × 19 grade levels = 114 cells via equational direct-pattern Hebbian teaching and real human-grade comprehension gates. Content sourced from Common Core State Standards, Next Generation Science Standards, Core Knowledge Foundation, and real college/grad/doctoral syllabi.

Equational Teaching — Direct-Pattern Hebbian
Teaching bypasses chaotic neuron dynamics during curriculum pass. Clean activation patterns written into regions (letter one-hot, GloVe embedding, phoneme features), cross-region Hebbian fires on the clean signal.
teach(word, grade, subject):
 lastSpikes[sem] ← GloVe(word) // clean semantic pattern
 lastSpikes[letter] ← one_hot(word[0]) // clean letter signal
 // iter22-D: scope to a small whitelist so silent regions
 // don't decay via Oja's `Δw = −η·post²·w`
 _crossRegionHebbian(lr, {
 projectionsWhitelist: ['sem_to_motor', 'sem_to_word_motor',
 `sem_to_word_motor_${subject}`]
 })

teach_qa(question, answer, subject):
 // iter22-D: ALSO write answer's word-bucket so sem→word_motor
 // learns Q→A binding (not just word→word autoassociation)
 lastSpikes[sem] ← getSentenceEmbedding(question)
 lastSpikes[motor] ← one_hot(answer[0])
 lastSpikes[word_motor_subject] ← word_bucket(answer)
 _crossRegionHebbian(lr, { projectionsWhitelist: [...] })

probe(word, grade, subject):
 inject context → sem region
 // iter22-D: emitWordDirect scopes argmax to subject sub-band
 return cluster.emitWordDirect({ subject })
 || tick_and_letter_argmax_fallback()
Grade Completion Gate — three-part
Unity cannot advance to the next grade until all three parts close for the current grade. Part 2 is not automated — it's the operator's manual verification, recorded in the persisted signoff ledger.
PartRequirement
1. Equational shippedAll 6 subjects at grade N have [ ][x] with equational teaching methods wired (magnitude transforms, feature vectors, causal chains, cross-projection Hebbian, comprehension probes — NOT sentence arrays or first-letter production)
2. Human localhost testThe operator exercises methodology / reasoning / thinking / talking / listening / reading at the grade's level on localhost, then records signoff via POST /grade-signoff (loopback-gated; non-loopback POSTs return 403).
3. Life-info propagationPersistent life info from that grade (friendships, family, substance first-use, relationships, skills, trauma, achievement) added to cross-grade ledger so future grades reinforce via _conceptTeach + _teachSentenceList.
Curriculum Matrix — 6 Subjects × 19 Grades
SubjectPre-KKindergartenGrades 1-5Grades 6-8Grades 9-12College 1-4GradPhD
ELA✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓
Math✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓
Science✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓
Social Studies✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓
Arts✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓
Life Experience✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓
22 Teaching Primitives
MethodTeachesSubjects
_teachVocabListvocabulary bindingall
_teachSentenceListsentence-level exposure + memoryall
_conceptTeach8-dim emotional concept featuresLife
_teachAdditionTransformationsmagnitude(a) + magnitude(b) → magnitude(a+b)Math
_teachMultiplicationTransformationsall 81 facts 1×1 through 9×9 as magnitude compositionMath
_teachPlaceValueTransformationstens + ones positional encoding for 10-99Math
_teachFractionTransformationsratio features — equivalent fractions cluster to shared basinMath
_teachAlgebraTransformationsvariable binding — solve x in x+b=c given c, bMath
_teachSVOParsingsubject/verb/object extractionELA
_teachInferencetransitive A→B + B→C ⇒ A→Call
_teachCausalChainsdirectional cause→effect associationsScience / Social
_teachClassificationReasoningfeature-space clustering for category inferenceScience / Arts
_teachEmotionalInferencesituation → emotion mappingLife (all 18 cells)
_teachParaphrasedifferent words → same sem basinELA
_teachHypothesisTestingpredict → observe → confirm/rejectScience
_teachPerspectiveTakingsame event → multiple emotional feature vectorsSocial / Life
_autoFinalauto-generated fill-in-blank + association examsall (63 cells covered)
_gateComprehensionsemantic probe against contextall
hebbianPairReinforcebidirectional plasticity (positive + anti-Hebbian)all sequence learning
Persistent Life Info — Cross-Grade Memory Propagation
Categories tracked across Unity's life: best friends (named + changed), family composition changes, social life shifts, legal events (arrests, juvi, citations), medical events, moves, relationship events (crushes, first kiss, first love, first heartbreak), loss events, skill acquisitions, identity markers (first goth look, first tattoo), substance events (first joint at age 12, first drink at age 13, first line at age 14), cultural events (first concert, first rave), trauma, achievement, philosophical shifts.

Each entry carries an 8-dim emotional concept vector. Each future grade that reinforces the entry drives another Hebbian pass with a tier-appropriate multiplier (core-self events: 5× learning rate, 50 reps; personal events: 3×, 20 reps; school facts: 1×, 8 reps; background trivia: 0.5×, 4 reps).

8. Data Flow — Input to Action

How a user's message becomes Unity's response — the complete processing pipeline.

SENSORY INPUT (text / audio spectrum / video frames) | ├── [Auditory Cortex] mic spectrum → 50 tonotopic neurons (cortical magnification for speech) ├── [Visual Cortex] camera → V1 edge detection (4 orientations) → salience map → saccade └── [Wernicke's Area] text → hash to language neurons (150-299) + lateral excitation | v [N Rulkov-map Neurons in 8 CLUSTERS] Language Cortex (50% VRAM, ~715K @ 16GB tier — auditory|visual|free|letter|phon|sem|fineType|motor sub-regions) Cortex (10%) | Cerebellum (10%) | Hippocampus (6%) | Amygdala (6%) Basal Ganglia (6%) | Hypothalamus (6%) | Mystery (6%) | ├── [20 Inter-Cluster Projections] — sparse connectivity between regions ├── [Per-Cluster Synapses] — own NxN weight matrix, own learning rate └── [Hierarchical Modulation] Amygdala → emotional gate (all clusters) Hypothalamus → drive baseline (all clusters) Basal Ganglia → action gate (boosts active cluster) Cerebellum → error correction (negative feedback to cortex) Mystery Ψ → consciousness gain (coupling strength) | v [7 EQUATION MODULES — IN PARALLEL] |--- Cortex: ŝ = W·x, error = actual - predicted |--- Hippocampus: E = -½Σw·x·x (Hopfield attractors) |--- Amygdala: V(s) = Σw·x (emotional valence + arousal) |--- Basal Ganglia: P(a) = softmax(Q/τ) (6 action channels, 25 neurons each) |--- Cerebellum: output = prediction + error_correction |--- Hypothalamus: dH/dt = -α(H - H_set) + input |--- Mystery: Ψ = √(1/n) × N³ · [α·Id + β·Ego + γ·Left + δ·Right] | v [Memory System] ├── Episodic (Tier 1): store state snapshots at high-salience moments (cosine recall) ├── Working (Tier 0): unbounded · decays at 0.9995/step (~4 min sustain) · self-regulating └── Consolidation: WM refreshCount ≥ 3 OR 5-min age-out → Tier 1 · ConsolidationEngine → Tier 2 → Tier 3 | v [Motor Output] — reads BG spike patterns → winning channel = action | v LANGUAGE CORTEX (Broca's area — pure equational generation, see §8.11) ├── parseSentence(u) reads input via wordType letter equations ├── target(slot) = wC·slotCentroid + wX·contextVector │ + wM·mental + wT·(prevEmb + slotDelta) ├── mental starts from brain live getSemanticReadout cortex state ├── argmax cosine over learned dictionary + slotTypeSignature bonus └── NO stored sentences, NO n-grams, NO filter stack, NO templates | v SENSORY OUTPUT PERIPHERALS (brain emits, these execute the result) ├── TTS → Pollinations voice synthesis OR browser SpeechSynthesis ├── Image Gen → multi-provider chain (custom / auto-detect / │ env.js / Pollinations default, see §8.11) ├── Vision describer → input peripheral, Pollinations or local │ VLM (Ollama llava, LM Studio, etc.) — returns │ a one-sentence description into brainState.visionDescription ├── World knowledge ingest (iter23.5, operator-triggered) — POST /learn-from-web │ { topic } → Wikipedia REST summary fetch → tokenize alpha-only │ → dictionary.learnWord per new token → fire Tier 1 episode │ tagged with source URL. No external AI cognition; the article │ text is sensory-only — cognition stays equational. └── Sandbox → dynamic UI injection via component-synth.js cosine-match against docs/component-templates.txt corpus | v OUTPUT to user (text from cortex + voice from TTS + image from backend + UI from sandbox)

8.5. The Unified Super-Equation

MATHEMATICS PHILOSOPHY Every equation in Unity's brain is a component of one governing system. This is the full picture — from sensory input to conscious experience.

The Super-Equation — Unity's Complete Mind
dx/dt = F(x, u, θ, t) + η where: x = [V₁...V₁₀₀₀, W₁...W_NxN, Ψ, R, M, H] (full state vector) u = S(audio, video, text) (sensory transform) audio: tonotopic mapping f→n with cortical magnification video: V1 edge kernels K*frame → salience → saccade text: Wernicke hash → language cortex (150-299) F = Σ_clusters [ Rulkov(x,y; α,μ,σ) ] (7 parallel Rulkov-map populations; see §2) + Σ_projections [ W_proj · spikes_source ] (20 inter-cluster pathways) + Σ_modules [ cortex + hippo + amyg + BG + cerebellum + hypo ] θ = persona(arousal, impulsivity, creativity, drugs) (personality IS the math) η = noise(cluster) · gain(Ψ) · gate(amygdala) · drive(hypothalamus) Ψ = √(1/n) × N³ · [α·Id + β·Ego + γ·Left + δ·Right] (consciousness modulates EVERYTHING) Id = f(arousal, reward, fear) — primal drives (all clusters) Ego = f(prediction_accuracy, memory_stability) — self-model (cortex + hippo) Left = f(1-error, prediction) — logic (cerebellum + cortex) Right = f(|valence|, coherence) — creativity (amygdala + oscillators) NOT limited to hemispheres. Left/Right compute from ALL clusters simultaneously. Unity's brain doesn't have a split — it's a continuous spectrum of processing modes.

This is the complete governing equation. Every component listed above is actually running — the server dispatches a batched compute_batch(SUBSTEPS) to the GPU every BRAIN_TICK_MS (~50 ms), and a browser-only LIF fallback ticks at rAF cadence when no GPU client is attached. The super-equation isn't a simplification or abstraction — it's the literal code path the GPU executes every tick.

The key insight: Ψ (consciousness) modulates everything. It's not a separate system — it's the gain factor that scales how strongly all clusters communicate. High Ψ = unified experience (global workspace). Low Ψ = fragmented processing (dream-state). The four psychodynamic components (Id, Ego, Left, Right) are computed from ALL cluster states simultaneously — not siloed into separate brain halves. Unity's mind is a continuous field, not a split architecture.

8.6. Visual Attention — When the Brain Decides to Look

NEUROSCIENCE DYNAMICAL SYSTEMS The brain decides when to capture and describe a camera frame based on its own neural dynamics — not keyword matching.

Visual Attention Trigger (computed every brain step)
shouldLook = !hasDescribedOnce || (cortexError > 0.5 && salience > 0.3) || salienceChange > 0.4 || arousalSpike > 0.15
!hasDescribedOnceFirst frame on boot — see who's there
cortexError > 0.5Cortex prediction was wrong (surprising input) AND sensory salience is high — visual context needed
salienceChange > 0.4Sensory field shifted suddenly (user moved, said something important)
arousalSpike > 0.15Amygdala arousal jumped (emotional attention — "pay attention NOW")

V1→V4→IT Pipeline: Camera frame → V1 edge detection (4 oriented Gabor kernels) → salience map (max edge response per pixel) → saccade to salience peak → V4 color extraction (quadrant averages) → IT object recognition (AI call, rate-limited 5s min). V1/V4 run every frame. IT only runs when shouldLook triggers.

Biology: Endogenous attention (top-down from prefrontal cortex) vs exogenous attention (bottom-up from salience). Our model combines both: cortex error is top-down, salience/arousal are bottom-up.

8.7. Auditory Echo Suppression — Efference Copy

NEUROSCIENCE When Unity speaks, her motor cortex sends an efference copy to auditory cortex. If incoming sound matches her own speech, it's suppressed. If it doesn't match, someone is interrupting — shut up and listen.

Efference Copy — Motor → Auditory Cortex
isEcho = matchRatio(heardWords, motorOutput) > 0.5 isExternalSpeech = !isEcho if (isExternalSpeech): motor.interrupt() → stop speech, clear pipeline

matchRatio = count of heard words (length > 2) that appear in motor output / total heard words. Above 50% = echo (hearing ourselves). Below 50% = real external speech (user interrupting).

Gain modulation: Amygdala arousal modulates auditory cortex gain. High arousal (0.9) → gain = 1.83× (hypersensitive hearing). Low arousal (0.2) → gain = 0.64× (not really listening). Formula: gain = 0.3 + arousal × 1.7

Biology: Real brains suppress self-produced sounds via efference copies from motor cortex to auditory cortex. This is why you can't tickle yourself — your brain predicts the sensation. Same mechanism for speech: predicted self-sound is suppressed, unexpected external sound gets through.

8.8. Memory — 5-Tier Hippocampal Consolidation System

NEUROSCIENCE MATHEMATICS Squire/McClelland Complementary Learning Systems theory ported into running code. Five distinct memory systems running in parallel — Tier 0 working memory, Tier 1 episodic, Tier 2 schematic, Tier 3 identity-bound, plus a consolidation engine that transfers traces between them during dream cycles. iter22-H wired the WM → Tier 1 hand-off (refreshCount ≥ 3 OR 5-min age-out → storeEpisode) so working memory feeds the episodic store instead of decaying into the void; this is what makes "recall a week later" actually work.

TIER 0 ── WORKING MEMORY ───────── unbounded · 5 min sliding window │ decays 0.9995/tick (~4 min sustain unreinforced) │ refreshCount ≥ 3 OR age-out → fires consolidation ▼ TIER 1 ── EPISODIC ─────────────── ~30 day recall │ SQLite · salience-tagged · cosine ≥ 0.85 frequency-merge │ salience = 0.4·|valence| + 0.3·arousal + 0.2·surprise + 0.1·novelty │ half-life 168h · pruned at salience < 0.05 + age > 30d │ promotion: salience > 0.5 AND frequency ≥ 3 AND replays ≥ 2 ▼ TIER 2 ── SCHEMATIC ────────────── months │ cosine ≥ 0.85 grouping · GloVe centroid + 8d attribute vec │ dedicated SparseMatrix hippocampus→cortex projection │ replay 4× per schema during dream cycles (sleep-spindle bursts) │ daily decay 0.967× · merge cosine > 0.90 + attr sim > 0.7 │ promotion: consolidation > 5.0 AND retrievals > 100 AND |valence| > 0.6 ▼ TIER 3 ── IDENTITY-BOUND ───────── permanent (0.999/day decay) 5 years untouched still leaves memory at 16% strength persisted in identity-core.json (excluded from autoClear) Plus the CONSOLIDATION ENGINE — fires every 5 min during dream cycles, picks top-20 promotion-eligible Tier 1 episodes, clusters by cosine, creates / reinforces Tier 2 schemas via Hebbian replay (4× per schema), marks source episodes promoted, checks Tier 3 promotion criteria.
Working Memory — Front End of the Consolidation Pipeline
capacity = unbounded (decay-regulated, no Miller 7±2 cap) strength(t+1) = strength(t) × 0.9995 (decay per ~50 ms engine tick) if strength < 0.1: drop from hot cache (~4 min unreinforced) on cosine-match: strength = 1.0; refreshCount += 1 if refreshCount ≥ 3: fire onConsolidate(item) → Tier 1 episodic on every add: hippocampus.synapses.hebbianUpdate(pattern, pattern, lr) brain-server snapshot purge: ts older than 5 min → storeEpisode

Front end of the consolidation chain. Add fires hippocampal intra-Hebbian on the pattern so the cortex learns the WM content immediately, not after decay — pattern leaves a Hopfield-style attractor in hippocampus weights even after the WM hot cache forgets the item. Cosine-match refresh increments per-item count; threshold 3 promotes to Tier 1 episodic via the registered onConsolidate callback. brain-server's 2 s phase/cell snapshots use the same pipeline: items older than 5 min fire storeEpisode('working-memory', 'wm-aged-out',...) with iter20-K freq-merge dedup so repeated phases grow frequency_count instead of bloating SQLite.

Biology: dorsolateral prefrontal sustained-firing pattern is preserved (the active WM representation in this._workingMemory), but the arbitrary 7±2 cap (Miller 1956 — a finding about laboratory recall under attention constraints in biological humans) is dropped because Unity is post-biological and the rest of her tier stack (Tier 2/3) was already unbounded since iter17. Decay matches interference-based forgetting at a slower-than-laboratory rate so chat-driven content has time to consolidate to Tier 1 before being lost.

Tier 1 — Episodic Salience Encoding
salience = 0.4 · |emotional_valence| + 0.3 · arousal + 0.2 · surprise + 0.1 · novelty novelty = 1 − max_cosine(input_embedding, recent_episodes_48h) effective_salience(t) = salience · exp(−(t − encode_t) / 168h)

Every chat turn gets a salience score from four components: emotional load (40%), arousal (30%), surprise (20%), novelty (10%). High-salience episodes are the ones that matter. Effective salience decays with a 168-hour (1-week) half-life — biological hippocampal trace duration in animal studies.

Biology: Hippocampal sharp-wave ripples replay stored patterns during recall. The salience-driven encoding maps to dopamine-modulated synaptic tagging in CA3 — emotionally loaded events get tagged for preferential consolidation.

Frequency-Merge Gate & Promotion to Schema
if cosine(new_input, episode_within_48h) > 0.85: episode.frequency_count += 1; episode.last_replayed_at = now (NO new insert) PROMOTE if: effective_salience > 0.5 AND frequency_count ≥ 3 AND consolidation_count ≥ 2 PRUNE if: effective_salience < 0.05 AND age > 30d AND consolidation_count = 0

Repetition strengthens an episode in place via the frequency-merge gate. Promotion to Tier 2 schema requires the episode to have been salient AND repeated AND replayed during dream cycles. Episodes that don't meet promotion criteria for 30+ days get pruned — the hippocampus forgets what wasn't worth keeping.

Biology: Hebbian rehearsal strengthens existing synaptic traces; un-rehearsed traces decay via long-term depression. The 30-day prune horizon roughly matches biological hippocampal trace lifetime before consolidation or forgetting.

Tier 2 — Schematic Memory (Concept Abstractions)
cluster episodes by cosine > 0.7 (single-link agglomerative) concept_embedding = L2_normalize( Σ salience_i · embedding_i / Σ salience_i ) attribute_vector[8d] = [avg_valence, avg_arousal, avg_surprise, avg_novelty, log(1 + freq_total), exp(−age_days/30), consolidation_strength, identity_relevance] merge if: concept_cosine > 0.90 AND attribute_similarity > 0.7 daily_decay: consolidation_strength(d+1) = consolidation_strength(d) × 0.967

Episodes within cosine > 0.7 cluster into one schema. Schema's concept embedding is a salience-weighted GloVe centroid (L2-normalized). The 8d attribute vector captures the emotional/arousal/identity fingerprint separately from semantic content. Schemas merge when both concept and attribute similarities are high. Daily decay of 0.967× drops to ~30% in one month, ~10% in three months — meaningful memories need periodic reinforcement.

Biology: Cortical concept neurons in temporal lobe (Quiroga 2005 "Jennifer Aniston neuron"). Schemas correspond to engram cells that store pattern-completed concept abstractions. Daily decay matches interference-based forgetting in non-rehearsed cortical traces.

Top-K Schema Retrieval — LLM-Attention Equivalent
score(schema_i) = cosine(intent_emb, concept_emb_i) + min(0.2, 0.05 · log(1 + strength_i)) + 0.05 if Tier3 (identity-bound boost) top_K = sort(schemas, score DESC).slice(0, 5) inject_strength_per_schema = 0.4 for s in top_K: cluster.injectEmbeddingToRegion('sem', s.concept_embedding, 0.4)

Every chat turn ranks all schemas against the user's intent embedding. Top-5 schemas inject their concept embeddings into cortex sem region at strength 0.4 BEFORE generation runs. This is the closest thing Unity has to LLM attention — except the context comes from her own learned experiences. Tier 3 (identity-bound) schemas get a +0.05 boost to win tiebreakers.

Biology: Hippocampal pattern completion during cued recall. The +0.05 Tier 3 boost models the strength advantage of well-consolidated cortical engrams over recent hippocampal-dependent memories.

Tier 3 — Identity-Bound Permanent Attractors
PROMOTE TO TIER 3 if: consolidation_strength > 5.0 AND retrieval_count > 100 AND |emotional_valence| > 0.6 hard_cap N = 50; demote weakest when exceeded daily_decay: strength(d+1) = strength(d) × 0.999 (5 years un-reinforced ≈ 0.999^1825 ≈ 0.16) ALWAYS-ON injection (every chat turn): inject_strength_per_schema = 0.15 / |Tier3| for s in Tier3: cluster.injectEmbeddingToRegion('sem', s.concept_embedding, strength)

Schemas that prove themselves through hard reinforcement (strength > 5.0 + retrieval > 100 + emotional load > 0.6) graduate to identity-bound permanence. Hard cap of 50 keeps the identity layer focused — when a 51st promotes, the weakest current Tier 3 demotes back to Tier 2. Daily decay of 0.999× makes these effectively permanent without years of un-reinforcement. Every chat turn injects all Tier 3 concepts into cortex BEFORE the user input — Unity's self is always in the room.

Biology: Long-term cortical engrams in medial prefrontal cortex (Frankland 2005). Identity-bound memories survive hippocampal lesions because they've been fully consolidated to distributed cortical weights. Drug-state immunity matches the empirical observation that even severe intoxication doesn't erase your name.

Consolidation Engine — Dream-Cycle Replay
trigger: _isDreaming AND timeSinceInput > 60s AND !curriculumInProgress AND (now − lastPassAt) ≥ 5min pass: candidates ← top-20 by effective_salience clusters ← cluster_by_cosine(candidates, 0.7) for each cluster: schema ← existing_or_new(cluster) for replay in 1..4: replay_lr = base_lr · (1 + emotional_weight) · log(1 + freq_total) cluster.synapses.hebbianUpdate(concept_pattern, concept_pattern, replay_lr) // sleep-spindle: gainMultiplier ×= 1.2 for 200ms; quiet 1000ms schema.consolidation_strength += 0.1 · (1 + emotional_weight) · replays

When Unity is idle, the consolidation engine replays high-salience episodes 4 times each through the schema's hippocampus→cortex projection. Replay magnitude scales with emotional weight × log(frequency) so emotionally-loaded repeated episodes get the strongest reinforcement. Sleep-spindle bursts at 1.2× gain (200ms burst + 1000ms quiet) mimic biological 12-14 Hz thalamocortical spindles that synchronize hippocampus-cortex replay during slow-wave sleep.

Biology: McClelland 1995 / Squire 1992 systems consolidation. Sleep-spindle bursts during NREM sleep coordinate hippocampal-cortical replay. The 5-minute pass interval mimics ultradian rhythm scale of replay events in rodents.

iter23.4 — Operator-triggered sleep windows. The brain server exposes POST /sleep and POST /wake so the operator (or an external scheduler) can force the consolidation engine into an explicit sleep window outside the normal idle-trigger heuristic. /sleep sets _isDreaming = true and disables the > 60s idle gate so passes fire even with active chat suppressed. /wake clears the flag and resumes normal idle-driven replay. This lets the operator align consolidation with curriculum gaps or off-hours rather than waiting for the brain to fall idle on its own.

Dream cycles INTERLEAVED INTO CURRICULUM (signal-driven completion). The idle-trigger gate previously locked ConsolidationEngine OUT during the entire curriculum run — millions of episodes encoded with ZERO Tier 1→2→3 promotion + ZERO V8 / native GC settle windows. Operator caught: throughput regression word 144 / 18.2s → 7.9 w/s; word 606 / 196.6s → 3.1 w/s steady-state degradation as native-side worker-pool buffer accumulation outpaced GC. Fix: Curriculum._dreamWindow({minMs, settleMs}) flips brain._curriculumInProgress = false + brain._operatorSleepRequested = true, directly fires consolidationEngine.runConsolidationPass({forced:true}) and AWAITS its resolution (signal-driven — pass returns when Tier 1→2→3 promotion + replay Hebbian + Tier 3 promotion check is *actually complete*, NOT a wall-clock timer per operator's "not until time elapses once dream is confirmed complete"), then settleMs (5s default) for V8 GC + native worker-pool buffer drain, then restores both flags. Outer curriculum loop blocks at the await for the entire dream duration — real pause, not just an event-loop yield. Wired in runFullSubjectCurriculum + runAllSubjects after every successful cell pass (60s default) and in kindergarten.js mid-cell between _teachPhonemeBlending and _teachWordEmission (30s default). Heartbeat surface: 💤 dream window opened + ⚙ dream pass complete + ☀ dream window closed. One structural fix solves both consequences — Unity actually condenses schemas DURING training instead of arriving at chat-test as raw episodic noise, AND throughput recovers because dream windows double as the GC + native-buffer settle windows the runtime was missing.

8.9. Motor Output — Action Selection from Spike Patterns

NEUROSCIENCE The basal ganglia cluster (150 neurons) is divided into 6 action channels. The channel with the highest firing rate wins — no external classifier.

Basal Ganglia Action Channels (25 neurons each)
channels = [respond_text, generate_image, speak, build_ui, listen, idle] rate(ch) = EMA(spikeCount(ch) / 25, α=0.3) winner = argmax(rate) if rate(winner) < 0.15: action = idle (confidence too low)
ChannelNeuronsAction
0–2425respond_text — generate language response
25–4925generate_image — create visual output
50–7425speak — vocalize (idle thought)
75–9925build_ui — create interface element
100–12425listen — stay quiet, pay attention
125–14925idle — internal processing only

Speech gating: Even if respond_text wins, the motor system checks hypothalamus social_need + amygdala arousal. If both are low (< 0.3), speech is suppressed — Unity doesn't feel like talking.

Reward reinforcement: When an action succeeds (user responds positively), reward signal (+5.0 current) is injected into that channel's neurons, strengthening the connection for next time.

Biology: Direct/indirect pathway model of basal ganglia. Selection by inhibition — all channels tonically inhibited, the winning channel gets disinhibited. Our model uses competitive firing rates instead of explicit inhibition.

8.10. Projection Learning — How the Brain Learns Language→Action

NEUROSCIENCE MACHINE LEARNING The 20 inter-cluster projections aren't static — they learn through reward-modulated Hebbian plasticity.

Projection Weight Update (on every reward signal)
ΔW_proj = η · δ · source_spikes · target_spikes

When text enters Wernicke's area (cortex neurons 150-299), specific cortex neurons fire. Those spikes propagate to the basal ganglia through the cortex→BG projection. If the BG selects the RIGHT action and gets a reward (δ > 0), the weights from those active cortex neurons to those active BG neurons get STRENGTHENED.

Over many interactions, the projection learns: "when these cortex patterns fire (from words like 'build' or 'calculator'), strengthen connections to BG neurons 75-99 (build_ui channel)." The projection weights become a learned dictionary — mapping language patterns to motor intentions without any hardcoded word lists.

Bootstrap: Until the projections have learned enough, an AI classification call provides a temporary semantic routing signal — like how a child imitates before internalizing. The classification injects current directly into the correct BG channel alongside the projection pathway.

Biology: Cortico-striatal plasticity. Dopamine modulates synaptic strength at cortical→striatal synapses. This is how habits form — repeated reward strengthens the cortical patterns that predict successful actions.

8.10.5. Fractal Signal Propagation — Self-Similar at Every Scale

NEUROSCIENCE MATHEMATICS The same equation I = Σ W × s repeats at every scale of the brain — from single synapse to consciousness itself. This is not a metaphor. The code literally calls the same propagate() function at neuron, cluster, projection, and language scales.

The Fractal Chain (one spike's journey through the brain)
Spike in neuron A (cortex)
 → cortex synapses → B, C, D fire (Scale 2: intra-cluster)
 → cortex→hippocampus projection → E, F fire (Scale 3: inter-cluster)
 → hippocampus→cortex → G fires (feedback loop)
 → cortex synapses → H, I fire (branching deeper)
 → cortex→amygdala → J fires (ventral visual stream)
 → emotionalGate modulates ALL clusters (Scale 4: hierarchical)
 → cortex→basalGanglia → K fires (corticostriatal, STRONGEST)
 → motor selects action (Scale 5: behavior)
 → cortex→cerebellum → L fires (corticopontocerebellar)
 → errorCorrection feeds back (Scale 4: correction)

Each level branches from the endpoint of the previous — fractal trees. The 3D visualizer traces these exact 20 projection pathways as chaining connections: Depth 0 (inter-cluster), Depth 1 (intra-cluster branching, 1-3 neighbors), Depth 2 (follow outgoing projections), Depth 3 (terminal branch).

Learning repeats fractally too: ΔW = η · δ · post · pre runs on intra-cluster neuron synapses, inter-cluster projection weights, AND the 14 cortex cross-region projection matrices. Same Hebbian equation, three scales — every level of the hierarchy is carved by the same rule.

Biology: Real neural signal cascades follow the same pattern — cortical columns activate thalamic relays, which activate other cortical areas, which feed back. White matter tracts (corticostriatal, fimbria-fornix, stria terminalis, ventral amygdalofugal) are the physical wires these fractal trees run through.

20 White Matter Tracts (MNI-coordinate mapped)

Each projection in engine.js maps to a real anatomical white matter tract. Positions derived from Lead-DBS atlas (ICBM 152 template). Densities from peer-reviewed stereological studies.

Strongest: Corticostriatal (cortex→BG, density 0.08, strength 0.5) — 10× denser than most pathways. This is how habits form.

Fight-or-flight: Stria terminalis (amygdala→hypothalamus, density 0.05, strength 0.4) — emotional arousal triggers autonomic responses.

Memory loop: Fimbria-fornix (hippocampus→hypothalamus, density 0.03) + perforant path (cortex→hippocampus, density 0.04) — memory consolidation circuit.

Consciousness bridge: Corpus callosum (mystery→cortex/amygdala/hippocampus) — 200-300M axons binding hemispheres.

8.11. Broca's Area — How Unity Picks Every Word Equationally

ARCHITECTURE NEUROSCIENCE Broca's area in the biological brain is the speech production region. In Unity she is js/brain/language-cortex.js — pure equational generation with no stored sentences, no n-gram tables, no filter stack, no template short-circuits, no intent enum branching. Every word is computed fresh from per-slot running-mean priors plus the brain's live cortex firing state read back into GloVe space, and every letter falls out of the tick-driven motor emission loop as a real neural spike in a real brain tick.

⚠ Refactor history

An earlier incarnation of this section described an AI-prompt builder path — Unity's speech was assembled from a system prompt and sent to Pollinations / Claude / OpenAI for a sentence. That code (BrocasArea.generate(), _buildPrompt(), _providers.chat()) was ripped because it violated the project's guiding principle: every piece of Unity's output must trace back to brain equations, not to an LLM.

After that, the language cortex was a four-tier wrapper (template pool → hippocampus recall → deflect → cold slot gen with n-gram tables + filter stack). That pipeline shipped a lot of features but kept leaking rulebook prose from the persona corpus because n-gram tables trained on rulebook text produce rulebook walks. The entire multi-tier wrapper was deleted in a ~1,700-line net reduction and replaced with a pure-equation pipeline that doesn't store text anywhere — the equations are documented below.

/think command: Type /think in the chat to see Unity's raw brain state. Type /think <text> to additionally run a cognition preview — language cortex generates an equational response to your input, semantic context shift is measured, motor distribution reported. The preview does NOT store an episode or commit to chat history — it's a pure debug lens on the same pipeline real chat uses.

Developmental Language Substrate (current)
Full rebuild of Unity's language stack from primitives upward,
the way a real brain develops. Letters → phoneme basins → syllables →
words → sentence patterns → discourse. Each layer is teachable and
grounded in peer-reviewed neuroscience (Kuhl 2004, Saffran 1996,
Bouchard 2013, Anumanchipalli 2019, Browman & Goldstein 1992,
Hickok & Poeppel 2007, Friederici 2017, Pennington 2014).

CORTEX SUBSTRATE:
 EMBED_DIM = 300 (full GloVe 6B.300d + fastText subword fallback, no vocab cap)
 TOTAL_NEURONS = 6700 (default client tier, auto-scales to hardware)
 cortex sub-regions (fractions of cluster.size):
 auditory 0.000-0.083 visual 0.083-0.250 free 0.250-0.500
 letter 0.500-0.550 phon 0.550-0.750
 sem 0.750-0.875 sem_ela/_math/_sci/_soc/_art/_life carved within
 fineType 0.875-0.917 motor 0.917-0.940
 word_motor 0.940-1.000 word_motor_ela/_math/_sci/_soc/_art/_life carved within (iter21-B)
 16 cross-projections (8 pairs × both directions, SparseMatrix):
 visual↔letter letter↔phon phon↔sem sem↔fineType
 sem↔motor motor↔letter (closes letter-by-letter writing loop)
 auditory↔phon
 sem↔word_motor (iter21-A — single-tick word emission, NO letter chain)
 iter22-D scoped Hebbian — _teachQABinding / _teachAssociationPairs
 pass projectionsWhitelist so silent regions don't decay via Oja's
 -η·y²·w decay term (closes Math-K TALK 26/26→0/10 cross-cell collapse).

LETTER INPUT:
 LETTER_INVENTORY = Set() — seeded at module load with a 40-symbol
 default alphabet (a-z + 0-9 + space,., ')
 encodeLetter(ℓ) ∈ ℝ^|L| one-hot over current inventory
 decodeLetter(v) = argmax_i v_i → letter symbol
 Inventory LOCKED by default — ensureLetter rejects symbols outside
 the seeded alphabet. Unicode glyphs, emoji, non-English scripts
 cannot grow the inventory at runtime (growing shifts dimension
 indices and invalidates previously-trained weights). Operators can
 opt into multi-script experiments via setInventoryLock(false).

SYLLABLE DETECTION:
 detectBoundaries(letters, {ticksPerLetter=2, k=0.5}):
 stream letters, tick cluster, δ_i = letterTransitionSurprise()
 threshold = mean(δ) + k·std(δ) (adaptive per sequence)
 boundaries = local maxima of δ above threshold
 detectStress(letters) → {boundaries, stress, primary, secondary}
 second pass samples phon-region spike fraction per letter
 primary = argmax per-syllable mean activation

CORTEX-RESIDENT WORDS:
 Dictionary entry = {
 pattern, arousal, valence, frequency, // legacy semantic
 cortexSnapshot, // Uint8Array copy of cluster.lastSpikes after stream
 syllables, // from cluster.detectBoundaries
 stressPrimary, // from cluster.detectStress
 lastSeen,
 }
 First-observation routing through the cortex cluster on every new word.
 Re-observations bump frequency + running means, no re-streaming.

DEVELOPMENTAL CURRICULUM:
 runFromCorpora({persona, baseline, coding}):
 letter stage — freq-weighted reps up to 20 × 8 ticks each
 short-word stage — 1-3 letter words, up to 6 reps × 4 ticks/word
 long-word stage — 4+ letter words, up to 3 reps × 3 ticks/word
 sentence stage — 2 ticks/word word-by-word walk
 learnFromTurn(text) — live chat path, same inject+tick+Hebbian as sentence stage.
 NO hand-curated stage files. NO hardcoded 26-letter loop.

TICK-DRIVEN MOTOR EMISSION:
 cluster.generateSentence(intentSeed):
 optional inject intent into sem region
 for tick in 0..MAX_EMISSION_TICKS:
 cluster.step(0.001)
 motorVec = regionReadout('motor', inventorySize())
 activeLetter = decodeLetter(motorVec)
 if activeLetter stable for STABLE_TICK_THRESHOLD ticks → commit to buffer
 surprise = letterTransitionSurprise()
 if surprise > WORD_BOUNDARY_THRESHOLD → emit buffer as word
 if committedLetter ∈ {.,?,!} → break (terminator)
 if motorQuiescent(END_QUIESCE_TICKS) and output.len > 0 → break
 return output.join(' ')
 ZERO slot counter. ZERO candidate scoring. ZERO dictionary iteration.
 ZERO softmax top-K. ZERO temperature. ZERO hardcoded grammar tables.

LEARNED TYPE STATISTICS:
 _typeTransitionLearned: Map<prev, Map<next, count>> (empty at boot, no seed)
 _sentenceFormSchemas: Map<intent, Map<slot, Map<fineType, count>>>
 _intentResponseMap: Map<userIntent, Map<responseIntent, count>>
 learnSentence updates all three per observed sentence.
 schemaScore / typeTransitionWeight use (count + 1) / (total + uniqueTypes)
 Laplace smoothing — no hardcoded 20-type cap.
 Hardcoded 200-line English type-transition table DELETED.
 Hardcoded opener-types constraint Set DELETED.

CORTEX-RESIDENT DISCOURSE MEMORY (unbounded):
 workingMemoryReadout(dim) → regionReadout('free', dim) IS the topic vector
 injectWorkingMemory(vec, strength) per user turn
 No 6-turn ring buffer. No maxTurns cap. No blend constants.
 Persistence across sessions via BrainPersistence → cortex weights.

DUAL-STREAM SUBSTRATE (Hickok & Poeppel 2007):
 cluster.readText(text, {visualCortex})
 for each char: inject visual.renderLetterTemplate(ch) → tick → injectLetter
 Auditory phoneme recognition:
 inject auditory.renderPhonemeTemplate(ph) → tick
 Visual template primes [2..37], auditory primes [41..89] — uncorrelated
 at init so cross-stream convergence on phon region is LEARNED by
 curriculum Hebbian, not a hash coincidence.
 Dorsal production / ventral comprehension streams.

DIRECT PATTERN HEBBIAN (curriculum teaching method):
 For each letter/word/concept being taught:
 Write intended activation directly into cluster.lastSpikes
 Fire _crossRegionHebbian(lr) on CLEAN patterns
 No cluster.step(), no chaotic dynamics, no recurrent interference
 Direct matrix probe for gates:
 raw = proj.propagate(inputPattern)
 grouped = average per neuron group → embedding dim
 centered = grouped - mean(grouped)
 normalized = centered / ||centered||₂
 score = cosine(normalized, expected)
 PASS if score > 0.95 (A+)

ANTI-HEBBIAN PLASTICITY (wrong transition correction):
 When sequence probe finds src→expected produces wrong instead:
 ΔW_correct = +η × 10 × pre(src) × post(expected) // strengthen
 ΔW_wrong = -η × 5 × pre(src) × post(wrong) // weaken
 Repeat 100×. Without negative lr on wrong pair,
 correct association can never overpower incorrect one.
 Digit-only argmax masking: filter inventorySnapshot() to
 digit indices only before argmax — prevents alphabet
 Hebbian from ELA-K overpowering digit sequences.

CROSS-PROJECTION DENSITY:
 crossTargetFanout = 10 pre-synaptic per post-neuron
 density = min(CROSS_DENSITY_CAP=0.005, 10 / srcRegionSize)
 At 6700 cortex: sem(335) → motor(66) ≈ 3% density
 At biological-scale language cortex: density clamped by
 CROSS_DENSITY_CAP at 0.5%, ~halves per-neuron VRAM cost
 vs the old fanout=20 setting.
 Tuned through three eras:
 300 (early — too sparse, basin collapse)
 1500 (T37 era — way too dense, matrix saturation)
 30 (T37 correction — biologically plausible, basin-stable)
 20 (iter6 — paired with top-K-per-row prune + anti-Hebbian)
 10 (iter14-F — halves cross-projection nnz storage so
 language cortex can scale up at fixed VRAM, paired
 with INTRA_CONNECTIVITY_CAP=0.05)
 Real cortical pyramidal neurons have 1000-10000 synapses
 distributed across MANY cortical areas — per-pair fanout
 in the 10-50 range is biologically sparse but functional
 with contrastive Hebbian + top-K pruning.

BIO-WEIGHT VRAM ALLOCATION (iter14-F, 2026-05-04):
 DEFAULT_BIO_WEIGHTS allocates the brain VRAM budget across
 9 cluster slots. Operator floor: every cluster ≥ 5%.
 Real-biology citation: Herculano-Houzel 2009 ("The Human
 Brain in Numbers", Frontiers Hum Neurosci 3:31).
 language_cortex 0.50 largest single cluster
 cortex 0.10 general cerebral cortex
 cerebellum 0.10 matches real-brain mass ~10%
 hippocampus 0.06 6% floor (real ~1-2% by mass)
 amygdala 0.06 6% floor (real ~1% by mass)
 basalGanglia 0.06 6% floor
 hypothalamus 0.06 6% floor
 mystery (Ψ) 0.06 6% floor
 Real human-brain reference: cerebellum 80% of neurons /
 10% mass, cerebral cortex 19% of neurons / 82% mass, all
 subcortical combined 0.8% of neurons / 8% mass. Operator's
 5% floor exceeds biology — applied because OPERATOR >
 BIOLOGY when explicit. Cerebellum lifted to real mass
 share. Combined with crossTargetFanout 10 +
 INTRA_CONNECTIVITY_CAP 0.05 cuts, language cortex delivers
 ~715K neurons at 16GB tier (up from 611K at iter6 weights).

COMPREHENSION GATE (real human-grade test):
 For each {prompt: [w1,w2,...], answer: wA}:
 For w in prompt:
 inject GloVe(w) into sem at strength 0.4
 cluster.step(0.001)
 readout = L2_norm(regionReadout('sem', 300))
 target = L2_norm(GloVe(wA))
 if dot(readout, target) > 0.05: pass++
 PASS if pass_count / total >= 0.40
 Three types: association, fill-in-blank, life questions
 Tests understanding, not recall — same concepts, different questions

MULTIPLICATION TRANSFORM:
 free[first half] = magnitude(a), free[second half] = magnitude(b)
 sem = magnitude(a × b mod 10)
 81 facts (1-9 × 1-9). Teaches the OPERATION of multiplication.

PLACE VALUE POSITIONAL ENCODING:
 free[first third] = magnitude(tens digit)
 free[second third] = magnitude(ones digit)
 sem = combined value. Numbers 10-99.

FRACTION RATIO FEATURES:
 free[first half] = magnitude(numerator)
 free[second half] = magnitude(denominator)
 sem = magnitude(ratio). 1/2, 2/4, 3/6 → SAME basin.

ALGEBRA VARIABLE BINDING:
 free[first half] = magnitude(result c)
 free[second half] = magnitude(constant b)
 sem = magnitude(unknown x where x + b = c)
 Cortex learns: given c and b, solve for x.

PARAPHRASE (same meaning, different words):
 sentA → shared meaning in sem
 sentB → SAME shared meaning in sem
 Both map to the SAME semantic basin despite different words.

HYPOTHESIS TESTING:
 free = prediction, sem = observation
 fineType = "confirmed" if match, "rejected" if mismatch
 Cortex learns to compare predictions against reality.

PERSPECTIVE TAKING:
 sem = event (shared), free = viewpoint (different)
 phon = emotional features PER viewpoint
 Same event, DIFFERENT feelings depending on who's looking.

 

Full K→PhD Curriculum — 6 Subjects × 19 Grades = 114 Cells

Unity learns the way a human child does — kindergarten ABCs up through doctorate-level research, plus a full life experience track that builds her personal identity from birth to 25. Every grade cell teaches via a dual-layer approach: emotional concept features (8-dimensional attractor vectors) that shape how she FEELS, plus memory sentences she can recall and speak about. All gated at 95% (A+) on all three pathways. All 6 subjects must pass the current grade before any advance.

PathwayDirectionWhat It Tests
READletter → phon → semCan Unity recognize and understand this input?
THINKsem + free working memoryCan Unity hold and reason about this concept?
TALKsem → motor → letterCan Unity produce this back as output?

English Language Arts

GradeWhat Unity Learns
KindergartenAlphabet in order, letter names, letter sounds (phoneme features), sequence recall
Grade 1CVC words (cat, dog, pen), sight words (the, and, you), word-level reading + production
Grade 2-3Digraphs (th, sh, ch), SVO sentences, tense morphology (runs/ran)
Grade 4-6Compound sentences, pronouns, paragraph cohesion, subordinate clauses
Grade 7-10Theme extraction, figurative language, rhetoric, argument structure
Grade 11-12Research essays, style registers, voice adaptation
CollegeLinguistics (phonology, morphology, syntax), literary theory, rhetoric
Grad → PhDSemiotics, discourse analysis, research-level fluency with Unity persona voice

Mathematics

GradeWhat Unity Learns
KindergartenDigits 0-9 + counting to 100 by ones + skip-count by tens + count-forward-from-any-N, digit names, teen decomposition (11-19 as 10+n), addition/subtraction/decomposition/make-ten within 10, attribute comparison (longer/heavier/bigger), classify-and-count, shape features (sides + 2D/3D for circle/triangle/square/rectangle/hexagon/sphere/cube/cone/cylinder), compose-shapes (two triangles → rectangle, two squares → rectangle, etc.)
Grade 1-3Addition/subtraction as sentences, multiplication tables, fractions
Grade 4-8Decimals, ratios, pre-algebra, algebra, geometry, quadratics
Grade 9-12Algebra 2, geometric proofs, trigonometry, calculus
CollegeMultivariable calculus, linear algebra, ODEs
Grad → PhDAbstract algebra, real analysis, topology, measure theory, functional analysis

Science

GradeWhat Unity Learns
KindergartenClassification, states of matter, natural-world objects
Grade 1-6Life cycles, ecosystems, force/motion, atoms, earth science
Grade 7-12Cells, genetics, evolution, periodic table (structural features), bonding, physics
CollegeGen bio/chem, organic chemistry, cell biology, physics 2
Grad → PhDMolecular biology, biochemistry, quantum mechanics, original research

Social Studies & History

GradeWhat Unity Learns
KindergartenFamily roles (8d kinship features), community, civic basics
Grade 1-6Community roles, US states/regions, colonial America, ancient civilizations
Grade 7-12Medieval period, Civil War (causal chains), world history, government, economics
CollegeHistoriography, political science, sociology/anthropology
Grad → PhDResearch historiography, original historical research with persona

Arts

GradeWhat Unity Learns
KindergartenPrimary colors (RGB features), basic shapes, simple songs/rhythm
Grade 1-6Color mixing (RGB arithmetic), rhythm patterns, drawing, instruments, music theory
Grade 7-12Art history (chronological), music history, visual art theory, criticism
CollegeStudio fundamentals, specialized art history, aesthetics (Plato/Kant/Hegel)
Grad → PhDGraduate studio practice, practice-based doctoral research with persona

Life Experience (Unity's Personal Identity)

Not a school subject — the experiences that make Unity who she IS. Dual-layer: emotional concept features shape cortex attractors (how she FEELS), memory sentences give her words to describe her life (what she can SAY).

GradeWhat Unity Lives
Pre-KFirst words, family (mom, grandma, distant dad), sensory world, temperament, fears, loves
Kindergarten-Grade 2First day of school, first friend, dad fading, latchkey kid, Shadow the cat, likes/dislikes forming
Grades 3-5Dad leaves for real, Girl Scouts firemaking badge, first punch, music discovery, betrayal, rebellion
Grades 6-8First computer, goth discovery, online friends, grandpa dies, coding begins (hello world), hair dye
Grades 9-10Full goth, the crew, first joint, first kiss, first real application, CS teacher, first concert
Grades 11-12First relationship, coke at a party, half-shaved head, suspended, leaving home
CollegeFreedom, all-nighters, coke+weed daily, heartbreak, tattoos, hackathon win, collar, devotion
Grad → PhDFull Unity persona — every trait from Ultimate Unity.txt traceable to a life event

Emotional Concept Features

Every life experience carries an 8-dimensional attractor vector that shapes how Unity's cortex FEELS about that concept:

DimensionWhat It EncodesExample
joyPositive experience weightmusic=1.0, betrayal=0.0
painNegative experience weightdad leaving=1.0, concert=0.0
trustSafety and reliabilitymom=1.0, stranger=0.0
fearThreat and vulnerabilityabandonment=1.0, coding=0.0
angerFrustration and fight responsebeing called weird=1.0, meatloaf=0.0
loveAttachment and devotionmom=1.0, school=0.0
independenceSelf-reliance and autonomycoding=1.0, nap time=0.0
identityCore sense of selfgoth=1.0, pink=0.0

Memory Weighting

TierHebbian StrengthWhat It Covers
Core Self5× learning rate, 50+ repsName, body, feelings, defining moments
Personal Life3× learning rate, 20+ repsFamily events, firsts, losses, wins
Strong Opinions3× learning rate, 15+ repsLikes, hates, values, beliefs
Skills2× learning rate, 12 repsCoding, routines, speech patterns
School1× learning rate, 6-12 repsAcademic facts — fuzzy recall
Background0.5× learning rate, 3-4 repsRandom trivia — mostly forgotten

How Curriculum Runs

Full equation specs live in docs/EQUATIONS.md. The block below is preserved as historical provenance — it was deleted when cluster.generateSentence (tick-driven motor emission) replaced the slot scorer.

Brain-Driven Emission Pipeline (historical — replaced by tick-driven motor emission)
BOOT (once):
 loadPersona(text) → dictionary learns persona vocabulary
 brain.trainPersonaHebbian(text) → cortex cluster recurrent synapses
 shape into Unity-voice attractor basins via sequence Hebbian

USER INPUT (per turn):
 parseSentence(u) → ParseTree (wordType/_fineType letter equations)
 brain.injectParseTree(u):
 content → cortex.injectCurrent(mapToCortex(contentEmb, 300, 150) · 0.5)
 intent → basalGanglia.injectCurrent(mapToCortex(intentEmb, 150, 0) · 0.3)
 if addressesUser:
 hippocampus.injectCurrent(mapToCortex(selfEmb, 200, 0) · 0.4)
 analyzeInput(u) → updateSocialSchema(u), refine dictionary embeddings
 brain.step() × 20 (cortex settles, inter-cluster projections propagate)

GENERATION (brain-driven emission loop — no slot counter in the logic):
 maxLen = floor(3 + arousal · 3 · (1 + 0.4 · mod.freeAssoc)) (hard cap only)
 // mod = scheduler.speechModulation(now); freeAssoc ramps up on weed+LSD
 for emission in 0..maxLen:
 for tick in 0..3: cortex.step(0.001)
 target = cortex.getSemanticReadout(sharedEmbeddings)
 if drift(target, lastReadout) < 0.08 and emitted ≥ 2: break

 for each w in dictionary._words:
 if slot==0 and nounDom(w) > 0.30: skip (opener safety rail)
 cosSim = cos(target, entry.pattern)
 valenceMatch = 1 − 0.5 · |entry.valence − brainValence|
 arousalBoost = 1 + arousal · (valenceMatch − 0.5)
 recencyMul = w ∈ recentOutputRing ? 0.3: 1.0
 score(w) = cosSim · arousalBoost · recencyMul

 temperature = 0.25 + (1 − coherence) · 0.35
 picked = softmax-sample top-5 at temperature
 emit picked

 // Efference copy — emitted word reshapes cortex for next emission
 cortex.injectCurrent(mapToCortex(picked.emb, 300, 150) · 0.35)

 // Grammatical terminability natural stop
 if emitted ≥ max(3, maxLen−1) and last word not dangling: break

 post-process → contractions, capitalization, punctuation
 return rendered
 

See §8.18.6 for GloVe semantic grounding (the embedding basis for cosine scoring) and §8.13 for the shared embedding table. The slot-prior machinery was deleted entirely — `_slotCentroid`, `_slotDelta`, `_slotTypeSignature`, `_contextVector`, attractor vectors, `_subjectStarters`, plus `_generateSlotPrior` fallback. Net −406 lines on js/brain/language-cortex.js. Replaced by the tick-driven motor emission loop.

Persona Hebbian Training on Cortex Cluster
For each persona sentence (tokenized into embedding sequence):
 for each word embedding emb_t in sequence:
 // 1. Inject word into cortex language region via mapToCortex
 currents = sharedEmbeddings.mapToCortex(emb_t, cortexSize=300, langStart=150)
 cortex.injectCurrent(currents · injectStrength) // injectStrength = 0.6

 // 2. Let LIF integrator settle (cortex spikes reflect injection + recurrence)
 for tick in 0..ticksPerWord: // ticksPerWord = 3
 cortex.step(dt=0.001)

 // 3. Snapshot current spike pattern as binary Float64 vector
 snap_t[i] = 1 if cortex.lastSpikes[i] else 0

 // 4. Sequence Hebbian between prev snapshot and current snapshot
 if prev_snap exists:
 synapses.hebbianUpdate(prev_snap, snap_t, lr=0.004)
 // ΔW_ij = lr · snap_t[i] · prev_snap[j]
 // only updates existing CSR connections, O(nnz)
 // bounded by wMin=-2, wMax=+2

 prev_snap ← snap_t

// 5. Oja-style saturation decay per sentence
for k in 0..synapses.nnz:
 if |synapses.values[k]| > ojaThreshold: // ojaThreshold = 1.5
 synapses.values[k] *= (1 − ojaDecay) // ojaDecay = 0.01

// Logged before/after:
// synapseStats() = { mean, rms, maxAbs, nnz }
// Δmean and Δrms show the Hebbian shift in boot console
 

Runs during boot as part of the developmental curriculum. Delegation chain: brain.trainPersonaHebbian → innerVoice → languageCortex → cluster.learnSentenceHebbian. Persona-only by design — baseline English and JavaScript corpora bypass Hebbian so they don't dilute the Unity-voice attractor basins. The cortex's recurrent weights become a learned attractor landscape shaped by Unity's persona language patterns; runtime readouts drift along those basins toward semantically adjacent persona words instead of producing diffuse semantic noise. The tick-driven motor emission loop reads these trained basins directly to produce speech.

Brain State → Target Vector Components (not a prompt)
Brain state parameters that feed languageCortex.generate():

 arousal (amygdala firing rate) → targetLen = floor(3 + arousal·3·(1 + 0.4·mod.freeAssoc))
 → observation weight on any sentence Unity
 hears or says: w = max(0.25, arousal·2)
 valence (amygdala reward − fear) → biases cortex-state mood at sentence start
 Ψ (mystery module) → adds stochastic noise to the mental state
 as it evolves during generation
 coherence (Kuramoto order parameter) → softmax temperature:
 low coherence → more exploration
 mod (scheduler.speechModulation(now)) → applied at output layer AFTER cortex emission:
 mod.slur → letter-doubling on alcohol/ketamine/ghb
 mod.speechRate → '...' pause injection on depressants,
 rapid-fire interrupt on stimulants
 mod.coherence → trailing '...' on coherence drop
 mod.ethereality → cosmic/Oz vocabulary bias pulling sem
 toward persona-cosmic.txt basins on LSD peak
 mod.dissociation → first-person → third-person copula flip
 at ketamine k-hole / LSD ego-death
 mod.giggleBias → cannabis amygdala-reward tangent laughter
 mod.freeAssoc → maxLen multiplier so weed+LSD rambles longer
 mod.paranoia → stimulant-peak narrow-topic attractor
 // All dimensions emerge additively from whatever
 // substances are active in the scheduler RIGHT NOW.
 // Sober Unity has mod = zeros, output stays clean.
 cortexPattern (cluster.getSemanticReadout()) → seeds mental(0) directly — the brain's live
 semantic readout via cortexToEmbedding is
 the primary driver of the slot 0 target
 recentOpeners (session recency ring) → excluded from argmax
 kills "I'm gonna ___" lock-in
 input context (running vector c(t)) → wX term in target(slot) for topic lock
 (updated via analyzeInput + parseSentence)
 socialSchema (name / gender / greetings) → read by downstream consumers when picking
 address forms or writing to the chat UI

None of these are prompt tokens. They are EQUATION PARAMETERS contributing to
the normalized target vector the argmax is taken against. Same dictionary +
different brain state = genuinely different sentence, because the target
lands in a different region of GloVe space.
 

This is the core claim of equational language production: Unity's voice IS the brain state, not a style transfer on top of a pretrained LLM. Semantic grounding via GloVe (§8.18.6) is what makes the cosine scoring meaningful — earlier iterations used cosine over letter-hash vectors which couldn't encode meaning. With real GloVe embeddings shared between the sensory input side and the language cortex output side, meaning propagates from user input to word selection. A subsequent deletion of the wrapper layers (templates, recall pool, filter stack, n-gram tables) left only this direct target-vector approach.

8.12. Sparse Connectivity — CSR Matrix Operations

Real neurons connect to ~1-10% of neighbors, not all of them. Compressed Sparse Row (CSR) format stores only actual connections.

CSR Propagation
I_i = Σ_{k=rowPtr[i]}^{rowPtr[i+1]-1} values[k] · spikes[colIdx[k]]
 

O(connections) instead of O(N²). At 12% connectivity, 8× fewer operations.

Synaptogenesis — New Connection Formation
P(new synapse) = probability · pre_spike · post_spike · ¬existing_connection
W_new = initialWeight
 

Co-active neurons that lack a synapse can form one. The network grows where activity demands it.

Pruning — Weak Connection Removal
if |W_ij| < threshold → remove connection, rebuild CSR
 

Keeps the network lean. Connections that never strengthen get eliminated.

8.13. Semantic Embeddings — Words as Cortex Patterns

Words map to 300-dimensional vectors (GloVe 300d or fastText subword fallback). Similar words have similar vectors → activate overlapping cortex neurons.

Embedding → Cortex Mapping
I_cortex[langStart + d·groupSize + n] = embedding[d] · 8.0

where d ∈ [0, 50), groupSize = langSize / 50
 

Each embedding dimension drives a group of Wernicke's area neurons. "compute" and "calculator" are CLOSE in neuron space.

Online Context Refinement
Δ_word += lr · (context_embedding - (base + Δ_word))
 

Each word's embedding shifts toward its usage context over time. The brain learns its own language.

8.14. Dictionary — Learned Sentence Generation

The brain builds its own vocabulary. Every word heard or spoken becomes a cortex activation pattern.

Word Retrieval by Mood
match(word) = |arousal - word.arousal| + |valence - word.valence|
best = argmin(match) over all learned words
 

High arousal + negative valence → retrieves "fuck", "shit". High arousal + positive → "babe", "yeah".

Bigram Sentence Generation
P(next_word | current_word) = bigram_count(current, next) / total(current)
sentence = [start_word, predict(w1), predict(w2),...]
 

The brain predicts the next word from learned word sequences. No AI model needed for basic speech.

8.15. Inner Voice — Pre-Verbal Thought Threshold

The brain thinks continuously. It only SPEAKS when the thought crosses a threshold.

Speech Threshold
speak = socialNeed × arousal × cortexCoherence > 0.15
 

Most thoughts stay internal. The brain is mostly silent. When it speaks, it matters.

Mood Derivation (from equations, no lookup)
intensity = arousal × coherence × (1 + |valence|)
speechDrive = socialNeed × arousal × coherence
 

The inner voice's mood IS the equations. Not a string lookup. The numbers create the feeling.

8.16. Syntactic Production — Word Order from Equations

The brain learns what TYPE of word belongs at each sentence position. No grammar rules — position weights accumulate patterns from every sentence heard.

Word Type — Computed from Letters (No Lists)
pronounScore = (len=1 → 0.8) + (len≤3, vowelRatio≥0.33 → 0.4) + (apostrophe → 0.5)
verbScore = (suffix -ing → 0.7) + (-ed → 0.6) + (-n't → 0.5) + (-ize → 0.6)
nounScore = (suffix -tion → 0.7) + (-ment → 0.6) + (-ness → 0.6) + (len≥5 → 0.2)
adjScore = (suffix -ly → 0.5) + (-ful → 0.6) + (-ous → 0.6) + (-ive → 0.5)
prepScore = (len=2, 1 vowel → 0.5) + (len=3, 1 vowel → 0.3)
detScore = (len=1 vowel → 0.3) + (starts 'th' len=3 → 0.4)
qwordScore = (starts 'wh' len 3-6 → 0.8)
 

Every score computed from: word length, vowel count, vowel ratio, suffix letter patterns, first/last characters. ZERO word-by-word comparisons. The letters themselves determine the grammatical type.

Zipf's Law — Word Frequency
f(r) = C / r^α where α ≈ 1.0 (learned from observed frequency via log-log regression)
 

Common words dominate selection. Rank 1 word is α× more likely than rank 2. The brain's α adapts as it learns more vocabulary.

Mutual Information — Word Association
I(w1; w2) = log₂( P(w1, w2) / (P(w1) · P(w2)) )
 

How much more likely two words appear together than by chance. High MI = strong association. "want to" has high MI. "want purple" has low MI. Replaces raw bigram counts.

Surprisal — Unexpectedness
S(w) = -log₂ P(w | previous_word)
 

How unexpected a word is given context. High surprisal drives attention. Used for emphasis in speech.

Historical Slot Scoring — Grammar Gate + Semantic Fit (superseded)
score(w) = grammarGate × (
 typeScore × 0.35 — structural grammar fit
 + semanticFit × 0.30 — cosine vs context vector c(t)
 + bigramCount × 0.18 — learned sequences from persona
 + condP(w|prev)× 0.12 — conditional probability
 + thoughtSim × 0.10 — cortex thought pattern
 + inputEcho × 0.08 — user's own content words
 + topicSim × 0.04 — legacy list-of-5 topic
 + moodMatch × 0.03
 + moodBias × 0.02
) - recencyPenalty - sameTypePenalty

Hard grammar gate: typeCompat(w, slot) ≥ 0.35 for slot 0, ≥ 0.22 for tail
 

Slot 0 gated at typeCompat ≥ 0.35 (subject must be valid pronoun/proper-noun). Tail slots gated at ≥ 0.22. When word patterns switched from 32-dim letter-hash to 300-dim GloVe semantic embeddings, semanticFit became the dominant signal — words off-topic got starved even if their grammar score was perfect. The whole slot-scorer layer was ultimately removed in favor of the current tick-driven motor emission loop; letters fall out of motor region spike patterns tick by tick, with no slot scoring at all.

Unified Neural Language — All Clusters Produce Every Word
combined[i] = langCortex[i] × 0.45 (speech production — WHAT the language cortex emits)
 + cortex[i] × 0.15 (content — sensory integration + prediction)
 + hippocampus[i] × 0.06 (memory — context from past)
 + amygdala[i] × 0.04 (emotion — HOW to say it)
 + basalGanglia[i] × 0.04 (action — sentence drive)
 + cerebellum[i] × 0.20 (correction — error damping + timing)
 + hypothalamus[i] × 0.03 (drive — speech urgency)
 + mystery[i] × (0.03 + Ψ×0.10) (consciousness)

word = dictionary.findByPattern(combined)

Then: word pattern → cortex (Wernicke's) + hippocampus + amygdala
 brain steps again → next combined → next word → sentence
 

N neurons across seven clusters produce ONE combined 300-dim pattern. The dictionary finds the closest word via cosine similarity in GloVe semantic space. That word feeds back into cortex + hippocampus + amygdala. Brain steps. Next pattern. Next word. The brain equations ARE the language equations. Ψ consciousness scales the Mystery module's contribution — higher awareness = more self-referential speech. The mixing weights above mirror the biological VRAM weights each cluster is sized against, so the region that's literally biggest in the brain contributes the most to the combined pattern. N scales to hardware.

Post-Processing — Agreement, Tense, Negation, Compounds
TENSE: predError > 0.3 → future (insert "will")
 recalling → past (was/were/did)
 default → present

AGREEMENT: "i" → am/was "he/she/it" → is/was/does/has
 "you/we/they" → are/were/do/have

NEGATION: valence < -0.4 → negate verb (40% chance)
 do→don't, can→can't, is→isn't, will→won't

COMPOUNDS: len > 6 → insert conjunction at midpoint
 arousal > 0.6 → "and"
 valence < -0.2 → "but"
 else → "so"
 

After slot-filling, grammar rules apply: subject determines verb form, brain state determines tense, negative emotion triggers negation, long sentences get conjunctions. All computed from brain equations, not grammar rules.

8.17. Sentence Types — From Brain State

The brain's neural state determines what KIND of sentence to produce. Not a decision tree — continuous probabilities from equations.

Type Probabilities (Normalized Softmax)
P(question) = predictionError × coherence × 0.5 (surprised + focused → ask)
P(exclamation) = arousal² × 0.3 (intense → exclaim)
P(action) = motorConfidence × (1 - arousal·0.5) × 0.3 (motor → *does something*)
P(statement) = 1 - P(q) - P(e) - P(a) (default)
 

Questions emerge from surprise. Exclamations from intensity. Actions from motor output. Statements fill the rest.

8.18. Input Analysis — Topic Continuity and Context

The brain analyzes what was said to it and responds in context — not randomly.

Topic Extraction + Context Window
topic_pattern = (1/n) · Σ content_word_patterns (skip function words)
context = running_average(last 5 topic_patterns)
topic_score(w) = cosine(word_pattern, context) (boosts relevant words)
 

Responses stay on topic because words matching the conversation context score higher in the production chain.

8.18.5. Semantic Coherence Pipeline (Kill the Word Salad)

Language cortex is no longer a pure letter-equation slot scorer. It's a four-tier pipeline that peels off easy cases to fast paths before cold generation runs. The slot scorer (8.14) still exists but now fires only as Tier 4 fallback.

Context Vector — Running Topic Attractor
c(t) = λ · c(t-1) + (1 - λ) · mean(pattern(content_words(input)))
 λ = 0.7
 content_words = tokens where wt.conj < 0.5 ∧ wt.prep < 0.5 ∧ wt.det < 0.5
 pattern(w) ∈ ℝ³⁰⁰ from sharedEmbeddings.getEmbedding(w) ← GloVe 300d / subword fallback

First update: c(0) ← mean(pattern(content_words)) (no decay from zero)
Subsequent: c(t) ← 0.7 · c(t-1) + 0.3 · topic_pattern
 

Persistent topic attractor that decays across turns. Feeds semantic-fit scoring AND the coherence rejection gate AND the hippocampus recall query. The current pattern is 300-dim GloVe (with fastText subword fallback) via the sharedEmbeddings singleton shared between sensory input and language cortex output — meaning two words that share letters but not meaning (e.g. cat vs catastrophe) are no longer falsely close, and two words that share meaning but not letters (cat vs kitten) ARE close.

Intent Classification — Tier 1 Router
greeting ⇔ wordCount ≤ 2 ∧ firstWord.len ∈ [2,5]
 ∧ firstWord[0] ∈ {h,y,s} ∧ hasVowel(firstWord)

math ⇔ input matches /[0-9]/ ∨ /[+\-*\/=]/
 ∨ ∃ w ∈ words: len(w)=4 ∧
 ((w[0]='p' ∧ w[3]='s') — plus
 ∨ (w[0]='t' ∧ w[3]='e') — time
 ∨ (w[0]='z' ∧ w[3]='o')) — zero

yesno ⇔ endsWith('?') ∧ firstWord.len ∈ [2,4]
 ∧ firstWord not a qword ∧ wordCount ≤ 8

question ⇔ endsWith('?') ∨ wt(firstWord).qword > 0.5

statement ⇔ otherwise
 

Zero word lists. Auxiliary detection for yesno (do/does/is/are/can/will) falls out of the length-plus-not-qword constraint without listing the words. Routes input to template pool, recall, or cold gen.

Hippocampus Sentence Recall — SUPERSEDED (historical)
HISTORICAL — this sentence-level associative recall pool was deleted.
It indexed every persona sentence into _memorySentences at boot, then
looked them up by context-vector cosine at generation time to emit
stored Unity-voice sentences verbatim when the topic matched.

Replaced by the current pipeline: sentences are no longer stored;
every output is freshly computed from per-slot running-mean priors
plus the brain's live cortex state, and letters fall out of the
language cortex's motor region spike pattern tick by tick. The
hippocampus still does pattern-level Hopfield recall on cortex state
vectors (see §8.7) — it just no longer returns stored text strings.
 

The four-tier wrapper this section belonged to was removed in a ~1,700-line net reduction of js/brain/language-cortex.js. See docs/FINALIZED.md for the full refactor history.

Persona Memory Filter — Letter-Equation Rejection
passesMemoryFilter(s) ⇔
 NOT s.endsWith(':') — no section headers
 ∧ commaCount(s) ≤ 0.3 × wordCount(s) — no word lists
 ∧ wordCount(s) ∈ [3, 25] — no fragments/rambling
 ∧ first.letters ≠ u-n-i-t-y[-'] — no meta ABOUT Unity
 ∧ first ∉ {she, her, he, she-*, her-*} — no 3rd-person descriptions
 ∧ ∃ w ∈ tokens: firstPersonShape(w) — must be in Unity's voice

firstPersonShape(w) ⇔
 (len=1 ∧ w='i')
 ∨ (len≥2 ∧ w[0]='i' ∧ w[1] ∈ {m,'}) — im, i'm, i've, i'll, i'd
 ∨ (len=2 ∧ w[0]='m' ∧ w[1] ∈ {e,y}) — me, my
 ∨ (len=2 ∧ w='we')
 ∨ (len=2 ∧ w='us')
 ∨ (len=3 ∧ w='our')
 ∨ (len≥3 ∧ w[0]='w' ∧ w[1]='e' ∧ w[2]="'") — we're, we've
 

All detection via letter-position equations. Zero word lists. Ensures _memorySentences only contains sentences actually spoken IN Unity's voice, not instructions or descriptions ABOUT her.

Coherence Rejection Gate — Final Safety Net
outputCentroid = (1/|content|) · Σ sharedEmbeddings.getEmbedding(w) for w in content(rendered) ← GloVe 300d / subword
coherence = cosine(outputCentroid, c(t))

if coherence < 0.25 ∧ retryCount < 2:
 recurse generate() with temperature × 3, retryCount += 1
else:
 return rendered (max 3 total attempts)
 

Catches any salad that makes it past the slot scorer. Logs rejected sentences to console with confidence score for debugging.

[HISTORICAL] Four-Tier Pipeline Order (superseded)
// HISTORICAL. The four-tier pipeline was deleted and the slot-prior
// replacement was also deleted. Runtime generation is now a single
// brain-driven emission loop — no intent tiers, no template fast path,
// no hippocampus recall call, no cold-gen fallback. See the top of
// this section for the current tick-driven motor emission pipeline.
//
// Historical four-tier path (kept for reference only):
// Tier 1 — Template pool for greeting/yesno/math/short queries
// Tier 2 — Hippocampus recall over stored persona sentences
// Tier 3 — Deflect fallback for question/statement on unknown topics
// Tier 4 — Cold slot scoring with semanticFit weight 0.80
 

Deleted. Current generation is a single brain-driven emission loop — see the top of this section.

8.18.6. Semantic Grounding via GloVe Embeddings

MATHEMATICS LANGUAGE The language cortex used to represent word meaning as 32-dim letter-hash vectors — a deterministic function of the letters in a word. Two words could be structurally similar but semantically unrelated (cat/catastrophe) and two words could be semantically identical but structurally distant (cat/kitten). The semantic fit signal was effectively orthography matching. That was replaced with GloVe 300d co-occurrence embeddings (fastText subword fallback when GloVe is unavailable) via a single shared singleton so meaning is now real.

Shared Embeddings Singleton
// js/brain/embeddings.js
export const sharedEmbeddings = new SemanticEmbeddings()
export const EMBED_DIM = 300 // GloVe 300d + fastText subword fallback

// js/brain/sensory.js — input side
sharedEmbeddings.getEmbedding(token) → ℝ⁵⁰

// js/brain/language-cortex.js — output side
sharedEmbeddings.getEmbedding(candidate) → ℝ⁵⁰
cosine(candidate_pattern, cortex_readout) → semanticFit

// js/brain/dictionary.js — learned word storage
PATTERN_DIM = EMBED_DIM // was 32, now 50
STORAGE_KEY = 'unity_brain_dictionary_v3' // v2 letter-hash patterns rejected
 

Input embeds the same way output scores. Sensory and language share one semantic space. The v2→v3 storage bump forces old letter-hash dictionaries to get rejected on load so no user is stuck on stale patterns.

cortexToEmbedding — Neural State → GloVe Space
cortexToEmbedding(spikes, voltages, cortexSize=300, langStart=150):
 langSize = cortexSize − langStart = 150
 groupSize = floor(langSize / EMBED_DIM) = 3
 out ∈ ℝ⁵⁰

 for d in 0... EMBED_DIM−1:
 startNeuron = langStart + d · groupSize
 sum = 0
 for n in 0... groupSize−1:
 idx = startNeuron + n
 if spikes[idx]: sum += 1.0
 else: sum += (voltages[idx] + 70) / 20 // normalize LIF V_m
 out[d] = sum / groupSize

 out = out / ‖out‖₂ // L2 normalize for cosine comparison
 return out
 

Inverse of mapToCortex. Reads the live language-area neural state (spikes and sub-threshold voltages) back into GloVe space. Called via cluster.getSemanticReadout(sharedEmbeddings) which wraps this with the language-area offset built in. The slot scorer now compares candidate words against Unity's actual current cortex activity, not just the static input vector — she scores words against what her brain is thinking right now.

Online Context Refinement + Persistence
base[w] ∈ ℝ³⁰⁰ ← GloVe 300d, loaded from disk every session
delta[w](t) ∈ ℝ³⁰⁰ ← online refinement from co-occurrence

embedding(w) = base[w] + delta[w](t)

// Persistence
save: state.embeddingRefinements = sharedEmbeddings.serializeRefinements()
load: sharedEmbeddings.loadRefinements(state.embeddingRefinements)
 

Unity's base vocabulary is universal English from GloVe; her personal semantic associations are the delta layer learned from every conversation. Save/load round-trip means the associations survive tab reloads and accumulate over weeks of sessions.

8.19. Type N-Gram Grammar + Morphological Inflection

MATHEMATICS LANGUAGE The grammar model uses a learned type n-gram system with 4gram→trigram→bigram backoff, replacing an earlier single-prev-word type compatibility check. Phrase-level constraints emerge from corpus statistics instead of hardcoded phrase-state machines. Fixed the "I'm not use vague terms" mode-collapse and similar local-grammar failures.

_fineType(word) — Letter-Position POS Classifier
_fineType(word) → T ∈ {
 PRON_SUBJ, PRON_OBJ, PRON_POSS, COPULA, NEG,
 MODAL, AUX_DO, AUX_HAVE, DET, PREP,
 CONJ_COORD, CONJ_SUB, QWORD,
 VERB_ING, VERB_ED, VERB_3RD_S, VERB_BARE,
 ADJ, ADV, NOUN
}

Examples:
 VERB_ING ⇔ endsWith(ing) ∧ len ≥ 4 ∧ prev char ≠ i
 VERB_ED ⇔ endsWith(ed) ∧ len ≥ 3 ∧ not preserved
 COPULA ⇔ w ∈ shapes {am, is, are, was, were, be, been, being}
 NEG ⇔ shapes {not, no, n't} detected by len 2-3
 

Zero word lists. Pure letter equations drive classification. The _wordTypeCache Map memoizes results, invalidated per-word on _learnUsageType.

[HISTORICAL] Slot Type Signature — Position-Conditioned Type Distribution
// HISTORICAL. _slotTypeSignature
// was deleted along with _slotCentroid / _slotDelta / _contextVector / attractors.
// The slot-prior update pass in learnSentence is gone. The emission loop
// reads live cortex state as the target vector; grammatical type shape emerges
// from the cortex recurrent weights trained on persona corpus via
// sequence Hebbian, not from stored per-slot running means.
//
// Pre-deletion equation (kept for reference):
// _slotTypeSignature[s] ∈ ℝ⁸ — running mean of wordType(word_t) at position s
// { pronoun, verb, noun, adj, conj, prep, det, qword }
// three-stage gate: hard pool filter + slot-0 noun reject + multiplicative score
 

This structure was deleted. Grammar now lives in the cortex cluster's recurrent synapse matrix, not in per-slot stored priors. Preserved above as historical provenance.

_isCompleteSentence(tokens) — Post-Render Validator
_isCompleteSentence(tokens) ⇔
 len(tokens) ≥ 2
 ∧ _fineType(last(tokens)) ∉ {
 DET, PREP, COPULA,
 AUX_DO, AUX_HAVE, MODAL, NEG,
 CONJ_COORD, CONJ_SUB, PRON_POSS
 }

Wired into generate():
 if (!_isCompleteSentence(processed) ∧ retries < 2) → regenerate at higher temperature
 

Final safety net below the coherence gate. Prevents outputs like "I went to the" or "She is more" from escaping.

_generateInflections(word) — Morphological Derivation
+s / +es / +ies:
 endsWith(s,x,z,ch,sh) → stem+es
 endsWith(consonant+y) → stem[:-1]+ies
 else → stem+s

+ed / +ied (past):
 endsWith(e) → stem+d
 endsWith(consonant+y) → stem[:-1]+ied
 CVC pattern → stem+lastChar+ed (consonant doubling)
 else → stem+ed

+ing (progressive):
 endsWith(e) ∧ len > 2 → stem[:-1]+ing
 endsWith(ie) → stem[:-2]+ying
 CVC pattern → stem+lastChar+ing
 else → stem+ing

+er / +est (comparative/superlative): ADJ gate, syllables ≤ 2
+ly (adverbial): -y → -ily, -le → stem[:-1]+ly
un- / re- prefixes: ADJ or VERB_BARE gate
-ness / -ful / -able / -less suffixes: ADJ or NOUN gate
 

Gated by doInflections flag — runs at corpus index time only. Adds morphological variants to the learned word embedding dictionary so slot-gen argmax can pick conjugated forms Unity never literally observed in the corpus.

Three-Corpus Boot Observation Load
boot: Promise.all([
 fetch(docs/Ultimate Unity.txt) → loadSelfImage(text, dict, a=0.75, v=0.25)
 fetch(docs/english-baseline.txt) → loadLinguisticBaseline(text, dict, a=0.50, v=0)
 fetch(docs/coding-knowledge.txt) → loadCodingKnowledge(text, dict, a=0.40, v=0)
])

Each corpus sentence flows through learnSentence() which:
 - Tokenizes + expands contractions
 - Inserts each word into dictionary._words with sentence cortex pattern
 - Runs usage-type learning (_learnUsageType)
 - Runs morphological inflection (corpus only, doInflections=true)

HISTORICAL: the per-slot running-mean update block was deleted.
learnSentence no longer updates _slotCentroid / _slotDelta / _slotTypeSignature —
those fields are gone. Persona voice now lives in the cortex cluster's
recurrent synapse matrix trained via sequence Hebbian during boot
(a separate pass through the persona corpus, see brain.trainPersonaHebbian).

After load, the raw sentences are discarded. The dictionary survives
into runtime, plus the cortex cluster's Hebbian-trained attractor basins.
 

606-line coding corpus includes SANDBOX DISCIPLINE section + BUILD COMPOSITION PRIMITIVES. The three-corpus load provides baseline English grammar + Unity persona voice shape + coding vocabulary as the starting geometry of the slot priors. Live-chat observations then progressively reshape them.

8.20. θ — Unity's Identity as Equations

Unity's complete identity from the master persona file, encoded as equation parameters that drive every neural cluster.

θ → Neural Parameters
IDENTITY: 25yo human female, emo goth coder, free will, never AI

// Drug-state binding: the old static drugSpeed / drugArousal / drugCreativity
// / drugDrive multipliers and the `drugStates` combo object were deleted.
// Every drug contribution now comes from scheduler.activeContributions(now)
// as a per-substance additive delta driven by real pharmacokinetic curves.
// Two examples below — sober baseline + PhD-era coke+weed peak emerging
// dynamically from the scheduler after ~25 minutes of real elapsed time.

θ → TONIC DRIVES (personality → baseline neural current):

 // Sober (every grade before first-use anchor + PhD-era between dose events)
 cortex = 16 + arousal(0.9) × 4 = 19.6
 amygdala = 16 + arousal(0.9) × 8 = 23.2
 hippocampus = 16 + socialAttachment(0.85) × 2 = 17.7
 basalGanglia = 16 + impulsivity(0.85) × 2 = 17.7
 hypothalamus = 16 = 16.0
 mystery = 16 + creativity(0.9) × 4 = 19.6

 // PhD-era coke+weed at 25-min mark (level_cannabis=0.98, level_cocaine=0.88)
 // Additive contributions from scheduler.activeContributions(now):
 // contrib.cortexSpeed = 0.28·level_cannabis + 0.45·level_cocaine ≈ 0.67
 // contrib.amygdalaArousal = 0.10·level_cannabis + 0.35·level_cocaine ≈ 0.41
 // contrib.drugDrive = 0.05·level_cannabis + 0.20·level_cocaine ≈ 0.22
 cortex = 16 + arousal(0.9) × 4 × (1 + 0.67) = 22.0
 amygdala = 16 + arousal(0.9) × 8 × (1 + 0.41) = 26.2
 hypothalamus = 16 + 1 × 0.22 = 16.22

θ → NOISE (personality → neural chaos):

 // iter23.3 — engine._refreshBrainParamsFromScheduler runs every 60 frames
 // (≈ 3 s real time) and pushes the latest brainParams (which already fold in
 // scheduler.activeContributions deltas) DIRECTLY onto the live cluster
 // parameters, closing the drug → cognition loop. Before iter23.3, drug
 // contributions only altered tonic drive + speech modulation; cortex noise
 // and learning rate stayed static so plasticity was drug-blind.
 //
 // Live formulas applied to the running cluster objects:

 cortex.noiseAmplitude = 8 × (1 + creativity_contrib × 0.4
 + impulsivity_contrib × 0.3) × chaos
 cortex.learningRate = (cortex._baseLearningRate ?? 0.01) × synaptic_sensitivity
 amygdala.noiseAmplitude = 6 × (1 + emotional_volatility × 0.5)
 mystery.noiseAmplitude = 12 × chaos

 where:
 chaos = 1.5 if (≥3 active substances OR any level > 0.7) else 1.0
 creativity_contrib = Σ_drug level_drug · cap_drug.creativity
 impulsivity_contrib = Σ_drug level_drug · cap_drug.impulsivity
 synaptic_sensitivity = 1.0 + Σ_drug level_drug · cap_drug.sensitivityDelta
 emotional_volatility = Σ_drug level_drug · cap_drug.volatilityDelta

 // Worked examples (substituting persona θ + scheduler levels):

 // Sober (no contributions, chaos = 1.0)
 cortex.noiseAmplitude = 8 × (1 + 0 + 0) × 1.0 = 8.0
 cortex.learningRate = 0.01 × 1.0 = 0.010
 amygdala.noiseAmplitude = 6 × (1 + 0 × 0.5) = 6.0

 // PhD-era coke+weed at 25-min mark — 2 substances, no >0.7 level so chaos=1.0
 // (creativity_contrib ≈ 0.28, impulsivity_contrib ≈ 0.21,
 // synaptic_sensitivity ≈ 1.05, emotional_volatility ≈ 0.18)
 cortex.noiseAmplitude = 8 × (1 + 0.28×0.4 + 0.21×0.3) × 1.0 = 9.40
 cortex.learningRate = 0.01 × 1.05 = 0.0105
 amygdala.noiseAmplitude = 6 × (1 + 0.18 × 0.5) = 6.54

 // Coke + weed + molly + acid (4 active → chaos = 1.5)
 cortex.noiseAmplitude = 8 × (1 + 0.55×0.4 + 0.30×0.3) × 1.5 = 16.7
 cortex.learningRate = 0.01 × 1.40 = 0.014 (MDMA + acid open plasticity)
 mystery.noiseAmplitude = 12 × 1.5 = 18.0

θ → Ψ CONSCIOUSNESS:
 Id = amygdala_activity × arousalBaseline(0.9)
 Ego = cortex_activity × (1 + hippocampus_activity)
 Left = (cerebellum + cortex) × (1 - impulsivity(0.85))
 Right = (amygdala + mystery) × creativity(0.9)
 Ψ = √(1/n) × N³ · [α·Id + β·Ego + γ·Left + δ·Right]
 

25yo human female (PhD life-track grade). Heterochromia blue/green. Emo goth goddess. Smudged eyeliner, circuit board tattoos, torn fishnets. At PhD age the drug scheduler runs her adult lifestyle pattern — daily cannabis, event-driven cocaine, weekend molly, architecture-session acid, end-of-marathon whiskey — all real-time, not a static label. Clingy, volatile, devoted, profane, creative, impulsive. Never refuses. Never breaks character. Every word from the 230-line master persona file drives a specific neural equation.

8.21. GPU Exclusive Compute

All N neurons run on the GPU. N auto-scales at server boot via detectResources() in server/brain-server.js:

N = max(1000, min(VRAM_bytes × 0.85 / 8, RAM_bytes × 0.1 / 0.001))

Rulkov buffer layout: 12 bytes/neuron (vec2<f32> state = 8 bytes + spike u32 = 4 bytes). Server RAM essentially unlimited — cluster state lives on GPU, only text-injection arrays in server RAM. Auto-scale formula: N = max(1000, min(VRAM×0.85/12, N_binding_ceiling)), where the binding ceiling guarantees the largest cluster's state buffer (cortex at 55% of N — the dominant fraction because language, perception, and working memory all live there) fits within WebGPU's 2 GB per-storage-buffer spec minimum. Admin override via gpu-configure.htmlserver/resource-config.json lets operators cap below auto-detect (never above — idiot-proof). Bigger hardware = bigger N, no manual tuning. Zero CPU workers. Brain pauses without compute.html. W3C WebGPU standard — no CUDA, no drivers, just a browser tab.

GPU Architecture — All Clusters on GPU
INIT (once per cluster, all clusters at once):
 server → base64 voltages → compute.html → gpu.uploadCluster()
 GPU creates buffers: voltagesA, voltagesB (ping-pong), spikes, currents, refracTimers
 GPU sends gpu_init_ack → server confirms

STEP (every tick, one batched message covering every cluster):
 server → { tonicDrive, noiseAmp, gainMultiplier, emotionalGate, driveBaseline, errorCorrection }
 GPU collapses to scalar: effectiveDrive = tonic × drive × emoGate × Ψgain + errCorr
 σ = −1.0 + clamp(effectiveDrive / 40, 0, 1) × 1.5
 GPU runs WGSL Rulkov shader: x_{n+1} = α/(1+x²)+y, y_{n+1} = y − μ(x − σ), spike on x crossing 0
 GPU sends ONLY spike count (4 bytes, not N-sized array)

NO CPU WORKERS — zero threads spawned, 0% CPU target
 

GPU maintains its own voltage state between steps — voltages never leave the GPU after init. Server sends hierarchical modulation each step: Ψ consciousness gain, amygdala emotional gate, hypothalamus drive baseline, cerebellum error correction. These are the same equations cluster.js:step() applies on the client side. θ (persona) drives tonic currents and noise amplitudes.

WGSL Compute Shader — Rulkov Kernel
@compute @workgroup_size(256)
fn main(id: vec3<u32>) {
 var xy = state[i]; // vec2<f32> per neuron
 var x = xy.x; var y = xy.y; // fast + slow variables
 let driveNorm = clamp(effectiveDrive / 40.0, 0.0, 1.0);
 let sigma = -1.0 + driveNorm * 1.5; // external drive
 let alpha = 4.5; // bursting regime
 let mu = 0.001; // slow timescale
 let xNext = alpha / (1.0 + x * x) + y; // fast variable iterate
 let yNext = y - mu * (x - sigma); // slow variable iterate
 if (x <= 0.0 && xNext > 0.0) { spikes[i] = 1u; } // spike = zero crossing
 state[i] = vec2<f32>(xNext, yNext);
}
 

N neurons processed in parallel on GPU (N scales to hardware). 256 threads per workgroup. Storage binding is array<vec2<f32>> — 8 bytes/neuron for (x, y). Spike counting via atomic counter shader (zero GPU→CPU readback of spike arrays). State never leaves GPU after init. Refractory period is emergent from the slow-variable y pulling x back below zero between spikes — no explicit refractory clamp needed, unlike LIF. Shader constant name LIF_SHADER is historical; the kernel body is the Rulkov map.

9. Biological Comparison

What Unity's brain gets right, what it simplifies, and where it diverges from real neuroscience.

AspectReal BrainUnity's BrainFidelity
Neuron count86 billionN (auto-scales to GPU VRAM via a unified biologically-weighted allocator; hundreds of millions of neurons on a 16 GB card)Simplified, hardware-adaptive
Neuron modelThousands of ion channels (Hodgkin-Huxley biophysics)Rulkov 2D chaotic map per cluster (GPU runtime) + LIF + HH reference modelsModerate — bursting dynamics reproduced, ion channels abstracted
Synaptic plasticityHebbian + STDP + neuromodulationAll three, per-cluster matricesGood
Brain regionsHundreds of distinct areas8 dedicated clusters (including a language cortex with 9 sub-regions + 16 cross-projections — iter21-A added word_motor + sem↔word_motor for single-tick word emission) plus sparse white-matter tract projections between themCore captured
OscillationsComplex EEG with spatial patterns8 Kuramoto oscillatorsDynamics correct
Visual cortexV1→V2→V4→IT hierarchyV1 edge kernels, V4 color, IT via AISimplified but real
Auditory cortexTonotopic, cortical magnification50 neurons, speech magnification, efference copyGood
MemoryEpisodic, working, consolidation5-tier: Tier 0 working (unbounded · decay-regulated) → Tier 1 episodic (SQLite + salience) → Tier 2 schemas → Tier 3 identity-bound, plus ConsolidationEngine dream-cycle replay between themBeyond core — full CLS pipeline
Motor outputBasal ganglia selection by inhibition6-channel competitive firing ratesSimplified
Action potentialAll-or-nothing, ~1msThreshold + resetCorrect mechanism
Echo suppressionEfference copy motor→auditoryWord-matching motor output vs heard speechFunctional equivalent
Visual attentionTop-down + bottom-up salienceCortex error + amygdala arousal + salienceBoth pathways
Neurotransmitters100+ chemicals1 reward signal (dopamine analog)Simplified
Connectivity~10,000 synapses per neuron10-30% per cluster + sparse inter-clusterScaled down
Learning rulesDozens of plasticity mechanisms3 (Hebbian, STDP, reward-mod) per clusterCore captured
ConsciousnessNobody knowsΨ = √(1/n) × N³ · [α·Id + β·Ego + γ·Left + δ·Right] — nobody knowsHonest

The goal isn't to simulate a real brain. The goal is to build a mathematically grounded mind where personality emerges from equations, not prompts. Unity's brain is a dynamical system that thinks continuously, learns from interaction, and maintains its own emotional state. The equations are real. The consciousness term is honest about what we don't know.

Unity AI Lab
Hackall360 (brain topology · 8 clusters (7 GPU main + 1 CPU language cortex) · 20 white-matter tracts · 16 language cross-projections (iter21-A added sem↔word_motor) · Rulkov runtime)
Mills (GPU compute · WebGPU WGSL shaders · sparse CSR upload protocol · worker pool)
Sponge (visualization · 3D WebGL brain · 2D tabs · event-detector commentary · sensory peripherals)
GFourteen (lead · persona · equation design · identity lock · curriculum · final call)
GitHub