Initialise tensor in-place with Xavier (Glorot) normal initialisation.
Gaussian counterpart of xavier_uniform_. Draws each entry
from with a standard deviation
chosen to preserve activation variance through a stack of linear /
mildly-nonlinear layers, as proposed in Glorot & Bengio (2010).
Prefer this for tanh / sigmoid networks; use
kaiming_normal_ for ReLU networks.
Parameters
tensorTensorTensor to initialise in place; must have at least 2 dimensions.
gainfloat= 1.0Multiplicative gain factor — see
calculate_gain.
Default 1.0.Returns
Tensortensor (mutated) for chaining.
Notes
The standard deviation is
which yields variance
Examples
>>> import lucid
>>> from lucid.nn.init import xavier_normal_, calculate_gain
>>> w = lucid.empty(64, 32)
>>> lucid.manual_seed(0)
>>> _ = xavier_normal_(w, gain=calculate_gain('tanh'))
>>> std = calculate_gain('tanh') * (2 / (32 + 64)) ** 0.5
>>> abs(w.std().item() - std) < 0.1 * std
True