libcity.model.traffic_flow_prediction.DSAN¶
-
class
libcity.model.traffic_flow_prediction.DSAN.Convs(n_layer, n_filter, input_window, input_dim, r_d=0.1)[源代码]¶ 基类:
torch.nn.modules.module.ModuleConv layers for input, to form a d-dimension representation
-
forward(inps)[源代码]¶ - 参数
inps – with shape [batch_size, input_window, row, column, N_d, input_dim] or [batch_size, input_window, row, column, input_dim]
Returns:
-
training: bool¶
-
-
class
libcity.model.traffic_flow_prediction.DSAN.DAE(L, d, n_h, num_hid, conv_layer, input_window, input_dim, ext_dim, r_d=0.1)[源代码]¶ 基类:
torch.nn.modules.module.ModuleDAE Dynamic Attention Encoder
-
forward(x_d, x_g, ex, cors_d, cors_g, threshold_mask_d, threshold_mask_g)[源代码]¶ - 参数
x_d – a subset of 𝑿 that contains the closest neighbors that share strong correlations with v_i within a local block.(X_d in figure 4)
x_g – all the training data (X in figure 4)
ex – time-related features for Temporal Positional Encoding
cors_d – Spatial Positional Encoding of x_d
cors_g – Spatial Positional Encoding of x_g
threshold_mask_d –
threshold_mask_g –
Returns:
-
training: bool¶
-
-
class
libcity.model.traffic_flow_prediction.DSAN.DSAN(config, data_feature)[源代码]¶ 基类:
libcity.model.abstract_traffic_state_model.AbstractTrafficStateModel-
calculate_loss(batch)[源代码]¶ 输入一个batch的数据,返回训练过程的loss,也就是需要定义一个loss函数
- 参数
batch (Batch) – a batch of input
- 返回
return training loss
- 返回类型
torch.tensor
-
generate_x(batch)[源代码]¶ from batch[‘X’] to :param batch: batch[‘X’].shape == [batch_size, input_window, row, column, feature_dim]
batch[‘y’].shape == [batch_size, output_window, row, column, output_dim]
- 返回
X in figure(2) shape == [batch_size, input_window, row, column, output_dim] dae_inp: X_d in figure(2) shape == [batch_size, input_window, row, column, L_D, L_D output_dim]
N_D = L_d * L_d ,L_d = 2 * l_d + 1
dae_inp_ex: external data for TPE shape == [batch_size, input_window, N, external_dim] sad_inp: x in figure(2) shape == [batch_size, output_window, N, output_dim] sad_inp_ex: external data for TPE shape == [batch_size, input_window, N, external_dim] cors: for SPE,shape == [1, 1, N_d, d] cors_g: for SPE, shape == [1, N, d] y:
- 返回类型
dae_inp_g
-
predict(batch)[源代码]¶ 输入一个batch的数据,返回对应的预测值,一般应该是**多步预测**的结果,一般会调用nn.Moudle的forward()方法
- 参数
batch (Batch) – a batch of input
- 返回
predict result of this batch
- 返回类型
torch.tensor
-
training: bool¶
-
-
class
libcity.model.traffic_flow_prediction.DSAN.DecoderLayer(d, n_h, num_hid, r_d=0.1, revert_q=False)[源代码]¶ 基类:
torch.nn.modules.module.ModuleEnc-D / Dec-S / Dec-T implementation
-
forward(x, kv, look_ahead_mask, threshold_mask)[源代码]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
注解
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
training: bool¶
-
-
class
libcity.model.traffic_flow_prediction.DSAN.DsanUse(L, d, n_h, row, column, num_hid, conv_layer, input_window, output_window, input_dim, ext_dim, device, r_d=0.1)[源代码]¶ 基类:
torch.nn.modules.module.ModuleDSAN use
-
forward(dae_inp_g, dae_inp, dae_inp_ex, sad_inp, sad_inp_ex, cors, cors_g, threshold_mask, threshold_mask_g, look_ahead_mask)[源代码]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
注解
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
training: bool¶
-
-
class
libcity.model.traffic_flow_prediction.DSAN.EncoderLayer(d, n_h, num_hid, r_d=0.1)[源代码]¶ 基类:
torch.nn.modules.module.ModuleEnc-G implementation
-
training: bool¶
-
-
class
libcity.model.traffic_flow_prediction.DSAN.MSA(d, n_h, self_att=True)[源代码]¶ 基类:
torch.nn.modules.module.ModuleMulti-space attention
-
forward(V, K, Q, M)[源代码]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
注解
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
split_heads(x)[源代码]¶ - 参数
x – shape == [batch_size, input_window, N, d]
- 返回
shape == [batch_size, input_window, n_h, N, d_h]
-
training: bool¶
-
-
class
libcity.model.traffic_flow_prediction.DSAN.SAD(L, d, n_h, num_hid, conv_layer, ext_dim, input_window, output_window, device, r_d=0.1)[源代码]¶ 基类:
torch.nn.modules.module.Module-
forward(x, ex, dae_output, look_ahead_mask)[源代码]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
注解
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
training: bool¶
-
-
libcity.model.traffic_flow_prediction.DSAN.cal_attention(Q, K, V, M, n_h)[源代码]¶ equ (3), calculate the attention mechanism performed by the i-th attention head :param Q: query, shape (N, h, L_q, d) :param K: key, shape (N, h, L_k, d) :param V: value, shape (N, h, L_k, d) :param M: mask, shape (N, h, L_q, L_k) :param n_h: number of attention head
- 返回
shape # (N, h, L_q, d)
- 返回类型
Att
-
libcity.model.traffic_flow_prediction.DSAN.create_masks(inp_g, inp_l, tar)[源代码]¶ - 参数
inp_g – shape == [batch_size, input_window, column, row, input_dim]
inp_l – shape == [batch_size, input_window, column, row, l_d, l_d, input_dim] torch.Size([64, 12, 192, 49, 2])
tar – shape == [batch_size, input_window, N, ext_dim] torch.Size([64, 12, 192, 8])
Returns:
-
libcity.model.traffic_flow_prediction.DSAN.create_threshold_mask(inp)[源代码]¶ - 参数
inp – [batch_size, input_window, column, row, input_dim]
Returns:
-
libcity.model.traffic_flow_prediction.DSAN.ex_encoding(d, num_hid, input_dim)[源代码]¶ implementation of TPE :param d: d-dimension representations :param num_hid: hidden layer size :param input_dim: input feature dimension
Returns:
-
libcity.model.traffic_flow_prediction.DSAN.get_angles(pos, l, d)[源代码]¶ equ (5) :param pos: row(r) / column(c) in equ (5) :param l: the l-th dimension, with shape (1, d) :param d: d dimension in total
Returns: angles with shape (1, d)