-
Notifications
You must be signed in to change notification settings - Fork 1
Routing Algorithm

Generated with Grok Build: Grok 4.5 · xAI Imagine (/imagine)
Per-tick pipeline in update_routing! (src/region_router.jl, main @ c9ff99c).
For each region i:
score_i = α · density_i + β · surprise_i + γ · momentum_i
| Symbol | Default | Meaning |
|---|---|---|
α (ALPHA) |
0.50 | Normalized spike / activity rate |
β (BETA) |
0.35 | Manifold surprise vs EMA |
γ (GAMMA) |
0.15 | Routing-weight momentum |
EMA_DECAY |
0.05 | EMA blend: 5% new estimate per tick |
MIN_SCORE |
0.01 | Soft floor before/during normalization |
EPSILON |
1e-6 | Stability floor |
spike_density[i] = regions[i].last_spike_rate
ema[i,:] ← (1 − EMA_DECAY) · ema[i,:] + EMA_DECAY · regions[i].output
surprise[i] = ‖output − ema‖ / (‖ema‖ + ε)
High surprise ⇒ readout moved relative to recent history (regime / attractor change).
momentum[i] = |routing_weights[i] − prev_routing_weights[i]|
On main, after each successful tick the code snapshots:
copyto!(router.prev_routing_weights, router.routing_weights)so post-update prev_routing_weights matches the just-written weights (interop notes this). Scoring still multiplies by γ; treat momentum semantics carefully when interpreting diagnostics across ticks.
For each destination region dst:
inhibited[dst] = max(
raw[dst] − Σ_src 1[adjacency[src,dst] > 0] · inhibition[src,dst] · raw[src],
MIN_SCORE
)
adjacency_matrix is a binary-style mask in the hot path (magnitude not used as a continuous weight).
- Subtract max for numerical stability
-
expand divide by(sum + ε) - Clamp entries below
MIN_SCORE, re-normalize
Result: routing_weights length n_regions, sum ≈ 1.
n_regions |
Default matrix |
|---|---|
| ≤ 4 | Top-left slice of historical asymmetric INHIBIT (4×4 table) |
| > 4 | Zero diagonal; off-diagonal `0.08 / |
Override with RegionRouter(; inhibition_matrix=M).
- In-place updates on pre-allocated buffers
- No heap alloc on the hot path after construction
- Float32 throughout
- Tick counter increments every call
α/β/γ, EMA decay, floors — module constants only. Per-router scoring config is not on this tip (tracked separately; e.g. open work around LIM-230 / GH#24).
Last updated: July 29, 2026
Updated by: Grok Build: Grok 4.5
Package tip reference: c9ff99c (main)