fn
normal
→Tensornormal(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)Return a tensor of samples drawn from a parametric normal distribution.
Each element is drawn independently from :
with mean and standard deviation .
Parameters
meanfloatMean of the distribution. Default:
0.0.stdfloatStandard deviation . Default:
1.0.sizelist[int] or tuple[int, ...]Shape of the output tensor. Required (keyword-only).
dtypelucid.dtypeFloating-point data type. Defaults to the global default.
devicestr or lucid.deviceTarget device —
"cpu" or "metal".requires_gradboolEnable autograd tracking. Default:
False.generatorlucid._C.engine.GeneratorExplicit 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, ...).
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
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))