ExponentialReg#

class brainstate.nn.ExponentialReg(weight=1.0, rate=1.0, fit_hyper=False)#

Exponential prior regularization (for positive parameters).

Implements regularization based on the negative log-likelihood of an exponential distribution:

\[L = \lambda \cdot \text{rate} \sum_i x_i\]
Parameters:
  • weight (float) – Regularization weight (lambda). Default is 1.0.

  • rate (float) – Rate parameter (1/mean). Default is 1.0.

  • fit_hyper (bool) – Whether to optimize hyperparameters. Default is False.

Examples

>>> import jax.numpy as jnp
>>> from brainstate.nn import ExponentialReg
>>> reg = ExponentialReg(weight=1.0, rate=1.0)
>>> value = jnp.array([0.5, 1.0, 2.0])  # positive values
>>> loss = reg.loss(value)

Notes

Exponential prior encourages small positive values and promotes sparsity. It’s the continuous analog of L1 regularization for positive parameters.

loss(value)[source]#

Calculate Exponential regularization loss.

Parameters:

value (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Parameter values (should be positive).

Returns:

Exponential negative log-likelihood loss.

Return type:

Array | ndarray | bool | number | bool | int | float | complex | Quantity

reset_value()[source]#

Return the mode of exponential (0).

Returns:

Zero.

Return type:

Array | ndarray | bool | number | bool | int | float | complex | Quantity

sample_init(shape)[source]#

Sample from Exponential distribution.

Parameters:

shape (int | Sequence[int] | integer | Sequence[integer]) – Shape of the sample.

Returns:

Sample from Exponential(rate).

Return type:

Array | ndarray | bool | number | bool | int | float | complex | Quantity