code: def _cjs_dist(draws, weights):
      """
      Calculate the cumulative Jensen-Shannon distance between original draws and weighted draws.
      """
  
      # sort draws and weights
      order = np.argsort(draws)
      draws = draws[order]
      weights = weights[order]
  
      binwidth = np.diff(draws)
  
      # ecdfs
      cdf_p = np.linspace(
          1 / len(draws), 1 - 1 / len(draws), len(draws) - 1
      )
      cdf_q = np.cumsum(weights / np.sum(weights))[:-1]
  
      # integrals of ecdfs
      cdf_p_int = np.dot(cdf_p, binwidth)
      cdf_q_int = np.dot(cdf_q, binwidth)
  
      # cjs calculation
      pq_numer = np.log2(
          cdf_p, out=np.zeros_like(cdf_p), where=cdf_p != 0
      )
      qp_numer = np.log2(
          cdf_q, out=np.zeros_like(cdf_q), where=cdf_q != 0
      )
  
      denom = 0.5 * (cdf_p + cdf_q)
      denom = np.log2(denom, out=np.zeros_like(denom), where=denom != 0)
  
      cjs_pq = np.sum(
          binwidth * (cdf_p * (pq_numer - denom))
      ) + 0.5 / np.log(2) * (cdf_q_int - cdf_p_int)
  
      cjs_qp = np.sum(
          binwidth * (cdf_q * (qp_numer - denom))
      ) + 0.5 / np.log(2) * (cdf_p_int - cdf_q_int)
  
      cjs_pq = max(0, cjs_pq)
      cjs_qp = max(0, cjs_qp)
  
      bound = cdf_p_int + cdf_q_int
  
      return np.sqrt((cjs_pq + cjs_qp) / bound)
  
imports: import itertools
  import warnings
  from copy import deepcopy
  from typing import List, Optional, Tuple, Union, Mapping, cast, Callable
  import numpy
  import pandas
  import scipy.stats
  from xarray_einstats import stats
  import xarray
  from scipy.optimize import minimize
  from typing_extensions import Literal
  from ..None import _log
  from ..data import InferenceData, convert_to_dataset, convert_to_inference_data, extract
  from ..rcparams import rcParams, ScaleKeyword, ICKeyword
  from ..utils import Numba, _numba_var, _var_names, get_coords
  from .density_utils import get_bins
  from .density_utils import histogram
  from .density_utils import kde
  from .diagnostics import _mc_error, _multichain_statistics, ess
  from .stats_utils import ELPDData, _circular_standard_deviation, smooth_data
  from .stats_utils import get_log_likelihood
  from .stats_utils import get_log_prior
  from .stats_utils import logsumexp
  from .stats_utils import make_ufunc
  from .stats_utils import stats_variance_2d
  from .stats_utils import wrap_xarray_ufunc
  from ..sel_utils import xarray_var_iter
  from ..labels import BaseLabeller
label_desc: Use image node_id 23 for calling a global function with example usage: _cjs_dist(draws, weights) and returns: np