code: def _fit_tfa(self, data, R, template_prior=None):
          
          if template_prior is None:
              template_centers = None
              template_widths = None
              template_centers_mean_cov = None
              template_widths_mean_var_reci = None
          else:
              template_centers = self.get_centers(template_prior)
              template_widths = self.get_widths(template_prior)
              template_centers_mean_cov =\
                  self.get_centers_mean_cov(template_prior)
              template_widths_mean_var_reci = 1.0 /\
                  self.get_widths_mean_var(template_prior)
          inner_converged = False
          np.random.seed(self.seed)
          n = 0
          while n < self.miter and not inner_converged:
              self._fit_tfa_inner(
                  data,
                  R,
                  template_centers,
                  template_widths,
                  template_centers_mean_cov,
                  template_widths_mean_var_reci)
              self._assign_posterior()
              inner_converged, _ = self._converged()
              if not inner_converged:
                  self.local_prior = self.local_posterior_
              else:
                  logger.info("TFA converged at %d iteration." % (n))
              n += 1
              gc.collect()
          return self
docs: TFA main algorithm
  
          Parameters
          ----------
  
          data: 2D array, in shape [n_voxel, n_tr]
              The fMRI data from one subject.
  
          R : 2D array, in shape [n_voxel, n_dim]
              The voxel coordinate matrix of fMRI data
  
          template_prior : 1D array,
              The template prior on centers and widths.
  
  
          Returns
          -------
          TFA
              Returns the instance itself.