code: def _assess_dimension_(spectrum, rank, n_samples, n_features):
      from scipy.special import gammaln
  
      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: import inspect
  import operator
  import os
  import warnings
  from contextlib import contextmanager
  from io import StringIO
  from math import log
  from pprint import pprint
  import numpy
label_desc: Use image node_id 13 for calling a global function with example usage: _assess_dimension_(spectrum, rank, n_samples, n_features) and returns: ll