Ejemplo n.º 1
0
 def test_no_stat(self):
     """Test on no stats / no permutations / don't repeat computations."""
     y, gt = sim_mi_cc(x, snr=1.)
     dt = DatasetEphy(x, y, roi, times=time)
     # compute permutations but not statistics
     kernel = np.hanning(3)
     wf = WfMi('cc', 'ffx', kernel=kernel, verbose=False)
     assert isinstance(wf.wf_stats, WfStats)
     wf.fit(dt, mcp='nostat', **kw_mi)
     assert len(wf.mi) == len(wf.mi_p) == n_roi
     assert len(wf.mi_p[0].shape) != 0
     # don't compute permutations nor stats
     wf = WfMi('cc', 'ffx', verbose=False)
     mi, pv = wf.fit(dt, mcp=None, **kw_mi)
     assert wf.mi_p[0].shape == (0, )
     assert pv.min() == pv.max() == 1.
     # don't compute permutations twice
     wf = WfMi('cc', 'ffx', verbose=False)
     t_start_1 = tst()
     wf.fit(dt, mcp='fdr', **kw_mi)
     t_end_1 = tst()
     t_start_2 = tst()
     wf.fit(dt, mcp='maxstat', **kw_mi)
     t_end_2 = tst()
     assert t_end_1 - t_start_1 > t_end_2 - t_start_2
Ejemplo n.º 2
0
 def test_definition(self):
     """Test workflow definition."""
     y, gt = sim_mi_cc(x, snr=1.)
     dt = DatasetEphy(x, y, roi, times=time)
     wf = WfMi(mi_type='cc', inference='rfx')
     wf.fit(dt, **kw_mi)
     wf.tvalues
Ejemplo n.º 3
0
 def test_conjunction_analysis(self):
     """Test the conjunction analysis."""
     y, gt = sim_mi_cc(x, snr=1.)
     dt = DatasetEphy(x, y, roi, times=time)
     wf = WfMi(mi_type='cc', inference='rfx')
     mi, pv = wf.fit(dt, **kw_mi)
     cj_ss, cj = wf.conjunction_analysis(dt)
     assert cj_ss.shape == (n_subjects, n_times, n_roi)
     assert cj.shape == (n_times, n_roi)
Ejemplo n.º 4
0
 def test_mi_cc(self):
     """Test method fit."""
     # built the regressor
     y, gt = sim_mi_cc(x, snr=1.)
     # run workflow
     for mi_meth in ['gc', 'bin']:
         dt = DatasetEphy(x, y, roi, times=time)
         WfMi(mi_type='cc',
              inference='ffx',
              mi_method=mi_meth,
              verbose=False).fit(dt, **kw_mi)
         WfMi(mi_type='cc',
              inference='rfx',
              mi_method=mi_meth,
              verbose=False).fit(dt, **kw_mi)
Ejemplo n.º 5
0
 def test_mi_cc(self):
     """Test method fit."""
     # built the regressor
     y, gt = sim_mi_cc(x, snr=1.)
     # run workflow
     dt = DatasetEphy(x.copy(), y=y, roi=roi, times=time)
     for est in est_list:
         estimator = est(mi_type='cc')
         WfMi(mi_type='cc',
              inference='ffx',
              estimator=estimator,
              verbose=False).fit(dt, **kw_mi)
         WfMi(mi_type='cc',
              inference='rfx',
              estimator=estimator,
              verbose=False).fit(dt, **kw_mi)
Ejemplo n.º 6
0
                                     n_epochs=n_epochs,
                                     n_times=n_times,
                                     modality=modality,
                                     random_state=0)

###############################################################################
# Simulate mutual information
# ---------------------------
#
# Once the data have been created, we simulate an increase of mutual
# information by creating a continuous variable `y` using the function
# :func:`frites.simulations.sim_mi_cc`. This allows to simulate model-based
# analysis by computing $I(data; y)$ where `data` and `y` are two continuous
# variables

y, _ = sim_mi_cc(data, snr=.1)

###############################################################################
# Create an electrophysiological dataset
# --------------------------------------
#
# Now, we use the :class:`frites.dataset.DatasetEphy` in order to create a
# compatible electrophysiological dataset

dt = DatasetEphy(data, y, roi=roi, times=time, verbose=False)

###############################################################################
# Define the workflow
# -------------------
#
# We now define the workflow for computing mi and evaluate statistics using the
Ejemplo n.º 7
0
plt.plot(time, mi)
plt.xlabel("Time (s)"), plt.ylabel("MI (bits)")
plt.title("Multivariate regressor")
plt.show()

###############################################################################
# Evaluate the statistics
# -----------------------
#
# In the section above, the input parameter `stat_method=None` specifies that
# no statistics are going to be computed. Here, we show how to compute either
# within (ffx) or between subject (rfx) statistics.

mi_type = 'cc'
n_perm = 200
y, _ = sim_mi_cc(x, snr=.1)

# within subject statistics (ffx=fixed-effect)
ffx_stat = 'ffx_cluster_tfce'
dt_ffx = DatasetEphy(x, y, roi)
wf_ffx = WfMi(mi_type, 'ffx')
mi_ffx, pv_ffx = wf_ffx.fit(dt_ffx,
                            mcp='cluster',
                            cluster_th='tfce',
                            n_perm=n_perm,
                            n_jobs=1)

# between-subject statistics (rfx=random-effect)
dt_rfx = DatasetEphy(x, y, roi)
wf_rfx = WfMi(mi_type, 'rfx')
mi_rfx, pv_rfx = wf_rfx.fit(dt_rfx,
Ejemplo n.º 8
0
 def test_sim_mi_cc(self):
     """Test function sim_mi_cc."""
     y, gt = sim_mi_cc(x, snr=.8)
     assert len(y) == len(x)
     assert all([k.shape == (n_epochs, ) for k in y])
     assert (len(gt) == n_times) and (gt.dtype == bool)