L1Reg#
- class brainstate.nn.L1Reg(weight=1.0, fit_hyper=False)#
L1 (Lasso) regularization.
Implements L1 regularization:
\[L = \lambda \sum_i |x_i|\]The corresponding prior is the Laplace distribution.
- Parameters:
- weight#
Regularization weight (trainable if
fit_hyper=True).- Type:
array_like or ParamState
Examples
>>> import jax.numpy as jnp >>> from brainstate.nn import L1Reg >>> reg = L1Reg(weight=0.01) >>> value = jnp.array([1.0, -2.0, 0.5]) >>> loss = reg.loss(value) # Returns 0.01 * (1.0 + 2.0 + 0.5)
Notes
L1 regularization encourages sparsity in the parameter values.