code: def test_mean_variance(latent_dist, mode, stein_kernel, verbose=True):
      pyro.clear_param_store()
  
      def model():
          pyro.sample("z", latent_dist)
  
      kernel = stein_kernel()
      adam = Adam({"lr": 0.05})
      svgd = SVGD(model, kernel, adam, 200, 0, mode=mode)
  
      bandwidth_start = 1.0
      bandwidth_end = 5.0
      n_steps = 301
  
      # scramble initial particles
      svgd.step()
      pyro.param("svgd_particles").unconstrained().data *= 1.3
      pyro.param("svgd_particles").unconstrained().data += 0.7
  
      for step in range(n_steps):
          kernel.bandwidth_factor = bandwidth_start + (
              step / n_steps
          ) * (bandwidth_end - bandwidth_start)
          squared_gradients = svgd.step()
          if step % 125 == 0:
              print("[step %03d] " % step, squared_gradients)
  
      final_particles = svgd.get_named_particles()["z"]
  
      if verbose:
          print(
              "[mean]: actual, expected = ",
              final_particles.mean(0).data.numpy(),
              latent_dist.mean.data.numpy(),
          )
          print(
              "[var]: actual, expected = ",
              final_particles.var(0).data.numpy(),
              latent_dist.variance.data.numpy(),
          )
  
      assert_equal(final_particles.mean(0), latent_dist.mean, prec=0.01)
      prec = 0.05 if mode == "multivariate" else 0.02
      assert_equal(
          final_particles.var(0), latent_dist.variance, prec=prec
      )
  
file_path: pyro/tests/infer/test_svgd.py
imports: import pytest
  import torch
  import pyro
  import pyro.distributions
  from pyro.infer import SVGD, IMQSteinKernel, RBFSteinKernel
  from pyro.infer.autoguide.utils import _product
  from pyro.optim import Adam
  from tests.common import assert_equal
label_desc: Use image node_id 1 for calling a global function with example usage: test_mean_variance(latent_dist, mode, stein_kernel, verbose) without return types