Md. Asif Uddin
Problem I.5.B01

Three inputs, two regions, one network

numeric▲△△

Every value here is exact; all are printed to 4 d.p. so they line up with the reproduction snippet.

STATEMENT

Push three inputs through the same two-layer network. Report the pre-activations, the activations and the output for each, and then answer the question the numbers are really for: which of the three inputs are processed by the same affine map, and how you can tell without computing the output at all.

GIVEN

Two inputs, three hidden ReLU units, one output. Row-major throughout (Vectors, matrices and the row-major convention 0.LA.01), so a layer is applied on the right.

W(1)=[110.50.511],b(1)=[0.50.250]\mat{W}^{(1)} = \begin{bmatrix} 1 & -1 & 0.5 \\ 0.5 & 1 & -1 \end{bmatrix}, \qquad \vec{b}^{(1)} = \begin{bmatrix} -0.5 & 0.25 & 0 \end{bmatrix}W(2)=[211.5],b(2)=0.75\mat{W}^{(2)} = \begin{bmatrix} 2 \\ -1 \\ 1.5 \end{bmatrix}, \qquad b^{(2)} = 0.75

The three inputs:

xa=[12],xb=[1.22.5],xc=[10]\vec{x}_a = \begin{bmatrix} 1 & 2 \end{bmatrix}, \qquad \vec{x}_b = \begin{bmatrix} 1.2 & 2.5 \end{bmatrix}, \qquad \vec{x}_c = \begin{bmatrix} -1 & 0 \end{bmatrix}

FIND

For each input: z(1)\vec{z}^{(1)}, a(1)\vec{a}^{(1)}, the activation pattern, and y^\hat{y}. Then the effective affine map y^=xw+c\hat{y} = \vec{x}\vec{w} + c that the network applies on each pattern.

STRATEGY

Compute the pre-activations first and read the pattern off their signs, before touching the second layer. The pattern is what decides everything that follows, so getting it in hand early turns the rest into arithmetic.

SOLUTION

Step 1 — the pre-activations for xa\vec{x}_a. This is the first half of one step of (I.5.1): each entry of z(1)\vec{z}^{(1)} pairs x\vec{x} with one column of W(1)\mat{W}^{(1)}.

z1=(1)(1)+(2)(0.5)0.5=1.5,z2=(1)(1)+(2)(1)+0.25=1.25z_1 = (1)(1) + (2)(0.5) - 0.5 = 1.5, \qquad z_2 = (1)(-1) + (2)(1) + 0.25 = 1.25z3=(1)(0.5)+(2)(1)+0=1.5z_3 = (1)(0.5) + (2)(-1) + 0 = -1.5

So z(1)=[1.51.251.5]\vec{z}^{(1)} = \begin{bmatrix} 1.5 & 1.25 & -1.5 \end{bmatrix} and the activation pattern is 110110 — units one and two on, unit three off.

Step 2 — activation and output. a(1)=[1.51.250]\vec{a}^{(1)} = \begin{bmatrix} 1.5 & 1.25 & 0 \end{bmatrix}, and

y^=(1.5)(2)+(1.25)(1)+(0)(1.5)+0.75=31.25+0.75=2.5\hat{y} = (1.5)(2) + (1.25)(-1) + (0)(1.5) + 0.75 = 3 - 1.25 + 0.75 = 2.5

Step 3 — the second input. z(1)=[1.951.551.9]\vec{z}^{(1)} = \begin{bmatrix} 1.95 & 1.55 & -1.9 \end{bmatrix}, pattern 110110 again, and y^=3.91.55+0.75=3.1\hat{y} = 3.9 - 1.55 + 0.75 = 3.1.

Step 4 — the third input. z(1)=[1.51.250.5]\vec{z}^{(1)} = \begin{bmatrix} -1.5 & 1.25 & -0.5 \end{bmatrix}, pattern 010010, a(1)=[01.250]\vec{a}^{(1)} = \begin{bmatrix} 0 & 1.25 & 0 \end{bmatrix}, and y^=1.25+0.75=0.5\hat{y} = -1.25 + 0.75 = -0.5.

Step 5 — the map each pattern selects. Write the pattern as a diagonal matrix D\mat{D} of ones and zeros. Then ReLU has been replaced by a fixed linear map, and the whole network collapses on that region into equation (I.5.3):

y^=x(W(1)DW(2))+(b(1)DW(2)+b(2))\hat{y} = \vec{x}\left(\mat{W}^{(1)}\mat{D}\,\mat{W}^{(2)}\right) + \left(\vec{b}^{(1)}\mat{D}\,\mat{W}^{(2)} + b^{(2)}\right)

For D=diag(1,1,0)\mat{D} = \mathrm{diag}(1,1,0):

w1=(1)(2)+(1)(1)=3,w2=(0.5)(2)+(1)(1)=0w_1 = (1)(2) + (-1)(-1) = 3, \qquad w_2 = (0.5)(2) + (1)(-1) = 0c=(0.5)(2)+(0.25)(1)+0.75=0.5c = (-0.5)(2) + (0.25)(-1) + 0.75 = -0.5

so on that region y^=3x1+0x20.5\hat{y} = 3x_1 + 0\,x_2 - 0.5. For D=diag(0,1,0)\mat{D} = \mathrm{diag}(0,1,0): w1=1w_1 = 1, w2=1w_2 = -1, c=0.5c = 0.5, giving y^=x1x2+0.5\hat{y} = x_1 - x_2 + 0.5.

Step 6 — the answer to the question actually asked. xa\vec{x}_a and xb\vec{x}_b share the pattern 110110, so they share one affine map; xc\vec{x}_c does not. You can tell from the signs of z(1)\vec{z}^{(1)} alone, which is three inner products — the second layer never enters the decision.

Answer

inputz(1)\vec{z}^{(1)}patterny^\hat{y}map on that region
xa\vec{x}_a(1.5, 1.25, 1.5)(1.5,\ 1.25,\ -1.5)1101102.52.53x1+0x20.53x_1 + 0x_2 - 0.5
xb\vec{x}_b(1.95, 1.55, 1.9)(1.95,\ 1.55,\ -1.9)1101103.13.13x1+0x20.53x_1 + 0x_2 - 0.5
xc\vec{x}_c(1.5, 1.25, 0.5)(-1.5,\ 1.25,\ -0.5)0100100.5-0.5x1x2+0.5x_1 - x_2 + 0.5

The first two inputs lie in one linear region and the third in another.

Check — numeric · i-5-b01-activation-pattern.py
def forward(x):
    z = [sum(x[i] * W1[i][j] for i in range(2)) + b1[j] for j in range(3)]
    a = [max(0.0, t) for t in z]
    return z, a, sum(a[j] * W2[j] for j in range(3)) + b2

Prints the three patterns 110110, 110110, 010010, the outputs 2.50002.5000, 3.10003.1000, 0.5000-0.5000, and each region’s affine map — which it then evaluates directly, as a second route to the same output.

Executed in CI. The digits above are the digits it printed.

Check — sanity

The effective map reproduces the output. On the region 110110, 3(1)+0(2)0.5=2.53(1) + 0(2) - 0.5 = 2.5 and 3(1.2)+0(2.5)0.5=3.13(1.2) + 0(2.5) - 0.5 = 3.1. Two different inputs, one formula, the right answers. That is the content of a linear region stated as an arithmetic check.

The dead unit cannot matter. Unit three is off for xa\vec{x}_a, so the third entry of W(2)\mat{W}^{(2)} — the value 1.51.5 — cannot influence y^\hat{y}. Change it to 150150 and recompute: still 2.52.5.

The second coordinate genuinely drops out. On region 110110 the coefficient of x2x_2 is exactly zero, so moving xa\vec{x}_a to (1,5)(1, 5) should not change the output as long as the pattern holds. Check the pattern first: z(1)=(3,4.25,4.5)\vec{z}^{(1)} = (3, 4.25, -4.5), still 110110, and y^=64.25+0.75=2.5\hat{y} = 6 - 4.25 + 0.75 = 2.5. It does not change.

Where this breaks

The whole calculation assumes the pattern is read at the given input. It is not a property of the network — it is a property of the network and the input together. A common mistake is to speak of “the dead units” of a model as though the set were fixed; unit three is off here and on for x=(2,0)\vec{x} = (2, 0), where z3=1z_3 = 1. Only a unit off for every input in the dataset is dead in the sense of I.3, and that is a much stronger and much rarer claim.

Variation

Find an input for which all three units are on, then one for which all three are off — or show that the second is impossible. I.5.X01 does exactly this by exhaustion, so try it by hand first.

Draws on