GammaReg#
- class brainstate.nn.GammaReg(weight=1.0, alpha=2.0, beta=1.0, fit_hyper=False)#
Gamma prior regularization (for positive parameters).
Implements regularization based on the negative log-likelihood of a Gamma distribution:
\[L = \lambda \left[ \sum_i \left(-(\alpha - 1) \log x_i + \beta x_i\right) + N \left( -\alpha \log\beta + \log\Gamma(\alpha) \right) \right]\]where \(N\) is the number of elements. The \(-\alpha \log\beta + \log\Gamma(\alpha)\) term is the log-normalizer that keeps the loss bounded below when
alpha/betaare trained.- Parameters:
Examples
>>> import jax.numpy as jnp >>> from brainstate.nn import GammaReg >>> reg = GammaReg(weight=1.0, alpha=2.0, beta=1.0) >>> value = jnp.array([0.5, 1.0, 2.0]) # positive values >>> loss = reg.loss(value)
Notes
Gamma prior is flexible for positive parameters. alpha=1 gives exponential distribution. The mode is (alpha-1)/beta for alpha >= 1.