class_docstr: Compiled Sequential Importance Sampling, allowing compilation of a guide
  program to minimise KL(model posterior || guide), and inference with
  importance sampling.
  
  **Reference**
  "Inference Compilation and Universal Probabilistic Programming" `pdf https://arxiv.org/pdf/1610.09900.pdf`
  
  :param model: probabilistic model defined as a function. Must accept a
      keyword argument named `observations`, in which observed values are
      passed as, with the names of nodes as the keys.
  :param guide: guide function which is used as an approximate posterior. Must
      also accept `observations` as keyword argument.
  :param optim: a Pyro optimizer
  :type optim: pyro.optim.PyroOptim
  :param num_inference_samples: The number of importance-weighted samples to
      draw during inference.
  :param training_batch_size: Number of samples to use to approximate the loss
      before each gradient descent step during training.
  :param validation_batch_size: Number of samples to use for calculating
      validation loss (will only be used if `.validation_loss` is called).
class_docstr_tok: ["Compiled","Sequential","Importance","Sampling",",","allowing","compilation","of","a","guide","program","to","minimise","KL","(","model","posterior","||","guide",")",",","and","inference","with","importance","sampling",".","*","*","Reference","*","*","''","Inference","Compilation","and","Universal","Probabilistic","Programming","''","`","pdf","https",":","\/\/arxiv.org\/pdf\/1610.09900.pdf","`",":","param","model",":","probabilistic","model","defined","as","a","function",".","Must","accept","a","keyword","argument","named","`","observations","`",",","in","which","observed","values","are","passed","as",",","with","the","names","of","nodes","as","the","keys",".",":","param","guide",":","guide","function","which","is","used","as","an","approximate","posterior",".","Must","also","accept","`","observations","`","as","keyword","argument",".",":","param","optim",":","a","Pyro","optimizer",":","type","optim",":","pyro.optim.PyroOptim",":","param","num_inference_samples",":","The","number","of","importance-weighted","samples","to","draw","during","inference",".",":","param","training_batch_size",":","Number","of","samples","to","use","to","approximate","the","loss","before","each","gradient","descent","step","during","training",".",":","param","validation_batch_size",":","Number","of","samples","to","use","for","calculating","validation","loss","(","will","only","be","used","if","`",".validation_loss","`","is","called",")","."]
docstr: :param model_trace: a trace from the model
  :type model_trace: pyro.poutine.trace_struct.Trace
  :returns: guide trace with sampled values matched to model_trace
  :rtype: pyro.poutine.trace_struct.Trace
  
  Returns a guide trace with values at sample and observe statements
  matched to those in model_trace.
  
  `args` and `kwargs` are passed to the guide.
docstr_tok: [":","param","model_trace",":","a","trace","from","the","model",":","type","model_trace",":","pyro.poutine.trace_struct.Trace",":","returns",":","guide","trace","with","sampled","values","matched","to","model_trace",":","rtype",":","pyro.poutine.trace_struct.Trace","Returns","a","guide","trace","with","values","at","sample","and","observe","statements","matched","to","those","in","model_trace",".","`","args","`","and","`","kwargs","`","are","passed","to","the","guide","."]
code: def _get_matched_trace(self, model_trace, *args, **kwargs):
      """
      :param model_trace: a trace from the model
      :type model_trace: pyro.poutine.trace_struct.Trace
      :returns: guide trace with sampled values matched to model_trace
      :rtype: pyro.poutine.trace_struct.Trace
  
      Returns a guide trace with values at sample and observe statements
      matched to those in model_trace.
  
      `args` and `kwargs` are passed to the guide.
      """
      kwargs["observations"] = {}
      for node in itertools.chain(
          model_trace.stochastic_nodes, model_trace.observation_nodes
      ):
          if "was_observed" in model_trace.nodes[node]["infer"]:
              model_trace.nodes[node]["is_observed"] = True
              kwargs["observations"][node] = model_trace.nodes[node][
                  "value"
              ]
  
      guide_trace = poutine.trace(
          poutine.replay(self.guide, model_trace)
      ).get_trace(*args, **kwargs)
  
      check_model_guide_match(model_trace, guide_trace)
      guide_trace = prune_subsample_sites(guide_trace)
  
      return guide_trace
  
file_path: pyro/pyro/infer/csis.py
imports: import itertools
  import torch
  import pyro
  import pyro.poutine
  from pyro.infer.importance import Importance
  from pyro.infer.util import torch_item
  from pyro.poutine.util import prune_subsample_sites
  from pyro.util import check_model_guide_match, warn_if_nan
label_desc: Use image node_id 7 for calling the CSIS obj's underlying member method code with example usage: obj._get_matched_trace(model_trace) and returns: guide_trace