code: def time_segment_matching_accuracy(data, win_size=6):
      nsubjs = len(data)
      (ndim, nsample) = data[0].shape
      accu = np.zeros(shape=nsubjs)
      nseg = nsample - win_size
      # mysseg prediction prediction
      trn_data = np.zeros((ndim * win_size, nseg), order="f")
      # the trn data also include the tst data, but will be subtracted when
      # calculating A
      for m in range(nsubjs):
          for w in range(win_size):
              trn_data[w * ndim : (w + 1) * ndim, :] += data[m][
                  :, w : (w + nseg)
              ]
      for tst_subj in range(nsubjs):
          tst_data = np.zeros((ndim * win_size, nseg), order="f")
          for w in range(win_size):
              tst_data[w * ndim : (w + 1) * ndim, :] = data[tst_subj][
                  :, w : (w + nseg)
              ]
  
          A = np.nan_to_num(
              stats.zscore((trn_data - tst_data), axis=0, ddof=1)
          )
          B = np.nan_to_num(stats.zscore(tst_data, axis=0, ddof=1))
  
          # compute correlation matrix
          corr_mtx = compute_correlation(B.T, A.T)
  
          for i in range(nseg):
              for j in range(nseg):
                  if abs(i - j) < win_size and i != j:
                      corr_mtx[i, j] = -np.inf
          max_idx = np.argmax(corr_mtx, axis=1)
          accu[tst_subj] = sum(max_idx == range(nseg)) / float(nseg)
  
      return accu
  
file_path: brainiak/examples/funcalign/searchlight_srm_example.py
imports: import numpy
  from mpi4py import MPI
  import sys
  import scipy.io
  from scipy.stats import stats
  from brainiak.searchlight.searchlight import Searchlight
  from brainiak.funcalign.srm import SRM
  from brainiak.fcma.util import compute_correlation
  import warnings
label_desc: Use image node_id 1 for calling a global function with example usage: time_segment_matching_accuracy(data, win_size) and returns: accu