Skip to content

Settings

mgsl.Schedule dataclass

The localisation grid of a run. Every field is required.

Parameters:

Name Type Description Default
n_paths int

Number of independent paths, i.e. of posterior samples.

required
tau_start float

Localisation time at which the paths start (> 0).

required
tau_final float

Localisation time the paths reach; the terminal fit that produces the samples is made there.

required
n_tau int

Number of grid points (geometric from tau_start to tau_final), at least 2. A run makes n_tau - 1 steps.

required

taus property

The grid, float64 array of shape (n_tau,).

mgsl.MGVIOptions dataclass

Settings of the local MGVI fits made at every step.

Parameters:

Name Type Description Default
n_samples_mgvi int

Number of residual draws per fit. Each is mirrored, so the fit averages over 2 * n_samples_mgvi points (NIFTy.re's n_samples with mirror_samples=True). Required.

required
n_iter_mgvi int

Number of rounds (draw residuals, then Newton) per fit. Required.

required
newton NewtonOptions

Newton-CG settings. Required (its maxiter has no default).

required
draw_cg CGOptions

Stopping rules of the CG solves that draw residuals.

CGOptions()
preconditioner callable

preconditioner(x, tau) returning a function v -> M^{-1} v, where M approximates the matrix the CG solves invert, the precision metric Lambda = (1 + tau) I + J^T F J at the current centre x (J the Jacobian of the forward model, F the Fisher metric of the noise model). x and v are 1-D arrays of length d: the latent flattened as by jax.flatten_util.ravel_pytree. It is called before every group of solves: once per round of residual draws and once per Newton step, so building it should be cheap compared with a solve. It may be a pytree (e.g. jax.tree_util.Partial) whose array leaves are passed at run time rather than compiled in.

None

mgsl.NewtonOptions dataclass

Stopping rules of the Newton-CG minimisation in each local fit.

The minimisation stops after maxiter steps, once the step taken has 1-norm <= xtol * d (d the latent dimension), or once the objective decreased by less than absdelta. Names, defaults and these stopping rules are those of NIFTy.re's Newton-CG. Differences: the inner CG starts from whichever of zero and the step that ignores the likelihood (y / (1 + tau) - x) has the smaller residual (NIFTy.re starts from zero), and stops on its residual only (NIFTy.re also stops it on the decrease of the CG objective), so it may take more iterations per solve.

Parameters:

Name Type Description Default
maxiter int

Maximum number of Newton steps per round. Required.

required
xtol float

Step-size tolerance, multiplied by the dimension d.

1e-5
absdelta float

Stop when the objective decreased by less than this. Off by default.

None
cg CGOptions

Iteration limits of the inner CG solves (and their tolerances if adaptive_cg is False).

CGOptions()
adaptive_cg bool

If True, the inner CG stops at a residual 1-norm of min(0.5, sqrt(|g|_1)) |g|_1 for gradient g (an inexact Newton method), ignoring cg.tol and cg.atol.

True
line_search ('armijo', 'nifty')

"armijo" (default): halves the step until the objective decreases by at least 1e-4 times the decrease predicted by the gradient (the Armijo condition), down to a step of 1e-12; a Newton direction that is not a descent direction (or not finite) is first replaced by steepest descent capped at length sqrt(d); a step is kept only if the objective strictly decreased. It never gives up after a fixed number of tries. "nifty" (NIFTy.re's line search): tries steps 1, 1/2, 1/4, ... along the Newton direction and takes the first that does not increase the objective; after six failures it restarts along the gradient (scaled by g.g / g.H.g); after nine it gives up and the centre stays put. absdelta only applies when fewer than two halvings were needed. On strongly curved posteriors it gives up more often than "armijo".

"armijo"

mgsl.CGOptions dataclass

Stopping rules of a conjugate-gradient solve.

The solve stops once the residual 2-norm is below max(tol * |b|, atol), after at least miniter and at most maxiter iterations. Names and defaults are those of NIFTy.re's conjugate gradients. CG tracks its residual by a recurrence that drifts from the true residual b - A x in floating point; the true residual is recomputed every refresh iterations and whenever the solve looks converged (one extra application of A each), so convergence is always judged on the true residual.

Parameters:

Name Type Description Default
tol float

Tolerance relative to the norm of the right-hand side b.

1e-5
atol float

Absolute tolerance on the residual norm.

0
miniter int

Minimum number of iterations. Default min(6, maxiter).

None
maxiter int

Maximum number of iterations. Default min(200, 20 d) for a latent of dimension d.

None
refresh int

Iterations between recomputations of the true residual (NIFTy.re uses 20). Without them, badly conditioned solves drift and can end far from the solution; but each refresh also perturbs the CG recurrence, so refreshing very often (every few iterations) slows convergence. Each refresh costs one extra application of A.

20

resolve(size)

(miniter, maxiter) for a system of the given size, with NIFTy.re's fallbacks.

mgsl.grid(tau_from, tau_to, n)

Geometric grid of n points from tau_from to tau_to.

The endpoints are exactly tau_from and tau_to (as float64), so a continuation built with grid(state.tau, ...) starts exactly where the state is.

Parameters:

Name Type Description Default
tau_from float

First and last point, 0 < tau_from < tau_to.

required
tau_to float

First and last point, 0 < tau_from < tau_to.

required
n int

Number of points, at least 2.

required

Returns:

Type Description
ndarray

Float64 array of shape (n,).