Identity#
- class braintools.init.Identity(scale=1.0, unit=Unit('1'))#
Identity matrix initialization.
Initializes weights to an identity matrix, optionally scaled by a scale factor. For non-square matrices, creates a matrix that is as close to identity as possible.
- Parameters:
scale (
float) – Multiplicative factor to apply to the identity matrix (default: 1.0).
Notes
The output depends on the rank of
size:1-D
(n,): an identity matrix is undefined, so a vector ofscale * ones(n)is returned (useful as a bias-like / pass-through init).2-D
(rows, cols):scale * eye(rows, cols)(identity, truncated or zero-padded for rectangular shapes).N-D:
scaletimes an identity placed in the trailing two dimensions, broadcast over the leading dimensions.
Examples
>>> import numpy as np >>> from braintools.init import Identity >>> >>> init = Identity(scale=1.0) >>> weights = init((100, 100)) >>> >>> # For rectangular matrices >>> weights = init((100, 50)) # Will create identity-like matrix