예제 #1
0
    def test_SSVEP_paradigm(self):
        paradigm = SSVEP(n_classes=None)
        dataset = FakeDataset(event_list=["13", "15", "17", "19"],
                              paradigm="ssvep")
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # Verify that they have the same length
        self.assertEqual(len(X), len(labels), len(metadata))
        # X must be a 3D array
        self.assertEqual(len(X.shape), 3)
        # labels must contain 4 values, defined in the dataset
        self.assertEqual(len(np.unique(labels)), 4)
        # metadata must have subjets, sessions, runs
        self.assertTrue("subject" in metadata.columns)
        self.assertTrue("session" in metadata.columns)
        self.assertTrue("run" in metadata.columns)
        # Only one subject in the metadata
        self.assertEqual(np.unique(metadata.subject), 1)
        # We should have two sessions in the metadata
        self.assertEqual(len(np.unique(metadata.session)), 2)
        # should return epochs
        epochs, _, _ = paradigm.get_data(dataset,
                                         subjects=[1],
                                         return_epochs=True)
        self.assertIsInstance(epochs, BaseEpochs)
예제 #2
0
    def test_SSVEP_singlepass(self):
        # Accept only single pass filter
        paradigm = SSVEP(fmin=2, fmax=25)
        dataset = FakeDataset(paradigm='ssvep')
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # Verify that they have the same length
        self.assertEqual(len(X), len(labels), len(metadata))
        # X must be a 3D array
        self.assertEqual(len(X.shape), 3)
        # labels must contain 2 values, as n_classes = 2 by default
        self.assertEqual(len(np.unique(labels)), 2)
예제 #3
0
    def test_SSVEP_singlepass(self):
        # Accept only single pass filter
        paradigm = SSVEP(fmin=2, fmax=25)
        dataset = FakeDataset(paradigm="ssvep")
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # Verify that they have the same length
        self.assertEqual(len(X), len(labels), len(metadata))
        # X must be a 3D array
        self.assertEqual(len(X.shape), 3)
        # labels must contain all 3 classes of dataset,
        # as n_classes is "None" by default (taking all classes)
        self.assertEqual(len(np.unique(labels)), 3)
        # should return epochs
        epochs, _, _ = paradigm.get_data(dataset, subjects=[1], return_epochs=True)
        self.assertIsInstance(epochs, BaseEpochs)
예제 #4
0
    def test_SSVEP_paradigm(self):
        paradigm = SSVEP(n_classes=None)
        dataset = FakeDataset(event_list=['13', '15', '17', '19'],
                              paradigm='ssvep')
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # Verify that they have the same length
        self.assertEqual(len(X), len(labels), len(metadata))
        # X must be a 3D array
        self.assertEqual(len(X.shape), 3)
        # labels must contain 4 values, defined in the dataset
        self.assertEqual(len(np.unique(labels)), 4)

        # metadata must have subjets, sessions, runs
        self.assertTrue('subject' in metadata.columns)
        self.assertTrue('session' in metadata.columns)
        self.assertTrue('run' in metadata.columns)

        # Only one subject in the metadata
        self.assertEqual(np.unique(metadata.subject), 1)

        # We should have two sessions in the metadata
        self.assertEqual(len(np.unique(metadata.session)), 2)
예제 #5
0
#
# Load 2 subjects of MAMEM3 dataset, with 3 session each

subj = [1, 3]
dataset = MAMEM3()
dataset.subject_list = subj

###############################################################################
# Choose paradigm
# ---------------
#
# We select the paradigm SSVEP, applying a bandpass filter (3-15 Hz) on
# the data and we keep only the first 3 classes, that is stimulation
# frequency of 6.66, 7.50 and 8.57 Hz.

paradigm = SSVEP(fmin=3, fmax=15, n_classes=3)

##############################################################################
# Create pipelines
# ----------------
#
# Use a Canonical Correlation Analysis classifier

interval = dataset.interval
freqs = paradigm.used_events(dataset)

pipeline = {}
pipeline["CCA"] = make_pipeline(SSVEP_CCA(interval=interval, freqs=freqs, n_harmonics=3))

##############################################################################
# Get data (optional)
interval = dataset.interval

###############################################################################
# Choose Paradigm
# ---------------
#
# We define the paradigms (SSVEP, SSSVEP_TRCA and FilterBankSSVEP) and use the dataset
# SSVEPExo. The SSVEP paradigm applied a bandpass filter (10-25 Hz) on
# the data, SSVEP_TRCA applied a bandpass filter (1-110 Hz) which correspond to almost
# no filtering, while the FilterBankSSVEP paradigm uses as many bandpass filters as
# there are stimulation frequencies (here 2). For each stimulation frequency
# the EEG is filtered with a 1 Hz-wide bandpass filter centered on the
# frequency. This results in ``n_classes`` copies of the signal, filtered for each
# class, as used in the filterbank motor imagery paradigms.

paradigm = SSVEP(fmin=10, fmax=25, n_classes=3)
paradigm_TRCA = SSVEP(fmin=1, fmax=110, n_classes=3)
paradigm_fb = FilterBankSSVEP(filters=None, n_classes=3)

###############################################################################
# Classes are defined by the frequency of the stimulation, here we use
# the first two frequencies of the dataset, 13 and 17 Hz.
# The evaluation function uses a LabelEncoder, transforming them
# to 0 and 1

freqs = paradigm.used_events(dataset)

##############################################################################
# Create Pipelines
# ----------------
#
for s in subj:
    for d in [MAMEM1(), MAMEM2(), MAMEM3()]:
        d._get_single_subject_data(s)
datasets = [MAMEM1(), MAMEM2(), MAMEM3()]
for d in datasets:
    d.subject_list = subj

###############################################################################
# Choose paradigm
# ---------------
#
# We select the paradigm SSVEP, applying a bandpass filter (3-15 Hz) on
# the data and we keep all the 5 classes, that is stimulation
# frequency of 6.66, 7.50 and 8.57, 10 and 12 Hz.

paradigm = SSVEP(fmin=3, fmax=15, n_classes=None)

##############################################################################
# Create pipelines
# ----------------
#
# Use a Canonical Correlation Analysis classifier

interval = datasets[0].interval
freqs = paradigm.used_events(datasets[0])

pipeline = {}
pipeline["CCA"] = make_pipeline(
    SSVEP_CCA(interval=interval, freqs=freqs, n_harmonics=3))

##############################################################################
예제 #8
0
 def test_SSVEP_noevent(self):
     # Assert error if events from paradigm and dataset dont overlap
     paradigm = SSVEP(events=["11", "12"], n_classes=2)
     dataset = FakeDataset(event_list=["13", "14"], paradigm="ssvep")
     self.assertRaises(AssertionError, paradigm.get_data, dataset)
예제 #9
0
 def test_SSVEP_noevent(self):
     # Assert error if events from paradigm and dataset dont overlap
     paradigm = SSVEP(events=['11', '12'], n_classes=2)
     dataset = FakeDataset(event_list=['13', '14'], paradigm='ssvep')
     self.assertRaises(AssertionError, paradigm.get_data, dataset)
예제 #10
0
subj = [1, 3]
for s in subj:
    MAMEM1()._get_single_subject_data(s)
dataset = MAMEM1()
dataset.subject_list = subj

###############################################################################
# Choose paradigm
# ---------------
#
# We select the paradigm SSVEP, applying a bandpass filter (3-15 Hz) on
# the data and we keep only the first 3 classes, that is stimulation
# frequency of 6.66, 7.50 and 8.57 Hz.

paradigm = SSVEP(fmin=3, fmax=15, n_classes=3)

##############################################################################
# Create pipelines
# ----------------
#
# Use a Canonical Correlation Analysis classifier

interval = dataset.interval
freqs = paradigm.used_events(dataset)

pipeline = {}
pipeline["CCA"] = make_pipeline(
    SSVEP_CCA(interval=interval, freqs=freqs, n_harmonics=3))

##############################################################################