class_docstr: Resampler for interactive tuning of generative models, typically
  when preforming prior predictive checks as an early step of Bayesian
  workflow.
  
  This is intended as a computational cache to speed up the interactive
  tuning of the parameters of prior distributions based on samples from a
  downstream simulation. The idea is that the simulation can be expensive,
  but that when one slightly tweaks parameters of the parameter distribution
  then one can reuse most of the previous samples via importance resampling.
  
  :param callable guide: A pyro model that takes no arguments. The guide
      should be diffuse, covering more space than the subsequent ``model``
      passed to :meth:`sample`. Must be vectorizable via ``pyro.plate``.
  :param callable simulator: An optional larger pyro model with a superset of
      the guide's latent variables. Must be vectorizable via ``pyro.plate``.
  :param int num_guide_samples: Number of inital samples to draw from the
      guide. This should be much larger than the ``num_samples`` requested in
      subsequent calls to :meth:`sample`.
  :param int max_plate_nesting: The maximum plate nesting in the model.
      If absent this will be guessed by running the guide.
code: def __init__(
      self,
      guide: Callable,
      simulator: Optional[Callable] = None,
      *,
      num_guide_samples: int,
      max_plate_nesting: Optional[int] = None,
  ):
      super().__init__()
      if max_plate_nesting is None:
          max_plate_nesting = _guess_max_plate_nesting(
              guide if simulator is None else simulator
          )
      self._particle_dim = -1 - max_plate_nesting
      self._gumbels: Optional[torch.Tensor] = None
  
      # Draw samples from the initial guide.
      with pyro.plate(
          "particles", num_guide_samples, dim=self._particle_dim
      ):
          trace = poutine.trace(guide).get_trace()
          self._old_logp = _log_prob_sum(trace, num_guide_samples)
  
          if simulator:
              # Draw extended samples from the simulator.
              trace = poutine.trace(
                  poutine.replay(simulator, trace)
              ).get_trace()
      self._samples = {
          name: site["value"]
          for name, site in trace.nodes.items()
          if site["type"] == "sample" and not site_is_subsample(site)
      }
  
file_path: pyro/pyro/infer/resampler.py
imports: from typing import Callable, Dict, Optional
  import torch
  import pyro
  import pyro.poutine
  from pyro.poutine.trace_struct import Trace
  from pyro.poutine.util import site_is_subsample
label_desc: Use image node_id 1 to create a new Resampler object  with example: obj = Resampler(guide, simulator)