MCPcopy Create free account
hub / github.com/kwuking/TimeMixer / FixedEmbedding

Class FixedEmbedding

layers/Embed.py:45–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45class FixedEmbedding(nn.Module):
46 def __init__(self, c_in, d_model):
47 super(FixedEmbedding, self).__init__()
48
49 w = torch.zeros(c_in, d_model).float()
50 w.require_grad = False
51
52 position = torch.arange(0, c_in).float().unsqueeze(1)
53 div_term = (torch.arange(0, d_model, 2).float()
54 * -(math.log(10000.0) / d_model)).exp()
55
56 w[:, 0::2] = torch.sin(position * div_term)
57 w[:, 1::2] = torch.cos(position * div_term)
58
59 self.emb = nn.Embedding(c_in, d_model)
60 self.emb.weight = nn.Parameter(w, requires_grad=False)
61
62 def forward(self, x):
63 return self.emb(x).detach()
64
65
66class TemporalEmbedding(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected