class_docstr: This analysis allows maximum likelihood estimation of regression models
  in the presence of both spatial and temporal covariance.
  
  ..math::
      Y \sim \mathcal{MN}(Xeta, time_cov, space_cov)
  
  Parameters
  ----------
  time_cov : subclass of CovBase
      TR noise covariance class following CovBase interface.
  space_cov : subclass of CovBase
      Voxel noise covariance class following CovBase interface.
  optimizer : string, default="L-BFGS-B"
      Scipy optimizer to use. For other options, see "method" argument
      of scipy.optimize.minimize
  optCtrl: dict, default=None
      Additional arguments to pass to scipy.optimize.minimize.
class_docstr_tok: ["This","analysis","allows","maximum","likelihood","estimation","of","regression","models","in","the","presence","of","both","spatial","and","temporal","covariance",".","..","math",":",":","Y","\\sim","\\mathcal","{","MN","}","(","X\beta",",","time_cov",",","space_cov",")","Parameters","--","--","--","--","--","time_cov",":","subclass","of","CovBase","TR","noise","covariance","class","following","CovBase","interface",".","space_cov",":","subclass","of","CovBase","Voxel","noise","covariance","class","following","CovBase","interface",".","optimizer",":","string",",","default=","''","L-BFGS-B","''","Scipy","optimizer","to","use",".","For","other","options",",","see","``","method","''","argument","of","scipy.optimize.minimize","optCtrl",":","dict",",","default=None","Additional","arguments","to","pass","to","scipy.optimize.minimize","."]
docstr: Compute the regression fit.
  
  Parameters
  ----------
  X : np.array, TRs by conditions.
      Design matrix
  y : np.array, TRs by voxels.
      fMRI data
docstr_tok: ["Compute","the","regression","fit",".","Parameters","--","--","--","--","--","X",":","np.array",",","TRs","by","conditions",".","Design","matrix","y",":","np.array",",","TRs","by","voxels",".","fMRI","data"]
code: def fit(self, X, y, naive_init=True):
      """Compute the regression fit.
  
      Parameters
      ----------
      X : np.array, TRs by conditions.
          Design matrix
      y : np.array, TRs by voxels.
          fMRI data
      """
  
      self.n_c = X.shape[1]
  
      if naive_init:
          # initialize to the least squares solution (basically all
          # we need now is the cov)
          sigma_inv_x = self.time_cov.solve(X)
          sigma_inv_y = self.time_cov.solve(y)
  
          beta_init = np.linalg.solve(
              (X.T).dot(sigma_inv_x), (X.T).dot(sigma_inv_y)
          )
  
      else:
          beta_init = np.random.randn(self.n_c, self.n_v)
  
      self.beta = tf.Variable(beta_init, name="beta")
  
      self.train_variables = [self.beta]
      self.train_variables.extend(self.time_cov.get_optimize_vars())
      self.train_variables.extend(self.space_cov.get_optimize_vars())
  
      def lossfn(theta):
          return -self.logp(X, y)
  
      val_and_grad = make_val_and_grad(lossfn, self.train_variables)
      x0 = pack_trainable_vars(self.train_variables)
  
      opt_results = minimize(
          fun=val_and_grad,
          x0=x0,
          jac=True,
          method=self.optMethod,
          **self.optCtrl,
      )
  
      unpacked_theta = unpack_trainable_vars(
          opt_results.x, self.train_variables
      )
  
      for var, val in zip(self.train_variables, unpacked_theta):
          var.assign(val)
  
      self.beta_ = self.beta.numpy()
  
file_path: brainiak/brainiak/matnormal/regression.py
imports: import tensorflow
  import numpy
  from sklearn.base import BaseEstimator
  from brainiak.matnormal.matnormal_likelihoods import matnorm_logp
  from brainiak.matnormal.utils import pack_trainable_vars, unpack_trainable_vars, make_val_and_grad
  from scipy.optimize import minimize
label_desc: Use image node_id 3 for calling the MatnormalRegression obj's underlying member method code with example usage: obj.fit(X, y, naive_init) and returns: unknown