How do you derive the Xavier (Glorot) and He initialisation variances from the requirement that activation variance stays constant from layer to layer?

Deep learning, Optimisation of deep networks
Level L3 Intermediate. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can do the variance calculation for a linear layer and adapt it to the activation function.

Key idea

Take zi=∑j=1ninWijxj, where nin is the fan-in (number of inputs) and the weights are independent and zero-mean, with variance σW2. Then Var⁡(zi)=nin σW2 E[xj2]. Keeping this equal to the previous layer's variance gives σW2=1/nin for a zero-mean (tanh-like) activation, and σW2=2/nin for ReLU.

Steps

  1. Assumptions: weights i.i.d. (independent and identically distributed) with mean 0 and variance σW2, independent of the inputs; biases 0.
  2. Variance of one term: Var⁡(Wijxj)=E[Wij2] E[xj2]−(E[Wij] E[xj])2=σW2 E[xj2]. Summing nin independent terms: Var⁡(zi)=ninσW2 E[xj2].
  3. Xavier: near 0, tanh is roughly linear and zero-mean, so E[x2]=Var⁡(x)≈Var⁡(zprev). Keeping the forward variance needs σW2=1/nin. The same argument on the backward pass needs σW2=1/nout, where nout is the fan-out. Glorot's compromise is σW2=2nin+nout.
  4. Uniform version: U[−a,a] has variance a2/3, so a=6nin+nout.
  5. He: with x=ReLU⁡(zprev) and zprev symmetric about 0, ReLU zeroes half the mass, so E[x2]=12Var⁡(zprev). Then Var⁡(z)=12ninσW2Var⁡(zprev), and keeping it constant needs σW2=2nin.
  6. Close with why it matters. After L layers the variance is multiplied by (ninσW2⋅c)L, with c=1 (tanh) or 12 (ReLU). This vanishes or explodes geometrically unless the factor is 1.

Common mistakes

How long your answer should be

About a page; 6–8 minutes.

Last checked on 4 December 2026.

Read this

Previous in Deep learning: With label smoothing ϵ on K classes, what is the target distribution, and what is the gradient of the cross-entropy loss with respect to the logits? For K=3, ϵ=0.1 and true class 2, what are the target vector and the logit gap the model is pushed towards?
Next in Deep learning: In a variational autoencoder (VAE), the encoder outputs mean μ=1.5 and log-variance log⁡σ2=ln⁡4 for a scalar latent variable z∼N(μ,σ2). How does the reparameterisation trick produce z for auxiliary noise ε=−0.5, why is it needed for backpropagation, and what are ∂z/∂μ and ∂z/∂(log⁡σ2)?