braindecode 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {Braindecode-0.1.2 → Braindecode-0.1.3}/Braindecode.egg-info/PKG-INFO +9 -2
  2. {Braindecode-0.1.2 → Braindecode-0.1.3}/Braindecode.egg-info/SOURCES.txt +6 -7
  3. {Braindecode-0.1.2 → Braindecode-0.1.3}/MANIFEST.in +1 -1
  4. {Braindecode-0.1.2 → Braindecode-0.1.3}/PKG-INFO +9 -2
  5. Braindecode-0.1.2/README.md → Braindecode-0.1.3/README.rst +8 -1
  6. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/experiments/experiment.py +4 -3
  7. {Braindecode-0.1.2 → Braindecode-0.1.3}/docs/Makefile +0 -3
  8. {Braindecode-0.1.2 → Braindecode-0.1.3}/docs/conf.py +1 -1
  9. {Braindecode-0.1.2 → Braindecode-0.1.3}/docs/index.rst +10 -9
  10. {Braindecode-0.1.2 → Braindecode-0.1.3}/docs/notebooks/TrialWise_Decoding.ipynb +60 -16
  11. Braindecode-0.1.3/docs/source/braindecode.datautils.rst +38 -0
  12. Braindecode-0.1.3/docs/source/braindecode.rst +32 -0
  13. {Braindecode-0.1.2 → Braindecode-0.1.3}/setup.py +2 -2
  14. Braindecode-0.1.2/braindecode/trial_segment.py +0 -198
  15. Braindecode-0.1.2/docs/source/braindecode.datasets.rst +0 -22
  16. Braindecode-0.1.2/docs/source/braindecode.rst +0 -56
  17. {Braindecode-0.1.2 → Braindecode-0.1.3}/Braindecode.egg-info/dependency_links.txt +0 -0
  18. {Braindecode-0.1.2 → Braindecode-0.1.3}/Braindecode.egg-info/not-zip-safe +0 -0
  19. {Braindecode-0.1.2 → Braindecode-0.1.3}/Braindecode.egg-info/requires.txt +0 -0
  20. {Braindecode-0.1.2 → Braindecode-0.1.3}/Braindecode.egg-info/top_level.txt +0 -0
  21. {Braindecode-0.1.2 → Braindecode-0.1.3}/LICENSE.txt +0 -0
  22. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/__init__.py +0 -0
  23. {Braindecode-0.1.2/braindecode/datasets → Braindecode-0.1.3/braindecode/datautils}/__init__.py +0 -0
  24. {Braindecode-0.1.2/braindecode → Braindecode-0.1.3/braindecode/datautils}/iterators.py +0 -0
  25. {Braindecode-0.1.2/braindecode/datasets → Braindecode-0.1.3/braindecode/datautils}/signal_target.py +0 -0
  26. {Braindecode-0.1.2/braindecode → Braindecode-0.1.3/braindecode/datautils}/splitters.py +0 -0
  27. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/experiments/__init__.py +0 -0
  28. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/experiments/monitors.py +0 -0
  29. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/experiments/stopcriteria.py +0 -0
  30. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/models/__init__.py +0 -0
  31. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/models/shallow_fbcsp.py +0 -0
  32. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/torchext/__init__.py +0 -0
  33. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/torchext/constraints.py +0 -0
  34. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/torchext/functions.py +0 -0
  35. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/torchext/losses.py +0 -0
  36. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/torchext/modules.py +0 -0
  37. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/torchext/util.py +0 -0
  38. {Braindecode-0.1.2 → Braindecode-0.1.3}/braindecode/util.py +0 -0
  39. {Braindecode-0.1.2 → Braindecode-0.1.3}/docs/source/braindecode.experiments.rst +0 -0
  40. {Braindecode-0.1.2 → Braindecode-0.1.3}/docs/source/braindecode.models.rst +0 -0
  41. {Braindecode-0.1.2 → Braindecode-0.1.3}/docs/source/braindecode.torchext.rst +0 -0
  42. {Braindecode-0.1.2 → Braindecode-0.1.3}/docs/source/modules.rst +0 -0
  43. {Braindecode-0.1.2 → Braindecode-0.1.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: Braindecode
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A deep learning for raw time-domain EEG decoding toolbox.
5
5
  Home-page: https://github.com/robintibor/braindecode
6
6
  Author: Robin Tibor Schirrmeister
@@ -17,7 +17,14 @@ Description: Note: The old braindecode repository has been moved to
17
17
  Installation
18
18
  ============
19
19
 
20
- Install pytorch from http://pytorch.org/.
20
+ First, install pytorch from http://pytorch.org/.
21
+
22
+ Then, install braindecode via pip:
23
+
24
+ .. code-block:: bash
25
+
26
+ pip install braindecode
27
+
21
28
 
22
29
  Documentation
23
30
  =============
@@ -1,6 +1,6 @@
1
1
  LICENSE.txt
2
2
  MANIFEST.in
3
- README.md
3
+ README.rst
4
4
  setup.py
5
5
  Braindecode.egg-info/PKG-INFO
6
6
  Braindecode.egg-info/SOURCES.txt
@@ -9,12 +9,11 @@ Braindecode.egg-info/not-zip-safe
9
9
  Braindecode.egg-info/requires.txt
10
10
  Braindecode.egg-info/top_level.txt
11
11
  braindecode/__init__.py
12
- braindecode/iterators.py
13
- braindecode/splitters.py
14
- braindecode/trial_segment.py
15
12
  braindecode/util.py
16
- braindecode/datasets/__init__.py
17
- braindecode/datasets/signal_target.py
13
+ braindecode/datautils/__init__.py
14
+ braindecode/datautils/iterators.py
15
+ braindecode/datautils/signal_target.py
16
+ braindecode/datautils/splitters.py
18
17
  braindecode/experiments/__init__.py
19
18
  braindecode/experiments/experiment.py
20
19
  braindecode/experiments/monitors.py
@@ -31,7 +30,7 @@ docs/Makefile
31
30
  docs/conf.py
32
31
  docs/index.rst
33
32
  docs/notebooks/TrialWise_Decoding.ipynb
34
- docs/source/braindecode.datasets.rst
33
+ docs/source/braindecode.datautils.rst
35
34
  docs/source/braindecode.experiments.rst
36
35
  docs/source/braindecode.models.rst
37
36
  docs/source/braindecode.rst
@@ -1,4 +1,4 @@
1
- include README.md
1
+ include README.rst
2
2
  include LICENSE.txt
3
3
 
4
4
  recursive-include docs *.ipynb *.rst conf.py Makefile
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: Braindecode
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A deep learning for raw time-domain EEG decoding toolbox.
5
5
  Home-page: https://github.com/robintibor/braindecode
6
6
  Author: Robin Tibor Schirrmeister
@@ -17,7 +17,14 @@ Description: Note: The old braindecode repository has been moved to
17
17
  Installation
18
18
  ============
19
19
 
20
- Install pytorch from http://pytorch.org/.
20
+ First, install pytorch from http://pytorch.org/.
21
+
22
+ Then, install braindecode via pip:
23
+
24
+ .. code-block:: bash
25
+
26
+ pip install braindecode
27
+
21
28
 
22
29
  Documentation
23
30
  =============
@@ -9,7 +9,14 @@ A deep learning for raw time-domain EEG decoding toolbox.
9
9
  Installation
10
10
  ============
11
11
 
12
- Install pytorch from http://pytorch.org/.
12
+ First, install pytorch from http://pytorch.org/.
13
+
14
+ Then, install braindecode via pip:
15
+
16
+ .. code-block:: bash
17
+
18
+ pip install braindecode
19
+
13
20
 
14
21
  Documentation
15
22
  =============
@@ -1,10 +1,11 @@
1
- from collections import OrderedDict
2
1
  import logging
2
+ import numpy as np
3
+ from collections import OrderedDict
3
4
  from copy import deepcopy
5
+
4
6
  import pandas as pd
5
- import numpy as np
6
7
 
7
- from braindecode.splitters import concatenate_sets
8
+ from braindecode.datautils.splitters import concatenate_sets
8
9
  from braindecode.experiments.stopcriteria import MaxEpochs, ColumnBelow, Or
9
10
  from braindecode.torchext.util import np_to_var, set_random_seeds
10
11
 
@@ -17,9 +17,6 @@ help:
17
17
  apidoc:
18
18
  sphinx-apidoc -o source ../braindecode/
19
19
 
20
- livehtml:
21
- sphinx-autobuild -b html . _build/html
22
-
23
20
  # Catch-all target: route all unknown targets to Sphinx using the new
24
21
  # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
25
22
  %: Makefile
@@ -45,7 +45,7 @@ extensions = ['sphinx.ext.autodoc',
45
45
  'nbsphinx',
46
46
  ]
47
47
 
48
- exclude_patterns = ['_build', '**.ipynb_checkpoints']
48
+ exclude_patterns = ['_build', '**.ipynb_checkpoints/**']
49
49
 
50
50
  napoleon_google_docstring = False
51
51
  napoleon_use_param = False
@@ -1,19 +1,20 @@
1
- .. Braindecode documentation master file, created by
2
- sphinx-quickstart on Sat Jul 1 01:51:38 2017.
3
- You can adapt this file completely to your liking, but it should at least
4
- contain the root `toctree` directive.
5
-
6
1
  Welcome to Braindecode
7
2
  =======================================
8
3
 
9
-
10
-
11
- Some simple explanation!?!
4
+ **Under construction**
5
+ A deep learning for raw time-domain EEG decoding toolbox.
12
6
 
13
7
 
14
8
  Installation
15
9
  =======================================
16
- Well something how to install it, right?
10
+
11
+ First, install pytorch from http://pytorch.org/.
12
+
13
+ Then, install braindecode via pip:
14
+
15
+ .. code-block:: bash
16
+
17
+ pip install braindecode
17
18
 
18
19
 
19
20
  Tutorials
@@ -5,6 +5,8 @@
5
5
  "execution_count": 1,
6
6
  "metadata": {
7
7
  "collapsed": true,
8
+ "deletable": true,
9
+ "editable": true,
8
10
  "nbsphinx": "hidden"
9
11
  },
10
12
  "outputs": [],
@@ -17,14 +19,20 @@
17
19
  },
18
20
  {
19
21
  "cell_type": "markdown",
20
- "metadata": {},
22
+ "metadata": {
23
+ "deletable": true,
24
+ "editable": true
25
+ },
21
26
  "source": [
22
27
  "# Trialwise Decoding"
23
28
  ]
24
29
  },
25
30
  {
26
31
  "cell_type": "markdown",
27
- "metadata": {},
32
+ "metadata": {
33
+ "deletable": true,
34
+ "editable": true
35
+ },
28
36
  "source": [
29
37
  "In this example, we will use a convolutional neural network on the [Physiobank EEG Motor Movement/Imagery Dataset](https://www.physionet.org/physiobank/database/eegmmidb/) to decode two classes:\n",
30
38
  "\n",
@@ -50,7 +58,10 @@
50
58
  },
51
59
  {
52
60
  "cell_type": "markdown",
53
- "metadata": {},
61
+ "metadata": {
62
+ "deletable": true,
63
+ "editable": true
64
+ },
54
65
  "source": [
55
66
  "You can use any way to load your EEG dataset, here we will use the [python-mne](https://www.martinos.org/mne/stable/index.html) library. For a tutorial from mne using Common Spatial Patterns to decode this data, see [here](http://martinos.org/mne/stable/auto_examples/decoding/plot_decoding_csp_eeg.html)."
56
67
  ]
@@ -110,14 +121,20 @@
110
121
  },
111
122
  {
112
123
  "cell_type": "markdown",
113
- "metadata": {},
124
+ "metadata": {
125
+ "deletable": true,
126
+ "editable": true
127
+ },
114
128
  "source": [
115
129
  "## Convert data to Braindecode Format"
116
130
  ]
117
131
  },
118
132
  {
119
133
  "cell_type": "markdown",
120
- "metadata": {},
134
+ "metadata": {
135
+ "deletable": true,
136
+ "editable": true
137
+ },
121
138
  "source": [
122
139
  "Braindecode has a minimalistic ```SignalAndTarget``` class, with attributes `X` for the signal and `y` for the labels. For trialwise decoding, X should have these dimensions: trials x channels x timesteps."
123
140
  ]
@@ -141,7 +158,10 @@
141
158
  },
142
159
  {
143
160
  "cell_type": "markdown",
144
- "metadata": {},
161
+ "metadata": {
162
+ "deletable": true,
163
+ "editable": true
164
+ },
145
165
  "source": [
146
166
  "We use the first 60 trials for training and the last 30 for testing."
147
167
  ]
@@ -156,7 +176,7 @@
156
176
  },
157
177
  "outputs": [],
158
178
  "source": [
159
- "from braindecode.datasets.signal_target import SignalAndTarget\n",
179
+ "from braindecode.datautils.signal_target import SignalAndTarget\n",
160
180
  "from braindecode.torchext.util import set_random_seeds\n",
161
181
  "\n",
162
182
  "train_set = SignalAndTarget(X[:60], y=y[:60])\n",
@@ -165,14 +185,20 @@
165
185
  },
166
186
  {
167
187
  "cell_type": "markdown",
168
- "metadata": {},
188
+ "metadata": {
189
+ "deletable": true,
190
+ "editable": true
191
+ },
169
192
  "source": [
170
193
  "## Create the model"
171
194
  ]
172
195
  },
173
196
  {
174
197
  "cell_type": "markdown",
175
- "metadata": {},
198
+ "metadata": {
199
+ "deletable": true,
200
+ "editable": true
201
+ },
176
202
  "source": [
177
203
  "Braindecode comes with some predefined convolutional neural network architectures for raw time-domain EEG. here, we use the shallow ConvNet model from [Deep learning with convolutional neural networks for brain mapping and decoding of movement-related information from the human EEG](https://arxiv.org/abs/1703.05051)."
178
204
  ]
@@ -205,7 +231,10 @@
205
231
  },
206
232
  {
207
233
  "cell_type": "markdown",
208
- "metadata": {},
234
+ "metadata": {
235
+ "deletable": true,
236
+ "editable": true
237
+ },
209
238
  "source": [
210
239
  "We use [Adam](https://arxiv.org/abs/1412.6980) to optimize the parameters of our network."
211
240
  ]
@@ -227,14 +256,20 @@
227
256
  },
228
257
  {
229
258
  "cell_type": "markdown",
230
- "metadata": {},
259
+ "metadata": {
260
+ "deletable": true,
261
+ "editable": true
262
+ },
231
263
  "source": [
232
264
  "## Training loop"
233
265
  ]
234
266
  },
235
267
  {
236
268
  "cell_type": "markdown",
237
- "metadata": {},
269
+ "metadata": {
270
+ "deletable": true,
271
+ "editable": true
272
+ },
238
273
  "source": [
239
274
  "This is a conventional stochastic gradient descent training loop:\n",
240
275
  "1. Get randomly shuffled batches of trials\n",
@@ -411,7 +446,7 @@
411
446
  ],
412
447
  "source": [
413
448
  "from braindecode.torchext.util import np_to_var, var_to_np\n",
414
- "from braindecode.iterators import get_balanced_batches\n",
449
+ "from braindecode.datautils.iterators import get_balanced_batches\n",
415
450
  "import torch.nn.functional as F\n",
416
451
  "from numpy.random import RandomState\n",
417
452
  "rng = RandomState((2017,6,30))\n",
@@ -460,21 +495,30 @@
460
495
  },
461
496
  {
462
497
  "cell_type": "markdown",
463
- "metadata": {},
498
+ "metadata": {
499
+ "deletable": true,
500
+ "editable": true
501
+ },
464
502
  "source": [
465
503
  "Eventually, we arrive at 63.3% accuracy, so 19 from 30 trials are correctly predicted. See in the next tutorial, how we can achieve better accuracies using cropped training."
466
504
  ]
467
505
  },
468
506
  {
469
507
  "cell_type": "markdown",
470
- "metadata": {},
508
+ "metadata": {
509
+ "deletable": true,
510
+ "editable": true
511
+ },
471
512
  "source": [
472
513
  "## Dataset References\n"
473
514
  ]
474
515
  },
475
516
  {
476
517
  "cell_type": "markdown",
477
- "metadata": {},
518
+ "metadata": {
519
+ "deletable": true,
520
+ "editable": true
521
+ },
478
522
  "source": [
479
523
  " This dataset was created and contributed to PhysioNet by the developers of the [BCI2000](http://www.schalklab.org/research/bci2000) instrumentation system, which they used in making these recordings. The system is described in:\n",
480
524
  " \n",
@@ -0,0 +1,38 @@
1
+ braindecode\.datautils package
2
+ ==============================
3
+
4
+ Submodules
5
+ ----------
6
+
7
+ braindecode\.datautils\.iterators module
8
+ ----------------------------------------
9
+
10
+ .. automodule:: braindecode.datautils.iterators
11
+ :members:
12
+ :undoc-members:
13
+ :show-inheritance:
14
+
15
+ braindecode\.datautils\.signal\_target module
16
+ ---------------------------------------------
17
+
18
+ .. automodule:: braindecode.datautils.signal_target
19
+ :members:
20
+ :undoc-members:
21
+ :show-inheritance:
22
+
23
+ braindecode\.datautils\.splitters module
24
+ ----------------------------------------
25
+
26
+ .. automodule:: braindecode.datautils.splitters
27
+ :members:
28
+ :undoc-members:
29
+ :show-inheritance:
30
+
31
+
32
+ Module contents
33
+ ---------------
34
+
35
+ .. automodule:: braindecode.datautils
36
+ :members:
37
+ :undoc-members:
38
+ :show-inheritance:
@@ -0,0 +1,32 @@
1
+ braindecode package
2
+ ===================
3
+
4
+ Subpackages
5
+ -----------
6
+
7
+ .. toctree::
8
+
9
+ braindecode.datautils
10
+ braindecode.experiments
11
+ braindecode.models
12
+ braindecode.torchext
13
+
14
+ Submodules
15
+ ----------
16
+
17
+ braindecode\.util module
18
+ ------------------------
19
+
20
+ .. automodule:: braindecode.util
21
+ :members:
22
+ :undoc-members:
23
+ :show-inheritance:
24
+
25
+
26
+ Module contents
27
+ ---------------
28
+
29
+ .. automodule:: braindecode
30
+ :members:
31
+ :undoc-members:
32
+ :show-inheritance:
@@ -5,7 +5,7 @@ from os import path
5
5
  here = path.abspath(path.dirname(__file__))
6
6
 
7
7
  # Get the long description from the relevant file
8
- with open(path.join(here, 'README.md'), encoding='utf-8') as f:
8
+ with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
9
9
  long_description = f.read()
10
10
 
11
11
 
@@ -15,7 +15,7 @@ setup(
15
15
  # Versions should comply with PEP440. For a discussion on single-sourcing
16
16
  # the version across setup.py and the project code, see
17
17
  # http://packaging.python.org/en/latest/tutorial.html#version
18
- version='0.1.2',
18
+ version='0.1.3',
19
19
 
20
20
  description='A deep learning for raw time-domain EEG decoding toolbox.',
21
21
  long_description=long_description, #this is the
@@ -1,198 +0,0 @@
1
- import logging
2
- import numpy as np
3
- import xarray as xr
4
-
5
- log = logging.getLogger(__name__)
6
-
7
-
8
- def create_target_series(cnt, marker_def, ival):
9
- """
10
- Compute one-hot encoded target series.
11
- Parameters
12
- ----------
13
- cnt : DateArray
14
- marker_def: OrderedDict (str -> list int)
15
- Dictionary mapping class names -> list of marker codes. Order of keys
16
- is used to determine indices of classes in one-hot encoded result.
17
- ival : (number, number) tuple
18
- Segmentation interval for each trial.
19
- Returns
20
- -------
21
- 2darray
22
- One-hot encoded target series.
23
-
24
- """
25
- assert 'fs' in cnt.attrs
26
- assert 'events' in cnt.attrs
27
- assert ival[0] < ival[1]
28
- sample_ival = cnt.attrs['fs'] * np.array(ival) / 1000.0
29
- sample_ival = np.int32(np.round(sample_ival))
30
- assert sample_ival[0] < sample_ival[1]
31
-
32
-
33
- class_names = marker_def.keys()
34
- targets = np.zeros((len(cnt.data), len(class_names)), dtype=np.int32)
35
- for i_sample, m in cnt.attrs['events']:
36
- for class_idx, classname in enumerate(class_names):
37
- if m in marker_def[classname]:
38
- start_index = i_sample + sample_ival[0]
39
- stop_index = i_sample + sample_ival[1]
40
- assert stop_index > start_index
41
- if start_index >= 0 and stop_index <= len(cnt.coords['time']):
42
- targets[start_index:stop_index, class_idx] = 1
43
- elif start_index < 0:
44
- log.warn("Ignoring trial, start index < 0: {:d}".format(
45
- start_index))
46
- else:
47
- assert stop_index > len(cnt.coords['time'])
48
- log.warn("Ignoring trial, start index > n_samples:"
49
- "{:d} > {:d} ".format(
50
- stop_index, len(cnt.coords['time'])))
51
- return targets
52
-
53
-
54
- def compute_trial_start_stop_samples(y, check_trial_lengths_equal=True,
55
- input_time_length=None):
56
- """Computes trial start and end samples (end is inclusive) from
57
- one-hot encoded y-matrix.
58
- Specify input time length to kick out trials that are too short after
59
- signal start.
60
-
61
- Parameters
62
- ----------
63
- y : 2darray
64
- check_trial_lengths_equal : bool
65
- (Default value = True)
66
- input_time_length : int, optional
67
- (Default value = None)
68
-
69
- Returns
70
- -------
71
-
72
- """
73
- #TODO: change to start stop
74
- trial_part = np.sum(y, 1) == 1
75
- boundaries = np.diff(trial_part.astype(np.int32))
76
- i_trial_starts = np.flatnonzero(boundaries == 1) + 1
77
- i_trial_stops = np.flatnonzero(boundaries == -1) + 1
78
- # it can happen that a trial is only partially there since the
79
- # cnt signal was split in the middle of a trial
80
- # for now just remove these
81
- # use that start marker should always be before or equal to end marker
82
- if i_trial_starts[0] >= i_trial_stops[0]:
83
- # cut out first trial which only has end marker
84
- i_trial_stops = i_trial_stops[1:]
85
- if i_trial_starts[-1] >= i_trial_stops[-1]:
86
- # cut out last trial which only has start marker
87
- i_trial_starts = i_trial_starts[:-1]
88
-
89
- assert (len(i_trial_starts) == len(i_trial_stops))
90
- assert (np.all(i_trial_starts < i_trial_stops))
91
- # possibly remove first trials if they are too early
92
- if input_time_length is not None:
93
- while i_trial_starts[0] < (input_time_length - 1):
94
- i_trial_starts = i_trial_starts[1:]
95
- i_trial_stops = i_trial_stops[1:]
96
- if check_trial_lengths_equal:
97
- # just checking that all trial lengths are equal
98
- all_trial_lens = np.array(i_trial_stops) - np.array(i_trial_starts)
99
- assert all(all_trial_lens == all_trial_lens[0]), (
100
- "All trial lengths should be equal...")
101
- return i_trial_starts, i_trial_stops
102
-
103
-
104
- def segment_dat(cnt, marker_def, ival):
105
- """Convert a continuous data object to an epoched one.
106
-
107
- Given a continuous data object, a definition of classes, and an
108
- interval, this method looks for markers as defined in ``marker_def``
109
- and slices the dat according to the time interval given with
110
- ``ival`` along the ``timeaxis``. The returned ``dat`` object stores
111
- those slices and the class each slice belongs to.
112
-
113
- Epochs that are too close to the borders and thus too short are
114
- ignored.
115
-
116
- If the segmentation does not result in any epochs (i.e. the markers
117
- in ``marker_def`` could not be found in ``dat``, the resulting
118
- epo.data will be an empty array.
119
-
120
- This method is also suitable for **online processing**, please read
121
- the documentation for the ``newsamples`` parameter and have a look
122
- at the Examples below.
123
-
124
- Parameters
125
- ----------
126
- dat : Data
127
- the data object to be segmented
128
- marker_def : dict
129
- The keys are class names, the values are lists of markers
130
- ival : [int, int]
131
- The interval in milliseconds to cut around the markers. I.e. to
132
- get the interval starting with the marker plus the remaining
133
- 100ms define the interval like [0, 100]. The start point is
134
- included, the endpoint is not (like: ``[start, end)``). To get
135
- 200ms before the marker until 100ms after the marker do:
136
- ``[-200, 100]`` Only negative or positive values are possible
137
- (i.e. ``[-500, -100]``)
138
-
139
- Returns
140
- -------
141
- epo : Data
142
- a copy of the resulting epoched data.
143
-
144
- Raises
145
- ------
146
- AssertionError
147
- * if ``dat`` has not ``.fs`` or ``.markers`` attribute or if
148
- ``ival[0] > ival[1]``.
149
-
150
- Examples
151
- --------
152
-
153
- Offline Experiment
154
-
155
- >>> # Define the markers belonging to class 1 and 2
156
- >>> md = {'class 1': ['S1', 'S2'],
157
- ... 'class 2': ['S3', 'S4']
158
- ... }
159
- >>> # Epoch the data -500ms and +700ms around the markers defined in
160
- >>> # md
161
- >>> epo = segment_dat(cnt, md, [-500, 700])
162
-
163
- """
164
-
165
- assert 'fs' in cnt.attrs
166
- assert 'events' in cnt.attrs
167
- y = create_target_series(cnt, marker_def, ival=ival)
168
- # Create classes per trial
169
- # and sample inds per trial from the target series
170
- starts, stops = compute_trial_start_stop_samples(y)
171
- classes = [np.argmax(y[i_s]) for i_s in starts]
172
- sample_inds_per_trial = [list(range(i_start, i_stop))
173
- for (i_start, i_stop) in zip(starts, stops)]
174
-
175
- if len(sample_inds_per_trial) == 0:
176
- assert "No epochs not tested yet"
177
- data = np.array([])
178
- else:
179
- timeaxis = list(cnt.dims).index('time')
180
- # np.take inserts a new dimension at `axis`...
181
- data = cnt.data.take(sample_inds_per_trial, axis=timeaxis)
182
- # we want that new dimension at axis 0 so we have to swap it.
183
- # before that we have to convert the negative axis indices to
184
- # their equivalent positive one, otherwise swapaxis will be one
185
- # off.
186
- data = data.swapaxes(0, timeaxis)
187
- time = np.linspace(ival[0], ival[1],
188
- data.shape[1], # assume timeaxis now on 1
189
- endpoint=False)
190
- epo = xr.DataArray(data,
191
- coords={'trials': classes, 'time': time,
192
- 'channels': cnt.channels,},
193
- dims=('trials', 'time','channels',))
194
- epo.attrs = cnt.attrs.copy()
195
- # remove events part
196
- epo.attrs.pop('events')
197
- return epo
198
-
@@ -1,22 +0,0 @@
1
- braindecode\.datasets package
2
- =============================
3
-
4
- Submodules
5
- ----------
6
-
7
- braindecode\.datasets\.signal\_target module
8
- --------------------------------------------
9
-
10
- .. automodule:: braindecode.datasets.signal_target
11
- :members:
12
- :undoc-members:
13
- :show-inheritance:
14
-
15
-
16
- Module contents
17
- ---------------
18
-
19
- .. automodule:: braindecode.datasets
20
- :members:
21
- :undoc-members:
22
- :show-inheritance:
@@ -1,56 +0,0 @@
1
- braindecode package
2
- ===================
3
-
4
- Subpackages
5
- -----------
6
-
7
- .. toctree::
8
-
9
- braindecode.datasets
10
- braindecode.experiments
11
- braindecode.models
12
- braindecode.torchext
13
-
14
- Submodules
15
- ----------
16
-
17
- braindecode\.iterators module
18
- -----------------------------
19
-
20
- .. automodule:: braindecode.iterators
21
- :members:
22
- :undoc-members:
23
- :show-inheritance:
24
-
25
- braindecode\.splitters module
26
- -----------------------------
27
-
28
- .. automodule:: braindecode.splitters
29
- :members:
30
- :undoc-members:
31
- :show-inheritance:
32
-
33
- braindecode\.trial\_segment module
34
- ----------------------------------
35
-
36
- .. automodule:: braindecode.trial_segment
37
- :members:
38
- :undoc-members:
39
- :show-inheritance:
40
-
41
- braindecode\.util module
42
- ------------------------
43
-
44
- .. automodule:: braindecode.util
45
- :members:
46
- :undoc-members:
47
- :show-inheritance:
48
-
49
-
50
- Module contents
51
- ---------------
52
-
53
- .. automodule:: braindecode
54
- :members:
55
- :undoc-members:
56
- :show-inheritance:
File without changes
File without changes