class_docstr: EXPERIMENTAL class used to construct predictive distribution. The predictive
  distribution is obtained by running the `model` conditioned on latent samples
  from `posterior_samples`. If a `guide` is provided, then posterior samples
  from all the latent sites are also returned.
  
  .. warning::
      The interface for the :class:`Predictive` class is experimental, and
      might change in the future.
  
  :param model: Python callable containing Pyro primitives.
  :param dict posterior_samples: dictionary of samples from the posterior.
  :param callable guide: optional guide to get posterior samples of sites not present
      in `posterior_samples`.
  :param int num_samples: number of samples to draw from the predictive distribution.
      This argument has no effect if ``posterior_samples`` is non-empty, in which case,
      the leading dimension size of samples in ``posterior_samples`` is used.
  :param return_sites: sites to return; by default only sample sites not present
      in `posterior_samples` are returned.
  :type return_sites: list, tuple, or set
  :param bool parallel: predict in parallel by wrapping the existing model
      in an outermost `plate` messenger. Note that this requires that the model has
      all batch dims correctly annotated via :class:`~pyro.plate`. Default is `False`.
code: def __init__(
      self,
      model,
      posterior_samples=None,
      guide=None,
      num_samples=None,
      return_sites=(),
      parallel=False,
  ):
      super().__init__()
      if posterior_samples is None:
          if num_samples is None:
              raise ValueError(
                  "Either posterior_samples or num_samples must be specified."
              )
          posterior_samples = {}
  
      for name, sample in posterior_samples.items():
          batch_size = sample.shape[0]
          if num_samples is None:
              num_samples = batch_size
          elif num_samples != batch_size:
              warnings.warn(
                  "Sample's leading dimension size {} is different from the "
                  "provided {} num_samples argument. Defaulting to {}.".format(
                      batch_size, num_samples, batch_size
                  ),
                  UserWarning,
              )
              num_samples = batch_size
  
      if num_samples is None:
          raise ValueError(
              "No sample sites in posterior samples to infer `num_samples`."
          )
  
      if guide is not None and posterior_samples:
          raise ValueError(
              "`posterior_samples` cannot be provided with the `guide` argument."
          )
  
      if return_sites is not None:
          assert isinstance(return_sites, (list, tuple, set))
  
      self.model = model
      self.posterior_samples = (
          {} if posterior_samples is None else posterior_samples
      )
      self.num_samples = num_samples
      self.guide = guide
      self.return_sites = return_sites
      self.parallel = parallel
  
file_path: pyro/pyro/infer/predictive.py
imports: import warnings
  from functools import reduce
  import torch
  import pyro
  import pyro.poutine
  from pyro.poutine.util import prune_subsample_sites
label_desc: Use image node_id 1 to create a new Predictive object from inherited base classes: torch.nn with example: obj = Predictive(model, posterior_samples, guide, num_samples, return_sites, parallel)