code: def clip_spectrum(s, k, discard=0.001):
      """Find how many factors should be kept to avoid storing spurious (tiny, numerically unstable) values.
  
      Parameters
      ----------
      s : list of float
          Eigenvalues of the original matrix.
      k : int
          Maximum desired rank (number of factors)
      discard: float
          Percentage of the spectrum's energy to be discarded.
  
      Returns
      -------
      int
          Rank (number of factors) of the reduced matrix.
  
  
      """
      # compute relative contribution of eigenvalues towards the energy spectrum
      rel_spectrum = np.abs(1.0 - np.cumsum(s / np.sum(s)))
      # ignore the last `discard` mass (or 1/k, whichever is smaller) of the spectrum
      small = 1 + len(np.where(rel_spectrum > min(discard, 1.0 / k))[0])
      k = min(k, small)  # clip against k
      logger.info(
          "keeping %i factors (discarding %.3f%% of energy spectrum)",
          k,
          100 * rel_spectrum[k - 1],
      )
      return k
  
imports: import logging
  import sys
  import time
  import numpy
  import scipy.linalg
  import scipy.sparse
  from scipy.sparse import sparsetools
  from gensim import interfaces, matutils, utils
  from gensim.models import basemodel
  from gensim.utils import is_empty
label_desc: Use image node_id 1 for calling a global function with example usage: clip_spectrum(s, k, discard) and returns: k