code: def _compute_reg_neighbors(
      n_ch_x, n_delays, reg_type, method="direct", normed=False
  ):
      """Compute regularization parameter from neighbors."""
      known_types = ("ridge", "laplacian")
      if isinstance(reg_type, str):
          reg_type = (reg_type,) * 2
      if len(reg_type) != 2:
          raise ValueError(
              f"reg_type must have two elements, got {len(reg_type)}"
          )
      for r in reg_type:
          if r not in known_types:
              raise ValueError(
                  f"reg_type entries must be one of {known_types}, got {r}"
              )
      reg_time = reg_type[0] == "laplacian" and n_delays > 1
      reg_chs = reg_type[1] == "laplacian" and n_ch_x > 1
      if not reg_time and not reg_chs:
          return np.eye(n_ch_x * n_delays)
      # regularize time
      if reg_time:
          reg = np.eye(n_delays)
          stride = n_delays + 1
          reg.flat[1::stride] += -1
          reg.flat[n_delays::stride] += -1
          reg.flat[n_delays + 1 : -n_delays - 1 : stride] += 1
          args = [reg] * n_ch_x
          reg = linalg.block_diag(*args)
      else:
          reg = np.zeros((n_delays * n_ch_x,) * 2)
  
      # regularize features
      if reg_chs:
          block = n_delays * n_delays
          row_offset = block * n_ch_x
          stride = n_delays * n_ch_x + 1
          reg.flat[n_delays:-row_offset:stride] += -1
          reg.flat[n_delays + row_offset :: stride] += 1
          reg.flat[row_offset:-n_delays:stride] += -1
          reg.flat[: -(n_delays + row_offset) : stride] += 1
      assert np.array_equal(reg[::-1, ::-1], reg)
  
      if method == "direct":
          if normed:
              norm = np.sqrt(np.diag(reg))
              reg /= norm
              reg /= norm[:, np.newaxis]
          return reg
      else:
          # Use csgraph. Note that our -1's above are really the neighbors!
          # If we ever want to allow arbitrary adjacency matrices, this is how
          # we'd want to do it.
          reg = laplacian(-reg, normed=normed)
      return reg
  
imports: import numpy
  from scipy import linalg
  from scipy.signal import fftconvolve
  from scipy.sparse.csgraph import laplacian
  from ..cuda import _setup_cuda_fft_multiply_repeated
  from ..filter import next_fast_len
  from ..fixes import jit
  from ..utils import ProgressBar, _check_option, _validate_type, logger, warn
  from .base import BaseEstimator
label_desc: Use image node_id 4 for calling a global function with example usage: _compute_reg_neighbors(n_ch_x, n_delays, reg_type, method, normed) and returns: reg, np, reg