braindecode 0.1.7__tar.gz → 0.1.9__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 (68) hide show
  1. {Braindecode-0.1.7 → Braindecode-0.1.9}/Braindecode.egg-info/PKG-INFO +1 -1
  2. {Braindecode-0.1.7 → Braindecode-0.1.9}/PKG-INFO +1 -1
  3. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datautil/signalproc.py +1 -2
  4. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/models/deep4.py +17 -8
  5. Braindecode-0.1.9/braindecode/torch_ext/modules.py +80 -0
  6. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/conf.py +4 -2
  7. Braindecode-0.1.9/docs/notebooks/BBCI_Data_Trialwise.ipynb +839 -0
  8. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/notebooks/visualization/Perturbation.ipynb +13 -3
  9. {Braindecode-0.1.7 → Braindecode-0.1.9}/setup.py +1 -1
  10. Braindecode-0.1.7/braindecode/torch_ext/modules.py +0 -30
  11. Braindecode-0.1.7/docs/notebooks/BBCI_Data_Trialwise.ipynb +0 -780
  12. {Braindecode-0.1.7 → Braindecode-0.1.9}/Braindecode.egg-info/SOURCES.txt +0 -0
  13. {Braindecode-0.1.7 → Braindecode-0.1.9}/Braindecode.egg-info/dependency_links.txt +0 -0
  14. {Braindecode-0.1.7 → Braindecode-0.1.9}/Braindecode.egg-info/not-zip-safe +0 -0
  15. {Braindecode-0.1.7 → Braindecode-0.1.9}/Braindecode.egg-info/requires.txt +0 -0
  16. {Braindecode-0.1.7 → Braindecode-0.1.9}/Braindecode.egg-info/top_level.txt +0 -0
  17. {Braindecode-0.1.7 → Braindecode-0.1.9}/LICENSE.txt +0 -0
  18. {Braindecode-0.1.7 → Braindecode-0.1.9}/MANIFEST.in +0 -0
  19. {Braindecode-0.1.7 → Braindecode-0.1.9}/README.rst +0 -0
  20. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/__init__.py +0 -0
  21. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datasets/__init__.py +0 -0
  22. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datasets/bbci.py +0 -0
  23. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datasets/bcic_iv_2a.py +0 -0
  24. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datasets/multiple.py +0 -0
  25. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datasets/sensor_positions.py +0 -0
  26. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datautil/__init__.py +0 -0
  27. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datautil/iterators.py +0 -0
  28. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datautil/signal_target.py +0 -0
  29. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datautil/splitters.py +0 -0
  30. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datautil/trial_segment.py +0 -0
  31. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/datautil/util.py +0 -0
  32. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/experiments/__init__.py +0 -0
  33. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/experiments/experiment.py +0 -0
  34. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/experiments/monitors.py +0 -0
  35. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/experiments/stopcriteria.py +0 -0
  36. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/mne_ext/__init__.py +0 -0
  37. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/mne_ext/signalproc.py +0 -0
  38. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/models/__init__.py +0 -0
  39. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/models/eegnet.py +0 -0
  40. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/models/shallow_fbcsp.py +0 -0
  41. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/models/util.py +0 -0
  42. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/torch_ext/__init__.py +0 -0
  43. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/torch_ext/constraints.py +0 -0
  44. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/torch_ext/functions.py +0 -0
  45. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/torch_ext/init.py +0 -0
  46. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/torch_ext/losses.py +0 -0
  47. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/torch_ext/util.py +0 -0
  48. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/util.py +0 -0
  49. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/visualization/__init__.py +0 -0
  50. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/visualization/perturbation.py +0 -0
  51. {Braindecode-0.1.7 → Braindecode-0.1.9}/braindecode/visualization/plot.py +0 -0
  52. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/Makefile +0 -0
  53. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/index.rst +0 -0
  54. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/notebooks/BBCI_Data.ipynb +0 -0
  55. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/notebooks/BBCI_Data_Start_Stop.ipynb +0 -0
  56. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/notebooks/Cropped_Decoding.ipynb +0 -0
  57. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/notebooks/Experiment_Class.ipynb +0 -0
  58. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/notebooks/TrialWise_Decoding.ipynb +0 -0
  59. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/source/braindecode.datasets.rst +0 -0
  60. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/source/braindecode.datautil.rst +0 -0
  61. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/source/braindecode.experiments.rst +0 -0
  62. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/source/braindecode.mne_ext.rst +0 -0
  63. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/source/braindecode.models.rst +0 -0
  64. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/source/braindecode.rst +0 -0
  65. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/source/braindecode.torch_ext.rst +0 -0
  66. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/source/braindecode.visualization.rst +0 -0
  67. {Braindecode-0.1.7 → Braindecode-0.1.9}/docs/source/modules.rst +0 -0
  68. {Braindecode-0.1.7 → Braindecode-0.1.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: Braindecode
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: A deep learning toolbox to decode raw time-domain EEG.
5
5
  Home-page: https://github.com/robintibor/braindecode
6
6
  Author: Robin Tibor Schirrmeister
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: Braindecode
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: A deep learning toolbox to decode raw time-domain EEG.
5
5
  Home-page: https://github.com/robintibor/braindecode
6
6
  Author: Robin Tibor Schirrmeister
@@ -17,7 +17,7 @@ def exponential_running_standardize(data, factor_new=0.001,
17
17
  :math:`m_t=\mathrm{factornew} \cdot mean(x_t) + (1 - \mathrm{factornew}) \cdot m_{t-1}`.
18
18
 
19
19
  Then, compute exponential running variance :math:`v_t` at time `t` as
20
- :math:`m_t=\mathrm{factornew} \cdot (m_t - x_t)^2 + (1 - \mathrm{factornew}) \cdot v_{t-1}`.
20
+ :math:`v_t=\mathrm{factornew} \cdot (m_t - x_t)^2 + (1 - \mathrm{factornew}) \cdot v_{t-1}`.
21
21
 
22
22
  Finally, standardize the data point :math:`x_t` at time `t` as:
23
23
  :math:`x'_t=(x_t - m_t) / max(\sqrt{v_t}, eps)`.
@@ -214,4 +214,3 @@ def filter_is_stable(a):
214
214
  "a: {:s}".format(str(a)))
215
215
  # from http://stackoverflow.com/a/8812737/1469195
216
216
  return np.all(np.abs(np.roots(a))<1)
217
-
@@ -2,7 +2,7 @@ import numpy as np
2
2
  from torch import nn
3
3
  from torch.nn import init
4
4
  from torch.nn.functional import elu
5
- from braindecode.torch_ext.modules import Expression
5
+ from braindecode.torch_ext.modules import Expression, AvgPool2dWithConv
6
6
  from braindecode.torch_ext.functions import identity
7
7
  from braindecode.torch_ext.util import np_to_var
8
8
 
@@ -45,7 +45,8 @@ class Deep4Net(object):
45
45
  double_time_convs=False,
46
46
  split_first_layer=True,
47
47
  batch_norm=True,
48
- batch_norm_alpha=0.1):
48
+ batch_norm_alpha=0.1,
49
+ stride_before_pool=False):
49
50
  if final_conv_length == 'auto':
50
51
  assert input_time_length is not None
51
52
 
@@ -53,7 +54,13 @@ class Deep4Net(object):
53
54
  del self.self
54
55
 
55
56
  def create_network(self):
56
- pool_class_dict = dict(max=nn.MaxPool2d, mean=nn.AvgPool2d)
57
+ if self.stride_before_pool:
58
+ conv_stride = self.pool_time_stride
59
+ pool_stride = 1
60
+ else:
61
+ conv_stride = 1
62
+ pool_stride = self.pool_time_stride
63
+ pool_class_dict = dict(max=nn.MaxPool2d, mean=AvgPool2dWithConv)
57
64
  first_pool_class = pool_class_dict[self.first_pool_mode]
58
65
  later_pool_class = pool_class_dict[self.later_pool_mode]
59
66
  model = nn.Sequential()
@@ -66,14 +73,15 @@ class Deep4Net(object):
66
73
  stride=1, ))
67
74
  model.add_module('conv_spat',
68
75
  nn.Conv2d(self.n_filters_time, self.n_filters_spat,
69
- (1, self.in_chans), stride=1,
76
+ (1, self.in_chans),
77
+ stride=(conv_stride, 1),
70
78
  bias=not self.batch_norm))
71
79
  n_filters_conv = self.n_filters_spat
72
80
  else:
73
81
  model.add_module('conv_time',
74
82
  nn.Conv2d(self.in_chans, self.n_filters_time,
75
83
  (self.filter_time_length, 1),
76
- stride=1,
84
+ stride=(conv_stride, 1),
77
85
  bias=not self.batch_norm))
78
86
  n_filters_conv = self.n_filters_time
79
87
  if self.batch_norm:
@@ -86,7 +94,7 @@ class Deep4Net(object):
86
94
  model.add_module('pool',
87
95
  first_pool_class(
88
96
  kernel_size=(self.pool_time_length, 1),
89
- stride=(self.pool_time_stride, 1)))
97
+ stride=(pool_stride, 1)))
90
98
  model.add_module('pool_nonlin', Expression(self.first_pool_nonlin))
91
99
 
92
100
  def add_conv_pool_block(model, n_filters_before,
@@ -97,7 +105,8 @@ class Deep4Net(object):
97
105
  model.add_module('conv' + suffix.format(block_nr),
98
106
  nn.Conv2d(n_filters_before, n_filters,
99
107
  (filter_length, 1),
100
- stride=1, bias=not self.batch_norm))
108
+ stride=(conv_stride, 1),
109
+ bias=not self.batch_norm))
101
110
  if self.batch_norm:
102
111
  model.add_module('bnorm' + suffix,
103
112
  nn.BatchNorm2d(n_filters,
@@ -110,7 +119,7 @@ class Deep4Net(object):
110
119
  model.add_module('pool' + suffix,
111
120
  later_pool_class(
112
121
  kernel_size=(self.pool_time_length, 1),
113
- stride=(self.pool_time_stride, 1)))
122
+ stride=(pool_stride, 1)))
114
123
  model.add_module('pool_nonlin' + suffix,
115
124
  Expression(self.later_pool_nonlin))
116
125
 
@@ -0,0 +1,80 @@
1
+ import numpy as np
2
+ import torch
3
+ import torch.nn.functional as F
4
+
5
+ from braindecode.torch_ext.util import np_to_var
6
+
7
+
8
+ class Expression(torch.nn.Module):
9
+ """
10
+ Compute given expression on forward pass.
11
+
12
+ Parameters
13
+ ----------
14
+ expression_fn: function
15
+ Should accept variable number of objects of type
16
+ `torch.autograd.Variable` to compute its output.
17
+ """
18
+ def __init__(self, expression_fn):
19
+ super(Expression, self).__init__()
20
+ self.expression_fn = expression_fn
21
+
22
+ def forward(self, *x):
23
+ return self.expression_fn(*x)
24
+
25
+ def __repr__(self):
26
+ if (hasattr(self.expression_fn, 'func') and
27
+ hasattr(self.expression_fn, 'kwargs')):
28
+ expression_str = "{:s} {:s}".format(
29
+ self.expression_fn.func.__name__,
30
+ str(self.expression_fn.kwargs))
31
+ else:
32
+ expression_str = self.expression_fn.__name__
33
+ return (self.__class__.__name__ + '(' +
34
+ 'expression=' + str(expression_str) + ')')
35
+
36
+
37
+ class AvgPool2dWithConv(torch.nn.Module):
38
+ """
39
+ Compute average pooling using a convolution, to have the dilation parameter.
40
+
41
+ Parameters
42
+ ----------
43
+ kernel_size: (int,int)
44
+ Size of the pooling region.
45
+ stride: (int,int)
46
+ Stride of the pooling operation.
47
+ dilation: int or (int,int)
48
+ Dilation applied to the pooling filter.
49
+ """
50
+ def __init__(self, kernel_size, stride, dilation=1):
51
+ super(AvgPool2dWithConv, self).__init__()
52
+ self.kernel_size = kernel_size
53
+ self.stride = stride
54
+ self.dilation = dilation
55
+ self.weights = None
56
+
57
+ def forward(self, x):
58
+ # Create weights for the convolution on demand:
59
+ # size or type of x changed...
60
+ in_channels = x.size()[1]
61
+ weight_shape = (in_channels, 1,
62
+ self.kernel_size[0], self.kernel_size[1])
63
+ if self.weights is None or (
64
+ (tuple(self.weights.size()) != tuple(weight_shape)) or (
65
+ self.weights.is_cuda != x.is_cuda
66
+ ) or (
67
+ self.weights.data.type() != x.data.type()
68
+ )):
69
+ n_pool = np.prod(self.kernel_size)
70
+ weights = np_to_var(
71
+ np.ones(weight_shape, dtype=np.float32) / float(n_pool))
72
+ weights = weights.type_as(x)
73
+ if x.is_cuda:
74
+ weights = weights.cuda()
75
+ self.weights = weights
76
+
77
+ pooled = F.conv2d(x, self.weights, bias=None, stride=self.stride,
78
+ dilation=self.dilation,
79
+ groups=in_channels,)
80
+ return pooled
@@ -21,6 +21,8 @@ import os
21
21
  import sys
22
22
  sys.path.insert(0, os.path.abspath('.'))
23
23
  sys.path.insert(0, os.path.abspath('..'))
24
+ import matplotlib
25
+ matplotlib.use('agg')
24
26
 
25
27
 
26
28
 
@@ -108,9 +110,9 @@ author = 'Robin Tibor Schirrmeister'
108
110
  # built documents.
109
111
  #
110
112
  # The short X.Y version.
111
- version = '0.1.6'
113
+ version = '0.1.9'
112
114
  # The full version, including alpha/beta/rc tags.
113
- release = '0.1.6'
115
+ release = '0.1.9'
114
116
 
115
117
  # The language for content autogenerated by Sphinx. Refer to documentation
116
118
  # for a list of supported languages.