Exercises — Neural network fundamentals — neuron, activation functions (ReLU, sigmoid, tanh)
Before we start, one reminder of the four objects we will reuse constantly — read this even if you think you know it, because every solution leans on it.

Look at the blueprint above (each curve is named in the legend, not just coloured): ReLU is a flat floor then a ramp. Sigmoid is a gentle S trapped between and . Tanh is a steeper S trapped between and . The arrows on the figure point out each curve by name. Keep this picture in your head — most L1/L2 answers are just "which curve am I standing on, and where?"
Level 1 — Recognition
Problem 1.1
Which activation function can output the value ? (Choose from ReLU, sigmoid, tanh.)
Recall Solution 1.1
WHAT we look at: the range (the set of possible outputs) of each function.
- ReLU output range is — it can never be negative (its floor is ).
- Sigmoid range is — strictly positive, never reaches or .
- Tanh range is — the only one that dips below zero.
lies between and , so it is only reachable by tanh.
WHAT IT LOOKS LIKE: on the figure, only the tanh curve (labelled in the legend) ever goes below the horizontal axis.
Problem 1.2
A neuron in a hidden layer of a 12-layer network needs an activation whose derivative does not shrink signals for positive inputs. Name it and give its full derivative (including the negative branch and the convention at ).
Recall Solution 1.2
ReLU. For , , so its slope is exactly . For , , a flat line with slope . At exactly the two branches meet at a corner where the derivative is not truly defined; by convention we simply assign it (grouping it with the side). Writing the whole thing: A slope of on the active branch means backpropagation multiplies by — the signal passes through undimmed, which is why ReLU is the default for deep hidden layers. Contrast: Vanishing and Exploding Gradients happens when slopes below multiply together across many layers.
Level 2 — Application
Problem 2.1
A neuron has weights , bias , inputs . Compute , then apply ReLU.
Recall Solution 2.1
Step 1 — weighted sum (WHAT & WHY): we multiply each input by its weight to score its contribution, then add the bias nudge. Here . Step 2 — activation: ReLU at exactly : Output . Note the edge case: sits on the corner of the ReLU curve. By our definition for , so the door is just closed.
Problem 2.2
For , compute to 4 decimals, then use the identity to get the derivative there.
Recall Solution 2.2
Step 1: .
Step 2 (WHY this identity): we don't want to re-differentiate from scratch every time; the identity lets us reuse the value we just computed. Reading it: a slope of about — already well under the maximum . The sigmoid is starting to flatten (saturate) at .
Problem 2.3
For , compute and then using .
Recall Solution 2.3
Step 1: .
Step 2 (WHY reuse the value): same trick as sigmoid — square the output and subtract from . Reading it: tanh at has a healthier slope () than sigmoid did at — that is the "stronger gradient near the middle" advantage of tanh.
Level 3 — Analysis
Problem 3.1
A student proposes a "two-layer linear network" with no activation: Show algebraically that this is equivalent to a single-layer linear model, and state in one sentence why that is a problem.
Recall Solution 3.1
Substitute into : Let and . Then which is a single linear layer. The problem in one sentence: no matter how many linear layers you stack, they collapse to one straight-line map, so the network can only draw straight decision boundaries and can never learn a curved pattern like XOR. The cure is inserting a non-linear between layers.
Problem 3.2
The maximum slope of sigmoid is , occurring at . Prove this maximum value using .
Recall Solution 3.2
WHY this method: is a product of two things that add to : let , so with .
Maximize : treat it as a downward parabola in . Its derivative w.r.t. is , zero at . So the peak is at , which happens at . Consequence: every sigmoid slope is . In a 10-layer stack the product of slopes is — this is exactly the vanishing gradient problem, and why gradient descent stalls.
Problem 3.3
Verify the identity at numerically (4 decimals), confirming both forms agree.
Recall Solution 3.3
Left side: .
Right side: ; then .
Both give — the identity holds. This is why tanh is "a stretched, shifted sigmoid": scale the input by , scale the output by , and shift down by to recenter on zero.
Level 4 — Synthesis
Problem 4.1
A control-output neuron for elevator deflection has weights , bias , inputs . The output must lie in where = full down, = full up. (a) Choose the correct activation and justify. (b) Compute the deflection.
Recall Solution 4.1
(a) Choice — WHY tanh: the output must be signed and bounded to . ReLU can't go negative (so no "down"); sigmoid is stuck in (no "down" either). Only tanh covers symmetrically around zero — perfect for a control surface that moves both ways from neutral.
(b) Compute (here ): Reading it: elevator deflects about of maximum downward (negative = down). Compare to Sensor Fusion in Aerospace, where such signed outputs feed the flight controller.
Problem 4.2
An anomaly detector's output neuron gives . (a) Which activation makes the output a probability, and why? (b) Compute that probability, and (c) using Binary Cross-Entropy Loss for a truly-anomalous sample (label ), compute the loss.
Recall Solution 4.2
(a) We need output in readable as "chance of anomaly," so sigmoid. ReLU could output (not a probability); tanh could go negative (a negative "chance" is nonsense).
(b) . → about confident it is anomalous.
(c) For a true anomaly (label ), binary cross-entropy is . Reading it: the loss is tiny because the network was confident and correct — exactly what we want. If it had predicted instead, the loss would balloon to .
Level 5 — Mastery
Problem 5.1 (Dead ReLU + a fix)
A neuron uses ReLU. Over the whole dataset its pre-activation is always , so every time. (a) Explain why gradient descent can never revive it (a "dead neuron"). (b) Replace ReLU with Leaky ReLU and compute and at . (c) Explain in one sentence why this rescues the neuron.
Recall Solution 5.1
(a) ReLU's slope for is . During backprop, the weight update is proportional to that slope, so an update of means the weights never change — the neuron is frozen at "off" forever. See also Weight Initialization Strategies, since bad init is a common cause.
(b) At (negative branch, Leaky ReLU uses ): (c) Because the slope is now instead of , a small non-zero gradient flows back, so the weights can still be nudged and the neuron may recover.
Problem 5.2 (Vanishing-gradient budget)
You stack sigmoid layers, and the best-case product of derivatives is . Find the largest for which this product stays above (so learning is not yet hopeless). Solve with logarithms.
Recall Solution 5.2
WHY logs: we need to unstack an exponent, and the logarithm is the tool that turns "power of" into "multiply by." Now (negative), so dividing flips the inequality: Since must be a whole number, the largest allowed is . Reading it: even in the best case, only about four stacked sigmoids keep gradients above — hard proof that deep sigmoid stacks are doomed, and why we reach for ReLU or the techniques in Vanishing and Exploding Gradients. This same reasoning appears when designing Convolutional Neural Networks and controlling Overfitting and Regularization.
Recall Self-test checklist
Range of ReLU / sigmoid / tanh? ::: / / . Why does a stack of linear layers collapse? ::: Composing linear maps gives another linear map . Maximum sigmoid slope and where? ::: , occurring at (where ). Which activation for a signed, bounded control output? ::: tanh. Which for a probability output? ::: sigmoid. How does Leaky ReLU revive a dead neuron? ::: It gives a small non-zero slope () for so gradients still flow.