Braindecode 1.3.0.dev175368549__tar.gz → 1.3.0.dev175435903__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 (148) hide show
  1. {braindecode-1.3.0.dev175368549/braindecode.egg-info → braindecode-1.3.0.dev175435903}/PKG-INFO +5 -1
  2. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/augmentation/functional.py +101 -0
  3. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/augmentation/transforms.py +74 -0
  4. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datautil/serialization.py +1 -1
  5. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/atcnet.py +11 -11
  6. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/attentionbasenet.py +4 -4
  7. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/attn_sleep.py +9 -7
  8. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/bendr.py +1 -1
  9. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/biot.py +25 -23
  10. braindecode-1.3.0.dev175435903/braindecode/models/config.py +230 -0
  11. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/contrawr.py +2 -2
  12. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/ctnet.py +33 -33
  13. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/deep4.py +4 -4
  14. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/deepsleepnet.py +4 -4
  15. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eegconformer.py +27 -22
  16. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eeginception_erp.py +1 -1
  17. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eeginception_mi.py +3 -3
  18. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eegitnet.py +3 -3
  19. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eegnet.py +1 -1
  20. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eegnex.py +1 -1
  21. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eegsimpleconv.py +1 -1
  22. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eegtcnet.py +3 -3
  23. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/fbcnet.py +1 -1
  24. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/fblightconvnet.py +1 -1
  25. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/fbmsnet.py +1 -1
  26. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/hybrid.py +1 -1
  27. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/ifnet.py +2 -2
  28. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/labram.py +39 -39
  29. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/medformer.py +14 -14
  30. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/msvtnet.py +9 -9
  31. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/patchedtransformer.py +46 -46
  32. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/sccnet.py +1 -1
  33. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/shallow_fbcsp.py +4 -2
  34. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/sinc_shallow.py +1 -2
  35. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/sleep_stager_blanco_2020.py +1 -1
  36. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/sleep_stager_chambon_2018.py +1 -1
  37. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/sparcnet.py +4 -4
  38. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/sstdpn.py +1 -1
  39. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/summary.csv +1 -1
  40. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/syncnet.py +1 -1
  41. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/tcn.py +3 -3
  42. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/tidnet.py +1 -1
  43. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/tsinception.py +1 -1
  44. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/usleep.py +3 -3
  45. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/util.py +154 -14
  46. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/blocks.py +3 -1
  47. braindecode-1.3.0.dev175435903/braindecode/version.py +1 -0
  48. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903/braindecode.egg-info}/PKG-INFO +5 -1
  49. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode.egg-info/SOURCES.txt +1 -0
  50. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode.egg-info/requires.txt +5 -0
  51. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/api.rst +8 -0
  52. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/whats_new.rst +7 -0
  53. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/pyproject.toml +5 -0
  54. braindecode-1.3.0.dev175368549/braindecode/version.py +0 -1
  55. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/LICENSE.txt +0 -0
  56. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/MANIFEST.in +0 -0
  57. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/NOTICE.txt +0 -0
  58. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/README.rst +0 -0
  59. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/__init__.py +0 -0
  60. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/augmentation/__init__.py +0 -0
  61. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/augmentation/base.py +0 -0
  62. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/classifier.py +0 -0
  63. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/__init__.py +0 -0
  64. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/base.py +0 -0
  65. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/bbci.py +0 -0
  66. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/bcicomp.py +0 -0
  67. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/bids.py +0 -0
  68. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/experimental.py +0 -0
  69. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/hub.py +0 -0
  70. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/hub_validation.py +0 -0
  71. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/mne.py +0 -0
  72. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/moabb.py +0 -0
  73. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/nmt.py +0 -0
  74. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/registry.py +0 -0
  75. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/sleep_physio_challe_18.py +0 -0
  76. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/sleep_physionet.py +0 -0
  77. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/tuh.py +0 -0
  78. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datasets/xy.py +0 -0
  79. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datautil/__init__.py +0 -0
  80. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datautil/channel_utils.py +0 -0
  81. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datautil/hub_formats.py +0 -0
  82. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/datautil/util.py +0 -0
  83. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/eegneuralnet.py +0 -0
  84. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/functional/__init__.py +0 -0
  85. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/functional/functions.py +0 -0
  86. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/functional/initialization.py +0 -0
  87. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/__init__.py +0 -0
  88. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/base.py +0 -0
  89. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eegminer.py +0 -0
  90. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/eegsym.py +0 -0
  91. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/luna.py +0 -0
  92. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/models/signal_jepa.py +0 -0
  93. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/__init__.py +0 -0
  94. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/activation.py +0 -0
  95. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/attention.py +0 -0
  96. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/convolution.py +0 -0
  97. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/filter.py +0 -0
  98. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/layers.py +0 -0
  99. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/linear.py +0 -0
  100. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/parametrization.py +0 -0
  101. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/stats.py +0 -0
  102. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/util.py +0 -0
  103. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/modules/wrapper.py +0 -0
  104. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/preprocessing/__init__.py +0 -0
  105. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/preprocessing/eegprep_preprocess.py +0 -0
  106. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/preprocessing/mne_preprocess.py +0 -0
  107. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/preprocessing/preprocess.py +0 -0
  108. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/preprocessing/util.py +0 -0
  109. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/preprocessing/windowers.py +0 -0
  110. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/regressor.py +0 -0
  111. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/samplers/__init__.py +0 -0
  112. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/samplers/base.py +0 -0
  113. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/samplers/ssl.py +0 -0
  114. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/training/__init__.py +0 -0
  115. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/training/callbacks.py +0 -0
  116. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/training/losses.py +0 -0
  117. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/training/scoring.py +0 -0
  118. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/util.py +0 -0
  119. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/visualization/__init__.py +0 -0
  120. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/visualization/confusion_matrices.py +0 -0
  121. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode/visualization/gradients.py +0 -0
  122. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode.egg-info/dependency_links.txt +0 -0
  123. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/braindecode.egg-info/top_level.txt +0 -0
  124. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/Makefile +0 -0
  125. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/_templates/autosummary/class.rst +0 -0
  126. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/_templates/autosummary/function.rst +0 -0
  127. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/cite.rst +0 -0
  128. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/conf.py +0 -0
  129. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/help.rst +0 -0
  130. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/index.rst +0 -0
  131. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/install/install.rst +0 -0
  132. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/install/install_pip.rst +0 -0
  133. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/install/install_source.rst +0 -0
  134. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/categorization/attention.rst +0 -0
  135. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/categorization/channel.rst +0 -0
  136. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/categorization/convolution.rst +0 -0
  137. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/categorization/filterbank.rst +0 -0
  138. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/categorization/gnn.rst +0 -0
  139. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/categorization/interpretable.rst +0 -0
  140. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/categorization/lbm.rst +0 -0
  141. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/categorization/recurrent.rst +0 -0
  142. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/categorization/spd.rst +0 -0
  143. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/models.rst +0 -0
  144. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/models_categorization.rst +0 -0
  145. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/models_table.rst +0 -0
  146. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/models/models_visualization.rst +0 -0
  147. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/docs/sg_execution_times.rst +0 -0
  148. {braindecode-1.3.0.dev175368549 → braindecode-1.3.0.dev175435903}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: braindecode
3
- Version: 1.3.0.dev175368549
3
+ Version: 1.3.0.dev175435903
4
4
  Summary: Deep learning software to decode EEG, ECG or MEG signals
5
5
  Author-email: Robin Tibor Schirrmeister <robintibor@gmail.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Alexandre Gramfort <agramfort@meta.com>
6
6
  Maintainer-email: Alexandre Gramfort <agramfort@meta.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Robin Tibor Schirrmeister <robintibor@gmail.com>
@@ -52,6 +52,9 @@ Requires-Dist: pytest-cov; extra == "tests"
52
52
  Requires-Dist: codecov; extra == "tests"
53
53
  Requires-Dist: pytest_cases; extra == "tests"
54
54
  Requires-Dist: mypy; extra == "tests"
55
+ Provides-Extra: typing
56
+ Requires-Dist: pydantic<3.0,>=2.0; extra == "typing"
57
+ Requires-Dist: numpydantic>=1.7; extra == "typing"
55
58
  Provides-Extra: docs
56
59
  Requires-Dist: sphinx_gallery; extra == "docs"
57
60
  Requires-Dist: sphinx_rtd_theme; extra == "docs"
@@ -76,6 +79,7 @@ Requires-Dist: braindecode[hub]; extra == "all"
76
79
  Requires-Dist: braindecode[tests]; extra == "all"
77
80
  Requires-Dist: braindecode[docs]; extra == "all"
78
81
  Requires-Dist: braindecode[eegprep]; extra == "all"
82
+ Requires-Dist: braindecode[typing]; extra == "all"
79
83
  Dynamic: license-file
80
84
 
81
85
  .. image:: https://badges.gitter.im/braindecodechat/community.svg
@@ -1,6 +1,7 @@
1
1
  # Authors: Cédric Rommel <cedric.rommel@inria.fr>
2
2
  # Alexandre Gramfort <alexandre.gramfort@inria.fr>
3
3
  # Gustavo Rodrigues <gustavenrique01@gmail.com>
4
+ # Bruna Lopes <brunajaflopes@gmail.com>
4
5
  #
5
6
  # License: BSD (3-clause)
6
7
 
@@ -1194,3 +1195,103 @@ def mask_encoding(
1194
1195
  X[mask] = 0
1195
1196
 
1196
1197
  return X, y # Return the masked tensor and labels
1198
+
1199
+
1200
+ def channels_rereference(
1201
+ X: torch.Tensor,
1202
+ y: torch.Tensor,
1203
+ random_state: int | np.random.RandomState | None = None,
1204
+ ) -> tuple[torch.Tensor, torch.Tensor]:
1205
+ """Randomly re-reference channels in EEG data matrix.
1206
+
1207
+ Part of the augmentations proposed in [1]_
1208
+
1209
+ Parameters
1210
+ ----------
1211
+ X : torch.Tensor
1212
+ EEG input example or batch.
1213
+ y : torch.Tensor
1214
+ EEG labels for the example or batch.
1215
+ random_state: int | numpy.random.Generator, optional
1216
+ Seed to be used to instantiate numpy random number generator instance.
1217
+ Defaults to None.
1218
+
1219
+ Returns
1220
+ -------
1221
+ torch.Tensor
1222
+ Transformed inputs.
1223
+ torch.Tensor
1224
+ Transformed labels.
1225
+
1226
+ References
1227
+ ----------
1228
+ .. [1] Mohsenvand, M.N., Izadi, M.R. &amp; Maes, P.. (2020). Contrastive
1229
+ Representation Learning for Electroencephalogram Classification. Proceedings
1230
+ of the Machine Learning for Health NeurIPS Workshop, in Proceedings of Machine
1231
+ Learning Research 136:238-253
1232
+
1233
+ """
1234
+
1235
+ rng = check_random_state(random_state)
1236
+ batch_size, n_channels, _ = X.shape
1237
+
1238
+ ch = rng.randint(0, n_channels, size=batch_size)
1239
+
1240
+ X_ch = X[torch.arange(batch_size), ch, :]
1241
+ X = X - X_ch.unsqueeze(1)
1242
+ X[torch.arange(batch_size), ch, :] = -X_ch
1243
+
1244
+ return X, y
1245
+
1246
+
1247
+ def amplitude_scale(
1248
+ X: torch.Tensor,
1249
+ y: torch.Tensor,
1250
+ scale: tuple,
1251
+ random_state: int | np.random.RandomState | None = None,
1252
+ ) -> tuple[torch.Tensor, torch.Tensor]:
1253
+ """Rescale amplitude of each channel based on a random sampled scaling value.
1254
+
1255
+ Part of the augmentations proposed in [1]_
1256
+
1257
+ Parameters
1258
+ ----------
1259
+ X : torch.Tensor
1260
+ EEG input example or batch.
1261
+ y : torch.Tensor
1262
+ EEG labels for the example or batch.
1263
+ scale : tuple of floats
1264
+ Interval from which ypu sample the scaling value
1265
+ random_state: int | numpy.random.Generator, optional
1266
+ Seed to be used to instantiate numpy random number generator instance.
1267
+ Defaults to None.
1268
+
1269
+ Returns
1270
+ -------
1271
+ torch.Tensor
1272
+ Transformed inputs.
1273
+ torch.Tensor
1274
+ Transformed labels.
1275
+
1276
+ References
1277
+ ----------
1278
+ .. [1] Mohsenvand, M.N., Izadi, M.R. &amp; Maes, P.. (2020). Contrastive
1279
+ Representation Learning for Electroencephalogram Classification. Proceedings
1280
+ of the Machine Learning for Health NeurIPS Workshop, in Proceedings of Machine
1281
+ Learning Research 136:238-253
1282
+
1283
+ """
1284
+
1285
+ rng = torch.Generator()
1286
+ rng.manual_seed(random_state)
1287
+ batch_size, n_channels, _ = X.shape
1288
+
1289
+ # Parameter for scaling amplitude / channel / trial
1290
+ l, h = scale
1291
+ s = l + (h - l) * torch.rand(
1292
+ batch_size, n_channels, 1, generator=rng, device=X.device, dtype=X.dtype
1293
+ )
1294
+
1295
+ X = s * X
1296
+
1297
+ return X, y
@@ -1,6 +1,7 @@
1
1
  # Authors: Cédric Rommel <cedric.rommel@inria.fr>
2
2
  # Alexandre Gramfort <alexandre.gramfort@inria.fr>
3
3
  # Gustavo Rodrigues <gustavenrique01@gmail.com>
4
+ # Bruna Lopes <brunajaflopes@gmail.com>
4
5
  #
5
6
  # License: BSD (3-clause)
6
7
 
@@ -13,9 +14,11 @@ from mne.channels import make_standard_montage
13
14
 
14
15
  from .base import Transform
15
16
  from .functional import (
17
+ amplitude_scale,
16
18
  bandstop_filter,
17
19
  channels_dropout,
18
20
  channels_permute,
21
+ channels_rereference,
19
22
  channels_shuffle,
20
23
  frequency_shift,
21
24
  ft_surrogate,
@@ -1271,3 +1274,74 @@ class MaskEncoding(Transform):
1271
1274
  "segment_length": segment_length,
1272
1275
  "n_segments": self.n_segments,
1273
1276
  }
1277
+
1278
+
1279
+ class ChannelsReref(Transform):
1280
+ """Randomly re-reference channels in EEG data matrix.
1281
+
1282
+ Part of the augmentations proposed in [1]_
1283
+
1284
+ Parameters
1285
+ ----------
1286
+ probability: float
1287
+ Float setting the probability of applying the operation.
1288
+ random_state: int | numpy.random.Generator, optional
1289
+ Seed to be used to instantiate numpy random number generator instance.
1290
+ Used to decide whether or not to transform given the probability
1291
+ argument, to sample which channels to shuffle and to carry the shuffle.
1292
+ Defaults to None.
1293
+
1294
+ References
1295
+ ----------
1296
+ .. [1] Mohsenvand, M.N., Izadi, M.R. &amp; Maes, P.. (2020). Contrastive
1297
+ Representation Learning for Electroencephalogram Classification. Proceedings
1298
+ of the Machine Learning for Health NeurIPS Workshop, in Proceedings of Machine
1299
+ Learning Research 136:238-253 Available from https://proceedings.mlr.press/v136/mohsenvand20a.html.
1300
+
1301
+ """
1302
+
1303
+ operation = staticmethod(channels_rereference) # type: ignore[assignment]
1304
+
1305
+ def __init__(self, probability, random_state=None):
1306
+ super().__init__(probability=probability, random_state=random_state)
1307
+
1308
+ def get_augmentation_params(self, *batch):
1309
+ """Return transform parameters"""
1310
+ return {
1311
+ "random_state": self.rng,
1312
+ }
1313
+
1314
+
1315
+ class AmplitudeScale(Transform):
1316
+ """Rescale amplitude based on a random sampled scaling value.
1317
+
1318
+ Part of the augmentations proposed in [1]_
1319
+
1320
+ Parameters
1321
+ ----------
1322
+ probability: float
1323
+ Float setting the probability of applying the operation.
1324
+ random_state: int | numpy.random.Generator, optional
1325
+ Seed to be used to instantiate numpy random number generator instance.
1326
+ Used to decide whether or not to transform given the probability
1327
+ argument, to sample which channels to shuffle and to carry the shuffle.
1328
+ Defaults to None.
1329
+
1330
+ References
1331
+ ----------
1332
+ .. [1] Mohsenvand, M.N., Izadi, M.R. &amp; Maes, P.. (2020). Contrastive
1333
+ Representation Learning for Electroencephalogram Classification. Proceedings
1334
+ of the Machine Learning for Health NeurIPS Workshop, in Proceedings of Machine
1335
+ Learning Research 136:238-253 Available from https://proceedings.mlr.press/v136/mohsenvand20a.html.
1336
+
1337
+ """
1338
+
1339
+ operation = staticmethod(amplitude_scale) # type: ignore[assignment]
1340
+
1341
+ def __init__(self, probability, interval=(0.5, 2), random_state=None):
1342
+ super().__init__(probability=probability, random_state=random_state)
1343
+ self.scale = interval
1344
+
1345
+ def get_augmentation_params(self, *batch):
1346
+ """Return transform parameters"""
1347
+ return {"random_state": self.rng, "scale": self.scale}
@@ -138,7 +138,7 @@ def _load_signals(fif_file, preload, is_raw):
138
138
  with open(pkl_file, "rb") as f:
139
139
  signals = pickle.load(f)
140
140
 
141
- if all(f.exists() for f in signals.filenames):
141
+ if all(Path(f).exists() for f in signals.filenames):
142
142
  if preload:
143
143
  signals.load_data()
144
144
  return signals
@@ -141,7 +141,7 @@ class ATCNet(EEGModuleMixin, nn.Module):
141
141
  - Pool sizes ``P1,P2`` trade temporal resolution for stability/compute; they set
142
142
  ``T_c = T/(P1·P2)`` and thus window width ``T_w``.
143
143
  - ``n_windows`` controls the ensemble over shifts (compute ∝ windows).
144
- - ``att_num_heads``, ``att_head_dim`` set attention capacity; keep ``H·d_h ≈ F2``.
144
+ - ``num_heads``, ``head_dim`` set attention capacity; keep ``H·d_h ≈ F2``.
145
145
  - ``tcn_depth``, ``tcn_kernel_size`` govern receptive field; larger values demand
146
146
  longer inputs (see minimum length above). The implementation warns and *rescales*
147
147
  kernels/pools/windows if inputs are too short.
@@ -194,10 +194,10 @@ class ATCNet(EEGModuleMixin, nn.Module):
194
194
  table 1 of the paper [1]_. Defaults to 0.3 as in [1]_.
195
195
  n_windows : int
196
196
  Number of sliding windows, denoted n in [1]_. Defaults to 5 as in [1]_.
197
- att_head_dim : int
197
+ head_dim : int
198
198
  Embedding dimension used in each self-attention head, denoted dh in
199
199
  table 1 of the paper [1]_. Defaults to 8 as in [1]_.
200
- att_num_heads : int
200
+ num_heads : int
201
201
  Number of attention heads, denoted H in table 1 of the paper [1]_.
202
202
  Defaults to 2 as in [1]_.
203
203
  att_dropout : float
@@ -248,13 +248,13 @@ class ATCNet(EEGModuleMixin, nn.Module):
248
248
  conv_block_depth_mult=2,
249
249
  conv_block_dropout=0.3,
250
250
  n_windows=5,
251
- att_head_dim=8,
252
- att_num_heads=2,
251
+ head_dim=8,
252
+ num_heads=2,
253
253
  att_drop_prob=0.5,
254
254
  tcn_depth=2,
255
255
  tcn_kernel_size=4,
256
256
  tcn_drop_prob=0.3,
257
- tcn_activation: nn.Module = nn.ELU,
257
+ tcn_activation: type[nn.Module] = nn.ELU,
258
258
  concat=False,
259
259
  max_norm_const=0.25,
260
260
  chs_info=None,
@@ -316,8 +316,8 @@ class ATCNet(EEGModuleMixin, nn.Module):
316
316
  self.conv_block_depth_mult = conv_block_depth_mult
317
317
  self.conv_block_dropout = conv_block_dropout
318
318
  self.n_windows = n_windows
319
- self.att_head_dim = att_head_dim
320
- self.att_num_heads = att_num_heads
319
+ self.head_dim = head_dim
320
+ self.num_heads = num_heads
321
321
  self.att_dropout = att_drop_prob
322
322
  self.tcn_depth = tcn_depth
323
323
  self.tcn_kernel_size = tcn_kernel_size
@@ -356,8 +356,8 @@ class ATCNet(EEGModuleMixin, nn.Module):
356
356
  [
357
357
  _AttentionBlock(
358
358
  in_shape=self.F2,
359
- head_dim=self.att_head_dim,
360
- num_heads=att_num_heads,
359
+ head_dim=self.head_dim,
360
+ num_heads=num_heads,
361
361
  dropout=att_drop_prob,
362
362
  )
363
363
  for _ in range(self.n_windows)
@@ -656,7 +656,7 @@ class _TCNResidualBlock(nn.Module):
656
656
  kernel_size=4,
657
657
  n_filters=32,
658
658
  dropout=0.3,
659
- activation: nn.Module = nn.ELU,
659
+ activation: type[nn.Module] = nn.ELU,
660
660
  dilation=1,
661
661
  ):
662
662
  super().__init__()
@@ -235,7 +235,7 @@ class AttentionBaseNet(EEGModuleMixin, nn.Module):
235
235
  kernel_size : int, default=9
236
236
  The kernel size used in certain types of attention mechanisms for convolution
237
237
  operations.
238
- activation: nn.Module, default=nn.ELU
238
+ activation: type[nn.Module] = nn.ELU,
239
239
  Activation function class to apply. Should be a PyTorch activation
240
240
  module class like ``nn.ReLU`` or ``nn.ELU``. Default is ``nn.ELU``.
241
241
  extra_params : bool, default=False
@@ -277,7 +277,7 @@ class AttentionBaseNet(EEGModuleMixin, nn.Module):
277
277
  freq_idx: int = 0,
278
278
  n_codewords: int = 4,
279
279
  kernel_size: int = 9,
280
- activation: nn.Module = nn.ELU,
280
+ activation: type[nn.Module] = nn.ELU,
281
281
  extra_params: bool = False,
282
282
  ):
283
283
  super(AttentionBaseNet, self).__init__()
@@ -453,7 +453,7 @@ class _FeatureExtractor(nn.Module):
453
453
  pool_length: int = 75,
454
454
  pool_stride: int = 15,
455
455
  drop_prob: float = 0.5,
456
- activation: nn.Module = nn.ELU,
456
+ activation: type[nn.Module] = nn.ELU,
457
457
  ):
458
458
  super().__init__()
459
459
 
@@ -592,7 +592,7 @@ class _ChannelAttentionBlock(nn.Module):
592
592
  n_codewords: int = 4,
593
593
  kernel_size: int = 9,
594
594
  extra_params: bool = False,
595
- activation: nn.Module = nn.ELU,
595
+ activation: type[nn.Module] = nn.ELU,
596
596
  ):
597
597
  super().__init__()
598
598
  self.conv = nn.Sequential(
@@ -90,8 +90,8 @@ class AttnSleep(EEGModuleMixin, nn.Module):
90
90
  d_ff=120,
91
91
  n_attn_heads=5,
92
92
  drop_prob=0.1,
93
- activation_mrcnn: nn.Module = nn.GELU,
94
- activation: nn.Module = nn.ReLU,
93
+ activation_mrcnn: type[nn.Module] = nn.GELU,
94
+ activation: type[nn.Module] = nn.ReLU,
95
95
  input_window_seconds=None,
96
96
  n_outputs=None,
97
97
  after_reduced_cnn_size=30,
@@ -230,7 +230,7 @@ class _SEBasicBlock(nn.Module):
230
230
  planes,
231
231
  stride=1,
232
232
  downsample=None,
233
- activation: nn.Module = nn.ReLU,
233
+ activation: type[nn.Module] = nn.ReLU,
234
234
  *,
235
235
  reduction=16,
236
236
  ):
@@ -278,8 +278,8 @@ class _MRCNN(nn.Module):
278
278
  self,
279
279
  after_reduced_cnn_size,
280
280
  kernel_size=7,
281
- activation: nn.Module = nn.GELU,
282
- activation_se: nn.Module = nn.ReLU,
281
+ activation: type[nn.Module] = nn.GELU,
282
+ activation_se: type[nn.Module] = nn.ReLU,
283
283
  ):
284
284
  super(_MRCNN, self).__init__()
285
285
  drate = 0.5
@@ -325,7 +325,7 @@ class _MRCNN(nn.Module):
325
325
  )
326
326
 
327
327
  def _make_layer(
328
- self, block, planes, blocks, stride=1, activate: nn.Module = nn.ReLU
328
+ self, block, planes, blocks, stride=1, activate: type[nn.Module] = nn.ReLU
329
329
  ): # makes residual SE block
330
330
  downsample = None
331
331
  if stride != 1 or self.inplanes != planes * block.expansion:
@@ -526,7 +526,9 @@ class _EncoderLayer(nn.Module):
526
526
  class _PositionwiseFeedForward(nn.Module):
527
527
  """Positionwise feed-forward network."""
528
528
 
529
- def __init__(self, d_model, d_ff, dropout=0.1, activation: nn.Module = nn.ReLU):
529
+ def __init__(
530
+ self, d_model, d_ff, dropout=0.1, activation: type[nn.Module] = nn.ReLU
531
+ ):
530
532
  super().__init__()
531
533
  self.w_1 = nn.Linear(d_model, d_ff)
532
534
  self.w_2 = nn.Linear(d_ff, d_model)
@@ -176,7 +176,7 @@ class BENDR(EEGModuleMixin, nn.Module):
176
176
  projection_head=False, # Whether encoder should project back to input feature size (unused in original fine-tuning)
177
177
  drop_prob=0.1, # General dropout probability (paper: 0.15 for pretraining, 0.0 for fine-tuning)
178
178
  layer_drop=0.0, # Probability of dropping transformer layers during training (paper: 0.01 for pretraining)
179
- activation=nn.GELU, # Activation function
179
+ activation: type[nn.Module] = nn.GELU, # Activation function
180
180
  # Transformer specific parameters
181
181
  transformer_layers=8,
182
182
  transformer_heads=8,
@@ -45,11 +45,11 @@ class BIOT(EEGModuleMixin, nn.Module):
45
45
 
46
46
  Parameters
47
47
  ----------
48
- emb_size : int, optional
48
+ embed_dim : int, optional
49
49
  The size of the embedding layer, by default 256
50
- att_num_heads : int, optional
50
+ num_heads : int, optional
51
51
  The number of attention heads, by default 8
52
- n_layers : int, optional
52
+ num_layers : int, optional
53
53
  The number of transformer layers, by default 4
54
54
  activation: nn.Module, default=nn.ELU
55
55
  Activation function class to apply. Should be a PyTorch activation
@@ -76,9 +76,9 @@ class BIOT(EEGModuleMixin, nn.Module):
76
76
 
77
77
  def __init__(
78
78
  self,
79
- emb_size=256,
80
- att_num_heads=8,
81
- n_layers=4,
79
+ embed_dim=256,
80
+ num_heads=8,
81
+ num_layers=4,
82
82
  sfreq=200,
83
83
  hop_length=100,
84
84
  return_feature=False,
@@ -87,12 +87,12 @@ class BIOT(EEGModuleMixin, nn.Module):
87
87
  chs_info=None,
88
88
  n_times=None,
89
89
  input_window_seconds=None,
90
- activation: nn.Module = nn.ELU,
90
+ activation: type[nn.Module] = nn.ELU,
91
91
  drop_prob: float = 0.5,
92
92
  # Parameters for the encoder
93
93
  max_seq_len: int = 1024,
94
- attn_dropout=0.2,
95
- attn_layer_dropout=0.2,
94
+ att_drop_prob=0.2,
95
+ att_layer_drop_prob=0.2,
96
96
  ):
97
97
  super().__init__(
98
98
  n_outputs=n_outputs,
@@ -103,10 +103,10 @@ class BIOT(EEGModuleMixin, nn.Module):
103
103
  sfreq=sfreq,
104
104
  )
105
105
  del n_outputs, n_chans, chs_info, n_times, sfreq
106
- self.emb_size = emb_size
106
+ self.embed_dim = embed_dim
107
107
  self.hop_length = hop_length
108
- self.att_num_heads = att_num_heads
109
- self.n_layers = n_layers
108
+ self.num_heads = num_heads
109
+ self.num_layers = num_layers
110
110
  self.return_feature = return_feature
111
111
  if (self.sfreq != 200) & (self.sfreq is not None):
112
112
  warn(
@@ -114,7 +114,7 @@ class BIOT(EEGModuleMixin, nn.Module):
114
114
  + "no guarantee to generalize well with the default parameters",
115
115
  UserWarning,
116
116
  )
117
- if self.n_chans > emb_size:
117
+ if self.n_chans > embed_dim:
118
118
  warn(
119
119
  "The number of channels is larger than the embedding size. "
120
120
  + "This may cause overfitting. Consider using a larger "
@@ -142,20 +142,20 @@ class BIOT(EEGModuleMixin, nn.Module):
142
142
  self.n_fft = int(self.sfreq)
143
143
 
144
144
  self.encoder = _BIOTEncoder(
145
- emb_size=emb_size,
146
- att_num_heads=att_num_heads,
147
- n_layers=n_layers,
145
+ emb_size=self.embed_dim,
146
+ num_heads=self.num_heads,
147
+ n_layers=self.num_layers,
148
148
  n_chans=self.n_chans,
149
149
  n_fft=self.n_fft,
150
150
  hop_length=hop_length,
151
151
  drop_prob=drop_prob,
152
152
  max_seq_len=max_seq_len,
153
- attn_dropout=attn_dropout,
154
- attn_layer_dropout=attn_layer_dropout,
153
+ attn_dropout=att_drop_prob,
154
+ attn_layer_dropout=att_layer_drop_prob,
155
155
  )
156
156
 
157
157
  self.final_layer = _ClassificationHead(
158
- emb_size=emb_size,
158
+ emb_size=self.embed_dim,
159
159
  n_outputs=self.n_outputs,
160
160
  activation=activation,
161
161
  )
@@ -250,7 +250,9 @@ class _ClassificationHead(nn.Sequential):
250
250
  (batch, n_outputs)
251
251
  """
252
252
 
253
- def __init__(self, emb_size: int, n_outputs: int, activation: nn.Module = nn.ELU):
253
+ def __init__(
254
+ self, emb_size: int, n_outputs: int, activation: type[nn.Module] = nn.ELU
255
+ ):
254
256
  super().__init__()
255
257
  self.activation_layer = activation()
256
258
  self.classification_head = nn.Linear(emb_size, n_outputs)
@@ -345,7 +347,7 @@ class _BIOTEncoder(nn.Module):
345
347
  The number of channels
346
348
  emb_size: int
347
349
  The size of the embedding layer
348
- att_num_heads: int
350
+ num_heads: int
349
351
  The number of attention heads
350
352
  n_layers: int
351
353
  The number of transformer layers
@@ -358,7 +360,7 @@ class _BIOTEncoder(nn.Module):
358
360
  def __init__(
359
361
  self,
360
362
  emb_size=256, # The size of the embedding layer
361
- att_num_heads=8, # The number of attention heads
363
+ num_heads=8, # The number of attention heads
362
364
  n_chans=16, # The number of channels
363
365
  n_layers=4, # The number of transformer layers
364
366
  n_fft=200, # Related with the frequency resolution
@@ -378,7 +380,7 @@ class _BIOTEncoder(nn.Module):
378
380
  )
379
381
  self.transformer = LinearAttentionTransformer(
380
382
  dim=emb_size,
381
- heads=att_num_heads,
383
+ heads=num_heads,
382
384
  depth=n_layers,
383
385
  max_seq_len=max_seq_len,
384
386
  attn_layer_dropout=attn_layer_dropout,