code: def _rit(
      X: np.ndarray,
      Y: np.ndarray,
      num_random_features_X: int,
      num_random_features_Y: int,
      num_permutations: int,
      num_runs: int,
      num_max_samples_per_run: int,
      approx_kernel: Callable[[np.ndarray, int], np.ndarray],
      scale_data: bool,
      n_jobs: Optional[int],
      p_value_adjust_func: Callable[
          [Union[np.ndarray, List[float]]], float
      ],
  ) -> float:
      """Implementation of the Randomized Independence Test based on the work:
      Strobl, Eric V., Kun Zhang, and Shyam Visweswaran.
      Approximate kernel-based conditional independence tests for fast non-parametric causal discovery.
      Journal of Causal Inference 7.1 (2019).
      """
      n_jobs = config.default_n_jobs if n_jobs is None else n_jobs
  
      X, Y = _convert_to_numeric(*shape_into_2d(X, Y))
  
      if scale_data:
          X = scale(X)
          Y = scale(Y)
  
      def evaluate_rit_on_samples(parallel_random_seed: int):
          set_random_seed(parallel_random_seed)
  
          if X.shape[0] > num_max_samples_per_run:
              random_indices = np.random.choice(
                  X.shape[0], num_max_samples_per_run, replace=False
              )
              X_samples = X[random_indices]
              Y_samples = Y[random_indices]
          else:
              X_samples = X
              Y_samples = Y
  
          random_features_x = scale(
              approx_kernel(X_samples, num_random_features_X)
          )
          random_features_y = scale(
              approx_kernel(Y_samples, num_random_features_Y)
          )
  
          permutation_results_of_statistic = []
          for i in range(num_permutations):
              permutation_results_of_statistic.append(
                  _estimate_rit_statistic(
                      random_features_x[
                          np.random.choice(
                              random_features_x.shape[0],
                              random_features_x.shape[0],
                              replace=False,
                          )
                      ],
                      random_features_y,
                  )
              )
  
          return 1 - (
              np.sum(
                  _estimate_rit_statistic(
                      random_features_x, random_features_y
                  )
                  > permutation_results_of_statistic
              )
              / len(permutation_results_of_statistic)
          )
  
      random_seeds = np.random.randint(
          np.iinfo(np.int32).max, size=num_runs
      )
      p_values = Parallel(n_jobs=n_jobs)(
          delayed(evaluate_rit_on_samples)(int(random_seeds[i]))
          for i in range(num_runs)
      )
  
      return p_value_adjust_func(p_values)
  
file_path: dowhy/dowhy/gcm/independence_test/kernel.py
imports: from typing import Callable, List, Optional, Union
  import numpy
  import scipy
  from causallearn.utils.KCI.KCI import KCI_CInd, KCI_UInd
  from joblib import Parallel, delayed
  from sklearn.preprocessing import scale
  import dowhy.gcm.config
  from dowhy.gcm.independence_test.kernel_operation import approximate_rbf_kernel_features
  from dowhy.gcm.stats import quantile_based_fwer
  from dowhy.gcm.util.general import auto_apply_encoders, auto_fit_encoders, set_random_seed, shape_into_2d
label_desc: Use image node_id 3 for calling a global function with example usage: _rit(X, Y, num_random_features_X, num_random_features_Y, num_permutations, num_runs, num_max_samples_per_run, approx_kernel, scale_data, n_jobs, p_value_adjust_func) and returns: p_value_adjust_func, unknown