参考: https://keras.io/examples/timeseries/timeseries_traffic_forecasting/
任务:
交通多步预测
准备数据
节点:228
计算每个节点之间的距离: 288 * 288
速度: 12672 * 288,时间 * 节点
为简化说明,只选取了26个节点
训练:6336 * 26
验证:2534 * 26
测试:3802 * 26
图数据
构图:邻接矩阵
-
每个node对应着一个向量计算distance matrix,这里实例中的原始数据已经给出.
-
将distance matrix转化为adj matrix。bool类型的矩阵
- adj通过np.where得到1对应的行和列,作为node和neighbour。也就是转化为两两的pair关系
实例中的方法大于一定阈值的都算有边,而百度风机的方法里每个节点计算最相关的k个
距离矩阵转化为邻接矩阵采用论文中的方法,tf中采用的方法是segment
以下实例中,segmeng_id针对的是向量,第一种ID0,也就是前两个的和,第二种ID1,也就是第三个的和。从而得到结果
c = tf.constant([[1,2,3,4], [-1,-2,-3,-4], [5,6,7,8]])
tf.math.segment_sum(c, tf.constant([0, 0, 1]))
==> [[0 0 0 0]
[5 6 7 8]]
模型
输入: batch * time_steps * node * feature
transpose: node * batch * time_steps * feature
GCN:周边消息传播
transpose: batch * node, time_steps, feature
LSTM:
dense: batch * node, pred_time_steps
output reshape: batch, pred_time_steps, node
其中的特殊之处在于GCN层,输入为node * batch * time_steps * feature
其中 in_feature = 1
多步预测
多步可以直接给出dense
Original: https://blog.csdn.net/weixin_38812492/article/details/125505132
Author: YueTann
Title: 时空预测2-GCN_LSTM
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/688754/
转载文章受原作者版权保护。转载请注明原作者出处!