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,
          The 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(np.pi) * (n_features - i) / 2.0
          )
  
      pl = np.sum(np.log(spectrum[:rank]))
      pl = -pl * n_samples / 2.0
  
      if rank == n_features:
          pv = 0
          v = 1
      else:
          v = np.sum(spectrum[rank:]) / (n_features - rank)
          pv = -np.log(v) * n_samples * (n_features - rank) / 2.0
  
      m = n_features * rank - rank * (rank + 1.0) / 2.0
      pp = log(2.0 * np.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: from math import log, sqrt
  import numpy
  from scipy import linalg
  from scipy.special import gammaln
  from scipy.sparse import issparse
  from ..externals import six
  from .base import _BasePCA
  from ..base import BaseEstimator, TransformerMixin
  from ..utils import deprecated
  from ..utils import check_random_state, as_float_array
  from ..utils import check_array
  from ..utils.extmath import fast_dot, fast_logdet, randomized_svd, svd_flip
  from ..utils.validation import check_is_fitted
  from ..utils.arpack import svds
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