code: def Ncomp_SVHT_MG_DLD_approx(X, zscore=True):
      
      beta = X.shape[0] / X.shape[1]
      if beta > 1:
          beta = 1 / beta
      omega = 0.56 * beta ** 3 - 0.95 * beta ** 2 + 1.82 * beta + 1.43
      if zscore:
          sing = np.linalg.svd(_zscore(X), False, False)
      else:
          sing = np.linalg.svd(X, False, False)
      thresh = omega * np.median(sing)
      ncomp = int(np.sum(np.logical_and(sing > thresh, np.logical_not(
          np.isclose(sing, thresh)))))
      # In the line above, we look for the singular values larger than
      # the threshold but excluding those that happen to be "just" larger
      # than the threshold by an amount close to the numerical precision.
      # This is to prevent close-to-zero singular values to be included if
      # the median of the eigenvalues is close to 0 (which could happen
      # when the input X has lower rank than its minimal size.
      return ncomp
docs: This function implements the approximate calculation of the
          optimal hard threshold for singular values, by Matan Gavish
          and David L. Donoho:
          "The optimal hard threshold for singular values is 4 / sqrt(3)"
          http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=6846297
  
      Parameters
      ----------
      X: 2-D numpy array of size [n_T, n_V]
          The data to estimate the optimal rank for selecting principal
          components.
      zscore: Boolean
          Whether to z-score the data before calculating number of components.
  
      Returns
      -------
      ncomp: integer
          The optimal number of components determined by the method of MG
          and DLD