Esempio n. 1
0
 def test_sim_multi_suj_ephy(self):
     """Test function sim_multi_suj_ephy."""
     # standard definition
     data, roi, time = sim_multi_suj_ephy(modality="intra",
                                          n_times=57,
                                          n_roi=5,
                                          n_sites_per_roi=7,
                                          n_epochs=7,
                                          n_subjects=5,
                                          random_state=0)
     assert len(data) == len(roi) == 5
     n_sites = [k.shape[1] for k in data]
     assert np.unique(n_sites).size != 1
     assert np.all([k.shape == (7, len(i), 57) for k, i in zip(data, roi)])
     # mne type
     data, _, _ = sim_multi_suj_ephy(n_subjects=5, as_mne=True)
     assert all([isinstance(k, EpochsArray) for k in data])
Esempio n. 2
0
# Simulate electrophysiological data
# ----------------------------------
#
# Let's start by simulating MEG / EEG electrophysiological data coming from
# multiple subjects using the function
# :func:`frites.simulations.sim_multi_suj_ephy`. As a result, the `x` output
# is a list of length `n_subjects` of arrays, each one with a shape of
# n_epochs, n_sites, n_times

modality = 'meeg'
n_subjects = 5
n_epochs = 400
n_times = 100
x, roi, time = sim_multi_suj_ephy(n_subjects=n_subjects,
                                  n_epochs=n_epochs,
                                  n_times=n_times,
                                  modality=modality,
                                  random_state=0)

###############################################################################
# Extract the discret variable
# ------------------------------
#
# As explains in the top description, the discret variable is used to describes
# for example conditions. Thus, by computing the mutual information between the
# electrophysiological data and your discret variable, you are looking for
# recording sites and time-points of data that correlates with conditions. This
# kind of analysis is similar to what is done in machine-learning. First,
# extract the conditions from the random dataset generated above.

x, y, _ = sim_mi_cd(x, snr=1., n_conditions=3)
Esempio n. 3
0
from frites.dataset import DatasetEphy

from time import time as tst

modality = 'meeg'
n_subjects = 5
n_epochs = 30
n_times = 20
n_roi = 2
n_sites_per_roi = 1
as_mne = False
n_perm = 5
x, roi, time = sim_multi_suj_ephy(n_subjects=n_subjects,
                                  n_epochs=n_epochs,
                                  n_times=n_times,
                                  n_roi=n_roi,
                                  n_sites_per_roi=n_sites_per_roi,
                                  modality=modality,
                                  random_state=1)
time = np.arange(n_times) / 512

kw_mi = dict(n_perm=n_perm, n_jobs=1)


class TestWfMi(object):  # noqa
    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)
# ---------------------------------------------------
#
# Similarly to the creation of a dataset for a single subject the function
# :func:`frites.simulations.sim_multi_suj_ephy` allows the creation of
# electrophysiological datasets for multiple subjects. The returned dataset is
# a list of length `n_subjects` composed with arrays of shape (n_epochs,
# n_sites, n_times)

modality = 'meeg'
n_subjects = 3
n_epochs = 10
n_roi = 1
n_sites_per_roi = 1
n_times = 100
data, roi, time = sim_multi_suj_ephy(modality=modality,
                                     n_epochs=n_epochs,
                                     n_subjects=n_subjects,
                                     n_roi=n_roi,
                                     n_times=n_times,
                                     n_sites_per_roi=n_sites_per_roi)

plt.figure(figsize=(10, 10))
for k in range(n_subjects):
    plt.subplot(n_subjects, 1, k + 1)
    plt.plot(time, data[k][:, 0, :].T, color='lightgray')
    plt.plot(time, data[k][:, 0, :].mean(0), lw=3)
    plt.ylabel("Amplitude (uV)")
    plt.title(f"Data for subject {k}")
    plt.autoscale(tight=True)
plt.show()