braindecode 1.8.1.dev182727546__tar.gz → 1.8.1.dev183301946__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 (208) hide show
  1. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/NOTICE.txt +4 -0
  2. {braindecode-1.8.1.dev182727546/braindecode.egg-info → braindecode-1.8.1.dev183301946}/PKG-INFO +1 -1
  3. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/augmentation/functional.py +6 -2
  4. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/base.py +119 -6
  5. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/tuh.py +20 -13
  6. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datautil/serialization.py +10 -6
  7. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/functional/__init__.py +4 -0
  8. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/functional/functions.py +111 -7
  9. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/__init__.py +2 -0
  10. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/attn_sleep.py +9 -11
  11. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/axon.py +15 -8
  12. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/base.py +34 -15
  13. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/biot.py +23 -9
  14. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/brainomni.py +89 -44
  15. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/brant.py +5 -4
  16. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/codebrain.py +29 -4
  17. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/csbrain.py +6 -2
  18. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/dance.py +1 -1
  19. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/deep4.py +10 -1
  20. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/dgcnn.py +7 -0
  21. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegconformer.py +5 -2
  22. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eeginception_mi.py +25 -94
  23. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegnex.py +16 -1
  24. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegpt.py +47 -74
  25. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegsym.py +17 -1
  26. braindecode-1.8.1.dev183301946/braindecode/models/guetschel2026.py +775 -0
  27. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/labram.py +55 -40
  28. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/luna.py +11 -13
  29. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/mapa.py +116 -73
  30. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/medformer.py +28 -20
  31. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/meta_neuromotor.py +45 -48
  32. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/msvtnet.py +8 -6
  33. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/mvpformer.py +172 -191
  34. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/neurorvq.py +17 -3
  35. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/neurorvq_tokenizer.py +108 -72
  36. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/patchedtransformer.py +0 -1
  37. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/reve.py +51 -53
  38. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/signal_jepa.py +6 -1
  39. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/sleep_stager_blanco_2020.py +13 -6
  40. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/sleepfm.py +54 -63
  41. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/summary.csv +1 -0
  42. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/tcn.py +5 -0
  43. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/tfm_tokenizer.py +8 -15
  44. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/tidnet.py +18 -1
  45. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/usleep.py +3 -2
  46. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/util.py +139 -33
  47. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/zuna.py +6 -0
  48. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/dance_modules.py +34 -26
  49. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/filter.py +45 -44
  50. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/layers.py +12 -21
  51. braindecode-1.8.1.dev183301946/braindecode/modules/linear_attention.py +128 -0
  52. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/quantization.py +51 -40
  53. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/preprocessing/preprocess.py +11 -0
  54. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/preprocessing/windowers.py +5 -4
  55. braindecode-1.8.1.dev183301946/braindecode/version.py +1 -0
  56. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946/braindecode.egg-info}/PKG-INFO +1 -1
  57. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode.egg-info/SOURCES.txt +2 -0
  58. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/api.rst +5 -0
  59. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/user_guide/channel_strategies.rst +1 -1
  60. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/whats_new.rst +89 -0
  61. braindecode-1.8.1.dev182727546/braindecode/version.py +0 -1
  62. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/LICENSE.txt +0 -0
  63. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/MANIFEST.in +0 -0
  64. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/README.rst +0 -0
  65. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/__init__.py +0 -0
  66. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/augmentation/__init__.py +0 -0
  67. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/augmentation/base.py +0 -0
  68. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/augmentation/transforms.py +0 -0
  69. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/classifier.py +0 -0
  70. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/__init__.py +0 -0
  71. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/_notebook_viewer.py +0 -0
  72. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bbci.py +0 -0
  73. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bcicomp.py +0 -0
  74. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bids/__init__.py +0 -0
  75. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bids/datasets.py +0 -0
  76. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bids/format.py +0 -0
  77. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bids/hub.py +0 -0
  78. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bids/hub_format.py +0 -0
  79. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bids/hub_io.py +0 -0
  80. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bids/hub_validation.py +0 -0
  81. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/bids/iterable.py +0 -0
  82. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/chb_mit.py +0 -0
  83. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/collate.py +0 -0
  84. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/mne.py +0 -0
  85. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/moabb.py +0 -0
  86. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/nmt.py +0 -0
  87. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/registry.py +0 -0
  88. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/siena.py +0 -0
  89. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/sleep_physio_challe_18.py +0 -0
  90. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/sleep_physionet.py +0 -0
  91. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/utils.py +0 -0
  92. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datasets/xy.py +0 -0
  93. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datautil/__init__.py +0 -0
  94. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datautil/channel_utils.py +0 -0
  95. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datautil/hub_formats.py +0 -0
  96. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/datautil/util.py +0 -0
  97. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/eegneuralnet.py +0 -0
  98. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/functional/_real_dft.py +0 -0
  99. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/functional/initialization.py +0 -0
  100. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/atcnet.py +0 -0
  101. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/attentionbasenet.py +0 -0
  102. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/barista.py +0 -0
  103. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/bendr.py +0 -0
  104. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/brainbert.py +0 -0
  105. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/brainmodule.py +0 -0
  106. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/cbramod.py +0 -0
  107. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/config.py +0 -0
  108. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/contrawr.py +0 -0
  109. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/ctnet.py +0 -0
  110. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/deepsleepnet.py +0 -0
  111. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/diver1.py +0 -0
  112. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eeg_clip.py +0 -0
  113. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegdino.py +0 -0
  114. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eeginception_erp.py +0 -0
  115. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegitnet.py +0 -0
  116. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegminer.py +0 -0
  117. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegnet.py +0 -0
  118. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegsimpleconv.py +0 -0
  119. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/eegtcnet.py +0 -0
  120. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/emg2qwerty.py +0 -0
  121. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/fbcnet.py +0 -0
  122. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/fblightconvnet.py +0 -0
  123. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/fbmsnet.py +0 -0
  124. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/hybrid.py +0 -0
  125. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/ifnet.py +0 -0
  126. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/mirepnet.py +0 -0
  127. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/mscformer.py +0 -0
  128. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/neuropose.py +0 -0
  129. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/popt.py +0 -0
  130. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/sccnet.py +0 -0
  131. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/seizure_transformer.py +0 -0
  132. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/sensingdynamics.py +0 -0
  133. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/shallow_fbcsp.py +0 -0
  134. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/sinc_shallow.py +0 -0
  135. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/sleep_stager_chambon_2018.py +0 -0
  136. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/sparcnet.py +0 -0
  137. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/sstdpn.py +0 -0
  138. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/steegformer.py +0 -0
  139. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/syncnet.py +0 -0
  140. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/tcformer.py +0 -0
  141. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/tmsanet.py +0 -0
  142. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/tsinception.py +0 -0
  143. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/models/vemg2pose.py +0 -0
  144. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/__init__.py +0 -0
  145. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/activation.py +0 -0
  146. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/attention.py +0 -0
  147. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/blocks.py +0 -0
  148. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/channels.py +0 -0
  149. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/convolution.py +0 -0
  150. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/linear.py +0 -0
  151. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/parametrization.py +0 -0
  152. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/popt_modules.py +0 -0
  153. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/stats.py +0 -0
  154. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/util.py +0 -0
  155. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/modules/wrapper.py +0 -0
  156. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/preprocessing/__init__.py +0 -0
  157. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/preprocessing/eegprep_preprocess.py +0 -0
  158. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/preprocessing/mne_preprocess.py +0 -0
  159. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/preprocessing/util.py +0 -0
  160. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/regressor.py +0 -0
  161. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/samplers/__init__.py +0 -0
  162. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/samplers/base.py +0 -0
  163. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/samplers/ssl.py +0 -0
  164. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/training/__init__.py +0 -0
  165. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/training/callbacks.py +0 -0
  166. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/training/losses.py +0 -0
  167. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/training/scoring.py +0 -0
  168. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/util.py +0 -0
  169. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/visualization/__init__.py +0 -0
  170. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/visualization/activations.py +0 -0
  171. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/visualization/attribution.py +0 -0
  172. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/visualization/confusion_matrices.py +0 -0
  173. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/visualization/frequency.py +0 -0
  174. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/visualization/metrics.py +0 -0
  175. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/visualization/sanity.py +0 -0
  176. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode/visualization/topology.py +0 -0
  177. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode.egg-info/dependency_links.txt +0 -0
  178. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode.egg-info/requires.txt +0 -0
  179. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/braindecode.egg-info/top_level.txt +0 -0
  180. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/Makefile +0 -0
  181. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/_templates/autosummary/class.rst +0 -0
  182. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/_templates/autosummary/class_in_subdir.rst +0 -0
  183. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/_templates/autosummary/function.rst +0 -0
  184. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/_templates/autosummary/function_in_subdir.rst +0 -0
  185. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/agent_docs.rst +0 -0
  186. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/cite.rst +0 -0
  187. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/conf.py +0 -0
  188. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/help.rst +0 -0
  189. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/index.rst +0 -0
  190. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/install/install.rst +0 -0
  191. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/install/install_pip.rst +0 -0
  192. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/install/install_source.rst +0 -0
  193. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/categorization/attention.rst +0 -0
  194. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/categorization/channel.rst +0 -0
  195. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/categorization/convolution.rst +0 -0
  196. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/categorization/filterbank.rst +0 -0
  197. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/categorization/gnn.rst +0 -0
  198. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/categorization/interpretable.rst +0 -0
  199. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/categorization/lbm.rst +0 -0
  200. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/categorization/recurrent.rst +0 -0
  201. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/categorization/spd.rst +0 -0
  202. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/models.rst +0 -0
  203. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/models_categorization.rst +0 -0
  204. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/models_table.rst +0 -0
  205. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/models/models_visualization.rst +0 -0
  206. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/docs/sg_execution_times.rst +0 -0
  207. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/pyproject.toml +0 -0
  208. {braindecode-1.8.1.dev182727546 → braindecode-1.8.1.dev183301946}/setup.cfg +0 -0
@@ -49,14 +49,18 @@ The following components are licensed under the MIT License:
49
49
  - `braindecode/modules/popt_modules.py`
50
50
  - `braindecode/models/brainomni.py`
51
51
  - `braindecode/modules/quantization.py`
52
+ - `braindecode/modules/linear_attention.py`
52
53
  - `braindecode/models/seizure_transformer.py`
53
54
  - `docs/_static/model/seizure_transformer_arch.png`
55
+ - `braindecode/models/guetschel2026.py`
54
56
  - `braindecode/models/tmsanet.py`
55
57
 
56
58
  The `brainomni.py` file is a derivative of `OpenTSLab/BrainOmni` (MIT), whose
57
59
  SEANet codec derives from Meta's `facebookresearch/encodec` (MIT). The
58
60
  `quantization.py` module holds the residual vector quantization derived from
59
61
  `lucidrains/vector-quantize-pytorch` (MIT) and the BrainOmni port.
62
+ The `linear_attention.py` module is the part of
63
+ `lucidrains/linear-attention-transformer` (MIT) that BIOT and TFMTokenizer run.
60
64
 
61
65
  ### Apache-2.0 Licensed Files
62
66
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: braindecode
3
- Version: 1.8.1.dev182727546
3
+ Version: 1.8.1.dev183301946
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>
@@ -3,6 +3,7 @@
3
3
  # Gustavo Rodrigues <gustavenrique01@gmail.com>
4
4
  # Bruna Lopes <brunajaflopes@gmail.com>
5
5
  # Sarthak Tayal <sarthaktayal2@gmail.com>
6
+ # Anton Soloviev <anton@praviel.com>
6
7
  #
7
8
  # License: BSD (3-clause)
8
9
 
@@ -931,7 +932,7 @@ def _rotate_signals(
931
932
  transformed_X = X.clone()
932
933
  sensors_positions = list(sensors_positions_matrix)
933
934
  for s, rot_sensors_matrix in enumerate(rot_sensors_matrices):
934
- rot_sensors_positions = list(rot_sensors_matrix.T)
935
+ rot_sensors_positions = list(rot_sensors_matrix)
935
936
  for time in range(X.shape[-1]):
936
937
  interpolator_t = Rbf(*sensors_positions, X[s, :, time])
937
938
  transformed_X[s, :, time] = torch.from_numpy(
@@ -1093,7 +1094,8 @@ def segmentation_reconstruction(
1093
1094
  y : torch.Tensor
1094
1095
  EEG labels for the example or batch.
1095
1096
  n_segments : int
1096
- Number of segments to use in the batch.
1097
+ Number of segments to use in the batch. Any remaining samples are
1098
+ included in the last segment.
1097
1099
  data_classes : list[tuple[int, torch.Tensor]]
1098
1100
  List of tuples. Each tuple contains the class index and the corresponding EEG data.
1099
1101
  rand_indices : array-like
@@ -1133,6 +1135,8 @@ def segmentation_reconstruction(
1133
1135
  for idx_segment in range(n_segments):
1134
1136
  start = idx_segment * segment_size
1135
1137
  end = (idx_segment + 1) * segment_size
1138
+ if idx_segment == n_segments - 1:
1139
+ end = window_size
1136
1140
 
1137
1141
  # Perform the data augmentation
1138
1142
  X_aug[np.arange(n_trials), :, start:end] = X_class[
@@ -14,13 +14,16 @@ from __future__ import annotations
14
14
  import bisect
15
15
  import html as _html
16
16
  import json
17
+ import mmap
17
18
  import os
18
19
  import shutil
19
20
  import warnings
20
21
  from abc import abstractmethod
21
22
  from collections import Counter
22
- from collections.abc import Callable, Hashable
23
+ from collections.abc import Callable, Hashable, Sequence
23
24
  from glob import glob
25
+ from itertools import chain
26
+ from operator import attrgetter
24
27
  from pathlib import Path
25
28
  from typing import Any, Generic, Iterable, no_type_check
26
29
 
@@ -28,6 +31,7 @@ import mne
28
31
  import mne.io
29
32
  import numpy as np
30
33
  import pandas as pd
34
+ from mne.io.constants import FIFF
31
35
  from mne.utils import _soft_import
32
36
  from mne.utils.docs import deprecated
33
37
  from torch.utils.data import ConcatDataset, Dataset, IterableDataset
@@ -220,6 +224,109 @@ def _compute_ch_pos(info, targets_from):
220
224
  return pos
221
225
 
222
226
 
227
+ _TAG_ROW = attrgetter("kind", "type", "size", "next", "pos")
228
+
229
+
230
+ def _tag_rows(tags):
231
+ """(kind, type, size, next, pos) of FIF tags as an int64 array (n, 5)."""
232
+ flat = chain.from_iterable(map(_TAG_ROW, tags))
233
+ return np.fromiter(flat, np.int64, 5 * len(tags)).reshape(-1, 5)
234
+
235
+
236
+ class _FifTagTable(Sequence):
237
+ """The data-buffer tags of a lazy FIF raw as one int64 array.
238
+
239
+ mne's FIF reader keeps one ``Tag`` object per data buffer in
240
+ ``raw._raw_extras[i]["ent"]`` (one per second of signal with mne's default
241
+ buffers), each with its attribute dict and integers once unpickled. A lazy
242
+ dataset of many recordings holds millions of them in RAM, and every forked
243
+ DataLoader worker copies the memory pages of those it reads (reference
244
+ counts). This holds the same fields in 40 bytes per buffer and returns an
245
+ equal ``Tag`` on access, so mne's own reads are unchanged.
246
+ """
247
+
248
+ def __init__(self, tags):
249
+ self.tag_class = type(tags[0])
250
+ self.table = _tag_rows(tags)
251
+
252
+ def __len__(self):
253
+ return len(self.table)
254
+
255
+ def __getitem__(self, i):
256
+ if isinstance(i, slice):
257
+ return [self.tag_class(*row) for row in self.table[i].tolist()]
258
+ return self.tag_class(*self.table[i].tolist())
259
+
260
+
261
+ _TAG_FIELDS = ("kind", "type", "size", "next", "pos", "data")
262
+
263
+
264
+ def _compact_fif_tags(inst):
265
+ """Swap the ``Tag`` lists of a FIF raw for `_FifTagTable` (in place).
266
+
267
+ Only gap-free lists of directory tags (no ``None``, no ``data``) with mne's
268
+ ``Tag`` fields are swapped; anything else is left as mne built it.
269
+ """
270
+ for extra in getattr(inst, "_raw_extras", ()):
271
+ tags = extra.get("ent")
272
+ if not isinstance(tags, list) or not tags:
273
+ continue
274
+ cls = type(tags[0])
275
+ if tuple(getattr(cls, "__dataclass_fields__", ())) == _TAG_FIELDS and all(
276
+ type(t) is cls and t.data is None for t in tags
277
+ ):
278
+ extra["ent"] = _FifTagTable(tags)
279
+ return inst
280
+
281
+
282
+ def _read_fif_window(raw, start, stop):
283
+ """Samples ``start:stop`` of a lazy FIF raw, copied from the file in one go.
284
+
285
+ mne reads, casts and calibrates the FIF data buffers of a range one at a
286
+ time (60 Python steps for a 60-s window saved with 1-s buffers, each through
287
+ a buffered file whose buffer is 4 MB on network file systems). Here one
288
+ slice of the memory-mapped file holds the bytes of every buffer in the
289
+ range and one multiply calibrates them, with mne's arithmetic (float64 data
290
+ times ``raw._cals``), so the values equal ``raw._getitem``'s. Returns None
291
+ (the caller uses mne) unless ``raw`` is a lazy, single-file, uncompressed
292
+ FIF raw of float32 buffers without projector, compensation or gaps.
293
+ """
294
+ if (
295
+ not isinstance(raw, mne.io.Raw)
296
+ or raw.preload
297
+ or len(raw._raw_extras) != 1
298
+ or raw._projector is not None
299
+ or raw._comp is not None
300
+ ):
301
+ return None
302
+ extra = raw._raw_extras[0]
303
+ fname, bounds = extra["filename"], extra["bounds"]
304
+ if not isinstance(fname, Path) or fname.suffix == ".gz":
305
+ return None
306
+ start, stop = start + raw._first_samps[0], stop + raw._first_samps[0]
307
+ first = np.searchsorted(bounds, start, side="right") - 1
308
+ tags = extra["ent"]
309
+ if isinstance(tags, _FifTagTable):
310
+ rows = tags.table[first : np.searchsorted(bounds, stop)]
311
+ else:
312
+ tags = tags[first : np.searchsorted(bounds, stop)]
313
+ if any(t is None for t in tags):
314
+ return None
315
+ rows = _tag_rows(tags)
316
+ if not len(rows) or (rows[:, 1] != FIFF.FIFFT_FLOAT).any():
317
+ return None
318
+ size, pos = rows[:, 2].tolist(), rows[:, 4].tolist()
319
+ # mmap: no copy through a 4 MB read buffer, and a cold file is read around
320
+ # the window by the kernel (as mne's 4 MB reads did), not window by window
321
+ with open(fname, "rb") as f, mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as m:
322
+ buf = m[pos[0] : pos[-1] + 16 + size[-1]]
323
+ one = np.concatenate(
324
+ [np.frombuffer(buf, ">f4", s // 4, p + 16 - pos[0]) for s, p in zip(size, pos)]
325
+ ).reshape(-1, extra["orig_nchan"])[start - bounds[first] : stop - bounds[first]]
326
+ picked = one[:, raw._read_picks[0]].T
327
+ return np.multiply(picked, raw._cals[:, np.newaxis], order="C")
328
+
329
+
223
330
  def _window_info(crop_inds, sfreq):
224
331
  """Extract window size from crop indices.
225
332
 
@@ -823,9 +930,11 @@ class EEGWindowsDataset(_ZarrMixin, RecordDataset):
823
930
  if self._zarr_data is not None:
824
931
  X = self._zarr_data[:, i_start:i_stop]
825
932
  else:
826
- X = self.raw._getitem(
827
- (slice(None), slice(i_start, i_stop)), return_times=False
828
- )
933
+ X = _read_fif_window(self.raw, i_start, i_stop)
934
+ if X is None:
935
+ X = self.raw._getitem(
936
+ (slice(None), slice(i_start, i_stop)), return_times=False
937
+ )
829
938
  X = np.array(X, dtype="float32")
830
939
  if self.transform is not None:
831
940
  X = self.transform(X)
@@ -1672,7 +1781,8 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1672
1781
  kwargs_path = os.path.join(path, ".".join([kwarg_name, "json"]))
1673
1782
  kwargs = getattr(self, kwarg_name)
1674
1783
  if kwargs is not None:
1675
- json.dump(kwargs, open(kwargs_path, "w"))
1784
+ with open(kwargs_path, "w") as f:
1785
+ json.dump(kwargs, f)
1676
1786
 
1677
1787
  @property
1678
1788
  def description(self) -> pd.DataFrame:
@@ -1742,7 +1852,10 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1742
1852
  # Create path if it doesn't exist
1743
1853
  os.makedirs(path, exist_ok=True)
1744
1854
 
1745
- path_contents = os.listdir(path)
1855
+ # With an offset the caller fills one directory piece by piece (preprocess
1856
+ # saves each recording at its index), so the other entries are expected:
1857
+ # skip the scan that would stat them all on every call and list them in a warning.
1858
+ path_contents = os.listdir(path) if offset == 0 else []
1746
1859
  n_sub_dirs = len(
1747
1860
  [e for e in path_contents if os.path.isdir(os.path.join(path, e))]
1748
1861
  )
@@ -11,10 +11,12 @@ TUH Abnormal EEG Corpus.
11
11
  from __future__ import annotations
12
12
 
13
13
  import glob
14
+ import json
14
15
  import os
15
16
  import re
16
17
  import warnings
17
18
  from datetime import datetime, timezone
19
+ from functools import cache
18
20
  from pathlib import Path
19
21
  from typing import Iterable, Literal
20
22
  from unittest import mock
@@ -183,11 +185,8 @@ class TUH(BaseConcatDataset):
183
185
  }
184
186
  raw.rename_channels(mapping_strip)
185
187
 
186
- montage1005 = mne.channels.make_standard_montage(
187
- resolve_montage_name("standard_1005")
188
- )
189
188
  mapping_eeg_names = {
190
- c.upper(): c for c in montage1005.ch_names if c.upper() in raw.ch_names
189
+ c.upper(): c for c in _standard_1005().ch_names if c.upper() in raw.ch_names
191
190
  }
192
191
 
193
192
  # Set channels whose type could not be inferred (defaulted to "eeg") to "misc":
@@ -210,10 +209,7 @@ class TUH(BaseConcatDataset):
210
209
 
211
210
  @staticmethod
212
211
  def _set_montage(raw):
213
- montage = mne.channels.make_standard_montage(
214
- resolve_montage_name("standard_1005")
215
- )
216
- raw.set_montage(montage, on_missing="ignore")
212
+ raw.set_montage(_standard_1005(), on_missing="ignore")
217
213
 
218
214
  @staticmethod
219
215
  def _create_dataset(
@@ -245,7 +241,11 @@ class TUH(BaseConcatDataset):
245
241
  # file paths, use this instead as before
246
242
  if "year" in description:
247
243
  meas_date = meas_date.replace(*description[["year", "month", "day"]])
248
- raw.set_meas_date(meas_date)
244
+ # FIF (e.g. preprocess(..., save_dir=...)) stores dates from 1901-12-13 to
245
+ # 2038-01-19 only: undated recordings (year 1 above) and de-identified ones
246
+ # (TUAB has 1899-12-30) keep their date in the description only.
247
+ in_fif_range = -(2**31) <= meas_date.timestamp() < 2**31
248
+ raw.set_meas_date(meas_date if in_fif_range else None)
249
249
 
250
250
  d = {
251
251
  "age": int(age),
@@ -255,9 +255,9 @@ class TUH(BaseConcatDataset):
255
255
  # if not, get it from meas_date in raw.info and add to description
256
256
  # if meas_date is None, create fake one
257
257
  if "year" not in description:
258
- d["year"] = raw.info["meas_date"].year
259
- d["month"] = raw.info["meas_date"].month
260
- d["day"] = raw.info["meas_date"].day
258
+ d["year"] = meas_date.year
259
+ d["month"] = meas_date.month
260
+ d["day"] = meas_date.day
261
261
 
262
262
  # read info relevant for preprocessing from raw without loading it
263
263
  if add_physician_reports:
@@ -269,6 +269,12 @@ class TUH(BaseConcatDataset):
269
269
  return base_dataset
270
270
 
271
271
 
272
+ @cache
273
+ def _standard_1005():
274
+ # Built once per process: set_montage copies the montage before using it.
275
+ return mne.channels.make_standard_montage(resolve_montage_name("standard_1005"))
276
+
277
+
272
278
  def _create_description(file_paths, version, ds_name):
273
279
  descriptions = [
274
280
  _parse_description_from_file_path(f, version, ds_name) for f in file_paths
@@ -289,7 +295,8 @@ def _read_date(file_path):
289
295
  date_path = file_path.replace(".edf", "_date.txt")
290
296
  # if date file exists, read it
291
297
  if os.path.exists(date_path):
292
- description = pd.read_json(date_path, typ="series").to_dict()
298
+ with open(date_path) as f:
299
+ description = json.load(f)
293
300
  # otherwise read edf file, extract date and store to file
294
301
  else:
295
302
  raw = mne.io.read_raw_edf(file_path, preload=False, verbose="error")
@@ -21,6 +21,7 @@ from ..datasets.base import (
21
21
  EEGWindowsDataset,
22
22
  RawDataset,
23
23
  WindowsDataset,
24
+ _compact_fif_tags,
24
25
  )
25
26
 
26
27
 
@@ -79,7 +80,8 @@ def _outdated_load_concat_dataset(path, preload, ids_to_load=None, target_name=N
79
80
  for path in paths:
80
81
  if is_raw and target_name is None:
81
82
  target_file_name = path / "target_name.json"
82
- target_name = json.load(open(target_file_name, "r"))["target_name"]
83
+ with open(target_file_name) as f:
84
+ target_name = json.load(f)["target_name"]
83
85
 
84
86
  all_signals, description = _load_signals_and_description(
85
87
  path=path, preload=preload, is_raw=is_raw, ids_to_load=ids_to_load
@@ -141,7 +143,7 @@ def _load_signals(fif_file, preload, is_raw):
141
143
  if all(Path(f).exists() for f in signals.filenames):
142
144
  if preload:
143
145
  signals.load_data()
144
- return signals
146
+ return _compact_fif_tags(signals)
145
147
  else: # This may happen if the file has been moved together with the pickle file.
146
148
  warnings.warn(
147
149
  f"Pickle file {pkl_file} exists, but the referenced fif "
@@ -171,7 +173,8 @@ def _load_signals(fif_file, preload, is_raw):
171
173
  if preload:
172
174
  signals._data, signals.preload = data, True
173
175
 
174
- return signals
176
+ # after the pickle above, which keeps mne's own layout on disk
177
+ return _compact_fif_tags(signals)
175
178
 
176
179
 
177
180
  def load_concat_dataset(path, preload, ids_to_load=None, target_name=None, n_jobs=1):
@@ -264,7 +267,8 @@ def _load_parallel(path, i, preload, is_raw, has_stored_windows):
264
267
  target_file_path = sub_dir / "target_name.json"
265
268
  target_name = None
266
269
  if target_file_path.exists():
267
- target_name = json.load(open(target_file_path, "r"))["target_name"]
270
+ with open(target_file_path) as f:
271
+ target_name = json.load(f)["target_name"]
268
272
 
269
273
  if is_raw and (not has_stored_windows):
270
274
  dataset = RawDataset(signals, description, target_name)
@@ -304,8 +308,8 @@ def _load_kwargs_json(kwargs_name, sub_dir):
304
308
  kwargs_file_name = ".".join([kwargs_name, "json"])
305
309
  kwargs_file_path = os.path.join(sub_dir, kwargs_file_name)
306
310
  if os.path.exists(kwargs_file_path):
307
- kwargs = json.load(open(kwargs_file_path, "r"))
308
- return kwargs
311
+ with open(kwargs_file_path) as f:
312
+ return json.load(f)
309
313
 
310
314
 
311
315
  def _is_outdated_saved(path):
@@ -3,11 +3,13 @@ from .functions import (
3
3
  daubechies_filters,
4
4
  drop_path,
5
5
  dwt_max_level,
6
+ fft_conv1d,
6
7
  hilbert_freq,
7
8
  identity,
8
9
  iou_1d,
9
10
  pairwise_iou_1d,
10
11
  plv_time,
12
+ prefer_fft_conv,
11
13
  rotate_pairs,
12
14
  safe_log,
13
15
  sinusoidal_positional_encoding,
@@ -22,11 +24,13 @@ __all__ = [
22
24
  "daubechies_filters",
23
25
  "drop_path",
24
26
  "dwt_max_level",
27
+ "fft_conv1d",
25
28
  "hilbert_freq",
26
29
  "identity",
27
30
  "iou_1d",
28
31
  "pairwise_iou_1d",
29
32
  "plv_time",
33
+ "prefer_fft_conv",
30
34
  "rotate_pairs",
31
35
  "safe_log",
32
36
  "sinusoidal_positional_encoding",
@@ -7,6 +7,7 @@
7
7
  from __future__ import annotations
8
8
 
9
9
  import math
10
+ from typing import Optional
10
11
 
11
12
  import numpy as np
12
13
  import torch
@@ -54,6 +55,95 @@ def spectral_input(x: torch.Tensor) -> torch.Tensor:
54
55
  return x.to(torch.promote_types(x.dtype, torch.float32))
55
56
 
56
57
 
58
+ def fft_conv1d(
59
+ x: torch.Tensor, weight: torch.Tensor, bias: Optional[torch.Tensor] = None
60
+ ) -> torch.Tensor:
61
+ """``F.conv1d(x, weight, bias, padding="same")`` computed with FFTs.
62
+
63
+ Equal to the direct convolution up to float rounding: the FFT is long
64
+ enough for a linear (not circular) convolution. Its cost barely grows with
65
+ the kernel size, so it is faster than the direct one for long kernels on
66
+ CPU (see :func:`prefer_fft_conv`). float16/bfloat16 inputs are computed in
67
+ float32 (:func:`spectral_input`) and cast back.
68
+
69
+ Parameters
70
+ ----------
71
+ x : torch.Tensor
72
+ Input of shape ``(batch, in_channels, n_times)``.
73
+ weight : torch.Tensor
74
+ Kernels of shape ``(out_channels, in_channels, kernel_size)``.
75
+ bias : torch.Tensor | None
76
+ Bias of shape ``(out_channels,)``.
77
+
78
+ Returns
79
+ -------
80
+ torch.Tensor
81
+ Output of shape ``(batch, out_channels, n_times)``, dtype and device of
82
+ ``x``. For an even ``kernel_size`` it is aligned like torch's
83
+ ``padding="same"`` (the extra zero padded on the right).
84
+ """
85
+ n_times, kernel_size = x.shape[-1], weight.shape[-1]
86
+ # >= n_times + kernel_size - 1 (no circular wrap-around), even and
87
+ # 5-smooth: the fast cases of a real FFT
88
+ n_fft = 2 * _next_fast_len((n_times + kernel_size) // 2)
89
+ xs = spectral_input(x)
90
+ # conv1d is a cross-correlation: a convolution with the flipped kernel
91
+ x_f = torch.fft.rfft(xs, n=n_fft).permute(2, 0, 1) # (freq, batch, in)
92
+ w_f = torch.fft.rfft(weight.to(xs).flip(-1), n=n_fft).permute(2, 1, 0)
93
+ # Per frequency (batch, in) @ (in, out) in complex numbers, as one real
94
+ # matmul (a complex one is slower on CPU): [Re x; Im x] @ [Re w, Im w]
95
+ # (columns interleaved) holds the four real products.
96
+ p = torch.cat([x_f.real, x_f.imag], 1) @ torch.view_as_real(w_f).flatten(2)
97
+ p = p.unflatten(1, [2, x.shape[0]]).unflatten(3, [-1, 2]) # x re/im, w re/im
98
+ y_f = torch.complex(
99
+ p[:, 0, :, :, 0] - p[:, 1, :, :, 1], p[:, 0, :, :, 1] + p[:, 1, :, :, 0]
100
+ )
101
+ y = torch.fft.irfft(y_f.permute(1, 2, 0), n=n_fft)
102
+ # "same" output t is sample t + kernel_size // 2 of the full convolution
103
+ y = y[..., kernel_size // 2 : kernel_size // 2 + n_times]
104
+ if bias is not None:
105
+ y = y + bias.to(y).unsqueeze(-1)
106
+ return y.to(x)
107
+
108
+
109
+ def prefer_fft_conv(x: torch.Tensor, kernel_size: int) -> bool:
110
+ """Whether :func:`fft_conv1d` is expected to beat a direct convolution.
111
+
112
+ Rule measured for :class:`~braindecode.models.EEGInceptionMI` (48 to 240
113
+ channels, 128-500 Hz, 2 CPU threads, oneDNN on and off): on CPU the FFT
114
+ wins for float16/bfloat16 inputs (no fast half-precision CPU convolution)
115
+ and from ``batch_size * kernel_size >= 600`` if also
116
+ ``in_channels * kernel_size >= 120``: with one or two input channels a
117
+ float32 direct convolution stays cheaper up to k = 85 / 31 (13 long
118
+ temporal convolutions of the model zoo, 22 channels x batch 32). GPUs and
119
+ HPUs (no complex dtype) keep the direct convolution.
120
+
121
+ Parameters
122
+ ----------
123
+ x : torch.Tensor
124
+ Input of the convolution, ``(batch, in_channels, n_times)``.
125
+ kernel_size : int
126
+ Kernel length in samples.
127
+ """
128
+ return x.device.type == "cpu" and (
129
+ x.element_size() == 2
130
+ or (x.shape[0] * kernel_size >= 600 and x.shape[1] * kernel_size >= 120)
131
+ )
132
+
133
+
134
+ def _next_fast_len(n: int) -> int:
135
+ """Smallest ``2^a 3^b 5^c >= n`` (scipy's ``next_fast_len(n, real=True)``)."""
136
+ n -= 1
137
+ m = 0
138
+ while m != 1:
139
+ n += 1
140
+ m = n
141
+ for p in [2, 3, 5]:
142
+ while m % p == 0:
143
+ m = m // p
144
+ return n
145
+
146
+
57
147
  def drop_path(
58
148
  x, drop_prob: float = 0.0, training: bool = False, scale_by_keep: bool = True
59
149
  ):
@@ -281,18 +371,24 @@ def plv_time(
281
371
  )
282
372
  # Normalize the analytic signal to obtain unit vectors (phasors).
283
373
  unit_phasor = analytic_signal / amplitude.unsqueeze(-1)
374
+ # The real/imaginary slices are strided (step 2): matmul copied each of
375
+ # them for every product, per batch matrix. Copy them once.
376
+ real = unit_phasor[..., 0].contiguous()
377
+ imag = unit_phasor[..., 1].contiguous()
378
+ real_t = real.transpose(-2, -1).contiguous()
379
+ imag_t = imag.transpose(-2, -1).contiguous()
284
380
 
285
381
  # Compute the real part of the outer product between phasors of
286
382
  # different channels.
287
- real_real = torch.matmul(unit_phasor[..., 0], unit_phasor[..., 0].transpose(-2, -1))
383
+ real_real = torch.matmul(real, real_t)
288
384
 
289
385
  # Compute the imaginary part of the outer product between phasors of
290
386
  # different channels.
291
- imag_imag = torch.matmul(unit_phasor[..., 1], unit_phasor[..., 1].transpose(-2, -1))
387
+ imag_imag = torch.matmul(imag, imag_t)
292
388
 
293
389
  # Compute the cross-terms for the real and imaginary parts.
294
- real_imag = torch.matmul(unit_phasor[..., 0], unit_phasor[..., 1].transpose(-2, -1))
295
- imag_real = torch.matmul(unit_phasor[..., 1], unit_phasor[..., 0].transpose(-2, -1))
390
+ real_imag = torch.matmul(real, imag_t)
391
+ imag_real = torch.matmul(imag, real_t)
296
392
 
297
393
  # Combine the real and imaginary parts to form the complex correlation.
298
394
  correlation_real = real_real + imag_imag
@@ -412,7 +508,14 @@ def dwt_max_level(n_times: int, filter_len: int) -> int:
412
508
  """
413
509
  if n_times < filter_len:
414
510
  return 0
415
- return max(0, int(math.floor(math.log2(n_times / (filter_len - 1)))))
511
+ # floor(log2(n_times / (filter_len - 1))) in integers (TorchScript has no
512
+ # math.log2): the largest level with (filter_len - 1) * 2**level <= n_times.
513
+ ratio = n_times // (filter_len - 1)
514
+ level = 0
515
+ while ratio >= 2:
516
+ ratio = ratio // 2
517
+ level += 1
518
+ return level
416
519
 
417
520
 
418
521
  def wavelet_decomposition(
@@ -456,8 +559,9 @@ def wavelet_decomposition(
456
559
  )
457
560
  approx, detail = F.conv1d(padded, weight, stride=2).unbind(dim=1)
458
561
  details.append(detail)
459
- out = torch.cat([approx, *reversed(details)], dim=-1)
460
- return out.reshape(*leading, -1)
562
+ details.reverse() # [cD_n, ..., cD_1]
563
+ out = torch.cat([approx] + details, dim=-1)
564
+ return out.reshape(list(leading) + [-1])
461
565
 
462
566
 
463
567
  def sinusoidal_positional_encoding(
@@ -39,6 +39,7 @@ from .emg2qwerty import EMG2QwertyNet
39
39
  from .fbcnet import FBCNet
40
40
  from .fblightconvnet import FBLightConvNet
41
41
  from .fbmsnet import FBMSNet
42
+ from .guetschel2026 import Guetschel2026
42
43
  from .hybrid import HybridNet
43
44
  from .ifnet import IFNet
44
45
  from .labram import Labram
@@ -139,6 +140,7 @@ __all__ = [
139
140
  "FBCNet",
140
141
  "FBLightConvNet",
141
142
  "FBMSNet",
143
+ "Guetschel2026",
142
144
  "MetaNeuromotorHand",
143
145
  "HybridNet",
144
146
  "IFNet",
@@ -143,6 +143,10 @@ class AttnSleep(EEGModuleMixin, nn.Module):
143
143
  sfreq=sfreq,
144
144
  )
145
145
  del n_outputs, n_chans, chs_info, n_times, input_window_seconds, sfreq
146
+ if self._n_chans_for_jit not in (None, 1):
147
+ raise ValueError(
148
+ f"AttnSleep takes single-channel input; got n_chans={self._n_chans_for_jit}."
149
+ )
146
150
 
147
151
  self.mapping = {
148
152
  "fc.weight": "final_layer.weight",
@@ -407,16 +411,12 @@ class _MRCNN(nn.Module):
407
411
  ##########################################################################################
408
412
 
409
413
 
410
- def _attention(
411
- query: torch.Tensor, key: torch.Tensor, value: torch.Tensor
412
- ) -> tuple[torch.Tensor, torch.Tensor]:
413
- """Implementation of Scaled dot product attention."""
414
+ def _attention(query: torch.Tensor, key: torch.Tensor) -> torch.Tensor:
415
+ """Scaled dot product attention weights."""
414
416
  # d_k - dimension of the query and key vectors
415
417
  d_k = query.size(-1)
416
418
  scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(d_k)
417
- p_attn = F.softmax(scores, dim=-1) # attention weights
418
- output = torch.matmul(p_attn, value) # (B, h, T, d_k)
419
- return output, p_attn
419
+ return F.softmax(scores, dim=-1) # attention weights
420
420
 
421
421
 
422
422
  class _MultiHeadedAttention(nn.Module):
@@ -464,10 +464,8 @@ class _MultiHeadedAttention(nn.Module):
464
464
  .transpose(1, 2)
465
465
  )
466
466
 
467
- x_raw, attn_weights = _attention(query, key, value)
468
- # apply dropout to the *weights*
469
- attn = self.dropout(attn_weights)
470
- # recompute the weighted sum with dropped weights
467
+ # apply dropout to the *weights*, then the weighted sum
468
+ attn = self.dropout(_attention(query, key))
471
469
  x = torch.matmul(attn, value)
472
470
 
473
471
  # merge heads and project