示例#1
0
 def test_functional_cc(self):
     """Functional test for cc MI."""
     # build the testing data
     x = np.random.rand(n_times, n_mv, n_samples)
     y = np.random.normal(size=(1, 1, n_samples,))
     x[sl_effect, :, :] += y
     y = np.tile(y, (n_times, 1, 1))
     # functional test
     for cop in [True, False]:
         for imp in [True, False]:
             c = GCMIEstimator(mi_type='cc', tensor=imp, copnorm=cop)
             mi = c.estimate(x, y)
             self._compare_effects(effect, mi)
示例#2
0
 def test_functional_cd(self):
     """Functional test for cd MI."""
     # build the testing data
     x = np.random.rand(n_times, n_mv, n_samples)
     x[sl_effect, :, 0:50] += 10.
     x[sl_effect, :, 50::] -= 10.
     y = np.array([0] * 50 + [1] * 50)
     # functional test
     for cop in [True, False]:
         for imp in [True, False]:
             c = GCMIEstimator(mi_type='cd', tensor=imp, copnorm=cop)
             mi = c.estimate(x, y)
             self._compare_effects(effect, mi)
示例#3
0
 def test_functional_ccd(self):
     """Functional test for ccd MI."""
     # build the testing data
     x = np.random.rand(n_times, n_mv, n_samples)
     y_pos = np.random.normal(size=(1, 1, 50))
     y_neg = np.random.normal(size=(1, 1, 50))
     x[sl_effect, :, 0:50] += y_pos
     x[sl_effect, :, 50::] -= y_neg
     y = np.tile(np.concatenate((y_pos, y_neg), axis=2), (n_times, 1, 1))
     z = np.array([0] * 50 + [1] * 50)
     # functional test
     for cop in [True, False]:
         for imp in [True, False]:
             c = GCMIEstimator(mi_type='ccd', tensor=imp, copnorm=cop)
             mi = c.estimate(x, y, z=z)
             self._compare_effects(effect, mi)
示例#4
0
    def __init__(self, inference='rfx', estimator=None, kernel=None,
                 verbose=None):
        """Init."""
        WfBase.__init__(self)
        assert inference in ['ffx', 'rfx'], (
            "'inference' input parameter should either be 'ffx' or 'rfx'")
        self._mi_type = 'cc'
        if estimator is None:
            estimator = GCMIEstimator(mi_type='cc', copnorm=False,
                                      verbose=verbose)
        assert estimator.settings['mi_type'] == self._mi_type
        self._copnorm = isinstance(estimator, GCMIEstimator)
        self._inference = inference
        self.estimator = estimator
        self._gcrn = inference == 'rfx'
        self._kernel = kernel
        set_log_level(verbose)
        self.clean()
        self._wf_stats = WfStats(verbose=verbose)
        # update internal config
        self.attrs.update(dict(mi_type=self._mi_type, inference=inference,
                               kernel=kernel))

        logger.info(f"Workflow for computing comodulations between distant "
                    f"brain areas ({inference})")
示例#5
0
 def test_smoke_ccc(self):
     """Smoke test for ccc MI."""
     for cop in [True, False]:
         for cat in [None, categories]:
             # tensor-based
             c = GCMIEstimator(mi_type='ccc', tensor=True, copnorm=cop)
             mi_t = c.estimate(x, y_c, z=z_c, categories=cat)
             # vector-based
             c = GCMIEstimator(mi_type='ccc', tensor=False, copnorm=cop)
             mi_v = c.estimate(x, y_c, z=z_c, categories=cat)
             np.testing.assert_array_almost_equal(mi_t, mi_v)
示例#6
0
 def test_support_dim(self):
     """Test the support for different dimensions."""
     y = np.random.rand(100)
     c = GCMIEstimator(mi_type='cc')
     # 1d
     x = np.random.rand(100)
     c = GCMIEstimator(mi_type='cc')
     mi = c.estimate(x, y)
     assert mi.shape == (1, 1)
     # 2d
     x = np.random.rand(1, 100)
     mi = c.estimate(x, y)
     assert mi.shape == (1, 1)
     # Nd
     x = np.random.rand(4, 5, 6, 1, 100)
     mi = c.estimate(x, y)
     assert mi.shape == (1, 4, 5, 6)
# Convert to DatasetEphy
dt = DatasetEphy(coh, y=stim, nb_min_suj=10, times="times", roi="roi")

mi_type = 'cd'
inference = 'rfx'
kernel = None

if avg:
    mcp = "fdr"
else:
    mcp = "cluster"

estimator = GCMIEstimator(mi_type='cd',
                          copnorm=True,
                          biascorrect=True,
                          demeaned=False,
                          tensor=True,
                          gpu=False,
                          verbose=None)
wf = WfMi(mi_type, inference, verbose=True, kernel=kernel, estimator=estimator)

kw = dict(n_jobs=20, n_perm=200)
cluster_th = None  # {float, None, 'tfce'}

mi, pvalues = wf.fit(dt, mcp=mcp, cluster_th=cluster_th, **kw)

###############################################################################
# Saving results
###############################################################################

# Path to results folder