5.6.7 · D4Machine Learning (Aerospace Applications)

Exercises — Feedforward network — forward pass

2,730 words12 min readBack to topic

This page is a self-test ladder for the forward pass. Work each problem on paper first, then open the collapsible solution. Every symbol used here was built in the parent note — but we re-anchor the essentials so you never get stuck on notation.

Recall The 3 objects you need before starting (definitions to memorise)

Every problem below uses the same three things. Picture a stack of layers, information flowing bottom-to-top.

  • ::: the activations (outputs) of the layer below — a column of numbers, one per neuron.
  • ::: the pre-activation: a weighted sum plus a bias. One number per neuron in layer .
  • ::: the activation: run each through the nonlinearity element-by-element.

Figure 1 — the four scalar activation shapes. Below, the orange ReLU is flat-then-rising with a sharp corner (the "kink") at ; the blue sigmoid and green tanh are smooth S-curves pinned between horizontal ceilings/floors (the dotted lines at ); the gray dashed line is the do-nothing identity. Keep this picture in mind: "squashing" literally means a curve that flattens toward those dotted rails as runs off to .

Figure — Feedforward network — forward pass

Level 1 — Recognition

Worked example Solution 1.1

maps the previous layer's activation (length ) into this layer (length ). So it has rows and columns.

  • : layer 1 has neurons, layer 0 has inputs shape .
  • : one bias per neuron in layer 1 length .

Check the multiplication: , and adding of length works. ✓

Worked example Solution 1.2

ReLU passes positives unchanged and clamps everything to — trace the orange curve in Figure 1: flat left of the kink, a straight ramp to its right.


Level 2 — Application

Worked example Solution 2.1

Step (a) pre-activation — a single dot product (row · column) plus bias: Step (b) activation: Why ? The weighted evidence came out net negative, and to the left of the kink (Figure 1) ReLU's output is flat at zero. The neuron "did not fire" — it detected a pattern that is absent for this input.

Worked example Solution 2.2

Sigmoid is applied element-by-element: .

Why these values? At the term , so top and bottom balance and we sit exactly on the S-curve's midpoint, — this is why sigmoid is centred at . As grows, shrinks toward , so the fraction climbs toward (but never reaches) ; that is why is high yet still under the ceiling. Both outputs land inside — the "squashing" you see the blue curve doing in Figure 1.

Worked example Solution 2.3

Layer 1 pre-activation (each row of dotted with ): Layer 1 activation (ReLU): both entries are positive, so we are on the ramp side of the kink and ReLU leaves them unchanged: . Layer 2 pre-activation: Layer 2 activation (linear): . Why linear at the end? A regression output must be free to take any real value; the identity (gray dashed line in Figure 1) applies no squashing, so the raw score passes straight through as the prediction.


Level 3 — Analysis

Worked example Solution 3.1

Substitute into : So and . Meaning: stacking linear maps gives one linear map — the extra layer bought us nothing. This is exactly why nonlinearity is essential.

Worked example Solution 3.2

Layer by layer: , then . Collapsed: ; . Then . ✓ Same answer.

Worked example Solution 3.3

The neuron outputs . It is dead whenever , i.e. .

  • Dead region: (output exactly ).
  • Active region: , where output rises with slope .
  • Kink (the corner) sits at , where .

This is the same corner you see on the orange curve in Figure 1, just shifted: the linear part inside ReLU moves the kink from to . That hinge is how networks build piecewise-linear approximations of curved aerospace dynamics.


Level 4 — Synthesis

Worked example Solution 4.1

Step 1 — exponentiate each logit: Step 2 — sum: . Step 3 — divide: Why exponentiate first? Raw logits can be negative, but probabilities cannot — maps every score to a positive number while preserving order (bigger logit → bigger ). Dividing by the sum then forces the total to ✓. The largest is class 0, which the index→name table reads as Nominal (probability ).

Worked example Solution 4.2

Layer 1 pre-activation (three dot products): Layer 1 activation (tanh, element-wise): Why is almost ? tanh saturates: once is a few units from zero the green curve in Figure 1 has already flattened against its ceiling, so is nearly maxed out, while and are still on the sloped middle and stay symmetric (). Layer 2 pre-activation: Softmax: ; sum . Why so close to a coin-flip? The two logits differ by only ; since is a gentle multiplier for small gaps, a tiny logit lead becomes just a modest probability lead. Predicted class: 1 = Degraded (probability ).


Level 5 — Mastery

Worked example Solution 5.1

The whole point: one matrix multiply handles the whole batch. Compute (bias broadcast to each column). Add to each column: Apply ReLU element-wise: Why one multiply for both samples? Each column is processed independently by the same , so stacking inputs side-by-side lets the hardware compute both passes in a single matrix product — this is exactly how real inference runs a whole batch of sensor frames at once. Column 1 is sample 1's activation ; column 2 is sample 2's .

Worked example Solution 5.2

Claim: softmax is invariant to adding a constant to every logit, because The cancels top and bottom. So we may pick to keep exponents (no overflow). Shifted logits: . Then ; sum . Why this is safe and exact: the cancellation above is algebraic, not an approximation — the probabilities are literally unchanged, but every exponent is now so and can never overflow.

Worked example Solution 5.3

Step 1 — hidden pre-activations (each row of dotted with , plus bias): Step 2 — activation (ReLU): both are , so we sit on the flat left side of the orange curve (Figure 1) and each clamps to zero: Step 3 — output. With every hidden activation zero, the output pre-activation is The weighted-sum term is the zero vector no matter what numbers sit in , so the prediction equals the output bias alone. Why this matters (the "dying ReLU" failure): overly negative biases push every neuron below its kink; once a neuron outputs for all realistic inputs it is stuck (its weights stop influencing the output), and if a whole layer dies the network freezes at a constant and ignores its sensors entirely. Fix in practice: careful bias initialisation, input normalisation, or leaky-ReLU which keeps a small slope on the negative side.