Run a shared cell through three inputs
numeric▲△△Exact values where possible; six decimal places for non-exact numerical results.
STATEMENT
Compute a recurrent forward pass without inventing a new weight for each step.
GIVEN
The scalar linear cell has , , and . Inputs are . The final readout is , with , , and target . Use .
FIND
All three states, the final prediction, loss, and number of trainable scalars.
STRATEGY
Keep one copy of each parameter. Substitute the preceding state at every step, then apply the readout only to the last state.
SOLUTION
This is (I.9.1) with an identity activation instead of tanh:
There are five trainable scalars: . The initial state is specified as a constant, not learned. Sequence length changes the number of operations, not this parameter count.
A short implementation reproduces the arithmetic:
xs = [1.0, 2.0, 0.0]
u, w, b, v, c = 1.0, 0.5, 0.0, 2.0, 0.0
h = 0.0
history = []
for x in xs:
h = u*x + w*h + b
history.append(h)
prediction = v*h + c
loss = 0.5*(prediction - 1.0)**2
print(history)
print(prediction, loss)It prints [1.0, 2.5, 1.25] and 2.5 1.125.
The reproduction script also runs the tanh example from the proposition,
so the identity activation is not silently treated as a nonlinear RNN.
Answer
The states are , the prediction is , the loss is , and the model has five trainable scalars.
Check — sanity
The third input is zero, but the third state is not zero: the recurrent term carries half the preceding state forward. With , this cell would forget the preceding input at each step.
Check — numeric · i-9-recurrence-checks.py
The complete reproduction script uses only the Python standard library. From a checkout of the repository, run:
python3 scripts/snippets/i-9-recurrence-checks.pyIt checks all fifteen problems, including analytic derivatives against central finite differences. The first line reports the three states above and loss . The nonlinear forward example ends with states , , and .
Executed in CI. The digits above are the digits it printed.
Where this breaks
Putting tanh back into the cell changes these numbers. It also introduces activation derivatives into the backward pass; the linear example is a controlled special case, not a replacement for those factors.
Variation
Reverse the first two inputs. The states become , giving prediction and loss . Shared parameters do not imply order invariance.