class_docstr: Hierarchical Topographical Factor Analysis (HTFA)
  
  Given multi-subject data, HTFA factorizes data from each subject as a
  spatial factor F and a weight matrix W per subject. Also at top
  level, it estimates global template across subjects:
  
  
  Parameters
  ----------
  
  K : int
      Number of factors to compute.
  
  n_subj : int
      Total number of subjects in dataset.
  
  max_global_iter : int, default: 10
      Number of global iterations to run the algorithm.
  
  max_local_iter : int, default: 10
      Number of local iterations to run on each subject within each
      global interation.
  
  threshold : float, default: 1.0
      Tolerance for terminate the parameter estimation
  
  nlss_method : {'trf', 'dogbox', 'lm'}, default: 'trf'
      Non-Linear Least Square (NLSS) algorithm used by scipy.least_suqares to
      perform minimization. More information at
      http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.optimize.least_squares.html
  
  nlss_loss: str or callable, default: 'linear'
      Loss function used by scipy.least_squares.
      More information at
      http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.optimize.least_squares.html
  
  jac : {'2-point', '3-point', 'cs', callable}, default: '2-point'
      Method of computing the Jacobian matrix.
      More information at
      http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.optimize.least_squares.html
  
  x_scale : float or array_like or 'jac', default: 1.0
      Characteristic scale of each variable for scipy.least_suqares.
      More information at
      http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.optimize.least_squares.html
  
  tr_solver: {None, 'exact', 'lsmr'}, default: None
      Method for solving trust-region subproblems, relevant only for 'trf'
      and 'dogbox' methods.
      More information at
      http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.optimize.least_squares.html
  
  weight_method : {'rr','ols'}, default: 'rr'
      Method for estimating weight matrix W given X and F.
      'rr' means ridge regression, 'ols' means ordinary least square.
  
  upper_ratio : float, default: 1.8
      The upper bound of the ratio between factor's width and brain diameter.
  
  lower_ratio : float, default: 0.02
      The lower bound of the ratio between factor's width and brain diameter.
  
  voxel_ratio : float, default: 0.25
      The percentage of voxels to sample in each inner iteration.
  
  tr_ratio : float, default: 0.1
      The percentage of trs to sample in each inner iteration.
  
  max_voxel : int, default: 5000
      The maximum number of voxels to sample in each inner iteration.
  
  max_tr : int, default: 500
      The maximum number of trs to sample in each inner iteration.
  
  comm : Intracomm
      MPI communication group, default MPI.COMM_WORLD
  
  verbose : boolean, default: False
      Verbose mode flag.
  
  
  Attributes
  ----------
  global_prior_ : 1D array
      The global prior on mean and variance of centers and widths.
  
  global_posterior_ : 1D array
      The global posterior on mean and variance of centers and widths.
  
  local_posterior_ : 1D array
      Local posterior on centers and widths of subjects allocated
      to this process.
  
  local_weights_ : 1D array
      Local posterior on weights allocated to this process.
  
  
  Notes
  -----
  We recommend to use data in MNI space to better interpret global template
class_docstr_tok: ["Hierarchical","Topographical","Factor","Analysis","(","HTFA",")","Given","multi-subject","data",",","HTFA","factorizes","data","from","each","subject","as","a","spatial","factor","F","and","a","weight","matrix","W","per","subject",".","Also","at","top","level",",","it","estimates","global","template","across","subjects",":","Parameters","--","--","--","--","--","K",":","int","Number","of","factors","to","compute",".","n_subj",":","int","Total","number","of","subjects","in","dataset",".","max_global_iter",":","int",",","default",":","10","Number","of","global","iterations","to","run","the","algorithm",".","max_local_iter",":","int",",","default",":","10","Number","of","local","iterations","to","run","on","each","subject","within","each","global","interation",".","threshold",":","float",",","default",":","1.0","Tolerance","for","terminate","the","parameter","estimation","nlss_method",":","{","'trf","'",",","'dogbox","'",",","'lm","'","}",",","default",":","'trf'","Non-Linear","Least","Square","(","NLSS",")","algorithm","used","by","scipy.least_suqares","to","perform","minimization",".","More","information","at","http",":","\/\/docs.scipy.org\/doc\/scipy-0.17.0\/reference\/generated\/scipy.optimize.least_squares.html","nlss_loss",":","str","or","callable",",","default",":","'linear'","Loss","function","used","by","scipy.least_squares",".","More","information","at","http",":","\/\/docs.scipy.org\/doc\/scipy-0.17.0\/reference\/generated\/scipy.optimize.least_squares.html","jac",":","{","'","2-point","'",",","'","3-point","'",",","'cs","'",",","callable","}",",","default",":","'","2-point'","Method","of","computing","the","Jacobian","matrix",".","More","information","at","http",":","\/\/docs.scipy.org\/doc\/scipy-0.17.0\/reference\/generated\/scipy.optimize.least_squares.html","x_scale",":","float","or","array_like","or","'jac","'",",","default",":","1.0","Characteristic","scale","of","each","variable","for","scipy.least_suqares",".","More","information","at","http",":","\/\/docs.scipy.org\/doc\/scipy-0.17.0\/reference\/generated\/scipy.optimize.least_squares.html","tr_solver",":","{","None",",","'exact","'",",","'lsmr","'","}",",","default",":","None","Method","for","solving","trust-region","subproblems",",","relevant","only","for","'trf'","and","'dogbox","'","methods",".","More","information","at","http",":","\/\/docs.scipy.org\/doc\/scipy-0.17.0\/reference\/generated\/scipy.optimize.least_squares.html","weight_method",":","{","'rr","'",",","'ols","'","}",",","default",":","'rr'","Method","for","estimating","weight","matrix","W","given","X","and","F.","'rr","'","means","ridge","regression",",","'ols","'","means","ordinary","least","square",".","upper_ratio",":","float",",","default",":","1.8","The","upper","bound","of","the","ratio","between","factor","'s","width","and","brain","diameter",".","lower_ratio",":","float",",","default",":","0.02","The","lower","bound","of","the","ratio","between","factor","'s","width","and","brain","diameter",".","voxel_ratio",":","float",",","default",":","0.25","The","percentage","of","voxels","to","sample","in","each","inner","iteration",".","tr_ratio",":","float",",","default",":","0.1","The","percentage","of","trs","to","sample","in","each","inner","iteration",".","max_voxel",":","int",",","default",":","5000","The","maximum","number","of","voxels","to","sample","in","each","inner","iteration",".","max_tr",":","int",",","default",":","500","The","maximum","number","of","trs","to","sample","in","each","inner","iteration",".","comm",":","Intracomm","MPI","communication","group",",","default","MPI.COMM_WORLD","verbose",":","boolean",",","default",":","False","Verbose","mode","flag",".","Attributes","--","--","--","--","--","global_prior_",":","1D","array","The","global","prior","on","mean","and","variance","of","centers","and","widths",".","global_posterior_",":","1D","array","The","global","posterior","on","mean","and","variance","of","centers","and","widths",".","local_posterior_",":","1D","array","Local","posterior","on","centers","and","widths","of","subjects","allocated","to","this","process",".","local_weights_",":","1D","array","Local","posterior","on","weights","allocated","to","this","process",".","Notes","--","--","-","We","recommend","to","use","data","in","MNI","space","to","better","interpret","global","template"]
docstr: Check convergence based on mean squared difference between
      prior and posterior
  
  Returns
  -------
  
  converged : boolean
      Whether the parameter estimation converged.
  
  mse : float
      Mean squared error between prior and posterior.
docstr_tok: ["Check","convergence","based","on","mean","squared","difference","between","prior","and","posterior","Returns","--","--","--","-","converged",":","boolean","Whether","the","parameter","estimation","converged",".","mse",":","float","Mean","squared","error","between","prior","and","posterior","."]
code: def _mse_converged(self):
      """Check convergence based on mean squared difference between
          prior and posterior
  
      Returns
      -------
  
      converged : boolean
          Whether the parameter estimation converged.
  
      mse : float
          Mean squared error between prior and posterior.
  
      """
  
      prior = self.global_prior_[0 : self.prior_size]
      posterior = self.global_posterior_[0 : self.prior_size]
      mse = mean_squared_error(
          prior, posterior, multioutput="uniform_average"
      )
      if mse > self.threshold:
          return False, mse
      else:
          return True, mse
  
imports: import numpy
  from mpi4py import MPI
  from scipy.optimize import linear_sum_assignment
  from sklearn.metrics import mean_squared_error
  from scipy.spatial import distance
  import logging
  from .tfa import TFA
  from ..utils.utils import from_tri_2_sym, from_sym_2_tri
label_desc: Use image node_id 3 for calling the HTFA obj's underlying member method code with example usage: obj._mse_converged() and returns: False,  mse, True,  mse