Reparameterizers¶
The numpyro.infer.reparam
module contains reparameterization strategies for
the numpyro.handlers.reparam
effect. These are useful for altering
geometry of a poorlyconditioned parameter space to make the posterior better
shaped. These can be used with a variety of inference algorithms, e.g.
Auto*Normal
guides and MCMC.
LocScale Decentering¶

class
LocScaleReparam
(centered=None, shape_params=())[source]¶ Bases:
numpyro.infer.reparam.Reparam
Generic decentering reparameterizer [1] for latent variables parameterized by
loc
andscale
(and possibly additionalshape_params
).This reparameterization works only for latent variables, not likelihoods.
References:
 Automatic Reparameterisation of Probabilistic Programs, Maria I. Gorinova, Dave Moore, Matthew D. Hoffman (2019)
Parameters:  centered (float) – optional centered parameter. If None (default) learn
a persite perelement centering parameter in
[0,1]
. If 0, fully decenter the distribution; if 1, preserve the centered distribution unchanged.  shape_params (tuple or list) – list of additional parameter names to copy unchanged from the centered to decentered distribution.

__call__
(name, fn, obs)[source]¶ Parameters:  name (str) – A sample site name.
 fn (Distribution) – A distribution.
 obs (numpy.ndarray) – Observed value or None.
Returns: A pair (
new_fn
,value
).
Neural Transport¶

class
NeuTraReparam
(guide, params)[source]¶ Bases:
numpyro.infer.reparam.Reparam
Neural Transport reparameterizer [1] of multiple latent variables.
This uses a trained
AutoContinuous
guide to alter the geometry of a model, typically for use e.g. in MCMC. Example usage:# Step 1. Train a guide guide = AutoIAFNormal(model) svi = SVI(model, guide, ...) # ...train the guide... # Step 2. Use trained guide in NeuTra MCMC neutra = NeuTraReparam(guide) model = netra.reparam(model) nuts = NUTS(model) # ...now use the model in HMC or NUTS...
This reparameterization works only for latent variables, not likelihoods. Note that all sites must share a single common
NeuTraReparam
instance, and that the model must have static structure. [1] Hoffman, M. et al. (2019)
 “NeuTralizing Bad Geometry in Hamiltonian Monte Carlo Using Neural Transport” https://arxiv.org/abs/1903.03704
Parameters:  guide (AutoContinuous) – A guide.
 params – trained parameters of the guide.

__call__
(name, fn, obs)[source]¶ Parameters:  name (str) – A sample site name.
 fn (Distribution) – A distribution.
 obs (numpy.ndarray) – Observed value or None.
Returns: A pair (
new_fn
,value
).

transform_sample
(latent)[source]¶ Given latent samples from the warped posterior (with possible batch dimensions), return a dict of samples from the latent sites in the model.
Parameters: latent – sample from the warped posterior (possibly batched). Returns: a dict of samples keyed by latent sites in the model. Return type: dict
Transformed Distributions¶

class
TransformReparam
[source]¶ Bases:
numpyro.infer.reparam.Reparam
Reparameterizer for
TransformedDistribution
latent variables.This is useful for transformed distributions with complex, geometrychanging transforms, where the posterior has simple shape in the space of
base_dist
.This reparameterization works only for latent variables, not likelihoods.

__call__
(name, fn, obs)[source]¶ Parameters:  name (str) – A sample site name.
 fn (Distribution) – A distribution.
 obs (numpy.ndarray) – Observed value or None.
Returns: A pair (
new_fn
,value
).
