Exercises — Weight initialization (Xavier, He)
This page is a self-test ladder. Each problem is followed by a collapsible solution — try it first, then reveal. We climb from recognising the two rules, to applying them, analysing failure, synthesising whole-network reasoning, and finally mastery (multi-step, edge cases).
Prerequisites you should have from the parent parent note: the two variance rules, the fan-in/fan-out idea, and the variance algebra from Variance and Expectation. Everything else is rebuilt below as needed.
The two rules we test against:

The figure above shows the whole logic as a decision tree — glance back at it while solving.
Level 1 — Recognition
Exercise 1.1
A layer uses the ReLU activation. Which initialization rule should you pick, and what is its variance formula?
Recall Solution 1.1
WHAT: ReLU zeroes negative inputs. WHY it matters: killing half the signal halves the variance, so we need the rule that pre-compensates with an extra factor of . Answer: He / Kaiming initialization, .
Exercise 1.2
A weight matrix has shape (rows columns), following the convention . What are and ?
Recall Solution 1.2
With , each row of dots into the input vector , so columns = inputs, rows = outputs.
- (columns, matches the input dimension).
- (rows, matches how many neurons produce outputs).
Exercise 1.3
True or false: "Initializing all weights to zero is safe because zero can neither explode nor vanish."
Recall Solution 1.3
False. Zero avoids explosion but destroys symmetry breaking: every neuron computes the same output and receives the same gradient, so they update identically forever and stay clones. You need random weights with controlled variance.
Level 2 — Application
Exercise 2.1
A dense layer maps with ReLU. Compute and for He initialization.
Recall Solution 2.1
WHY He: ReLU activation. Fan-in is the input dimension . Sample each weight from .
Exercise 2.2
A tanh layer maps . Give the Xavier normal variance and the Xavier uniform bound .
Recall Solution 2.2
WHY Xavier: tanh → sum both fans. Here . Normal variance: Uniform bound: a flat has variance . Set : Sample from .
Exercise 2.3
A layer maps with sigmoid. Give the Xavier normal .
Recall Solution 2.3
Sigmoid → Xavier. .
Level 3 — Analysis
Exercise 3.1
A ReLU net has 8 layers, each with , but the engineer used standard normal weights (). Compute the per-layer variance gain and the total scaling after 8 layers.
Recall Solution 3.1
WHAT is the gain? One ReLU layer multiplies activation variance by (the is ReLU halving). Plug in: WHY the power: each layer multiplies by , so 8 stacked layers give : The activation variance blows up by ten-quadrillion → exploding. This is the depth-power effect from the parent note.
Exercise 3.2
Same 8-layer, ReLU net, but now with He init. Show the total scaling is .
Recall Solution 3.2
He gives . Variance is preserved through every layer → stable. That's exactly the design purpose of the factor .
Exercise 3.3
Suppose an engineer used Xavier ( with , so ) on a ReLU net. Compute the per-layer gain and the total after 20 layers. Does it explode or vanish?
Recall Solution 3.3
Gain , so signal shrinks each layer. The activations vanish by a factor of about a million → vanishing (Vanishing and Exploding Gradients). Using Xavier on ReLU under-scales by exactly the missing factor of .

The figure shows how gain raised to depth diverges (amber) or decays (cyan) away from the stable line .
Level 4 — Synthesis
Exercise 4.1
Derive the He constant from scratch. Starting from and the ReLU fact , find the that keeps .
Recall Solution 4.1
WHAT we track: the input to layer is with variance . After the linear step: After ReLU: WHY set them equal: to keep the layer output the same size as its input we require . Cancel : The is exactly the reciprocal of ReLU's .
Exercise 4.2
An autoencoder has an encoder layer (ReLU) and a decoder layer (tanh output). Choose the initialization variance for each layer.
Recall Solution 4.2
Each layer is decided independently by its own activation and its own fans.
- Encoder , ReLU → He, :
- Decoder , tanh → Xavier, : Notice they came out numerically close by coincidence — but the reasons differ (ReLU-halving vs symmetric-sum).
Exercise 4.3
For the forward goal we found ; for the backward goal . Show that Xavier's is the harmonic-style compromise, and check it reduces to both when .
Recall Solution 4.3
WHAT Xavier does: instead of choosing forward OR backward, it averages the two requirements. Writing as the "constraint number":
- forward demands
- backward demands
Average the two demands: , hence Edge check : , which matches both the forward and backward exactly. So when fans are equal there is no compromise at all — Xavier is optimal for both directions.
Level 5 — Mastery
Exercise 5.1
A network has three ReLU layers with fan-ins . He init is used everywhere. Compute each layer's , and confirm the total activation-variance gain across all three layers is .
Recall Solution 5.1
He variance per layer :
- Layer 1: ,
- Layer 2: ,
- Layer 3: ,
Per-layer gain for every layer regardless of . Total gain → perfectly stable. He self-corrects at each layer independently.
Exercise 5.2
Degenerate/edge case. A "layer" has (a single input feature) and uses ReLU. What is the He ? Then explain what happens to variance preservation, given that a single input has no averaging.
Recall Solution 5.2
He: , so . The formula still targets in expectation: . ✔ BUT the variance-preservation argument relied on summing many independent terms so the law-of-large-numbers smooths fluctuations. With there is a single term — no averaging — so the actual has huge relative fluctuation even though its variance equals on average. Lesson: the theory is asymptotic in fan-in; tiny fans are noisy but the mean scaling is still correct.
Exercise 5.3
Mixed net + backward stability. A layer maps with tanh. Using Xavier, compute the forward gain and the backward gain . Interpret why neither is exactly .
Recall Solution 5.3
Xavier: .
- Forward gain:
- Backward gain:
Interpretation: because , the single variance cannot satisfy both directions. Xavier lands between them — signal shrinks slightly forward () and grows slightly backward (), and their geometric mean is close to . That controlled split is the whole point of the "average the two demands" compromise, connecting to Backpropagation gradient flow.
Exercise 5.4
Synthesis with normalization. A colleague says "we use Batch Normalization after every layer, so weight init doesn't matter." Give a one-line quantitative reason init still helps at the very start of training.
Recall Solution 5.4
Batch norm re-centres/re-scales activations after the linear step, but at step 0 the pre-norm activations still pass through the nonlinearity; a wildly scaled init (e.g. gain per layer, as in Exercise 3.1) can push ReLU/tanh into saturated or dead regions before BN's running statistics settle, producing dead units and unstable first gradients. Good init keeps the initial forward pass in a sane range so BN starts from healthy statistics — the two are complementary, not redundant. See Deep Network Training Stability.
Connections
- Vanishing and Exploding Gradients — the exact failure computed in L3.
- Activation Functions (ReLU, tanh, sigmoid) — decides He vs Xavier every time.
- Batch Normalization — the complement discussed in Exercise 5.4.
- Backpropagation — source of the backward gain in Exercise 5.3.
- Variance and Expectation — the algebra behind every derivation.
- Deep Network Training Stability — the umbrella goal.
- ← Back to the parent topic