class_docstr: A trace implementation of ELBO-based SVI. The estimator is constructed
  along the lines of references [1] and [2]. There are no restrictions on the
  dependency structure of the model or the guide. The gradient estimator includes
  partial Rao-Blackwellization for reducing the variance of the estimator when
  non-reparameterizable random variables are present. The Rao-Blackwellization is
  partial in that it only uses conditional independence information that is marked
  by :class:`~pyro.plate` contexts. For more fine-grained Rao-Blackwellization,
  see :class:`~pyro.infer.tracegraph_elbo.TraceGraph_ELBO`.
  
  References
  
  [1] Automated Variational Inference in Probabilistic Programming,
      David Wingate, Theo Weber
  
  [2] Black Box Variational Inference,
      Rajesh Ranganath, Sean Gerrish, David M. Blei
class_docstr_tok: ["A","trace","implementation","of","ELBO-based","SVI",".","The","estimator","is","constructed","along","the","lines","of","references","[","1","]","and","[","2","]",".","There","are","no","restrictions","on","the","dependency","structure","of","the","model","or","the","guide",".","The","gradient","estimator","includes","partial","Rao-Blackwellization","for","reducing","the","variance","of","the","estimator","when","non-reparameterizable","random","variables","are","present",".","The","Rao-Blackwellization","is","partial","in","that","it","only","uses","conditional","independence","information","that","is","marked","by",":","class",":","`","~pyro.plate","`","contexts",".","For","more","fine-grained","Rao-Blackwellization",",","see",":","class",":","`","~pyro.infer.tracegraph_elbo.TraceGraph_ELBO","`",".","References","[","1","]","Automated","Variational","Inference","in","Probabilistic","Programming",",","David","Wingate",",","Theo","Weber","[","2","]","Black","Box","Variational","Inference",",","Rajesh","Ranganath",",","Sean","Gerrish",",","David","M.","Blei"]
code: def _differentiable_loss_particle(self, model_trace, guide_trace):
      elbo_particle = 0
      surrogate_elbo_particle = 0
      log_r = None
  
      # compute elbo and surrogate elbo
      for name, site in model_trace.nodes.items():
          if site["type"] == "sample":
              elbo_particle = elbo_particle + torch_item(
                  site["log_prob_sum"]
              )
              surrogate_elbo_particle = (
                  surrogate_elbo_particle + site["log_prob_sum"]
              )
  
      for name, site in guide_trace.nodes.items():
          if site["type"] == "sample":
              log_prob, score_function_term, entropy_term = site[
                  "score_parts"
              ]
  
              elbo_particle = elbo_particle - torch_item(
                  site["log_prob_sum"]
              )
  
              if not is_identically_zero(entropy_term):
                  surrogate_elbo_particle = (
                      surrogate_elbo_particle - entropy_term.sum()
                  )
  
              if not is_identically_zero(score_function_term):
                  if log_r is None:
                      log_r = _compute_log_r(model_trace, guide_trace)
                  site = log_r.sum_to(site["cond_indep_stack"])
                  surrogate_elbo_particle = (
                      surrogate_elbo_particle
                      + (site * score_function_term).sum()
                  )
  
      return -elbo_particle, -surrogate_elbo_particle
  
imports: import weakref
  import pyro
  import pyro.ops.jit
  from pyro.distributions.util import is_identically_zero
  from pyro.infer.elbo import ELBO
  from pyro.infer.enum import get_importance_trace
  from pyro.infer.util import MultiFrameTensor, get_plate_stacks, is_validation_enabled, torch_item
  from pyro.util import check_if_enumerated, warn_if_nan
label_desc: Use image node_id 3 for calling the Trace_ELBO obj's underlying member method code with example usage: obj._differentiable_loss_particle(model_trace, guide_trace) and returns: unknown,  unknown