code: def power_iteration(
      tensor, n_repeat=10, n_iteration=10, verbose=False
  ):
      """A single Robust Tensor Power Iteration
  
      Parameters
      ----------
      tensor : tl.tensor
          input tensor to decompose
      n_repeat : int, default is 10
          number of initializations to be tried
      n_iteration : int, default is 10
          number of power iterations
      verbose : bool
          level of verbosity
  
      Returns
      -------
      (eigenval, best_factor, deflated)
  
      eigenval : float
          the obtained eigenvalue
      best_factors : tl.tensor list
          the best estimated eigenvector, for each mode of the input tensor
      deflated : tl.tensor of same shape as `tensor`
          the deflated tensor (i.e. without the estimated component)
      """
      order = tl.ndim(tensor)
  
      # A list of candidates for each mode
      scores = []
  
      for i in range(n_repeat):
          factors = [
              tl.tensor(
                  np.random.random_sample(s), **tl.context(tensor)
              )
              for s in tl.shape(tensor)
          ]
  
          for _ in range(n_iteration):
              for mode in range(order):
                  factor = tl.tenalg.multi_mode_dot(
                      tensor, factors, skip=mode
                  )
                  factor = factor / tl.norm(factor, 2)
                  factors[mode] = factor
  
          score = tl.tenalg.multi_mode_dot(tensor, factors)
          scores.append(score)  # round(score, 2))
  
          if (i == 0) or (score > best_score):
              best_score = score
              best_factors = factors
  
      if verbose:
          print(f"Best score of {n_repeat}: {best_score}")
  
      # Refine the init
      for _ in range(n_iteration):
          for mode in range(order):
              factor = tl.tenalg.multi_mode_dot(
                  tensor, best_factors, skip=mode
              )
              factor = factor / tl.norm(factor, 2)
              best_factors[mode] = factor
  
      eigenval = tl.tenalg.multi_mode_dot(tensor, best_factors)
      deflated = tensor - outer(best_factors) * eigenval
  
      if verbose:
          explained = tl.norm(deflated) / tl.norm(tensor)
          print(f"Eigenvalue: {eigenval}, explained: {explained}")
  
      return eigenval, best_factors, deflated
  
file_path: tensorly/tensorly/decomposition/_cp_power.py
imports: import tensorly
  from ._base_decomposition import DecompositionMixin
  from ..cp_tensor import validate_cp_rank
  from tensorly.tenalg import outer
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: power_iteration(tensor, n_repeat, n_iteration, verbose) and returns: eigenval,  best_factors,  deflated