Decorators#
Model decorators for blayers.
autoreshape: Auto-reshape 1D arrays to (n, 1)autoreparam: Auto-reparameterize LocScale distributions for VI and MCMC
Usage:
@autoreshape
@autoreparam
def my_model(x, y=None):
...
- blayers.decorators.autoreshape(fn)[source]#
Decorator that ensures all array inputs have shape (n, d), not (n,).
blayers expects arrays with explicit trailing dimensions. This decorator auto-reshapes 1D arrays to (n, 1) so you don’t have to do it manually.
- Usage:
@autoreshape def model(x, y=None):
mu = AdaptiveLayer()(‘mu’, x) return gaussian_link(mu, y)
- Parameters:
fn (Callable[[...], Any])
- Return type:
Callable[[…], Any]
- blayers.decorators.autoreparam(model_fn=None, *, centered=0.0)[source]#
Auto-reparameterize LocScale distributions in a model for VI and MCMC.
Automatically applies
LocScaleReparamto all LocScale distributions (Normal, LogNormal, StudentT, Cauchy, Laplace, Gumbel) found in the model, which can improve NUTS mixing and diagonal-guide VI by removing prior funnel geometries. Strongly informed coefficients may favor centering.Works with or without parentheses:
@autoreparam def model(x, y): ... @autoreparam() def model(x, y): ... @autoreparam(centered=0.5) def model(x, y): ...
- Parameters:
model_fn (Callable[[...], Any] | None) – The model function (when used without parentheses).
centered (float) – Degree of centering for
LocScaleReparam. 0.0 = fully non-centered (default, best for weak data); 1.0 = fully centered (better when data is informative).
- Return type:
Any