Md. Asif Uddin
    Problem I.9.B01

    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 ht=uxt+wht−1+bh_t=ux_t+wh_{t-1}+b has u=1u=1, w=1/2w=1/2, b=0b=0 and h0=0h_0=0. Inputs are (1,2,0)(1,2,0). The final readout is z3=vh3+cz_3=vh_3+c, with v=2v=2, c=0c=0, and target y=1y=1. Use L=(z3−y)2/2\mathcal L=(z_3-y)^2/2.

    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:

    h1=1+(1/2)0=1,h2=2+(1/2)1=5/2,h3=0+(1/2)(5/2)=5/4,z3=2(5/4)=5/2,L=12(5/2−1)2=9/8.\begin{aligned} h_1&=1+(1/2)0=1,\\ h_2&=2+(1/2)1=5/2,\\ h_3&=0+(1/2)(5/2)=5/4,\\ z_3&=2(5/4)=5/2,\\ \mathcal L&=\tfrac12(5/2-1)^2=9/8. \end{aligned}

    There are five trainable scalars: u,w,b,v,cu,w,b,v,c. 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 (1,2.5,1.25)(1,2.5,1.25), the prediction is 2.52.5, the loss is 1.1251.125, 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 w=0w=0, 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.py

    It checks all fifteen problems, including analytic derivatives against central finite differences. The first line reports the three states above and loss 1.1250001.125000. The nonlinear forward example ends with states 00, 0.4621170.462117, 0.8428860.842886 and 0.3981450.398145.

    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 (2,2,1)(2,2,1), giving prediction 22 and loss 1/21/2. Shared parameters do not imply order invariance.

    Draws on