class_docstr: Wrapper class for Markov Chain Monte Carlo algorithms. Specific MCMC algorithms
  are TraceKernel instances and need to be supplied as a ``kernel`` argument
  to the constructor.
  
  .. note:: The case of `num_chains > 1` uses python multiprocessing to
      run parallel chains in multiple processes. This goes with the usual
      caveats around multiprocessing in python, e.g. the model used to
      initialize the ``kernel`` must be serializable via `pickle`, and the
      performance / constraints will be platform dependent (e.g. only
      the "spawn" context is available in Windows). This has also not
      been extensively tested on the Windows platform.
  
  :param kernel: An instance of the ``TraceKernel`` class, which when
      given an execution trace returns another sample trace from the target
      (posterior) distribution.
  :param int num_samples: The number of samples that need to be generated,
      excluding the samples discarded during the warmup phase.
  :param int warmup_steps: Number of warmup iterations. The samples generated
      during the warmup phase are discarded. If not provided, default is
      is the same as `num_samples`.
  :param int num_chains: Number of MCMC chains to run in parallel. Depending on
      whether `num_chains` is 1 or more than 1, this class internally dispatches
      to either `_UnarySampler` or `_MultiSampler`.
  :param dict initial_params: dict containing initial tensors in unconstrained
      space to initiate the markov chain. The leading dimension's size must match
      that of `num_chains`. If not specified, parameter values will be sampled from
      the prior.
  :param hook_fn: Python callable that takes in `(kernel, samples, stage, i)`
      as arguments. stage is either `sample` or `warmup` and i refers to the
      i'th sample for the given stage. This can be used to implement additional
      logging, or more generally, run arbitrary code per generated sample.
  :param str mp_context: Multiprocessing context to use when `num_chains > 1`.
      Only applicable for Python 3.5 and above. Use `mp_context="spawn"` for
      CUDA.
  :param bool disable_progbar: Disable progress bar and diagnostics update.
  :param bool disable_validation: Disables distribution validation check.
      Defaults to ``True``, disabling validation, since divergent transitions
      will lead to exceptions. Switch to ``False`` to enable validation, or
      to ``None`` to preserve existing global values.
  :param dict transforms: dictionary that specifies a transform for a sample site
      with constrained support to unconstrained space.
  :param List[str] save_params: Optional list of a subset of parameter names to
      save during sampling and diagnostics. This is useful in models with
      large nuisance variables. Defaults to None, saving all params.
class_docstr_tok: ["Wrapper","class","for","Markov","Chain","Monte","Carlo","algorithms",".","Specific","MCMC","algorithms","are","TraceKernel","instances","and","need","to","be","supplied","as","a","``","kernel","``","argument","to","the","constructor",".","..","note",":",":","The","case","of","`","num_chains",">","1","`","uses","python","multiprocessing","to","run","parallel","chains","in","multiple","processes",".","This","goes","with","the","usual","caveats","around","multiprocessing","in","python",",","e.g",".","the","model","used","to","initialize","the","``","kernel","``","must","be","serializable","via","`","pickle","`",",","and","the","performance","\/","constraints","will","be","platform","dependent","(","e.g",".","only","the","``","spawn","''","context","is","available","in","Windows",")",".","This","has","also","not","been","extensively","tested","on","the","Windows","platform",".",":","param","kernel",":","An","instance","of","the","``","TraceKernel","``","class",",","which","when","given","an","execution","trace","returns","another","sample","trace","from","the","target","(","posterior",")","distribution",".",":","param","int","num_samples",":","The","number","of","samples","that","need","to","be","generated",",","excluding","the","samples","discarded","during","the","warmup","phase",".",":","param","int","warmup_steps",":","Number","of","warmup","iterations",".","The","samples","generated","during","the","warmup","phase","are","discarded",".","If","not","provided",",","default","is","is","the","same","as","`","num_samples","`",".",":","param","int","num_chains",":","Number","of","MCMC","chains","to","run","in","parallel",".","Depending","on","whether","`","num_chains","`","is","1","or","more","than","1",",","this","class","internally","dispatches","to","either","`","_UnarySampler","`","or","`","_MultiSampler","`",".",":","param","dict","initial_params",":","dict","containing","initial","tensors","in","unconstrained","space","to","initiate","the","markov","chain",".","The","leading","dimension","'s","size","must","match","that","of","`","num_chains","`",".","If","not","specified",",","parameter","values","will","be","sampled","from","the","prior",".",":","param","hook_fn",":","Python","callable","that","takes","in","`","(","kernel",",","samples",",","stage",",","i",")","`","as","arguments",".","stage","is","either","`","sample","`","or","`","warmup","`","and","i","refers","to","the","i'th","sample","for","the","given","stage",".","This","can","be","used","to","implement","additional","logging",",","or","more","generally",",","run","arbitrary","code","per","generated","sample",".",":","param","str","mp_context",":","Multiprocessing","context","to","use","when","`","num_chains",">","1","`",".","Only","applicable","for","Python","3.5","and","above",".","Use","`","mp_context=","''","spawn","''","`","for","CUDA",".",":","param","bool","disable_progbar",":","Disable","progress","bar","and","diagnostics","update",".",":","param","bool","disable_validation",":","Disables","distribution","validation","check",".","Defaults","to","``","True","``",",","disabling","validation",",","since","divergent","transitions","will","lead","to","exceptions",".","Switch","to","``","False","``","to","enable","validation",",","or","to","``","None","``","to","preserve","existing","global","values",".",":","param","dict","transforms",":","dictionary","that","specifies","a","transform","for","a","sample","site","with","constrained","support","to","unconstrained","space",".",":","param","List","[","str","]","save_params",":","Optional","list","of","a","subset","of","parameter","names","to","save","during","sampling","and","diagnostics",".","This","is","useful","in","models","with","large","nuisance","variables",".","Defaults","to","None",",","saving","all","params","."]
docstr: Gets some diagnostics statistics such as effective sample size, split
  Gelman-Rubin, or divergent transitions from the sampler.
code: def diagnostics(self):
      """
      Gets some diagnostics statistics such as effective sample size, split
      Gelman-Rubin, or divergent transitions from the sampler.
      """
      diag = diagnostics(self._samples)
      for diag_name in self._diagnostics[0]:
          diag[diag_name] = {
              "chain {}".format(i): self._diagnostics[i][diag_name]
              for i in range(self.num_chains)
          }
      return diag
  
imports: import copy
  import json
  import logging
  import queue
  import signal
  import threading
  import warnings
  from abc import ABC, abstractmethod
  from collections import OrderedDict
  from typing import Dict
  import torch
  import torch.multiprocessing
  import pyro
  import pyro.poutine
  from pyro.infer.mcmc.hmc import HMC
  from pyro.infer.mcmc.logger import DIAGNOSTIC_MSG, ProgressBar, TqdmHandler, initialize_logger
  from pyro.infer.mcmc.nuts import NUTS
  from pyro.infer.mcmc.util import diagnostics, diagnostics_from_stats, print_summary, select_samples
  from pyro.ops.streaming import CountMeanVarianceStats, StatsOfDict, StreamingStats
  from pyro.util import optional
label_desc: Use image node_id 4 for calling the MCMC obj's underlying member method code with example usage: obj.diagnostics() and returns: diag