summaryrefslogtreecommitdiff
path: root/THEORY.md
blob: 676d28e98a0c47b47cbbdb96ce40314ceafb9353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# SDIL theory and cost audit

This note states the minimum claims that can be proved for the implemented
estimators and innovation rule. It deliberately separates an unbiased neural
teaching direction from a useful parameter update: the completed experiments
show that a high hidden-state cosine can coexist with poor optimization.

## 1. Simultaneous multi-layer perturbation

Consider one example and collect the hidden-state gradients
`g_l = dL/dh_l` for hidden blocks `l=1,...,H`, where `g_l` has dimension
`d_l`. For one simultaneous Rademacher intervention, draw independent
`xi_l in {-1,+1}^{d_l}` and linearize the centered loss difference as

```text
D = sum_j <g_j, xi_j>.
```

The gradient and descent estimators for layer `l` are

```text
g_hat_l = xi_l D,        q_l = -g_hat_l.
```

Independence and `E[xi_l xi_l^T] = I` give

```text
E[g_hat_l] = g_l.
```

Because a Rademacher vector has deterministic squared norm `d_l`, the exact
linearized mean-squared error is

```text
E ||g_hat_l - g_l||^2
  = (d_l - 1) ||g_l||^2
    + d_l sum_{j != l} ||g_j||^2.
```

Averaging `K` independent directions divides this expression by `K`. The first
term is ordinary directional-estimator variance; the second is cross-layer
interference. Thus simultaneous perturbation is unbiased but its relative
variance grows with layer width and with the total gradient energy injected at
other layers. This predicts why K1 can work in an easy/depth-flat regime yet
fail to train a moving context vectorizer on a compositional task.

For comparison, layerwise Rademacher perturbation removes the cross-layer term.
The current layerwise implementation uses Gaussian directions, for which

```text
E ||g_hat_l - g_l||^2 = (d_l + 1) ||g_l||^2 / K.
```

Layerwise targets therefore buy variance reduction with depth-dependent replay
cost; they are not a free scalable replacement for simultaneous calibration.

### Finite perturbation bias

Suppose the third derivative of the loss has operator norm at most `M` in the
perturbation neighborhood, and let `D_total = sum_l d_l`. A centered antithetic
difference has directional error at most

```text
M sigma^2 ||xi||^3 / 6.
```

For simultaneous Rademacher directions this gives the conservative layerwise
bias bound

```text
||E[g_hat_l] - g_l||
  <= (M sigma^2 / 6) sqrt(d_l) D_total^(3/2).
```

The important dependence is `O(sigma^2)`, with a dimension-dependent constant.
Reducing K removes variance but not this bias; increasing width/depth without a
sigma audit is therefore unsafe.

### Perturbing the representable convolutional subspace

The failed ResNet-20 run exposed a separate projection problem.  Its
translation-shared feedback field for example `i`, channel `c`, and spatial
site `s` is

```text
p_ics = b_ic + t_ics v_ic,       t_ics = tanh(h_ics).
```

The legacy estimator perturbs every `h_ics` independently, constructs a full
unit target, and only then averages its delta-rule update into the shared
`b/v` parameterization.  At K1, almost all sampled energy can lie outside this
two-dimensional per-channel subspace.  SDIL-v2 instead draws independent
Rademacher coefficients `z^b_ic,z^v_ic` and intervenes along

```text
xi_ics = (z^b_ic + t_ics z^v_ic) / sqrt(2).
```

Let `q_ics=-dL/dh_ics`, let `S` be the number of spatial sites, and let `D` be
the centered directional loss derivative.  Then

```text
qhat^b_ic = -sqrt(2) D z^b_ic / S,
qhat^v_ic = -sqrt(2) D z^v_ic / S
```

are unbiased for the two negative-gradient moments

```text
qbar^b_ic = mean_s q_ics,
qbar^v_ic = mean_s (q_ics t_ics).
```

All other examples, channels, and layers contribute zero-mean cross terms.
For BatchNorm, `D` is the derivative of the summed minibatch loss, so the same
identity targets each example's contribution including the true cross-example
Jacobian coupling.

This does not mistake moments for expansion coefficients.  The predicted
moments of `p=b+t v` are

```text
pbar^b = b + mean(t) v,
pbar^v = mean(t) b + mean(t^2) v.
```

Consequently updating the two vectorizer pathways with
`qhat^b-pbar^b` and `qhat^v-pbar^v` is exactly the expected gradient of the
original full-field squared prediction error.  It uses the same two causal
loss queries per direction as unit perturbation, but avoids estimating
unrepresentable spatial components.  It remains a variance reduction, not a
guarantee of useful feedback or stable end-to-end optimization; those require
a separately frozen empirical gate.

### Perturbing the vectorizer parameter subspace

The channel-moment estimator still samples one independent base/gate
coefficient for every example and channel and only afterward regresses those
noisy coefficients on the output context.  The quantity the local delta rule
actually needs is much smaller.  For

```text
p_ics = (A c_i)_c + t_ics (G c_i)_c
```

define the normalized prediction objective

```text
J(A,G) = (1 / 2B) sum_i mean_s ||p_i - q_i||^2,
q_i = -d ell_i / dh_i.
```

Its causal target terms are matrices, not per-example coefficient fields:

```text
U_A = (1/B) sum_i mean_s(q_ics) c_i^T,
U_G = (1/B) sum_i mean_s(q_ics t_ics) c_i^T.
```

Draw independent Rademacher matrices `Xi_A,Xi_G` with the same shapes as
`A,G`, independently across layers, and intervene along

```text
d_ics = ((Xi_A c_i)_c + t_ics (Xi_G c_i)_c) / sqrt(2).
```

Let `D` be the centered derivative of the summed minibatch loss under all
layer interventions. Since `D=-sum_ics q_ics d_ics`, independence gives

```text
Uhat_A = -sqrt(2) D Xi_A / (B S),     E[Uhat_A] = U_A,
Uhat_G = -sqrt(2) D Xi_G / (B S),     E[Uhat_G] = U_G.
```

Cross-layer and A/G cross terms vanish in expectation. The prediction terms
`(1/B) sum mean(p)c^T` and `(1/B) sum mean(pt)c^T` are locally available
exactly, so subtracting them from `Uhat_A,Uhat_G` gives an unbiased stochastic
gradient of `J`. BatchNorm changes neither identity: `D` is explicitly the
summed minibatch derivative and therefore includes its true cross-example
Jacobian.

This estimator perturbs only the shared mapping that will survive
amortization. It uses the same two loss queries per direction as the earlier
estimators. It does not uniformly dominate them for every context covariance
or batch size, but at the frozen batch-128 synthetic audit its one-direction
MSE is `0.03381x` the coefficient-then-regress estimator's MSE. The executable
mean has cosine `0.96928` and norm ratio `1.04888` to the exact A/G target.
Those mechanics do not establish task utility; a separately frozen gate is
still required.

## 2. What is sufficient for a descent step

Flatten all forward parameters into `theta`, let `p = grad L(theta)`, and let
`v` be the complete local update before multiplying by the learning rate:

```text
theta_next = theta + eta v.
```

If the loss is `beta`-smooth and

```text
c = <-p, v> / (||p|| ||v||) > 0,
```

then the descent lemma gives

```text
L(theta_next) - L(theta)
 <= -eta c ||p|| ||v|| + (beta eta^2 / 2) ||v||^2.
```

Consequently the update is guaranteed to descend only when

```text
0 < eta < 2 c ||p|| / (beta ||v||).
```

This separates three quantities that a neural-state cosine conflates:

1. direction (`c`);
2. gain (`||v|| / ||p||`);
3. curvature (`beta`).

For a local layer, multiplying a hidden teaching vector by the activation gain
and presynaptic activity maps it into parameter space. A positive
`cos(r_l, -g_l)` does not by itself imply a positive cosine after aggregating
examples, parameters, and layers, and even perfect parameter alignment can
increase loss if its gain makes the step exceed the bound. This is why future
diagnostics must include parameter-update cosine, norm ratio, and realized
single-step loss change rather than reporting hidden cosine alone.

## 3. Somato-dendritic innovation as conditional nuisance removal

The regression residual has a stronger interpretation than the linear model
alone suggests. Let `F_h` be the information available to a soma-only
predictor in a neutral period, let `n` denote ordinary apical traffic, and set

```text
m(h) = E[n | F_h].
```

For every square-integrable soma-measurable predictor `g(h)`, conditional
expectation gives the orthogonality and Pythagorean identities

```text
E <n - m(h), g(h)> = 0,

E ||n - g(h)||^2
  = E ||n - m(h)||^2 + E ||m(h) - g(h)||^2.
```

Thus `n-m(h)` is the unique minimum-power innovation after subtracting any
function of the available somatic statistic. This is an `L2` projection
statement, not a Gaussian or linear assumption. If task-period apical activity
is `a=s+n` and the neutral traffic law is invariant, neutral fitting yields

```text
r = a - m(h) = s + n - m(h).
```

It removes the largest soma-predictable nuisance component without projecting
out any part of the task-only instruction `s`. The implemented diagonal affine
predictor is the corresponding optimal projection only within each cell's
restricted span `{1,h_i}`; it cannot remove traffic predictable only from
population context or unobserved state. This restriction is consistent with
the failed broad endogenous-traffic gate and prevents the theorem from being
used to claim arbitrary contextual denoising.

The norm-matched raw control isolates direction from magnitude. For every
positive per-example scalar `alpha`,

```text
cos(alpha a, -g) = cos(a, -g).
```

Choosing `alpha=||r||/||a||` gives raw feedback exactly the innovation's norm
but cannot rotate it toward the descent direction at the same network state.
Across training, rescaling can of course change the subsequent trajectory;
this is why the matched control is still trained end to end rather than being
replaced by the algebraic observation.

The finite-dimensional special case used for the main experiment writes
neutral traffic as a linear somatic component plus unpredictable noise.

Write apical activity during a task period as

```text
a = s + M h + epsilon,
```

where `s` is the instructional component, `M h` is ordinary traffic predictable
from soma, and `epsilon` is unpredictable noise. In neutral periods `s=0`.
Assume `Sigma_h = E[h h^T]` is nonsingular and `E[epsilon h^T]=0`. Population
least squares on neutral periods yields

```text
P_neutral = E[a h^T | neutral] Sigma_h^(-1) = M.
```

The task-period innovation is then

```text
r_neutral = a - P_neutral h = s + epsilon.
```

If `s`, `M h`, and `epsilon` are mutually uncorrelated, a squared-cosine/SNR
proxy improves from

```text
raw:       S / (S + T + E)
innovation:S / (S + E),
```

where `S`, `T`, and `E` are their expected squared norms. The gain is strict
whenever predictable traffic has nonzero power.

Task-period fitting has a different estimand. Let

```text
C = E[s h^T] Sigma_h^(-1).
```

Then `P_task = M + C` and

```text
r_task = s - C h + epsilon.
```

It removes the soma-predictable projection of the teaching signal itself. This
proves the identification role of neutral periods and also defines the failure
boundary: residualization cannot remove contextual traffic that remains
unpredictable from the chosen per-cell soma statistic, and it can erase credit
when the predictor is fit on task periods.

For the diagonal normalized-LMS predictor used in the code, an ideal noiseless
cell with neutral relation `a=m h` follows

```text
p_(t+1) = p_t + eta_P (m - p_t),
traffic residual power fraction = (1 - eta_P)^(2t).
```

The relevant timescale is therefore the product of learning rate and number of
neutral updates. Too few neutral updates leave traffic; task-period updates
converge to the wrong coefficient regardless of speed.

## 4. Hardware-independent complexity

Let `H` be the number of hidden layers, `K` the perturbation directions per
event, `e` the number of ordinary minibatches between events, `B` the batch
size, and `F_l` the affine work of layer `l`. Define `F=sum_l F_l` and suffix
work `S_l=sum_{j>l} F_j`.

| method | activity phases / passes | transport | scalar task-loss observations | extra affine work | main transient memory |
|:--|:--|:--|:--|:--|:--|
| BP | forward + reverse | exact transposed Jacobians | ordinary supervised loss | about one reverse pass | saved activations / graph |
| FA | forward + reverse-like serial feedback | fixed random feedback | ordinary loss | `O(F)` feedback work | activations + feedback states |
| DFA | forward + direct feedback | fixed random output maps | ordinary loss | `O(sum_l d_l d_out)` | activations + feedback states |
| learned NP, simultaneous | ordinary forward; one duplicate clean plus `2K` noisy full forwards every `e` batches | learned direct maps; no weight transport | `2KB/e` per ordinary batch | `(1+2K)F/e` | up to `2KB` noisy examples in the vectorized implementation |
| learned NP, layerwise | ordinary forward; clean baseline plus antithetic suffix replays | learned direct maps | `(1+2KH)B/e` | `(F + 2K sum_l S_l)/e`, quadratic in depth for balanced layers | serial suffix replay, no `2K` batch expansion |
| direct NP | layerwise or simultaneous estimator every update | none beyond causal intervention | same formulas with `e=1` | same formulas with `e=1` | estimator dependent |
| canonical EP | free relaxation then nudged relaxation | symmetric energy weights | label injected in nudged phase | `T_free + T_nudged` recurrent steps | persistent/free and nudged states |
| Dual Prop `DP^T` VGG | one inference phase, 17 forward-only layer passes in the author CIFAR protocol | dyadic forward/top-down states | ordinary target loss | 17 layer passes before update | two states per dyadic unit |
| BurstCCN | one burst/event-probability phase with plastic W/Y/Q pathways | separate plastic feedback pathways | ordinary supervised target | architecture-dependent local W/Y/Q updates | event and burst states plus feedback weights |

The project ledger reports the exact realized loss observations,
forward-equivalent examples, peak allocated memory, and wall time. Asymptotic
labels never replace those measurements. In particular, the frozen direct-NP
C2 diagnosis costs `68.4x` ordinary work, whereas the frozen CIFAR d20 K1/e4
protocol uses 16x fewer logical queries, 11x less calibration work, and 5.3x
less total work than K16/e4 while retaining its gain over DFA.

## 5. Executable checks

Run:

```bash
python experiments/verify_theory.py
```

The verifier checks the exact Rademacher MSE across depth, width, and K; the
quadratic finite-sigma bias law; the smooth-descent step threshold; the
conditional-projection Pythagorean identity and norm-matching direction
invariance; neutral predictor convergence across `eta_P` and update counts;
and the task-fit teaching-signal absorption predicted above.