code: def summary(samples, prob=0.9, group_by_chain=True):
      """
      Returns a summary table displaying diagnostics of ``samples`` from the
      posterior. The diagnostics displayed are mean, standard deviation, median,
      the 90% Credibility Interval, :func:`~pyro.ops.stats.effective_sample_size`,
      :func:`~pyro.ops.stats.split_gelman_rubin`.
  
      :param dict samples: dictionary of samples keyed by site name.
      :param float prob: the probability mass of samples within the credibility interval.
      :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).
      """
      if not group_by_chain:
          samples = {k: v.unsqueeze(0) for k, v in samples.items()}
  
      summary_dict = {}
      for name, value in samples.items():
          value_flat = torch.reshape(value, (-1,) + value.shape[2:])
          mean = value_flat.mean(dim=0)
          std = value_flat.std(dim=0)
          median = value_flat.median(dim=0)[0]
          hpdi = stats.hpdi(value_flat, prob=prob)
          n_eff = _safe(stats.effective_sample_size)(value)
          r_hat = stats.split_gelman_rubin(value)
          hpd_lower = "{:.1f}%".format(50 * (1 - prob))
          hpd_upper = "{:.1f}%".format(50 * (1 + prob))
          summary_dict[name] = OrderedDict(
              [
                  ("mean", mean),
                  ("std", std),
                  ("median", median),
                  (hpd_lower, hpdi[0]),
                  (hpd_upper, hpdi[1]),
                  ("n_eff", n_eff),
                  ("r_hat", r_hat),
              ]
          )
      return summary_dict
  
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 6 for calling a global function with example usage: summary(samples, prob, group_by_chain) and returns: summary_dict