code: def diagnostics_from_stats(statistics, num_samples, num_chains):
      """
      Computes diagnostics from streaming statistics.
      Currently only Gelman-Rubin is computed.
  
      :param dict statistics: Dictionary of streaming statistics.
      :param int num_samples: Number of samples.
      :param int num_chains: Number of chains.
      :return: dictionary of diagnostic stats for each sample site.
      """
      diag = {}
      mean_var_dict = {}
      for (_, name), stat in statistics.items():
          if name in mean_var_dict:
              mean, var = mean_var_dict[name]
              mean.append(stat["mean"])
              var.append(stat["variance"])
          elif "mean" in stat and "variance" in stat:
              mean_var_dict[name] = ([stat["mean"]], [stat["variance"]])
  
      for name, (m, v) in mean_var_dict.items():
          mean_var_dict[name] = (torch.stack(m), torch.stack(v))
  
      for name, (m, v) in mean_var_dict.items():
          N = num_samples
          var_within = v.mean(dim=0)
          var_estimator = (N - 1) / N * var_within
          if num_chains > 1:
              var_between = m.var(dim=0)
              var_estimator = var_estimator + var_between
          else:
              var_within = var_estimator
  
          diag[name] = OrderedDict(
              {"r_hat": (var_estimator / var_within).sqrt()}
          )
  
      return diag
  
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 11 for calling a global function with example usage: diagnostics_from_stats(statistics, num_samples, num_chains) and returns: diag