LogUniformReg#

class brainstate.nn.LogUniformReg(weight=1.0, lower=0.001, upper=1000.0, fit_hyper=False)#

Log-uniform (Jeffreys) prior regularization (scale-invariant).

Implements regularization based on the negative log-likelihood of a log-uniform distribution:

\[L = \lambda \sum_i \log x_i\]
Parameters:
  • weight (float) – Regularization weight (lambda). Default is 1.0.

  • lower (float) – Lower bound. Default is 1e-3.

  • upper (float) – Upper bound. Default is 1e3.

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

Examples

>>> import jax.numpy as jnp
>>> from brainstate.nn import LogUniformReg
>>> reg = LogUniformReg(weight=1.0, lower=1e-3, upper=1e3)
>>> value = jnp.array([0.1, 1.0, 10.0])  # positive values
>>> loss = reg.loss(value)

Notes

Log-uniform (Jeffreys) prior is scale-invariant and commonly used as a weakly informative prior for scale parameters.

loss(value)[source]#

Calculate Log-uniform regularization loss.

Parameters:

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

Returns:

Log-uniform negative log-likelihood loss.

Return type:

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

reset_value()[source]#

Return the geometric mean (sqrt(lower * upper)).

Returns:

Geometric mean.

Return type:

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

sample_init(shape)[source]#

Sample from Log-uniform distribution.

Parameters:

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

Returns:

Sample from LogUniform(lower, upper).

Return type:

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