Custom models#
Use the provided template to register a custom forward model alongside the built-in library:
Copy
docs/model_template.pynext to your code (e.g.,my_models.py).Edit
model_apply(fields, offsets, observables=None)to return a predicted data cube shaped like(frames, *spatial).Edit
parametrization_factory(spatial_shape)to return(params, unpack_fn)so the optimizer can map raw parameters to physical fields.Fill in
parameter_unitsfor every field returned byunpack_fn.
Optional helpers:
required_observables: declare extra maps that must be provided viaexperiment.insert_observables(...)(e.g.,("t1_map",)).regularizer_configs/reg_weights/regularizer_type: define default regularizers (override inrun_fitor study plans).Use
estimate_param_scales+autoscale_regularizer_configs(inmrax.opt.regularizers) to normalize per-parameter regularizer weights by parameter magnitude when scales differ widely.parameter_constant_dims: collapse parameters along spatial axes when you know they are constant.
Once defined, construct the model from your module and pass it to run_fit or attach
it to an experiment/study.