code: def ess(
      data,
      *,
      var_names=None,
      method="bulk",
      relative=False,
      prob=None,
      dask_kwargs=None,
  ):
      r"""Calculate estimate of the effective sample size (ess).
  
      Parameters
      ----------
      data : obj
          Any object that can be converted to an :class:`arviz.InferenceData` object.
          Refer to documentation of :func:`arviz.convert_to_dataset` for details.
          For ndarray: shape = (chain, draw).
          For n-dimensional ndarray transform first to dataset with :func:`arviz.convert_to_dataset`.
      var_names : str or list of str
          Names of variables to include in the return value Dataset.
      method : str, optional, default "bulk"
          Select ess method. Valid methods are:
  
          - "bulk"
          - "tail"     # prob, optional
          - "quantile" # prob
          - "mean" (old ess)
          - "sd"
          - "median"
          - "mad" (mean absolute deviance)
          - "z_scale"
          - "folded"
          - "identity"
          - "local"
      relative : bool
          Return relative ess
          ``ress = ess / n``
      prob : float, or tuple of two floats, optional
          probability value for "tail", "quantile" or "local" ess functions.
      dask_kwargs : dict, optional
          Dask related kwargs passed to :func:`~arviz.wrap_xarray_ufunc`.
  
      Returns
      -------
      xarray.Dataset
          Return the effective sample size, :math:`\hat{N}_{eff}`
  
      Notes
      -----
      The basic ess (:math:`N_{\mathit{eff}}`) diagnostic is computed by:
  
      .. math:: \hat{N}_{\mathit{eff}} = \frac{MN}{\hat{\tau}}
  
      .. math:: \hat{\tau} = -1 + 2 \sum_{t'=0}^K \hat{P}_{t'}
  
      where :math:`M` is the number of chains, :math:`N` the number of draws,
      :math:`\hat{\rho}_t` is the estimated _autocorrelation at lag :math:`t`, and
      :math:`K` is the last integer for which :math:`\hat{P}_{K} = \hat{\rho}_{2K} +
      \hat{\rho}_{2K+1}` is still positive.
  
      The current implementation is similar to Stan, which uses Geyer's initial monotone sequence
      criterion (Geyer, 1992; Geyer, 2011).
  
      References
      ----------
      * Vehtari et al. (2019) see https://arxiv.org/abs/1903.08008
      * https://mc-stan.org/docs/2_18/reference-manual/effective-sample-size-section.html
        Section 15.4.2
      * Gelman et al. BDA (2014) Formula 11.8
  
      See Also
      --------
      arviz.rhat : Compute estimate of rank normalized splitR-hat for a set of traces.
      arviz.mcse : Calculate Markov Chain Standard Error statistic.
      plot_ess : Plot quantile, local or evolution of effective sample sizes (ESS).
      arviz.summary : Create a data frame with summary statistics.
  
      Examples
      --------
      Calculate the effective_sample_size using the default arguments:
  
      .. ipython::
  
          In [1]: import arviz as az
             ...: data = az.load_arviz_data('non_centered_eight')
             ...: az.ess(data)
  
      Calculate the ress of some of the variables
  
      .. ipython::
  
          In [1]: az.ess(data, relative=True, var_names=["mu", "theta_t"])
  
      Calculate the ess using the "tail" method, leaving the `prob` argument at its default
      value.
  
      .. ipython::
  
          In [1]: az.ess(data, method="tail")
  
      """
      methods = {
          "bulk": _ess_bulk,
          "tail": _ess_tail,
          "quantile": _ess_quantile,
          "mean": _ess_mean,
          "sd": _ess_sd,
          "median": _ess_median,
          "mad": _ess_mad,
          "z_scale": _ess_z_scale,
          "folded": _ess_folded,
          "identity": _ess_identity,
          "local": _ess_local,
      }
  
      if method not in methods:
          raise TypeError(
              f"ess method {method} not found. Valid methods are:\n{', '.join(methods)}"
          )
      ess_func = methods[method]
  
      if (method == "quantile") and prob is None:
          raise TypeError(
              "Quantile (prob) information needs to be defined."
          )
  
      if isinstance(data, np.ndarray):
          data = np.atleast_2d(data)
          if len(data.shape) < 3:
              if prob is not None:
                  return ess_func(  # pylint: disable=unexpected-keyword-arg
                      data, prob=prob, relative=relative
                  )
  
              return ess_func(data, relative=relative)
  
          msg = (
              "Only uni-dimensional ndarray variables are supported."
              " Please transform first to dataset with `az.convert_to_dataset`."
          )
          raise TypeError(msg)
  
      dataset = convert_to_dataset(data, group="posterior")
      var_names = _var_names(var_names, dataset)
  
      dataset = dataset if var_names is None else dataset[var_names]
  
      ufunc_kwargs = {"ravel": False}
      func_kwargs = (
          {"relative": relative}
          if prob is None
          else {"prob": prob, "relative": relative}
      )
      return _wrap_xarray_ufunc(
          ess_func,
          dataset,
          ufunc_kwargs=ufunc_kwargs,
          func_kwargs=func_kwargs,
          dask_kwargs=dask_kwargs,
      )
  
imports: import warnings
  from collections.abc import Sequence
  import numpy
  import packaging
  import pandas
  import scipy
  from scipy import stats
  from ..data import convert_to_dataset
  from ..utils import Numba, _numba_var, _stack, _var_names
  from .density_utils import histogram
  from .stats_utils import _circular_standard_deviation, _sqrt
  from .stats_utils import autocov
  from .stats_utils import not_valid
  from .stats_utils import quantile
  from .stats_utils import stats_variance_2d
  from .stats_utils import wrap_xarray_ufunc
label_desc: Use image node_id 2 for calling a global function with example usage: ess(data) and returns: _wrap_xarray_ufunc, ess_func, ess_func