2025年【MGT】代码解读之model-MGT

【MGT】代码解读之model-MGT论文解读 Meta Graph Transformer A Novel Framework for Spatial Temporal Traffic Prediction 代码链接 https github com lonicera yx MGT 壹 测试主框架 一 文件目录 文件夹 MGT main

大家好,我是讯享网,很高兴认识大家。

论文解读:《Meta Graph Transformer: A Novel Framework for Spatial–Temporal Traffic Prediction》

代码链接:https://github.com/lonicera-yx/MGT


壹、测试主框架

一、文件目录

在这里插入图片描述
讯享网
文件夹MGT-main下包含4个子文件夹,一个数据压缩文件,一个main.py等等。
MGT.py位于子文件夹models中,包含了3个def和14个class

二、if 主函数测试MGT

if __name__ == '__main__': print(os.getcwd()) #cfgs = yaml.safe_load(open('cfgs/HZMetro_MGT.yaml'))['model'] cfgs = yaml.safe_load(open('../cfgs/HZMetro_MGT.yaml'))['model'] model = MGT(cfgs) # dummy data 虚拟数据 B, P, Q, N, C = 10, 4, 4, 80, 2 # B:batch_size P:history Q:feture N:Nodes C:Features M = 73, 2 # M is tuple eigenmaps_k = 8 #拉普拉斯特征映射降维方法的参数 n = 3 inputs = torch.randn(B, P, N, C, dtype=torch.float32)#(10,4,80,2) targets = torch.randn(B, Q, N, C, dtype=torch.float32)#(10,4,80,2) inputs_time0 = torch.randint(M[0], (B, P), dtype=torch.int64)#(10,4) max_int is 73 targets_time0 = torch.randint(M[0], (B, Q), dtype=torch.int64)#(10,4) inputs_time1 = torch.randint(M[1], (B, P), dtype=torch.int64)#(10,4) max_int is 2 targets_time1 = torch.randint(M[1], (B, Q), dtype=torch.int64)#(10,4) eigenmaps = torch.randn(N, eigenmaps_k, dtype=torch.float32)#(80,8) transition_matrices = torch.rand(n, N, N, dtype=torch.float32)#(3,80,80) extras = [inputs_time0, targets_time0, inputs_time1, targets_time1] statics = { 
   'eigenmaps': eigenmaps, 'transition_matrices': transition_matrices} # forward outputs1 = model(inputs, targets, *extras, statics) #*和见注释1 outputs2 = model(inputs, None, *extras, statics) 

讯享网

贰、MGT

def __init__ 结构搭建

在这里插入图片描述

在原文中有MTG的各种变形(如下),我们不考虑这些,只考经典的MTG
在这里插入图片描述
所以,在MGT下,self.noTE=self.noSE=False.共包含5个层结构:时间嵌入层、空间嵌入层、时空嵌入层、编码器结构、解码器结构。

def forward流程图

流程图中的input是一个,为了美观,所以拆分为两个分别作为输入。

dict
小讯
上一篇 2025-02-25 22:22
下一篇 2025-02-11 09:47

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/107655.html