3.1.3 · D4Neural Network Fundamentals

Exercises — Forward propagation computation

2,334 words11 min readBack to topic

Quick reminder of the machine you are running, one layer at a time: Read this out loud as "Weigh, Bias, Bend". Every exercise below is just this line applied carefully.


Level 1 — Recognition

L1.1 — Name the pieces

In the expression , which symbol is added (not multiplied), and what does adding it let a neuron do?

Recall Solution

(the bias) is added. Adding — not multiplying — means it shifts the pre-activation up or down. Consequence: a neuron can output a nonzero value even when every input . Geometrically its decision boundary need not pass through the origin. (Multiplying instead would only scale the inputs — see the L1 mistake below.)

L1.2 — Shape spotting

A layer has inputs and neurons. State the shapes of , , , and for a single input vector.

Recall Solution
  • is (the inputs).
  • is output rows, input columns, so that produces numbers.
  • is (one bias per neuron).
  • is .

Sanity chain: , and adding () keeps it . ✔

L1.3 — Which activation goes where?

You are building a 3-class classifier. Which activation belongs on the output layer, and which belongs on a hidden layer? Give one reason each.

Recall Solution
  • Output layer: softmax. Reason: it turns 3 raw scores into 3 positive numbers that sum to — a valid probability distribution over the classes.
  • Hidden layer: ReLU (or tanh). Reason: it is a cheap per-unit nonlinearity that breaks the linear collapse without coupling units together. See Activation functions.

Level 2 — Application

L2.1 — One neuron by hand

A single neuron has weights , bias , and input . Compute the pre-activation , then the activation under ReLU.

Recall Solution

Weigh + Bias: Bend (ReLU clips negatives to 0): The neuron is "dead" for this input — ReLU gated it shut.

L2.2 — A full hidden layer

Layer with input , ReLU activation, Find and .

Recall Solution

Each row of dotted with the input, plus that row's bias: Apply ReLU element-wise:

L2.3 — Softmax output

An output layer produces logits . Compute the softmax probabilities and name the predicted class.

Recall Solution

Exponentiate each logit (why: make them positive and monotonic in the score): Divide by the sum (why: force them to add to ): Predicted class = index 1 (the largest logit ⇒ the largest probability).


Level 3 — Analysis

L3.1 — The collapse proof

Show explicitly that two stacked linear layers with no activation, — equal a single linear layer. State the effective weight and bias.

Recall Solution

Substitute the first into the second: So — one linear map. Consequence: depth without a nonlinearity buys zero extra expressive power. This is exactly why activations are non-optional, and why the Universal approximation theorem needs a nonlinear . See Matrix multiplication for why is itself a single matrix.

L3.2 — ReLU makes it piecewise-linear

Using the network from Worked Example 1 of the parent note (, , ReLU hidden; , , identity output), compute the output for . Then explain what changed versus the parent's input .

Recall Solution

Layer 1 pre-activation: ReLU: both positive, unchanged: . Layer 2: , so .

What changed: for neuron 1 had , so ReLU killed it — the network was in a region where only neuron 2 was active (one linear piece). For both neurons are active — a different linear piece. ReLU networks are stitched together from such flat pieces, one per on/off pattern of the hidden units. See figure.

Figure — Forward propagation computation

L3.3 — Batch shape audit

You process examples through a layer with inputs and units. Someone wrote with shaped and shaped . Is this legal? Fix it if not, and give the shape of .

Recall Solution

Not legal. with being and being requires the inner dimensions to match ( vs ) — they don't. The correct batch form keeps on the left: Inner dims match ✔. is . The bias () is broadcast across all columns. Rule of thumb: the weight matrix always left-multiplies the data, and its column count equals the input size .


Level 4 — Synthesis

L4.1 — Build a 2-layer net end-to-end

Design and run a network that maps to a 2-class probability. Use one hidden layer of 2 ReLU units and a softmax output of 2 units.

Recall Solution

Hidden pre-activation: ReLU: . Output logits: Softmax: : Predicted class 0 with probability .

L4.2 — Choose activations for a scenario

You must predict a house price (a single real number, possibly large) from features. Your friend puts a sigmoid on the output layer. Explain the failure, and state the correct output activation and why.

Recall Solution

Failure: sigmoid squashes its output into . A house price can be — the sigmoid can never reach it; it saturates at . Worse, in the saturated region the gradient , so learning stalls (see Vanishing and exploding gradients). Correct choice: the identity (linear) output activation for regression, so can take any real value. Hidden layers can still use ReLU to provide nonlinearity; only the final layer's range must match the target's range.


Level 5 — Mastery

L5.1 — Count the linear regions

For the L3.2 network ( hidden ReLU units), how many distinct on/off patterns can the hidden layer have, and therefore at most how many linear pieces can the overall function have? Which pattern was active for vs ?

Recall Solution

Each of the ReLU units is independently on () or off (): possible patterns, hence at most 4 linear pieces.

  • For : ⇒ pattern (off, on).
  • For : ⇒ pattern (on, on).

Two different patterns ⇒ two different linear pieces, exactly the piecewise-linear behaviour of ReLU nets. More units ⇒ exponentially more possible pieces ⇒ more expressive power, connecting to the Universal approximation theorem.

L5.2 — Symbolic forward pass, then a numeric check

Let a scalar-input scalar-output net be with . (a) Find the value of where the ReLU switches on. (b) Give the two linear formulas (one per side) and evaluate at and .

Recall Solution

(a) Kink location: ReLU switches at . (b) Two pieces:

  • For (ReLU off, output ): (flat).
  • For (ReLU on): .

Evaluate:

  • : on the flat side ⇒ .
  • : on the sloped side ⇒ .

The function is a hinge: flat then rising, joined at the kink . See figure.

Figure — Forward propagation computation

L5.3 — Why forward prop is the front half of learning

In one paragraph, explain how the forward pass you have been computing connects to Backpropagation, and why you must run forward before you can run backward.

Recall Solution

The forward pass computes every and and finally the prediction , from which a loss is measured. Backpropagation then computes how the loss changes with respect to each weight by applying the chain rule backwards through the very same layers. But the chain rule's local derivatives (e.g. ReLU's slope , or the softmax Jacobian) are evaluated at the values produced during the forward pass. So those cached values are the raw material backprop consumes — you cannot differentiate at a point you never computed. Forward first, backward second: the same pipeline, run in two directions.


Recall One-line recap of the whole page

Every exercise was the same three moves — Weigh, Bias, Bend — done carefully: get the shapes right, exponentiate before you normalise, keep on the left, and remember ReLU turns the network into linear pieces glued at kinks the weights and biases choose.

Flashcards

For a layer with inputs and units, what shape must be and why?
— output rows, input columns — so produces an -vector.
Why exponentiate before normalising in softmax?
To make every score positive and monotonic; dividing raw scores could give negative "probabilities" and won't handle negative logits.
Where in input space does a ReLU unit bend?
At , not at — the weight and bias relocate the kink.
How many linear pieces can a hidden layer of ReLU units produce at most?
, one per on/off pattern of the units.
Why must forward propagation run before backpropagation?
Backprop's local derivatives are evaluated at the cached values that only the forward pass produces.