当前位置:网站首页>【长时间序列预测】Aotoformer 代码详解之[3]模型整体架构分析
【长时间序列预测】Aotoformer 代码详解之[3]模型整体架构分析
2022-06-11 02:26:00 【理心炼丹】
1. 模型整体架构图:

显然,一个编码器-解码器架构。先不考虑batch_sizes,编码器将输入的序列(L,d)编码为(L, d_model),d_model 为设置的参数表示将输入嵌入到多少维度。
编码器输入为:
enc_out:[32, 96, 512] # 假设batch_sizes=32, 输入序列长度=96,输入序列嵌入维度=512
编码器的输出:
enc_out:[32, 96, 512] 。编码器只进行了输入的维度进行了一系列变换,并没有改变长度96。
解码器的输入为:
dec_out:[32, 48 + 192, 512] # lable_len = 48,pred_len = 192。
解码器的输出为:
seasonal_part:[32, 48 + 192, c_out];trend_part:[32, 48 + 192, c_out] # c_out 为数据的实际维度。
最终输出:
outputs:[32, 192, c_out]
序列分解模块已在前文中进行了详细描述。
图中所谓的 前馈模块是集成在 EncoderLayer 和 DecoderLayer 中的,不过是一些Conv1d -> activation -> dropout -> Conv1d -> dropout 。
所需注意的只有一点:解码器的第二个自相关模块的输入是来自于编码器的输出作为(k, v),以及前一个解码器的输出作为 q。显然,二者的长度是不一样的。(图中信号的引出表示同一个东西,比如q, k, v来自一个输出就是一个信号复制的3次)
k = v :[32,96,512]
q: [32, 48 + 192, 512]
所以,AutoCorrelation 类的 forward 函数中:
B, L, H, E = queries.shape # 32 48+192 4 512/4 # 假设多头=4
_, S, _, D = values.shape # 32 96 4 512/4
if L > S:
zeros = torch.zeros_like(queries[:, :(L - S), :]).float()
values = torch.cat([values, zeros], dim=1)
keys = torch.cat([keys, zeros], dim=1)
else:
values = values[:, :L, :, :]
keys = keys[:, :L, :, :]因此,采用的方案是把 k, v 后面进行了补0到和q 一样长。
因此,我们知道了编码器和解码器并不会对长度进行修改。
2. 模型的输入
2.1 编码器的输入
编码器输入为:enc_out:[32, 96, 512],是如何得到的呢?
答案通过enc_embedding,
输入包括两部分:
除了时间戳以外的数据 x_enc:[32, 96, enc_in] #enc_in 就是输入数据的维度
时间戳信息 x_mark_enc:[32, 96, 4] # 如果 args.embed == 'timeF' ,freq='h' 请看前文的数据处理
enc_embedding是DataEmbedding_wo_pos类的对象。该类的forward 函数中将 x_enc(Conv1d) 与 x_mark_enc(Linear) 的shape都编码为 [32, 96, 512] ,然后相加,即得到编码器的输入 enc_out:[32, 96, 512] 。
2.1 解码器的输入
对 x_enc:[32, 96, enc_in] 进行前文的序列分解得到两个序列:
seasonal_init:[32, 96, enc_in]
trend_init:[32, 96, enc_in]
对 x_enc 求均值,和造一个 0 值序列。
mean = torch.mean(x_enc, dim=1).unsqueeze(1).repeat(1, self.pred_len, 1) # mean 会把dim=1 那个维度干掉[32, enc_in] -> [32, 1, enc_in] -> [32, 192, enc_in]
zeros = torch.zeros([x_enc.shape[0], self.pred_len, x_enc.shape[2]], device=x_enc.device) # 源代码中的 x_dec 完全没必要,替换为 x_enc 就行了。之所以那么做,作者是为了统一接口让别的模型一样传递输入。 [32, 192, enc_in] # decoder input
trend_init = torch.cat([trend_init[:, -self.label_len:, :], mean], dim=1)
seasonal_init = torch.cat([seasonal_init[:, -self.label_len:, :], zeros], dim=1)seasonal_init:[32, 48 + 192, enc_in]
trend_init:[32, 48 + 192, enc_in]
dec_embedding 嵌入 与上文的 enc_embedding 一样。输入:
seasonal_init:[32, 48 + 192, enc_in]
x_mark_dec:[32, 48 + 192, 4]
dec_out: [32, 48 + 192, 512]
3. 解码器的加法怎么做的?
其实论文中的架构图简化了。因此,我重画了解码器部分。

参考:
计划更新:[4]模型部件之自相关层-AC
边栏推荐
- Multilevel mesoporous organometallic framework material zif-8 loaded with lactic acid oxidase (LOD) / ferric oxide (Fe304) / doxorubicin / insulin /cas9 protein / metronidazole / emodin methyl ether
- What do you know about the set class? Soul questions from Volume I
- GCC C inline assembly
- 同一个用户的两次请求SessionId竟然不一致-----记录问题
- Setting access to win10 shared folder without verification
- Jetpack compose box control
- Technology sharing | quick intercom, global intercom
- Jetpack compose scaffold and bottomappbar (bottom navigation)
- What is the relationship between precious metal silver and spot Silver
- Uni app - one click access to user information
猜你喜欢

How to read PMBOK guide in 3 steps (experience + data sharing)

逃离大城市的年轻人:扛住了房价和压力,没扛住流行病

学习太极创客 — ESP8226 (二)

ADVANCE. AI CEO Shoudong will share the compliance of cross-border e-commerce using AI technology at the 2022 emerging market brands online Summit

To view the data in redis, in addition to the command line and client, you have a third option

Technology sharing | quick intercom, global intercom

Unity animator rewind

App test_ Summary of test points

Learning Tai Chi Maker - esp8226 (II)

app 测试 常用 adb 命令集合
随机推荐
20220610 星期五
Write my Ini configuration file error
CPT 102_LEC 17
String operation methods: replace, delete and split strings
深度学习基础篇【4】从0开始搭建EasyOCR并进行简单文字识别
Epoll principle and Application & ET mode and lt mode
Looking at the ups and downs of the mobile phone accessories market from the green Union's sprint for IPO
Metal organic framework materials (fe-mil-53, mg-mof-74, ti-kumof-1, fe-mil-100, fe-mil-101) supported on isoflurane / methotrexate / doxorubicin (DOX) / paclitaxel / ibuprofen / camptothecin
WordPress article directory plug-in luckywp table of contents setup tutorial
[189. rotation array]
When a logical deletion encounters a unique index, what are the problems and solutions?
STC8A8K64D4 EEPROM读写失败
Use of CIN and cout
How to add two factor authentication for WordPress websites
年金保險理財產品可以複利嗎?利率是多少?
Principle of everything for fast search
ADVANCE.AI首席执行官寿栋将在2022新兴市场品牌出海线上峰会分享跨境电商运用AI技术合规
【斐波那契数列】
Cyclodextrin metal organic framework( β- Cd-mof) loaded with dimercaptosuccinic acid / emodin / quercetin / sucralose / diflunisal / omeprazole (OME)
CPT 102_LEC 18
https://github.com/thuml/Autoformer