code: def two_point(
      data, bins, method="standard", data_R=None, random_state=None
  ):
      """Two-point correlation function
  
      Parameters
      ----------
      data : array_like
          input data, shape = [n_samples, n_features]
      bins : array_like
          bins within which to compute the 2-point correlation.
          shape = Nbins + 1
      method : string
          "standard" or "landy-szalay".
      data_R : array_like (optional)
          if specified, use this as the random comparison sample
      random_state : integer, np.random.RandomState, or None
          specify the random state to use for generating background
  
      Returns
      -------
      corr : ndarray
          the estimate of the correlation function within each bin
          shape = Nbins
      """
      data = np.asarray(data)
      bins = np.asarray(bins)
      rng = check_random_state(random_state)
  
      if method not in ["standard", "landy-szalay"]:
          raise ValueError(
              "method must be 'standard' or 'landy-szalay'"
          )
  
      if bins.ndim != 1:
          raise ValueError("bins must be a 1D array")
  
      if data.ndim == 1:
          data = data[:, np.newaxis]
      elif data.ndim != 2:
          raise ValueError("data should be 1D or 2D")
  
      n_samples, n_features = data.shape
  
      # shuffle all but one axis to get background distribution
      if data_R is None:
          data_R = data.copy()
          for i in range(n_features - 1):
              rng.shuffle(data_R[:, i])
      else:
          data_R = np.asarray(data_R)
          if (data_R.ndim != 2) or (data_R.shape[-1] != n_features):
              raise ValueError(
                  "data_R must have same n_features as data"
              )
  
      factor = len(data_R) * 1.0 / len(data)
  
      # Fast two-point correlation functions added in scikit-learn v. 0.14
      KDT_D = KDTree(data)
      KDT_R = KDTree(data_R)
  
      counts_DD = KDT_D.two_point_correlation(data, bins)
      counts_RR = KDT_R.two_point_correlation(data_R, bins)
  
      DD = np.diff(counts_DD)
      RR = np.diff(counts_RR)
  
      # check for zero in the denominator
      RR_zero = RR == 0
      RR[RR_zero] = 1
  
      if method == "standard":
          corr = factor**2 * DD / RR - 1
      elif method == "landy-szalay":
          counts_DR = KDT_R.two_point_correlation(data, bins)
  
          DR = np.diff(counts_DR)
  
          corr = (factor**2 * DD - 2 * factor * DR + RR) / RR
  
      corr[RR_zero] = np.nan
  
      return corr
  
file_path: astroML/astroML/correlation.py
imports: import numpy
  from sklearn.neighbors import KDTree
  from sklearn.utils import check_random_state
label_desc: Use image node_id 4 for calling a global function with example usage: two_point(data, bins, method, data_R, random_state) and returns: corr