code: def test_permutation_isc():
      # Set parameters for toy time series data
      n_subjects = 20
      n_TRs = 60
      n_voxels = 30
      random_state = 42
      group_assignment = [1] * 10 + [2] * 10
  
      logger.info("Testing permutation test")
  
      # Create dataset with two groups in pairwise approach
      data = np.dstack(
          (
              simulated_timeseries(
                  10,
                  n_TRs,
                  n_voxels=n_voxels,
                  noise=1,
                  data_type="array",
                  random_state=3,
              ),
              simulated_timeseries(
                  10,
                  n_TRs,
                  n_voxels=n_voxels,
                  noise=5,
                  data_type="array",
                  random_state=4,
              ),
          )
      )
      iscs = isc(data, pairwise=True, summary_statistic=None)
  
      observed, p, distribution = permutation_isc(
          iscs,
          group_assignment=group_assignment,
          pairwise=True,
          summary_statistic="mean",
          n_permutations=200,
      )
  
      # Create data with two groups in leave-one-out approach
      data_1 = simulated_timeseries(
          10,
          n_TRs,
          n_voxels=n_voxels,
          noise=1,
          data_type="array",
          random_state=3,
      )
      data_2 = simulated_timeseries(
          10,
          n_TRs,
          n_voxels=n_voxels,
          noise=10,
          data_type="array",
          random_state=4,
      )
      iscs = np.vstack(
          (
              isc(data_1, pairwise=False, summary_statistic=None),
              isc(data_2, pairwise=False, summary_statistic=None),
          )
      )
  
      observed, p, distribution = permutation_isc(
          iscs,
          group_assignment=group_assignment,
          pairwise=False,
          summary_statistic="mean",
          n_permutations=200,
      )
  
      # One-sample leave-one-out permutation test
      data = simulated_timeseries(
          n_subjects,
          n_TRs,
          n_voxels=n_voxels,
          data_type="array",
          random_state=random_state,
      )
      iscs = isc(data, pairwise=False, summary_statistic=None)
  
      observed, p, distribution = permutation_isc(
          iscs,
          pairwise=False,
          summary_statistic="median",
          n_permutations=200,
      )
  
      # One-sample pairwise permutation test
      iscs = isc(data, pairwise=True, summary_statistic=None)
  
      observed, p, distribution = permutation_isc(
          iscs,
          pairwise=True,
          summary_statistic="median",
          n_permutations=200,
      )
  
      # Small one-sample pairwise exact test
      data = simulated_timeseries(
          12,
          n_TRs,
          n_voxels=n_voxels,
          data_type="array",
          random_state=random_state,
      )
      iscs = isc(data, pairwise=False, summary_statistic=None)
  
      observed, p, distribution = permutation_isc(
          iscs,
          pairwise=False,
          summary_statistic="median",
          n_permutations=10000,
      )
  
      # Small two-sample pairwise exact test (and unequal groups)
      data = np.dstack(
          (
              simulated_timeseries(
                  3,
                  n_TRs,
                  n_voxels=n_voxels,
                  noise=1,
                  data_type="array",
                  random_state=3,
              ),
              simulated_timeseries(
                  4,
                  n_TRs,
                  n_voxels=n_voxels,
                  noise=50,
                  data_type="array",
                  random_state=4,
              ),
          )
      )
      iscs = isc(data, pairwise=True, summary_statistic=None)
      group_assignment = [1, 1, 1, 2, 2, 2, 2]
  
      observed, p, distribution = permutation_isc(
          iscs,
          group_assignment=group_assignment,
          pairwise=True,
          summary_statistic="mean",
          n_permutations=10000,
      )
  
      # Small two-sample leave-one-out exact test (and unequal groups)
      data_1 = simulated_timeseries(
          3,
          n_TRs,
          n_voxels=n_voxels,
          noise=1,
          data_type="array",
          random_state=3,
      )
      data_2 = simulated_timeseries(
          4,
          n_TRs,
          n_voxels=n_voxels,
          noise=50,
          data_type="array",
          random_state=4,
      )
      iscs = np.vstack(
          (
              isc(data_1, pairwise=False, summary_statistic=None),
              isc(data_2, pairwise=False, summary_statistic=None),
          )
      )
      group_assignment = [1, 1, 1, 2, 2, 2, 2]
  
      observed, p, distribution = permutation_isc(
          iscs,
          group_assignment=group_assignment,
          pairwise=False,
          summary_statistic="mean",
          n_permutations=10000,
      )
  
      # Check output p-values
      data = correlated_timeseries(20, 60, noise=0.5, random_state=42)
      iscs = isc(data, pairwise=False)
      observed, p, distribution = permutation_isc(iscs, pairwise=False)
      assert np.all(iscs[:, :2] > 0.5)
      assert np.all(iscs[:, -1] < 0.5)
      assert p[0] < 0.05 and p[1] < 0.05
      assert p[2] > 0.01
  
      iscs = isc(data, pairwise=True)
      observed, p, distribution = permutation_isc(iscs, pairwise=True)
      assert np.all(iscs[:, :2] > 0.5)
      assert np.all(iscs[:, -1] < 0.5)
      assert p[0] < 0.05 and p[1] < 0.05
      assert p[2] > 0.01
  
      # Check that ISC computation and permutation observed are same
      iscs = isc(data, pairwise=False)
      observed, p, distribution = permutation_isc(
          iscs, pairwise=False, summary_statistic="median"
      )
      assert np.allclose(
          observed,
          isc(data, pairwise=False, summary_statistic="median"),
          rtol=1e-03,
      )
  
      # Check that ISC computation and permuation observed are same
      iscs = isc(data, pairwise=True)
      observed, p, distribution = permutation_isc(
          iscs, pairwise=True, summary_statistic="mean"
      )
      assert np.allclose(
          observed,
          isc(data, pairwise=True, summary_statistic="mean"),
          rtol=1e-03,
      )
  
      logger.info("Finished testing permutaton test")
  
file_path: brainiak/tests/isc/test_isc.py
imports: import numpy
  import logging
  import pytest
  from brainiak.isc import isc, isfc, bootstrap_isc, permutation_isc, squareform_isfc, timeshift_isc, phaseshift_isc
  from scipy.spatial.distance import squareform
label_desc: Use image node_id 8 for calling a global function with example usage: test_permutation_isc() without return types