code: def do_elbo_test(
      self, reparameterized, n_steps, lr, prec, difficulty=1.0
  ):
      n_repa_nodes = (
          torch.sum(self.which_nodes_reparam)
          if not reparameterized
          else self.N
      )
      logger.info(
          " - - - - - DO GAUSSIAN %d-CHAIN ELBO TEST  [reparameterized = %s; %d/%d] - - - - - "
          % (self.N, reparameterized, n_repa_nodes, self.N)
      )
      if self.N < 0:
  
          def array_to_string(y):
              return str(
                  map(lambda x: "%.3f" % x.detach().cpu().numpy()[0], y)
              )
  
          logger.debug("lambdas: " + array_to_string(self.lambdas))
          logger.debug(
              "target_mus: " + array_to_string(self.target_mus[1:])
          )
          logger.debug(
              "target_kappas: "
              + array_to_string(self.target_kappas[1:])
          )
          logger.debug(
              "lambda_posts: " + array_to_string(self.lambda_posts[1:])
          )
          logger.debug(
              "lambda_tilde_posts: "
              + array_to_string(self.lambda_tilde_posts)
          )
          pyro.clear_param_store()
  
      adam = optim.Adam({"lr": lr, "betas": (0.95, 0.999)})
      elbo = TraceGraph_ELBO()
      loss_and_grads = elbo.loss_and_grads
      # loss_and_grads = elbo.jit_loss_and_grads  # This fails.
      svi = SVI(
          self.model,
          self.guide,
          adam,
          loss=elbo.loss,
          loss_and_grads=loss_and_grads,
      )
  
      for step in range(n_steps):
          t0 = time.time()
          svi.step(
              reparameterized=reparameterized, difficulty=difficulty
          )
  
          if step % 5000 == 0 or step == n_steps - 1:
              kappa_errors, log_sig_errors, loc_errors = [], [], []
              for k in range(1, self.N + 1):
                  if k != self.N:
                      kappa_error = param_mse(
                          "kappa_q_%d" % k, self.target_kappas[k]
                      )
                      kappa_errors.append(kappa_error)
  
                  loc_errors.append(
                      param_mse("loc_q_%d" % k, self.target_mus[k])
                  )
                  log_sig_error = param_mse(
                      "log_sig_q_%d" % k,
                      -0.5 * torch.log(self.lambda_posts[k]),
                  )
                  log_sig_errors.append(log_sig_error)
  
              max_errors = (
                  np.max(loc_errors),
                  np.max(log_sig_errors),
                  np.max(kappa_errors),
              )
              min_errors = (
                  np.min(loc_errors),
                  np.min(log_sig_errors),
                  np.min(kappa_errors),
              )
              mean_errors = (
                  np.mean(loc_errors),
                  np.mean(log_sig_errors),
                  np.mean(kappa_errors),
              )
              logger.debug(
                  "[max errors]   (loc, log_scale, kappa) = (%.4f, %.4f, %.4f)"
                  % max_errors
              )
              logger.debug(
                  "[min errors]   (loc, log_scale, kappa) = (%.4f, %.4f, %.4f)"
                  % min_errors
              )
              logger.debug(
                  "[mean errors]  (loc, log_scale, kappa) = (%.4f, %.4f, %.4f)"
                  % mean_errors
              )
              logger.debug(
                  "[step time = %.3f;  N = %d;  step = %d]\n"
                  % (time.time() - t0, self.N, step)
              )
  
      assert_equal(0.0, max_errors[0], prec=prec)
      assert_equal(0.0, max_errors[1], prec=prec)
      assert_equal(0.0, max_errors[2], prec=prec)
  
imports: import logging
  import os
  import time
  from unittest import TestCase
  import numpy
  import pytest
  import torch
  import pyro
  import pyro.distributions
  import pyro.optim
  from pyro.distributions.testing import fakes
  from pyro.infer import SVI, TraceGraph_ELBO
  from pyro.poutine import Trace
  from tests.common import assert_equal
label_desc: Use image node_id 7 for calling the GaussianChainTests obj's underlying member method code with example usage: obj.do_elbo_test(reparameterized, n_steps, lr, prec, difficulty) and returns: str