class_docstr: Class for event segmentation of continuous fMRI data
  
  Parameters
  ----------
  n_events: int
      Number of segments to learn
  
  step_var: Callable[[int], float] : default 4 * (0.98 ** (step - 1))
      The Gaussian variance to use during fitting, as a function of the
      number of steps. Should decrease slowly over time.
  
  n_iter: int, default: 500
      Maximum number of steps to run during fitting
  
  event_chains: ndarray with length = n_events
      Array with unique value for each separate chain of events, each linked
      in the order they appear in the array
  
  split_merge: bool, default: False
      Determines whether merge/split proposals are used during fitting with
      fit(). This can improve fitting performance when events are highly
      uneven in size, but requires additional time
  
  split_merge_proposals: int, default: 1
      Number of merges and splits to consider at each step. Computation time
      scales as O(proposals^2) so this should usually be a small value
  
  Attributes
  ----------
  p_start, p_end: length n_events+1 ndarray
      initial and final prior distributions over events
  
  P: n_events+1 by n_events+1 ndarray
      HMM transition matrix
  
  ll_ : ndarray with length = number of training datasets
      Log-likelihood for training datasets over the course of training
  
  segments_:  list of (time by event) ndarrays
      Learned (soft) segmentation for training datasets
  
  event_var_ : float
      Gaussian variance at the end of learning
  
  event_pat_ : voxel by event ndarray
      Learned mean patterns for each event
class_docstr_tok: ["Class","for","event","segmentation","of","continuous","fMRI","data","Parameters","--","--","--","--","--","n_events",":","int","Number","of","segments","to","learn","step_var",":","Callable","[","[","int","]",",","float","]",":","default","4","*","(","0.98","*","*","(","step","-","1",")",")","The","Gaussian","variance","to","use","during","fitting",",","as","a","function","of","the","number","of","steps",".","Should","decrease","slowly","over","time",".","n_iter",":","int",",","default",":","500","Maximum","number","of","steps","to","run","during","fitting","event_chains",":","ndarray","with","length","=","n_events","Array","with","unique","value","for","each","separate","chain","of","events",",","each","linked","in","the","order","they","appear","in","the","array","split_merge",":","bool",",","default",":","False","Determines","whether","merge\/split","proposals","are","used","during","fitting","with","fit","(",")",".","This","can","improve","fitting","performance","when","events","are","highly","uneven","in","size",",","but","requires","additional","time","split_merge_proposals",":","int",",","default",":","1","Number","of","merges","and","splits","to","consider","at","each","step",".","Computation","time","scales","as","O","(","proposals^2",")","so","this","should","usually","be","a","small","value","Attributes","--","--","--","--","--","p_start",",","p_end",":","length","n_events+1","ndarray","initial","and","final","prior","distributions","over","events","P",":","n_events+1","by","n_events+1","ndarray","HMM","transition","matrix","ll_",":","ndarray","with","length","=","number","of","training","datasets","Log-likelihood","for","training","datasets","over","the","course","of","training","segments_",":","list","of","(","time","by","event",")","ndarrays","Learned","(","soft",")","segmentation","for","training","datasets","event_var_",":","float","Gaussian","variance","at","the","end","of","learning","event_pat_",":","voxel","by","event","ndarray","Learned","mean","patterns","for","each","event"]
docstr: Learn a segmentation on training data
  
  Fits event patterns and a segmentation to training data. After
  running this function, the learned event patterns can be used to
  segment other datasets using find_events
  
  Parameters
  ----------
  X: time by voxel ndarray, or a list of such ndarrays
      fMRI data to be segmented. If a list is given, then all datasets
      are segmented simultaneously with the same event patterns
  
  y: not used (added to comply with BaseEstimator definition)
  
  Returns
  -------
  self: the EventSegment object
docstr_tok: ["Learn","a","segmentation","on","training","data","Fits","event","patterns","and","a","segmentation","to","training","data",".","After","running","this","function",",","the","learned","event","patterns","can","be","used","to","segment","other","datasets","using","find_events","Parameters","--","--","--","--","--","X",":","time","by","voxel","ndarray",",","or","a","list","of","such","ndarrays","fMRI","data","to","be","segmented",".","If","a","list","is","given",",","then","all","datasets","are","segmented","simultaneously","with","the","same","event","patterns","y",":","not","used","(","added","to","comply","with","BaseEstimator","definition",")","Returns","--","--","--","-","self",":","the","EventSegment","object"]
code: def fit(self, X, y=None):
      """Learn a segmentation on training data
  
      Fits event patterns and a segmentation to training data. After
      running this function, the learned event patterns can be used to
      segment other datasets using find_events
  
      Parameters
      ----------
      X: time by voxel ndarray, or a list of such ndarrays
          fMRI data to be segmented. If a list is given, then all datasets
          are segmented simultaneously with the same event patterns
  
      y: not used (added to comply with BaseEstimator definition)
  
      Returns
      -------
      self: the EventSegment object
      """
  
      X = self._fit_validate(X)
      n_train = len(X)
      n_dim = X[0].shape[0]
      self.classes_ = np.arange(self.n_events)
  
      # Initialize variables for fitting
      log_gamma = []
      for i in range(n_train):
          log_gamma.append(np.zeros((X[i].shape[1], self.n_events)))
      step = 1
      best_ll = float("-inf")
      self.ll_ = np.empty((0, n_train))
      while step <= self.n_iter:
          iteration_var = self.step_var(step)
  
          # Based on the current segmentation, compute the mean pattern
          # for each event
          seg_prob = [
              np.exp(lg) / np.sum(np.exp(lg), axis=0)
              for lg in log_gamma
          ]
          mean_pat = np.empty((n_train, n_dim, self.n_events))
          for i in range(n_train):
              mean_pat[i, :, :] = X[i].dot(seg_prob[i])
          mean_pat = np.mean(mean_pat, axis=0)
  
          # Based on the current mean patterns, compute the event
          # segmentation
          self.ll_ = np.append(self.ll_, np.empty((1, n_train)), axis=0)
          for i in range(n_train):
              logprob = self._logprob_obs(X[i], mean_pat, iteration_var)
              log_gamma[i], self.ll_[-1, i] = self._forward_backward(
                  logprob
              )
  
          if step > 1 and self.split_merge:
              curr_ll = np.mean(self.ll_[-1, :])
              self.ll_[-1, :], log_gamma, mean_pat = self._split_merge(
                  X, log_gamma, iteration_var, curr_ll
              )
  
          # If log-likelihood has started decreasing, undo last step and stop
          if np.mean(self.ll_[-1, :]) < best_ll:
              self.ll_ = self.ll_[:-1, :]
              break
  
          self.segments_ = [np.exp(lg) for lg in log_gamma]
          self.event_var_ = iteration_var
          self.event_pat_ = mean_pat
          best_ll = np.mean(self.ll_[-1, :])
          logger.debug("Fitting step %d, LL=%f", step, best_ll)
  
          step += 1
  
      return self
  
imports: import numpy
  from scipy import stats
  import logging
  import copy
  from sklearn.base import BaseEstimator
  from sklearn.utils.validation import check_is_fitted, check_array
  from sklearn.exceptions import NotFittedError
  import itertools
  from .None import _utils
label_desc: Use image node_id 4 for calling the EventSegment obj's underlying member method code with example usage: obj.fit(X, y) and returns: self