Continual backpropagation maintains plasticity by doing continually what initialisation did once: it tracks a utility for every hidden unit and, at a small fixed rate, reinitialises the least useful mature units. Implement the three pieces for one hidden layer with incoming weights W_in of shape (d, U) and outgoing weights W_out of shape (U, m).
update_utility(u, h, W_out, eta)
u is the (U,) running utility, h an (N, U) batch of the layer's activations. The instantaneous utility of unit is its mean absolute activation over the batch times the sum of absolute outgoing weights, . Return .select_replacements(u, age, maturity, n_replace)
age >= maturity. Return the sorted list of the n_replace eligible units with the lowest utility (ties by lower index, stable sort), or fewer if not enough are eligible.reinit_units(W_in, W_out, idx, rng, scale)
W_in and W_out where, for each unit in idx, the incoming column W_in[:, j] is redrawn as rng.normal(0, scale, size=d) (one draw per unit, in the order of idx) and the outgoing row W_out[j, :] is set to zero. Inputs must not be modified.cbp_step(state, h, rng, eta, rho, maturity, scale)
state is a dict with keys "W_in", "W_out", "u", "age", "acc" (a float accumulator for fractional replacements, initially 0.0). Update the utility, increment every age by one, add rho * U to the accumulator, take n = int(acc) as the number of units to replace this step and subtract it from the accumulator, select and reinitialise those units, reset their utility and age to zero, and return the new state dict (new arrays, inputs untouched).