MCPcopy Create free account
hub / github.com/Anoise/WTFlib / Coord1dPosEncoding

Function Coord1dPosEncoding

LDPS_Graph/layers/PatchTST_layers.py:89–94  ·  view source on GitHub ↗
(q_len, exponential=False, normalize=True)

Source from the content-addressed store, hash-verified

87 return cpe
88
89def Coord1dPosEncoding(q_len, exponential=False, normalize=True):
90 cpe = (2 * (torch.linspace(0, 1, q_len).reshape(-1, 1)**(.5 if exponential else 1)) - 1)
91 if normalize:
92 cpe = cpe - cpe.mean()
93 cpe = cpe / (cpe.std() * 10)
94 return cpe
95
96def positional_encoding(pe, learn_pe, q_len, d_model):
97 # Positional encoding

Callers 1

positional_encodingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected