Optimizers and regularizers#

mrax.opt.optimizers.make_optimizer() provides Optax transformations, FISTA and split Bregman through one factory. Fitting, reconstruction and diagnostics use the shared executor. See Fitting controls for a workflow overview.

Proximal solvers#

FISTA follows the accelerated proximal-gradient recurrence [BeckTeboulle2009]. Full backtracking updates the trial step, momentum and extrapolated gradient point together [Scheinberg2014]. "classic" selects the original nonincreasing-step rule. The optional gradient restart follows [ODonoghue2015]. A restart retains the last certified step scale.

The native TV/box prox uses accelerated dual projected gradients [BeckTeboulleTV2009], with masked finite differences, higher orders and warm starts. Its primal-dual gap controls accuracy. Accepted parameters satisfy the boxes, while extrapolation follows the FISTA recurrence.

Split Bregman follows the augmented-primal, split-shrinkage and multiplier recurrence [Goldstein2009]. It initializes splits from the current field differences and multipliers at zero. TV weights enter shrinkage. bregman_penalty fixes the augmented constraint penalty.

The primal solve uses projected Armijo steps: matrix-free Newton/CG for at most 32 real unknowns and an eight-pair L-BFGS inverse for larger systems. Positive-curvature secants use gradients with matching splits and multipliers. A two-level local/coarse preconditioner conditions CG. Curvature shifts damp Newton directions, with acceptance evaluated on the augmented objective. One bounded inverse/line-search restart handles a failed large-system primal step. Shrinkage and multiplier updates follow a certified primal step.

Smooth-model intermediates are recomputed during differentiation so curvature probes do not retain a full reverse-mode tape for an image series. This reduces memory use.

Convex convergence results apply under the assumptions in the cited papers. For nonlinear MRI objectives, assess the projected KKT residual, constraint residuals and sensitivity to starting values.

Controls#

Both solvers default to proximal_tolerance=1e-8 and proximal_max_steps=2048. Named, injected and factory-based fits share these defaults. Injected transformations retain their explicit constructor settings.

Option

Meaning

fista_backtracking

"full" or "classic" step/momentum rule.

fista_restart

"gradient" or "none" momentum restart.

proximal_tolerance / proximal_max_steps

Native-TV gap target and inner work limit. Newton/CG residual target and total CG work limit, respectively.

bregman_penalty

Fixed augmented penalty, separate from TV strength.

bregman_inner_steps

Primal iterations before shrinkage and multiplier updates. Default one.

proximal_max_step_size

Upper limit for the trial step.

grad_clip_norm

Trial-step cap with consistent gradient/proximal scaling.

Newton/CG uses a relative residual target based on sqrt(proximal_tolerance) and floating-point resolution. Larger subproblems use inexact forcing that tightens toward stationarity. The residual uses the positive-preconditioner energy norm. L-BFGS work follows bregman_inner_steps. Its split shrinkage is analytic.

Native field TV uses affine physical coordinates. Fixed block scales transform coordinates, bounds and TV operators together. Use parameter_space="auto" or "physical" for this fitting path. Smooth FISTA and explicit raw-coordinate proximal penalties also support raw coordinates.

Optimizer-level regularizer_weight supplies gradient decay for ordinary Optax transformations and proximal penalties for the two proximal solvers. It accepts a scalar or matching parameter tree. AdamW additionally applies its decoupled decay.

Injected and direct Optax use#

Fitting binds the physical objective, bounds and TV operators for named, injected and factory-provided transformations:

run_fit(experiment, model, data, optimizer_name="fista", **options)
run_fit(experiment, model, data,
        optimizer=make_optimizer("fista", 0.02), **options)
run_fit(experiment, model, data,
        optimizer_factory=lambda rate: make_optimizer("fista", rate),
        **options)

For a direct Optax loop, supply the smooth value_fn to update and use optax.apply_updates. FISTA reevaluates gradients at extrapolated points. Split Bregman solves its augmented primal objective. Configure gradient clipping, bounds and proximal terms on the solver transformation.

Fixed-step classic FISTA also supports caller-supplied extrapolated gradients: set gradient_at_extrapolated=True and evaluate at mrax.opt.optimizers.fista_extrapolated_params(). Generic optax.chain composition belongs to direct loops with explicit objective and proximal terms. Model-fitting field-TV binding uses the transformation directly.

State and termination#

Zero schedule entries pause optimizer, split and multiplier updates. Positive entries resume them. Convergence uses the configured stationarity checks. Split-Bregman state also records primal/dual residuals, inner work, preconditioner rebuilds and quasi-Newton history diagnostics.

Status 3 reports an uncertified proximal or line-search step. Status 4 reports a precision-limited rounded step with a nonzero composite KKT residual. Both retain the last accepted state for inspection. Higher precision or an explicit model-domain decision may be appropriate.

Resume using the same implementation and its complete state. Start a fresh optimizer when changing solver family or upgrading from the released FISTA or split-Bregman state layouts. Fitting describes FitError and checkpoint continuation.

Factory#

mrax.opt.optimizers.make_optimizer(optimizer_name: str, step_size: float | Callable[[Array], Array], regularizer_weight=0.0, regularizer_prox: Callable[[Array, float], Array] | None = None, base_optimizer_factory: Callable[[float | Callable[[Array], Array]], GradientTransformation] | None = None, box_constraints: Tuple[object, object] | None = None, bregman_penalty: float = 1.0, device: str | Device = 'cpu', *, proximal_context=None, proximal_tolerance: float = 1e-08, proximal_max_steps: int = 2048, bregman_inner_steps: int = 1, proximal_max_step_size: float | None = None, grad_clip_norm: float | None = None, fista_restart: str = 'gradient', fista_backtracking: str = 'full') → GradientTransformation#

Single entry point to build optimizers, with optional proximal variants.

  • fista uses Euclidean gradient and proximal steps with acceleration. split_bregman uses augmented primal solves, exact split shrinkage, and Bregman multiplier updates. Both retain their solver at zero weight.

  • Proximal callbacks receive the appropriate scalar, array, or tree threshold. Base factories are restricted to plain optax.sgd. Adam is unsupported. Pass the differentiable smooth objective as value_fn to update for safeguarded trials. The fitting API supplies it automatically. Direct fixed-step supplied-gradient callers evaluate FISTA gradients at state.y (stored under state['solver']). Check state['status'] for failure.

  • All other optimizers are resolved from Optax and only support L2 weight decay plus optional box constraints. grad_clip_norm optionally clips their full gradient.

mrax.opt.optimizers.fista_extrapolated_params(params, state)#

Return the gradient point in the caller’s original parameter PyTree.

Direct fixed-step FISTA callers using supplied gradients differentiate here, then pass gradient_at_extrapolated=True to update. Objective-callback loops and ordinary fitting evaluate this point internally.

Regularizers#

mrax.opt.regularizers.spatial_smoothness_penalty(field: Array, axes: tuple[int, ...] | None = None, mask: Array | None = None) → Array#

Encourage smooth parameter maps via finite-difference gradients.

mrax.opt.regularizers.total_variation_penalty(field: Array, axes: tuple[int, ...] | None = None, mask: Array | None = None, *, smoothed: bool = False) → Array#

Masked isotropic TV. Smoothing is an explicit gradient-only option.

mrax.opt.regularizers.higher_order_total_variation_penalty(field: Array, order: int = 2, axes: tuple[int, ...] | None = None, mask: Array | None = None, *, smoothed: bool = False) → Array#

Masked higher-order TV with the complete finite-difference stencil.

mrax.opt.regularizers.make_regularizer_fn(reg_type: str, axes: tuple[int, ...] | None = None, *, smoothed_tv=False, formulation='native')#
mrax.opt.regularizers.estimate_field_scales(fields: Mapping[str, object], *, mask: ndarray | None = None, method: str = 'median', min_scale: float = 1e-06) → dict[str, float]#

Estimate per-field scales for regularizer normalization.

mrax.opt.regularizers.estimate_param_scales(model, field_shape: tuple[int, ...], *, mask: ndarray | None = None, method: str = 'median', min_scale: float = 1e-06, param_specs: Mapping[str, Mapping[str, object]] | None = None) → dict[str, float]#

Estimate parameter scales from a model’s initialization or param specs.

mrax.opt.regularizers.autoscale_regularizer_configs(regularizer_configs: Mapping[str, list[dict]] | None, param_scales: Mapping[str, float], *, type_exponents: Mapping[str, float] | None = None, min_scale: float = 1e-06) → dict[str, list[dict]] | None#

Scale regularizer weights by parameter magnitude.

Low-level operations#

mrax.opt.ops.soft_threshold(x: Array, threshold: float) → Array#

Element-wise soft thresholding (supports complex inputs).

mrax.opt.ops.isotropic_shrinkage(v: Array, threshold: float) → Array#

Vector soft thresholding used for isotropic total variation.

mrax.opt.ops.forward_gradient2d(x: Array) → Array#

Forward finite differences with zero Neumann boundary.

mrax.opt.ops.divergence2d(v: Array) → Array#

Adjoint of forward_gradient2d (negative divergence).

mrax.opt.ops.conjugate_gradient(matvec: Callable[[Array], Array], b: Array, x0: Array | None = None, max_iters: int = 25, tol: float = 1e-06) → Array#

JAX-compatible conjugate gradient solver for SPD systems.