normal(mean: float = 0.0, std: float = 1.0, size: list[int] | tuple[int, ...], dtype: DTypeLike = None, device: DeviceLike = None, requires_grad: bool = False, generator: _C_engine.Generator | None = None)Implementing kernel
C++ engine symbols that back this Python API.Return a tensor of samples drawn from a parametric normal distribution.
Each element is drawn independently from :
with mean and standard deviation .
Parameters
Mean of the distribution. Default:
0.0. A tensor
selects the reference's tensor overloads (see Notes).Standard deviation . Default:
1.0.sizelist[int] or tuple[int, ...]Shape of the output tensor. Required with a float
mean and
std (keyword, or third positional); none with a tensor.dtypelucid.dtype= NoneFloating-point data type. Defaults to the global default.
devicestr or lucid.device= NoneTarget device —
"cpu" or "metal".requires_ gradbool= FalseEnable autograd tracking. Default:
False.Explicit generator. Defaults to the global default.
Returns
TensorTensor of shape size with samples.
Notes
This is a convenience wrapper around randn with an affine shift:
The output is therefore equivalent to
mean + std * lucid.randn(*size, ...).
With a tensor mean or std it draws one sample per element of
their broadcast shape, in the dtype they promote to, with no gradient to
either; only generator= is taken besides.
Weight initialisation recipes commonly parameterise the normal distribution directly:
- LeCun normal (LeCun et al., 1998):
- Glorot normal (Glorot & Bengio, 2010):
- **He normal** (He et al., 2015):
Examples
>>> import lucid
>>> _ = lucid.manual_seed(0)
>>> x = lucid.normal(mean=5.0, std=2.0, size=(1000,))
>>> abs(float(x.mean()) - 5.0) < 0.2
True
>>> abs(float(x.std()) - 2.0) < 0.2
True
>>> lucid.normal(lucid.zeros(2, 3), lucid.ones(3)).shape # per-element
(2, 3)
>>> lucid.normal(0.0, 1.0, (4,)).shape # shape by position
(4,)
He-normal initialisation for a Conv2d kernel:
>>> fan_in = 3 * 3 * 64 # kernel_h × kernel_w × C_in
>>> w = lucid.normal(0.0, (2.0 / fan_in) ** 0.5, size=(128, 64, 3, 3))