code: def _assess_dimension_(spectrum, rank, n_samples, n_features):
      """Compute the likelihood of a rank ``rank`` dataset.
  
      The dataset is assumed to be embedded in gaussian noise of shape(n,
      dimf) having spectrum ``spectrum``.
  
      Parameters
      ----------
      spectrum : array of shape (n)
          Data spectrum.
      rank : int
          Tested rank value.
      n_samples : int
          Number of samples.
      n_features : int
          Number of features.
  
      Returns
      -------
      ll : float
          Log-likelihood.
  
      Notes
      -----
      This implements the method of `Thomas P. Minka:
      Automatic Choice of Dimensionality for PCA. NIPS 2000: 598-604`
      """
      if rank > len(spectrum):
          raise ValueError(
              "The tested rank cannot exceed the rank of the dataset"
          )
  
      pu = -rank * log(2.0)
      for i in range(rank):
          pu += (
              gammaln((n_features - i) / 2.0)
              - log(gs.pi) * (n_features - i) / 2.0
          )
  
      pl = gs.sum(gs.log(spectrum[:rank]))
      pl = -pl * n_samples / 2.0
  
      if rank == n_features:
          pv = 0
          v = 1
      else:
          v = gs.sum(spectrum[rank:]) / (n_features - rank)
          pv = -gs.log(v) * n_samples * (n_features - rank) / 2.0
  
      m = n_features * rank - rank * (rank + 1.0) / 2.0
      pp = log(2.0 * gs.pi) * (m + rank + 1.0) / 2.0
  
      pa = 0.0
      spectrum_ = spectrum.copy()
      spectrum_[rank:n_features] = v
      for i in range(rank):
          for j in range(i + 1, len(spectrum)):
              pa += log(
                  (spectrum[i] - spectrum[j])
                  * (1.0 / spectrum_[j] - 1.0 / spectrum_[i])
              ) + log(n_samples)
  
      ll = pu + pl + pv + pp - pa / 2.0 - rank * log(n_samples) / 2.0
  
      return ll
  
imports: import numbers
  from math import log
  from scipy.special import gammaln
  from sklearn.decomposition._base import _BasePCA
  from sklearn.utils.extmath import stable_cumsum, svd_flip
  import geomstats.backend
  from geomstats.geometry.matrices import Matrices
  from geomstats.geometry.symmetric_matrices import SymmetricMatrices
  from geomstats.learning.exponential_barycenter import ExponentialBarycenter
  from geomstats.learning.frechet_mean import FrechetMean
label_desc: Use image node_id 1 for calling a global function with example usage: _assess_dimension_(spectrum, rank, n_samples, n_features) and returns: ll