Functions 15
calculate_gain
functionFull reference ↗- tensorplay.nn.init.calculate_gain(nonlinearity, param=None)[source]
Return the recommended gain value for the given nonlinearity.
Supported names: linear/conv{1,2,3}d/conv_transpose{1,2,3}d and sigmoid map to 1, tanh to 5/3, relu to sqrt(2), selu to 3/4, and leaky_relu to sqrt(2 / (1 + negative_slope**2)) where the slope is taken from
param(default 0.01).
constant_
functionFull reference ↗- tensorplay.nn.init.constant_(tensor, val)[source]
Fill
tensorin-place with the scalarval.
dirac_
functionFull reference ↗- tensorplay.nn.init.dirac_(tensor, groups=1)[source]
Fill the {3, 4, 5}-D
tensorin-place with Dirac delta kernels.Preserves identity of inputs in convolutional layers; with
groups > 1each group of output channels preserves identity independently.
eye_
functionFull reference ↗- tensorplay.nn.init.eye_(tensor)[source]
Fill the 2-D
tensorin-place with the identity matrix.As many inputs as possible are preserved through a Linear layer.
kaiming_normal_
functionFull reference ↗- tensorplay.nn.init.kaiming_normal_(tensor, a=0, mode='fan_in', nonlinearity='leaky_relu', generator=None)[source]
Fill
tensorin-place with N(0, std^2) where std = gain / sqrt(fan).
kaiming_uniform_
functionFull reference ↗- tensorplay.nn.init.kaiming_uniform_(tensor, a=0, mode='fan_in', nonlinearity='leaky_relu', generator=None)[source]
Fill
tensorin-place with U(-bound, bound) where bound = gain * sqrt(3 / fan).
normal_
functionFull reference ↗- tensorplay.nn.init.normal_(tensor, mean=0.0, std=1.0, generator=None)[source]
Fill
tensorin-place with samples from N(mean, std^2).
ones_
functionFull reference ↗- tensorplay.nn.init.ones_(tensor)[source]
Fill
tensorin-place with the scalar value 1.
orthogonal_
functionFull reference ↗- tensorplay.nn.init.orthogonal_(tensor, gain=1, generator=None)[source]
Fill
tensorin-place with a (semi) orthogonal matrix.The tensor must have at least 2 dimensions; trailing dimensions are flattened. Rows (or columns, when narrower) are orthonormalized with a QR factorization of a standard-normal sample, and Q is rescaled by the diagonal signs of R so its distribution is uniform over the orthogonal group.
sparse_
functionFull reference ↗- tensorplay.nn.init.sparse_(tensor, sparsity, std=0.01, generator=None)[source]
Fill the 2-D
tensorin-place as a sparse matrix.Each column gets
sparsity * rowszeroed entries (a random row subset per column); the remaining entries come from N(0, std^2).
trunc_normal_
functionFull reference ↗- tensorplay.nn.init.trunc_normal_(tensor, mean=0.0, std=1.0, a=-2.0, b=2.0, generator=None)[source]
Fills the input Tensor with values drawn from a truncated normal distribution.
Method is based on the rejection-sampling scheme in https://people.sc.fsu.edu/~jburkardt/presentations/truncated_normal.pdf —
uniform_
functionFull reference ↗- tensorplay.nn.init.uniform_(tensor, a=0.0, b=1.0, generator=None)[source]
Fill
tensorin-place with samples from U(a, b).
xavier_normal_
functionFull reference ↗- tensorplay.nn.init.xavier_normal_(tensor, gain=1.0, generator=None)[source]
Fill
tensorin-place with N(0, std^2) where std = gain * sqrt(2 / (fan_in + fan_out)).
xavier_uniform_
functionFull reference ↗- tensorplay.nn.init.xavier_uniform_(tensor, gain=1.0, generator=None)[source]
Fill
tensorin-place with U(-a, a) where a = gain * sqrt(6 / (fan_in + fan_out)).
zeros_
functionFull reference ↗- tensorplay.nn.init.zeros_(tensor)[source]
Fill
tensorin-place with the scalar value 0.

