# Protocol 021 (planned): does the cortical circuit change how recent inputs enter its decisions?
Status: draft, revision 3          Date: 2026-10-24

Written on 23-24 October 2026 (UTC), while protocol 017's milestone-2 runs were still on the server and before any of their exports had been fetched or analysed. The first version's SHA-256 (`d3b30448…`) was recorded in the project handoff at 23:22:45 UTC. This revision 1 was written after a first review and also before protocol 017's analysis. Its hash is recorded the same way.

**Revision 1 (24 Oct, after the first review, before protocol 017's analysis):**
- each lesion is now paired with its own network instance;
- a gain-matched lesion is required;
- the primary measure moved from the clipped decision signal to the linear population-vector components;
- decoding windows are aligned per condition from the probe;
- the boundary rule, margin, sample-size rule, gates and fallback timing are now fixed;
- no design choice is left to be made after protocol 017's result.

**Revision 2 (24 Oct, the owner's fast track, before protocol 017's analysis):**
- four main runs instead of six: the plain lesion is characterised in the probe only, and the main runs keep intact and matched for both instances;
- one pre-freeze review;
- the identity check, probes and calibration run as one automated server queue, with the declared rules applied by code.

**Revision 3 (24 Oct, before protocol 017's analysis), matching the queue's code (`work/controller-021/server/`):**
- the calibration rate is the mean L4E rate over whole steps 5 to 19 of the calibration sequence, which is the probe sequence's first 20 steps;
- the confirmation compares probe-matched with probe-intact over steps 5 to 119;
- the identity check uses a 20-step sequence (seed 213) in two presentations of 10 steps.
## Goal
Protocol 017 asks whether the cat circuit carries the previous input into its next decision when steps are separated by 147 ms blanks. If the answer is "no carry-over", the circuit is a relay at that timing and that design stops, as the project plan requires. The next design removes the blanks and shortens the steps, so recent inputs necessarily overlap inside the circuit. The question is then whether the cortical circuit itself changes how recent inputs enter a decision, compared with the same network with its intracortical connections switched off. A "yes" would be the first evidence that the circuit's computation, not only its input filter, shapes the controller's decisions. Everything stays in simulation.

## Branching rule (fixed before protocol 017's result exists)
- **017 reads "decoding failed":** decoding is revisited first, with a new decoder rule declared from milestone-1 data. Protocol 021 waits.
- **Any other reading** ("dynamics", "dynamics, size unresolved", "no carry-over", "inconclusive"): protocol 021 goes ahead as designed here. 017's own declared secondary history terms (lag 2, |s(t−1)|, s(t)·|s(t−1)|) are reported with its results either way.
- **Remaining choices** are settled only by the rules below, from 021's own probe and calibration runs on their own sequence. None uses protocol 017's numbers. A deviation from these rules makes the protocol a new version, with the reason stated.

## Non-goals
- No token, wallet, exchange, key or real order. The executor stays simulated, as in protocol 017.
- No claim of financial usefulness, and no biological claim beyond the 2 mm reduction.
- No change to frozen protocol 017 or to its server files. Changed code gets new file versions in a new package, and protocol 017 is never run with them.

## Context
- **Reused from protocol 017:**
  - engine: the 2 mm reduction of LSV1M;
  - encoder: orientation 90° + 45°·s and contrast 30 + 70·|s| percent;
  - decoder: balanced population vector over layer 4 excitatory cells, with 017's neuron weights;
  - the four-stage decision log, the simulated executor and the replay check.
- **Why history dependence is expected even without cortex.** The retina/LGN stage filters the image with a biphasic temporal kernel 200 ms long (Cai et al. 1997 form, `SpatioTemporalFilterRetinaLGN_defaults`, 7 ms resolution). With back-to-back steps shorter than 200 ms, every condition mixes recent inputs. The quantity of interest is the difference intracortical connections make.
- **LGN cell positions** are drawn from the network seed (`RandomStructure` with `mozaik.pynn_rng`). Runs of one network instance therefore share their LGN input, and runs of different instances do not.
- **The L4E afferent weight** is `sheets.l4_cortex_exc.AfferentConnection.base_weight`, 0.0012 in `param_spont`.
- **Cost, from protocol 017's runs:**
  - LGN input: about 1.0 to 1.2 s per 7 ms frame;
  - simulation: about 110 to 130 s per simulated second intact, and about 184 s feedforward-only;
  - about 15 min to build the network;
  - 5.2 GB after 3,132 frames (limit 6.5 GB).

## Design
- **Timing.**
  - 10 frames (70 ms) per step with no gap, via `FELISYN_STEP_FRAMES` and `FELISYN_GAP_FRAMES` in the new `controller_experiments.py`. Its defaults reproduce 017 frame for frame.
  - Presentations of at most 300 steps, with a 504 ms lead-in in the first.
  - **Fallback, fixed now:** if either probe condition fails the decoding gate, or more than 10 % of its decoded steps are clipped or wrapped (rule below), steps of 15 frames (105 ms) are used and the probe is repeated. If that also fails, the design is revised and reported as a failure of this timing.
- **Market.** I.i.d. uniform signals. The main sequence uses seed 211 and the probe and calibration sequences seed 212, so lagged inputs are uncorrelated by construction.
- **Conditions of the main runs**, all on the main sequence, in this order:
  1. intact-A;
  2. matched-A (017's five overrides, with the L4E afferent weight scaled by k);
  3. intact-B and matched-B: the same with `pynn_seed 6`.
  - Each lesion is contrasted only with the intact run of its own instance.
- **Probe and calibration (milestone 1 of 021, on the probe sequence, instance A):**
  1. the LGN cache identity check (`docs/specs/2026-10-24-lgn-input-cache.md`);
  2. probe-intact and probe-lesion, 120 steps each;
  3. **calibration of k:** two lesion runs with k = 0.5 and k = 0.25 on the probe sequence's first 20 steps. Their mean L4E rates over whole steps 5 to 19 are interpolated linearly in log rate against k, to match probe-intact's rate over the same steps, and k is rounded to 0.01 (bounded to 0.05 to 1). probe-matched (120 steps) then confirms it: k is accepted if probe-matched's rate over steps 5 to 119 is within ±20 % of probe-intact's. Otherwise one more interpolation step uses all three points (each over steps 5 to 19), and that k is accepted with the mismatch reported. Instance B uses the same k, and its rates are reported.
- **Kernels and windows (from the probe only).**
  - For each probe condition, the population vector z = Σ_i w_i n_i e^{2iφ_i} is computed in 10 ms bins. It is regressed on the step inputs ζ(t) = e^{2iθ_in(t)}, which gives a complex response kernel h(τ) for τ = 0 to 350 ms after step onset.
  - The latency L is the first bin where Re(h(τ)·conj(h_peak)) ≥ 0.5·|h_peak|².
  - Each condition type's decoding window is [L, L + step length], used for both instances.
- **Primary measure (linear population code).**
  - Per run, a complex least-squares fit: z(t) = α + β·ζ(t) + Σ_{k=1..4} γ_k·ζ(t−k) + ε·ζ(t+1). Here z(t) is the population vector in that run's window, and ρ_k = Re(γ_k / β) is the share of the lag-k input aligned with the current input's representation.
  - **Primary:** Δρ₁ = ρ₁(intact) − ρ₁(matched), computed within each instance and paired on the same bootstrap resamples. Margin: 0.10.
  - **Why 0.10:** a previous input with a tenth of the current input's weight shifts the decoded signal by up to about 0.09, about a third of the 0.25 request threshold. Smaller shares rarely change a request.
- **Gates.**
  - **Decoding gate:** as in 017 (accuracy above the permuted-signal null and gain interval above 0), for every run.
  - **Lead gate:** |Re(ε / β)| ≤ 0.05 with its interval inside ±0.10, for every run.
  - A run failing a gate makes every contrast that involves it "not applicable", so that instance reads "inconclusive".
- **Readings.**
  - Each instance's contrast is first placed in a category, as in 017:
    - material change: beyond the margin;
    - change, size unresolved: excludes 0 and reaches beyond the margin;
    - small change: excludes 0 and lies within the margin;
    - no material change: includes 0 and lies within the margin;
    - inconclusive.
  - The categories of the two instances then give the reading:
    - **"change":** both show material change, with the same sign. Intracortical connections then change how recent inputs enter decisions.
    - **"change, size unresolved":** both are material or unresolved, with the same sign.
    - **"no material change":** both are no material or small change.
    - **"mixed or inconclusive":** anything else.
- **Secondary measures, declared and reported:**
  - the plain lesion's (017's five overrides) kernel, latency and ρ from the probe, against probe-intact (instance A only);
  - Δρ for lags 2 to 4 and for the sum;
  - the decision-signal regression ŝ(t) = a + b·s(t) + Σ c_k·s(t−k) + e·s(t+1) per run, its contrasts, and the share of clipped or wrapped steps;
  - each run's kernel latency and decay time (peak to 1/e);
  - request agreement between each intact run and its lesions;
  - the executor summary.
- **Rows and resampling.**
  - Lags are taken only within a presentation.
  - The first 5 steps of every presentation are excluded: 350 ms covers the lead-in or the 150 ms blank between presentations plus the 200 ms LGN kernel. The last step of every presentation is also excluded, because of the lead term.
  - Moving blocks of 10 steps over the remaining rows, 2,000 resamples, seed 21.
- **Sample size.**
  - A null simulation uses the probe's per-condition errors, intact and matched.
  - N is the smallest multiple of 100, at least 300, whose projected half-width of Δρ₁ is at most 0.05. The cap is 900.
  - If the half-width at the cap exceeds 0.07, the design is revised before freezing.
- **LGN cache.** Used only after its identity check passes. matched-X reads intact-X's entries; intact-B computes its own.
- **Refusals.** The analysis refuses any export whose step frames, gap frames, sequence, overrides or k differ from the contract.

## Risks and edge cases
- **Operating point.** The plain lesion raises L4E rates about six-fold (017 smoke runs). The matched lesion is the control for that; the plain lesion is characterised in the probe only. Remaining differences in time course are visible in the kernels.
- **Decoder nonlinearity.** Overlapping responses can swing or wrap the decoded angle. The primary measure uses the linear components; the decision-level results report clipped and wrapped steps.
- **Instances.** Each contrast stays within one instance, and the two instances must agree.
- **Cost.**
  - Identity check: 5 short runs.
  - Probes and calibration: 5 runs.
  - Four main runs: about 6.5 h with the cache (intact runs about 2 h, matched runs about 1.2 h).
  - One job at a time, starting only after protocol 017's runs have been fetched.

## Test plan
- **Stimulus:** with default frames the new version yields exactly 017's frame sequence; with 10 and 0 it yields back-to-back steps (`work/controller-021/test_stimulus_v2.py`).
- **Analysis on synthetic data:**
  - known complex and real lag weights are recovered;
  - the boundary rows are excluded;
  - the gates and every reading are reached;
  - the latency rule finds a known delay;
  - the calibration rule finds a known k.
- **Sample size:** null simulation for N.
- **Reviews:** one pre-freeze review by the agentkit reviewer, then `scripts/agent-verify.sh`.

## Done when
- [x] First version's SHA-256 recorded in HANDOFF before protocol 017's analysis (23:22:45 UTC)
- [x] Revision 1's SHA-256 recorded in HANDOFF before protocol 017's analysis (23:36:25 UTC)
- [x] Revision 2's SHA-256 recorded in HANDOFF before protocol 017's analysis (23:48:41 UTC)
- [ ] Revision 3's SHA-256 recorded in HANDOFF before protocol 017's analysis
- [ ] Cache identity check, probes and calibration run; k, windows and N set by the rules above
- [ ] Protocol 021 frozen after reviews, with its hash in HANDOFF
- [ ] Four main runs, analysis, results package and journal note; an X post only if it is a breakthrough
- [ ] `scripts/agent-verify.sh` passes; owner deploys; live check

## Open questions
None. Every remaining choice has a rule above.
