Three Taps and a Shortcut

Convolutional ArchitecturesMedium+20 XP+20

Three Taps and a Shortcut

Stacking more layers onto a deep plain network made it worse — worse on the training set, which rules out overfitting and leaves an optimisation failure. The fix was one addition: carry a block's input past its layers and add it back, so the block computes F(x)+xF(x) + xF(x)+x instead of F(x)F(x)F(x).

Here you will run a stack of those blocks over a single row of a feature map, so the whole thing stays small enough to follow by hand.

Task: write residual_stack(signal, kernels), returning the final row as a plain list, rounded to 4 decimal places.

  • signal is a list of numbers — one row of a feature map.
  • kernels is a list of blocks, one 3-tap filter [k0,k1,k2][k_0, k_1, k_2][k0​,k1​,k2​] each.
  • A block takes the row xxx handed to it and returns a row of the same length:

Fi=k0 xi−1+k1 xi+k2 xi+1,yi=max⁡(0, Fi)+xiF_i = k_0\,x_{i-1} + k_1\,x_i + k_2\,x_{i+1}, \qquad y_i = \max(0,\, F_i) + x_iFi​=k0​xi−1​+k1​xi​+k2​xi+1​,yi​=max(0,Fi​)+xi​

  • Anything off either end reads as 000 — zero padding, so the length never changes.
  • Blocks run in order, each one taking the row the previous block produced.
  • Round only the values you finally return.

One of the tests hands a block a filter of all zeros. In a plain stack that layer would wipe the row out and everything after it would be working with nothing; here it is forced to pass its input straight through. That is the whole argument for skip connections — a layer with nothing useful to add costs nothing instead of doing damage, which is what stopped extra depth from being a risk.

x
→
conv
→
conv
→
+

An ordinary pair of conv layers. The input has to pass through both.

Examples

signal = [1.0, 2.0, 3.0, 2.0, 1.0]
kernels = [[0.5, 0.0, -0.5], [1.0, 1.0, 1.0]]
returns [4.0, 8.0, 11.0, 11.0, 7.0]
signal = [2.0, -1.0, 0.5, 4.0]
kernels = [[-1.0, 0.5, -1.0]]
returns [4.0, -1.0, 0.5, 5.5]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run