AI Wiki中文/EN

He initialization: preserve the right moment

He 初始化

Derive rectifier second-moment scaling and use exact sign enumeration to distinguish variance and a backward zero-atom caveat.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

ReLU removes half the squared signal, not half its variance

A symmetric preactivation takes positive and negative values equally in distribution. ReLU discards the negative side. The squared response therefore retains half the preactivation’s second moment. But the response now has positive mean, so its variance is smaller than its second moment. Confusing those two quantities loses the reason for He initialization’s factor of two.

He and colleagues, ICCV 2015, Section 2.2 explicitly separates the squared expectation from variance. Glorot and Bengio,2010, Section 4.2.1 supplies the linearized comparison. Read ReLU, expectation and variance and Xavier initialization first.

Follow second moments across the activation

Let Z have a distribution symmetric about zero and a finite second moment. For H=ReLU(Z):

E[H2]=12E[Z2],E[H]=12E[∣Z∣],Var⁡(H)=12E[Z2]−14(E[∣Z∣])2.\mathbb E[H^2]=\frac12\mathbb E[Z^2],\qquad \mathbb E[H]=\frac12\mathbb E[|Z|],\qquad \operatorname{Var}(H)=\frac12\mathbb E[Z^2]-\frac14\bigl(\mathbb E[|Z|]\bigr)^2.

Positive and negative values contribute equal squared mass; zero contributes nothing. Thus the first identity holds even if there is a probability mass at zero. For a standard normal Z, the second moment of H is 1/2, its mean is 1/√(2π), and its variance is 1/2−1/(2π). These are distinct numbers.

Now form a preactivation Z=ΣWᵢXᵢ with zero bias and fan n. Assume independent zero-mean weights of variance v, independent of inputs, with cross terms vanishing and common input second moment q. Then E[Z²]=nvq. Symmetric weights give the needed symmetry of Z under this setup. After ReLU:

qout=nv2 qin,vHe=2n,std⁡(W)=2n.q_{\mathrm{out}}=\frac{nv}{2}\,q_{\mathrm{in}},\qquad v_{\mathrm{He}}=\frac2n,\qquad \operatorname{std}(W)=\sqrt{\frac2n}.

The factor 2/n is a variance, while √(2/n) is a standard deviation. A zero-mean Gaussian with that variance is the original paper’s forward initialization choice. This equation targets the activation second moment in an initialization model; it does not make the ReLU activation zero mean or hold automatically after training creates correlations.

A fixed negative slope changes the multiplier

For rₐ(z)=z on the positive side and az on the negative side, symmetry gives:

E[ra(Z)2]=1+a22E[Z2],v=2n(1+a2).\mathbb E[r_a(Z)^2]=\frac{1+a^2}{2}\mathbb E[Z^2],\qquad v=\frac2{n(1+a^2)}.

ReLU is a=0; a=1 is the identity function. At fan 2 and a=1/4, the appropriate variance from this rule is 16/17, rather than 1. This uses the slope at initialization. If PReLU learns a different slope later, the starting rule does not automatically rescale the weights again.

Enumerate a distribution that exposes the difference

The complete Python 3.12 program implements a local-seeded Gaussian weight initializer and separately enumerates independent input signs and weight signs. Each input is±1; each weight is±s. For fan 2 and s=1, weight variance is 1=2/fan, so the ReLU forward second-moment rule is met exactly.

from fractions import Fraction as F
from itertools import product
from math import sqrt
from random import Random


def moment_audit(fan_in=2, weight_scale=1, alpha=0):
    if type(fan_in) is not int or not 1<=fan_in<=4:raise ValueError('fan from 1 to 4 required')
    if any(type(v) not in (int,F) or not 0<=v<=4 for v in (weight_scale,alpha)):
        raise ValueError('nonnegative bounded rational scale and slope required')
    scale=F(weight_scale);alpha=F(alpha);count=0
    sz=sz2=sh=sh2=active=F(0)
    for x in product((-1,1),repeat=fan_in):
        for signs in product((-1,1),repeat=fan_in):
            z=scale*sum(a*b for a,b in zip(x,signs))
            h=z if z>0 else alpha*z
            sz+=z;sz2+=z*z;sh+=h;sh2+=h*h;active+=int(z>0);count+=1
    mean=sh/count
    return dict(z_mean=sz/count,z_second=sz2/count,h_mean=mean,
                h_second=sh2/count,h_variance=sh2/count-mean*mean,active_probability=active/count)


def weight_variance(fan_in, alpha=0):
    if type(fan_in) is not int or not 1<=fan_in<=1024:raise ValueError('positive bounded fan required')
    if type(alpha) not in (int,F) or not 0<=alpha<=4:raise ValueError('bounded rational slope required')
    return F(2,fan_in)/(1+F(alpha)**2)


def gaussian_weights(fan_in, fan_out, seed, alpha=0):
    variance=weight_variance(fan_in,alpha)
    if type(fan_out) is not int or not 1<=fan_out<=64 or type(seed) is not int or not 0<=seed<=1000000:
        raise ValueError('bounded integer output fan and seed required')
    rng=Random(seed);std=sqrt(float(variance))
    return [[rng.gauss(0,std) for _ in range(fan_in)] for _ in range(fan_out)]


if __name__=='__main__':
    for scale,alpha in [(F(1),F(0)),(F(1,2),F(0)),(F(1),F(1,4))]:
        print('weight scale:',scale,'negative slope:',alpha)
        print('moments:',{key:str(value) for key,value in moment_audit(2,scale,alpha).items()})
    print('fan2 desired variance: ReLU',weight_variance(2),'slope1/4',weight_variance(2,F(1,4)))
    weights=gaussian_weights(2,3,7)
    print('Gaussian matrix shape:',len(weights),len(weights[0]),'first row:',*[f'{v:.9f}' for v in weights[0]])

Actual output:

weight scale: 1 negative slope: 0
moments: {'z_mean': '0', 'z_second': '2', 'h_mean': '1/2', 'h_second': '1', 'h_variance': '3/4', 'active_probability': '1/4'}
weight scale: 1/2 negative slope: 0
moments: {'z_mean': '0', 'z_second': '1/2', 'h_mean': '1/4', 'h_second': '1/4', 'h_variance': '3/16', 'active_probability': '1/4'}
weight scale: 1 negative slope: 1/4
moments: {'z_mean': '0', 'z_second': '2', 'h_mean': '3/8', 'h_second': '17/16', 'h_variance': '59/64', 'active_probability': '1/4'}
fan2 desired variance: ReLU 1 slope1/4 16/17
Gaussian matrix shape: 3 2 first row: -0.255880288 0.511431513

At fan 2 and unit weight scale, Z is−2,0 or 2 with probabilities 1/4,1/2 and 1/4. H therefore has mean 1/2, second moment 1 and variance 3/4. The input second moment 1 is preserved, while the output variance is not 1. The sixteen joint input/weight configurations are all evaluated, so no sampling error explains this difference.

Reducing the weight scale to 1/2 changes its variance to 1/4, and the output second moment becomes 1/4. Keeping unit scale but adding negative slope 1/4 instead gives output second moment 17/16. The example exposes why the slope correction matters. The sign audit is separate from the Gaussian sampler, whose finite sample is not required to have exact population moments. Neither check establishes identical training behavior for all moment-matched distributions.

A zero atom changes a backward shortcut

In this discrete example P(Z>0)=1/4, not 1/2, because half the mass is exactly at zero. With the backward convention ReLU′(0)=0, the expected squared activation derivative is 1/4. The forward half-second-moment identity remains exact, but a backward calculation that blindly replaces the gate by a half-probability variable would be wrong here.

The original paper’s backward argument uses equally likely zero/one derivatives and independence approximations involving the upstream gradient and weights. These conditions must be checked separately from forward symmetry. A continuous symmetric nondegenerate preactivation has no zero atom, but the needed gradient independence is still an additional assumption.

Each audit costs O(n 4ⁿ) arithmetic, capped at fan 4, with constant accumulated state apart from the sign tuples. The tests check all literal moments, symmetry identities for several fans and slopes, and invalid parameter values. The Gaussian sampler costs O(fan_in·fan_out) time and storage and draws each weight separately. This is a small implementation and exact moment reference, not a trained network.

Fan-in and fan-out describe different objectives

The forward rule uses the number of inputs to one unit. Under the corresponding backward approximations, preserving gradient variance instead uses fan-out. For an ungrouped k×k convolution, these counts are k² times the input and output channel counts, respectively. Grouping and transposed operations need actual connection accounting.

Preserving each coordinate’s second moment on average does not preserve every direction, singular value or sample. Some finite realizations can still have poor conditioning, dead units or large responses. Input normalization, biases, activation choice and architectural structure remain relevant.

The paper notes a first-layer convention: raw inputs have not passed through an earlier ReLU, so indexing a preactivation-to-preactivation recurrence needs care. Our derivation explicitly considers an affine map followed by ReLU and preserves its input-to-output second moment. These descriptions use different layer boundaries; they should not be mixed without identifying the quantity being preserved.

Which half-factor is justified?

  1. In the fan 2 sign example, what are the ReLU output mean, second moment and variance?

Answer 1: Mean 1/2, second moment 1 and variance 3/4.

  1. Why is E[ReLU′(Z)²] equal to 1/4 under the chosen zero derivative?

Answer 2: Only the Z=2 outcomes are active; their probability is 1/4. The zero atom is inactive by convention.

  1. What variance does the rule prescribe at fan 2 and negative slope 1/4?

Answer 3: 16/17, using 2/[2(1+1/16)].

  1. Does the forward symmetry identity alone justify all backward independence assumptions?

Answer 4: No. Gate probabilities and their dependence on gradients and weights require separate analysis.

Read which moment the paper preserves

The original ICCV 2015 paper’s equations 8–12 distinguish E[X²] from Var(X), then derive the forward scale. Equations 13–16 state separate backward assumptions; the PReLU extension appears on the following page. The method is often called Kaiming initialization. The source’s ImageNet experiments are not reproduced here.

Our sign enumeration and zero-atom counterexample are original. They add a concrete check to the paper’s moment analysis and avoid replacing assumptions with a slogan about keeping variance constant. Continue to vanishing gradients for what happens along particular derivative paths.

Make a prediction, then check

In the exact sign example, which output quantity remains1?

Choose one answer

Learning objectives

  • Distinguish post-ReLU second moment from variance.
  • Check separate forward and backward assumptions.

Prerequisites & connections

Explore related knowledge →

References

  1. Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification
    Kaiming He; Xiangyu Zhang; Shaoqing Ren; Jian Sun · 2015
  2. Understanding the difficulty of training deep feedforward neural networks
    Xavier Glorot; Yoshua Bengio · 2010

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.

  • Single-agent authored technical review: bounded primary-source locations, assumptions, original derivations, exact/literal references and matching bilingual equations/examples/exercises. Not independent human or second-agent review.
  • Four focused CPython3.12.4 tests passed per chapter. Symmetry trajectories, exact sign-law moments, initializer sampling and directional Jacobian products are checked against literal references, analytic identities and finite differences. All four examples use the standard library.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.