code: def diagnostics(samples, group_by_chain=True):
      """
      Gets diagnostics statistics such as effective sample size and
      split Gelman-Rubin using the samples drawn from the posterior
      distribution.
  
      :param dict samples: dictionary of samples keyed by site name.
      :param bool group_by_chain: If True, each variable in `samples`
          will be treated as having shape `num_chains x num_samples x sample_shape`.
          Otherwise, the corresponding shape will be `num_samples x sample_shape`
          (i.e. without chain dimension).
      :return: dictionary of diagnostic stats for each sample site.
      """
      diagnostics = {}
      for site, support in samples.items():
          if not group_by_chain:
              support = support.unsqueeze(0)
          site_stats = OrderedDict()
          site_stats["n_eff"] = _safe(stats.effective_sample_size)(
              support
          )
          site_stats["r_hat"] = stats.split_gelman_rubin(support)
          diagnostics[site] = site_stats
      return diagnostics
  
imports: import functools
  import traceback
  import warnings
  from collections import OrderedDict, defaultdict
  from functools import partial, reduce
  from itertools import product
  import torch
  from opt_einsum import shared_intermediates
  from torch.distributions import biject_to
  import pyro
  import pyro.poutine
  from pyro.distributions.util import broadcast_shape, logsumexp
  from pyro.infer import config_enumerate
  from pyro.infer.autoguide.initialization import InitMessenger, init_to_uniform
  from pyro.infer.util import is_validation_enabled
  from pyro.ops import stats
  from pyro.ops.contract import contract_to_tensor
  from pyro.ops.integrator import potential_grad
  from pyro.poutine.subsample_messenger import _Subsample
  from pyro.poutine.util import prune_subsample_sites
  from pyro.util import check_site_shape, ignore_jit_warnings
label_desc: Use image node_id 5 for calling a global function with example usage: diagnostics(samples, group_by_chain) and returns: diagnostics