code: def _bw_isj(x, grid_counts=None, x_std=None, x_range=None):
      """Improved Sheather-Jones bandwidth estimation.
  
      Improved Sheather and Jones method as explained in [1]_. This method is used internally by the
      KDE estimator, resulting in saved computation time as minimums, maximums and the grid are
      pre-computed.
  
      References
      ----------
      .. [1] Kernel density estimation via diffusion.
         Z. I. Botev, J. F. Grotowski, and D. P. Kroese.
         Ann. Statist. 38 (2010), no. 5, 2916--2957.
      """
      x_len = len(x)
      if x_range is None:
          x_min = np.min(x)
          x_max = np.max(x)
          x_range = x_max - x_min
  
      # Relative frequency per bin
      if grid_counts is None:
          x_std = np.std(x)
          grid_len = 256
          grid_min = x_min - 0.5 * x_std
          grid_max = x_max + 0.5 * x_std
          grid_counts, _, _ = histogram(
              x, grid_len, (grid_min, grid_max)
          )
      else:
          grid_len = len(grid_counts) - 1
  
      grid_relfreq = grid_counts / x_len
  
      # Discrete cosine transform of the data
      a_k = _dct1d(grid_relfreq)
  
      k_sq = np.arange(1, grid_len) ** 2
      a_sq = a_k[range(1, grid_len)] ** 2
  
      t = _root(_fixed_point, x_len, args=(x_len, k_sq, a_sq), x=x)
      h = t**0.5 * x_range
      return h
  
imports: import warnings
  import numpy
  from scipy.fftpack import fft
  from scipy.optimize import brentq
  from scipy.signal import convolve, convolve2d, gaussian
  from scipy.sparse import coo_matrix
  from scipy.special import ive
  from ..utils import _cov, _dot, _stack, conditional_jit
label_desc: Use image node_id 3 for calling a global function with example usage: _bw_isj(x, grid_counts, x_std, x_range) and returns: h