Skip to content

NIFTy.re adapter

spectracles.nifty connects a Posterior to NIFTy.re for MGVI and geoVI. It needs the optional dependency: pip install "spectracles[nifty]". Importing the module doesn't import NIFTy; only to_nifty does.

spectracles.nifty.to_nifty(posterior)

The posterior's likelihood as a NIFTy.re likelihood on the latents ΞΎ.

The returned jft.Likelihood is already amended with the forward model, so its domain is the dict of latents (keyed by parameter path) and NIFTy's standard-normal prior on them is exactly the latent-space prior. Use it with jft.optimize_kl; turn results back into models with posterior.latent.to_model and posterior.latent.posterior_summary.

spectracles.nifty.stages(latent, spec, n_iterations)

Staged VI in the schedule-builder vocabulary, for jft.optimize_kl.

Each pattern (globs as in build_schedule) maps to a ParamSpec built with free_in, free_after, free_until or fixed_in, with VI iterations in place of optimisation phases. A parameter not mentioned is free in every iteration. A parameter that is not free at iteration i is held fixed at its current value: it goes in both constants (not updated by the KL minimisation) and point_estimates (no samples drawn along it).

Parameters:

Name Type Description Default
latent LatentSpace

The posterior's latent space.

required
spec dict[str, ParamSpec]

Mapping from path pattern to ParamSpec. A shared parameter can be named by any of its paths.

required
n_iterations int

The number of VI iterations (n_total_iterations). Specs may not refer to later iterations; past the end, the pattern of the helpers continues naturally (e.g. free_after stays free).

required

Returns:

Type Description
dict

{"constants": callable, "point_estimates": callable}, each taking the

dict

iteration number and returning a tuple of latent keys. Pass with

dict

jft.optimize_kl(..., **stages(...)).