VariationalPosterior.to_torch#
- VariationalPosterior.to_torch(orig_flag=True, *, dtype=None, device=None)[source]#
Export a snapshot as a torch probability distribution.
- Parameters:
- orig_flagbool, optional
Return a distribution in original parameter coordinates (default True), or in the internal unconstrained coordinates if False.
- dtypetorch.dtype, optional
Export precision, either
torch.float64(default) ortorch.float32. This does not change the NumPy posterior.- devicestr or torch.device, optional
Device for the distribution’s tensors, default CPU.
- Returns:
- distributiontorch.distributions.Distribution
A Gaussian mixture, transformed to original coordinates when requested, with event shape
(D,). Itslog_probsupports differentiation with respect to its input. Mixture sampling is not reparameterized.
- Raises:
- ImportError
If torch is absent; install
pyvbmc[torch].- ValueError
If the posterior or transformer cannot define the distribution.
Notes
Parameters are copied; later changes to either object do not affect the other. Conversion draws no random numbers. Sampling the exported distribution uses torch’s RNG, controlled by
torch.manual_seed, independently ofself.rng. No torch objects are stored on this VP. In original space, density inputs must be finite and strictly inside parameter bounds. Samples rounded to a bound are moved to the nearest representable interior point; the analytic density transform is not clamped. Explicit float32 exports have less resolution near bounds.
See Torch distribution for a short example and installation details in Optional integrations. The worked PyVBMC Example 9: Torch and JAX models and posterior exports uses the export for posterior probability predictions and density gradients.