@pre_model
decorated functions@post_model
decorated functions@pre_model
and @post_model
decorators convert simple user functions into protocol-compliant transformations. Instead of complex return value management, these decorators provide mutable context objects that can be modified directly:
@pre_model
and @post_model
decorators handle protocol conversionctx.y0s
, ctx.theta
, ctx.states
attributesnumpyro.sample()
and numpyro.deterministic()
PreModel
and PostModel
protocols are used internally by Catalax and are not intended for direct user implementation.
@pre_model
decorator enables custom transformations applied after parameter sampling but before model simulation. Common use cases include parameter space transformations, initial condition inference, and experimental condition modeling.
PreModelContext
with mutable attributes (ctx.y0s
, ctx.theta
, ctx.constants
, etc.) that can be modified directly. The ctx.shapes
attribute provides dimension information for proper broadcasting operations.
ctx.shapes
object provides essential dimension information (y0s
, data
, constants
, times
) enabling proper array operations and broadcasting across measurements.
@post_model
decorator enables custom transformations applied after model simulation but before likelihood evaluation. This is essential for converting model states to experimentally measurable quantities when observables don’t directly correspond to individual model species.
PostModelContext
with ctx.states
containing simulation results, and can modify it to match experimental observables.
ctx.shapes
object provides essential dimension information for proper array operations:
ctx.shapes.y0s
: Initial conditions dimensions (n_measurements, n_species)
ctx.shapes.data
: Observed data dimensions (n_measurements, n_timepoints, n_observables)
ctx.shapes.constants
: Constants dimensions (n_measurements, n_constants)
ctx.shapes.times
: Time points dimensions (n_measurements, n_timepoints)
numpyro.sample()
to introduce new random variablesnumpyro.deterministic()
to track transformations for model interpretationnumpyro.plate()
for vectorized operations across measurements or speciesctx.y0s
, ctx.theta
, ctx.states
) directly rather than returning valuesctx.shapes
information to ensure proper broadcastingnumpyro.deterministic()
variables