NIFTy.re adaptor¶
mgsl.nifty
¶
Adaptor for NIFTy.re (optional: imports nifty.re only when used).
Usage::
import operator
import nifty.re as jft
from jax.tree_util import Partial
import mgsl.nifty
noise_std_inv = Partial(operator.mul, 1 / sd) # NIFTy.re wants an operator here
lh = jft.Gaussian(data, noise_std_inv=noise_std_inv).amend(model) # model: a jft.Model
lik = mgsl.nifty.from_likelihood(lh)
result = mgsl.sample(key, lik, mu, schedule, options)
samples = mgsl.nifty.to_samples(result) # a nifty.re Samples
from_likelihood(lh, **primals_kw)
¶
An :class:mgsl.Likelihood from a NIFTy.re likelihood on the standardised latent.
lh must be a likelihood whose primals are the latent with a standard-normal prior,
usually likelihood.amend(model) for a NIFTy.re Model. NIFTy.re's energy is the
negative log-likelihood, its metric the Fisher metric pulled back to the latent (J^T F J) and its
left_sqrt_metric the Fisher square root; they map onto log_likelihood, fisher
and fisher_sqrt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lh
|
Likelihood
|
Not a |
required |
**primals_kw
|
Extra keyword arguments passed to every call of |
{}
|
Notes
optimize_kl's point_estimates and constants have no equivalent: fix such
parameters inside the forward model instead.
to_samples(result)
¶
The samples of an :class:mgsl.Result as nifty.re.Samples.
pos is the sample mean and the samples are stored relative to it, so Samples.at,
.pos and NIFTy.re's tools work as for optimize_kl output.