class_docstr: An objective similar to ELBO, but with Maximum Mean Discrepancy (MMD)
  between marginal variational posterior and prior distributions
  instead of KL-divergence between variational posterior and prior distributions
  as in vanilla ELBO.
  The simplest example is MMD-VAE model [1]. The corresponding loss function is given as follows:
  
      :math: `L(\theta, \phi) = -E_{p_{data}(x)} E_{q(z | x; \phi)} \log p(x | z; \theta) +
      MMD(q(z; \phi) \| p(z))`,
  
  where z is a latent code. MMD between two distributions is defined as follows:
  
      :math: `MMD(q(z) \| p(z)) = E_{p(z), p(z')} k(z,z') + E_{q(z), q(z')} k(z,z') - 2 E_{p(z), q(z')} k(z,z')`,
  
  where k is a kernel.
  
  DISCLAIMER: this implementation treats only the particle dimension as batch dimension when computing MMD.
  All other dimensions are treated as event dimensions.
  For this reason, one needs large `num_particles` in order to have reasonable variance of MMD Monte-Carlo estimate.
  As a consequence, it is recommended to set `vectorize_particles=True` (default).
  The general case will be implemented in future versions.
  
  :param kernel: A kernel used to compute MMD.
      An instance of :class: `pyro.contrib.gp.kernels.kernel.Kernel`,
      or a dict that maps latent variable names to instances of :class: `pyro.contrib.gp.kernels.kernel.Kernel`.
      In the latter case, different kernels are used for different latent variables.
  
  :param mmd_scale: A scaling factor for MMD terms.
      Float, or a dict that maps latent variable names to floats.
      In the latter case, different scaling factors are used for different latent variables.
  
  References
  
  [1] `A Tutorial on Information Maximizing Variational Autoencoders (InfoVAE)`
      Shengjia Zhao
      https://ermongroup.github.io/blog/a-tutorial-on-mmd-variational-autoencoders/
  
  [2] `InfoVAE: Balancing Learning and Inference in Variational Autoencoders`
      Shengjia Zhao, Jiaming Song, Stefano Ermon
docstr: :returns: returns an estimate of the MMD-VAE-type loss [1]
  :rtype: float
  
  Computes the MMD-VAE-type loss with an estimator that uses num_particles many samples/particles.
  
  References
  
  [1] `A Tutorial on Information Maximizing Variational Autoencoders (InfoVAE)`
      Shengjia Zhao
      https://ermongroup.github.io/blog/a-tutorial-on-mmd-variational-autoencoders/
docstr_tok: [":","returns",":","returns","an","estimate","of","the","MMD-VAE-type","loss","[","1","]",":","rtype",":","float","Computes","the","MMD-VAE-type","loss","with","an","estimator","that","uses","num_particles","many","samples\/particles",".","References","[","1","]","`","A","Tutorial","on","Information","Maximizing","Variational","Autoencoders","(","InfoVAE",")","`","Shengjia","Zhao","https",":","\/\/ermongroup.github.io\/blog\/a-tutorial-on-mmd-variational-autoencoders\/"]
code: def loss(self, model, guide, *args, **kwargs):
      """
      :returns: returns an estimate of the MMD-VAE-type loss [1]
      :rtype: float
  
      Computes the MMD-VAE-type loss with an estimator that uses num_particles many samples/particles.
  
      References
  
      [1] `A Tutorial on Information Maximizing Variational Autoencoders (InfoVAE)`
          Shengjia Zhao
          https://ermongroup.github.io/blog/a-tutorial-on-mmd-variational-autoencoders/
      """
      loss = self.differentiable_loss(model, guide, *args, **kwargs)
      return torch_item(loss)
  
imports: from collections import defaultdict
  import torch
  import pyro
  import pyro.ops.jit
  from pyro import poutine
  from pyro.infer.elbo import ELBO
  from pyro.infer.enum import get_importance_trace
  from pyro.infer.util import is_validation_enabled, torch_item
  from pyro.util import check_if_enumerated, warn_if_nan
label_desc: Use image node_id 9 for calling the Trace_MMD obj's underlying member method code with example usage: obj.loss(model, guide) and returns: torch_item