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: Computes normalized weighted variance around event pattern
  
  Utility function for computing variance in a training set of weighted
  event examples. For each event, the sum of squared differences for all
  timepoints from the event pattern is computed, and then the weights
  specify how much each of these differences contributes to the
  variance (normalized by the number of voxels).
  
  Parameters
  ----------
  D : timepoint by voxel ndarray
      fMRI data for which to compute event variances
  
  weights : timepoint by event ndarray
      specifies relative weights of timepoints for each event
  
  event_pat : voxel by event ndarray
      mean event patterns to compute variance around
  
  Returns
  -------
  ev_var : ndarray of variances for each event
docstr_tok: ["Computes","normalized","weighted","variance","around","event","pattern","Utility","function","for","computing","variance","in","a","training","set","of","weighted","event","examples",".","For","each","event",",","the","sum","of","squared","differences","for","all","timepoints","from","the","event","pattern","is","computed",",","and","then","the","weights","specify","how","much","each","of","these","differences","contributes","to","the","variance","(","normalized","by","the","number","of","voxels",")",".","Parameters","--","--","--","--","--","D",":","timepoint","by","voxel","ndarray","fMRI","data","for","which","to","compute","event","variances","weights",":","timepoint","by","event","ndarray","specifies","relative","weights","of","timepoints","for","each","event","event_pat",":","voxel","by","event","ndarray","mean","event","patterns","to","compute","variance","around","Returns","--","--","--","-","ev_var",":","ndarray","of","variances","for","each","event"]
code: def calc_weighted_event_var(self, D, weights, event_pat):
      """Computes normalized weighted variance around event pattern
  
      Utility function for computing variance in a training set of weighted
      event examples. For each event, the sum of squared differences for all
      timepoints from the event pattern is computed, and then the weights
      specify how much each of these differences contributes to the
      variance (normalized by the number of voxels).
  
      Parameters
      ----------
      D : timepoint by voxel ndarray
          fMRI data for which to compute event variances
  
      weights : timepoint by event ndarray
          specifies relative weights of timepoints for each event
  
      event_pat : voxel by event ndarray
          mean event patterns to compute variance around
  
      Returns
      -------
      ev_var : ndarray of variances for each event
      """
      Dz = stats.zscore(D, axis=1, ddof=1)
      ev_var = np.empty(event_pat.shape[1])
      for e in range(event_pat.shape[1]):
          # Only compute variances for weights > 0.1% of max weight
          nz = weights[:, e] > np.max(weights[:, e]) / 1000
          sumsq = np.dot(
              weights[nz, e],
              np.sum(np.square(Dz[nz, :] - event_pat[:, e]), axis=1),
          )
          ev_var[e] = sumsq / (
              np.sum(weights[nz, e])
              - np.sum(np.square(weights[nz, e]))
              / np.sum(weights[nz, e])
          )
      ev_var = ev_var / D.shape[1]
      return ev_var
  
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 11 for calling the EventSegment obj's underlying member method code with example usage: obj.calc_weighted_event_var(D, weights, event_pat) and returns: ev_var