braindecode.functional.sinusoidal_positional_encoding#
- braindecode.functional.sinusoidal_positional_encoding(n_positions, dim)[source]#
Fixed sine/cosine positional-encoding table of shape
(n_positions, dim).The standard encoding of Vaswani et al. (2017): for position \(p\) and channel \(i\), \(pe[p, 2i] = \sin(p / 10000^{2i/d})\) and \(pe[p, 2i+1] = \cos(p / 10000^{2i/d})\). PyTorch ships no sinusoidal encoding (
nn.Embeddingis a learned lookup), so braindecode models that need one share this primitive instead of re-deriving it. An odddimis computed on the next even width and truncated, reproducing the per-model wrappers (e.g.medformerodd-d_model).