fn
sparse_
→Tensorsparse_(tensor: Tensor, sparsity: float, std: float = 0.01)Initialise a 2-D tensor in-place with a sparse random matrix.
For each column, a random subset of floor(sparsity * rows) rows
is set to zero; the remaining entries are drawn from
. Sparse initialisation, due to
Martens (2010), encourages each output unit to depend on only a
small number of inputs at the start of training and helps in
ill-conditioned regimes — particularly for very wide layers where a
dense Gaussian would have an unfavourable condition number.
Parameters
tensorTensorTwo-dimensional tensor to fill in place.
sparsityfloatFraction of entries in each column that are zeroed. Must lie in
[0, 1].stdfloat= 0.01Standard deviation of the Gaussian used for the non-zero
entries. Default
0.01.Returns
Tensortensor (mutated) for chaining.
Raises
ValueErrorIf
tensor.ndim != 2 or sparsity is outside [0, 1].Notes
The expected per-entry variance is
Examples
>>> import lucid
>>> from lucid.nn.init import sparse_
>>> w = lucid.empty(256, 256)
>>> sparse_(w, sparsity=0.9, std=0.01)