class_docstr: Probabilistic Shared Response Model (SRM)
  
  Given multi-subject data, factorize it as a shared response S among all
  subjects and an orthogonal transform W per subject:
  
  .. math:: X_i \approx W_i S, \forall i=1 \dots N
  
  Parameters
  ----------
  
  n_iter : int, default: 10
      Number of iterations to run the algorithm.
  
  features : int, default: 50
      Number of features to compute.
  
  rand_seed : int, default: 0
      Seed for initializing the random number generator.
  
  
  Attributes
  ----------
  
  w_ : list of array, element i has shape=[voxels_i, features]
      The orthogonal transforms (mappings) for each subject.
  
  s_ : array, shape=[features, samples]
      The shared response.
  
  sigma_s_ : array, shape=[features, features]
      The covariance of the shared response Normal distribution.
  
  mu_ : list of array, element i has shape=[voxels_i]
      The voxel means over the samples for each subject.
  
  rho2_ : array, shape=[subjects]
      The estimated noise variance :math:`\rho_i^2` for each subject
  
  
  Note
  ----
  
     The number of voxels may be different between subjects. However, the
     number of samples must be the same across subjects.
  
     The probabilistic Shared Response Model is approximated using the
     Expectation Maximization (EM) algorithm proposed in [Chen2015]_. The
     implementation follows the optimizations published in [Anderson2016]_.
  
     This is a single node version.
  
     The run-time complexity is :math:`O(I (V T K + V K^2 + K^3))` and the
     memory complexity is :math:`O(V T)` with I - the number of iterations,
     V - the sum of voxels from all subjects, T - the number of samples, and
     K - the number of features (typically, :math:`V \gg T \gg K`).
class_docstr_tok: ["Probabilistic","Shared","Response","Model","(","SRM",")","Given","multi-subject","data",",","factorize","it","as","a","shared","response","S","among","all","subjects","and","an","orthogonal","transform","W","per","subject",":","..","math",":",":","X_i","\\approx","W_i","S",",","\\forall","i=1","\\dots","N","Parameters","--","--","--","--","--","n_iter",":","int",",","default",":","10","Number","of","iterations","to","run","the","algorithm",".","features",":","int",",","default",":","50","Number","of","features","to","compute",".","rand_seed",":","int",",","default",":","0","Seed","for","initializing","the","random","number","generator",".","Attributes","--","--","--","--","--","w_",":","list","of","array",",","element","i","has","shape=","[","voxels_i",",","features","]","The","orthogonal","transforms","(","mappings",")","for","each","subject",".","s_",":","array",",","shape=","[","features",",","samples","]","The","shared","response",".","sigma_s_",":","array",",","shape=","[","features",",","features","]","The","covariance","of","the","shared","response","Normal","distribution",".","mu_",":","list","of","array",",","element","i","has","shape=","[","voxels_i","]","The","voxel","means","over","the","samples","for","each","subject",".","rho2_",":","array",",","shape=","[","subjects","]","The","estimated","noise","variance",":","math",":","`","\\rho_i^2","`","for","each","subject","Note","--","--","The","number","of","voxels","may","be","different","between","subjects",".","However",",","the","number","of","samples","must","be","the","same","across","subjects",".","The","probabilistic","Shared","Response","Model","is","approximated","using","the","Expectation","Maximization","(","EM",")","algorithm","proposed","in","[","Chen2015","]","_",".","The","implementation","follows","the","optimizations","published","in","[","Anderson2016","]","_",".","This","is","a","single","node","version",".","The","run-time","complexity","is",":","math",":","`","O","(","I","(","V","T","K","+","V","K^2","+","K^3",")",")","`","and","the","memory","complexity","is",":","math",":","`","O","(","V","T",")","`","with","I","-","the","number","of","iterations",",","V","-","the","sum","of","voxels","from","all","subjects",",","T","-","the","number","of","samples",",","and","K","-","the","number","of","features","(","typically",",",":","math",":","`","V","\\gg","T","\\gg","K","`",")","."]
docstr: Calculate the log-likelihood function
  
  
  Parameters
  ----------
  
  chol_sigma_s_rhos : array, shape=[features, features]
      Cholesky factorization of the matrix (Sigma_S + sum_i(1/rho_i^2)
      * I)
  
  log_det_psi : float
      Determinant of diagonal matrix Psi (containing the rho_i^2 value
      voxels_i times).
  
  chol_sigma_s : array, shape=[features, features]
      Cholesky factorization of the matrix Sigma_S
  
  trace_xt_invsigma2_x : float
      Trace of :math:`\sum_i (||X_i||_F^2/\rho_i^2)`
  
  inv_sigma_s_rhos : array, shape=[features, features]
      Inverse of :math:`(\Sigma_S + \sum_i(1/\rho_i^2) * I)`
  
  wt_invpsi_x : array, shape=[features, samples]
  
  samples : int
      The total number of samples in the data.
  
  
  Returns
  -------
  
  loglikehood : float
      The log-likelihood value.
docstr_tok: ["Calculate","the","log-likelihood","function","Parameters","--","--","--","--","--","chol_sigma_s_rhos",":","array",",","shape=","[","features",",","features","]","Cholesky","factorization","of","the","matrix","(","Sigma_S","+","sum_i","(","1\/rho_i^2",")","*","I",")","log_det_psi",":","float","Determinant","of","diagonal","matrix","Psi","(","containing","the","rho_i^2","value","voxels_i","times",")",".","chol_sigma_s",":","array",",","shape=","[","features",",","features","]","Cholesky","factorization","of","the","matrix","Sigma_S","trace_xt_invsigma2_x",":","float","Trace","of",":","math",":","`","\\sum_i","(","||X_i||_F^2\/\\rho_i^2",")","`","inv_sigma_s_rhos",":","array",",","shape=","[","features",",","features","]","Inverse","of",":","math",":","`","(","\\Sigma_S","+","\\sum_i","(","1\/\\rho_i^2",")","*","I",")","`","wt_invpsi_x",":","array",",","shape=","[","features",",","samples","]","samples",":","int","The","total","number","of","samples","in","the","data",".","Returns","--","--","--","-","loglikehood",":","float","The","log-likelihood","value","."]
code: def _likelihood(
      self,
      chol_sigma_s_rhos,
      log_det_psi,
      chol_sigma_s,
      trace_xt_invsigma2_x,
      inv_sigma_s_rhos,
      wt_invpsi_x,
      samples,
  ):
      """Calculate the log-likelihood function
  
  
      Parameters
      ----------
  
      chol_sigma_s_rhos : array, shape=[features, features]
          Cholesky factorization of the matrix (Sigma_S + sum_i(1/rho_i^2)
          * I)
  
      log_det_psi : float
          Determinant of diagonal matrix Psi (containing the rho_i^2 value
          voxels_i times).
  
      chol_sigma_s : array, shape=[features, features]
          Cholesky factorization of the matrix Sigma_S
  
      trace_xt_invsigma2_x : float
          Trace of :math:`\\sum_i (||X_i||_F^2/\\rho_i^2)`
  
      inv_sigma_s_rhos : array, shape=[features, features]
          Inverse of :math:`(\\Sigma_S + \\sum_i(1/\\rho_i^2) * I)`
  
      wt_invpsi_x : array, shape=[features, samples]
  
      samples : int
          The total number of samples in the data.
  
  
      Returns
      -------
  
      loglikehood : float
          The log-likelihood value.
      """
      log_det = (
          np.log(np.diag(chol_sigma_s_rhos) ** 2).sum()
          + log_det_psi
          + np.log(np.diag(chol_sigma_s) ** 2).sum()
      )
      loglikehood = (
          -0.5 * samples * log_det - 0.5 * trace_xt_invsigma2_x
      )
      loglikehood += 0.5 * np.trace(
          wt_invpsi_x.T.dot(inv_sigma_s_rhos).dot(wt_invpsi_x)
      )
      # + const --> -0.5*nTR*nvoxel*subjects*math.log(2*math.pi)
  
      return loglikehood
  
imports: import logging
  import numpy
  import scipy
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.utils import assert_all_finite
  from sklearn.utils.validation import NotFittedError
label_desc: Use image node_id 5 for calling the SRM obj's underlying member method code with example usage: obj._likelihood(chol_sigma_s_rhos, log_det_psi, chol_sigma_s, trace_xt_invsigma2_x, inv_sigma_s_rhos, wt_invpsi_x, samples) and returns: loglikehood