libcity.model.traffic_flow_prediction.ASTGCN

class libcity.model.traffic_flow_prediction.ASTGCN.ASTGCN(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

forward(batch)[源代码]

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 Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

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.ASTGCN.ASTGCNBlock(device, in_channels, k, nb_chev_filter, nb_time_filter, time_strides, cheb_polynomials, num_of_vertices, num_of_timesteps)[源代码]

基类:torch.nn.modules.module.Module

forward(x)[源代码]
参数

x – (batch_size, N, F_in, T)

返回

(batch_size, N, nb_time_filter, output_window)

返回类型

torch.tensor

training: bool
class libcity.model.traffic_flow_prediction.ASTGCN.ASTGCNSubmodule(device, nb_block, in_channels, k, nb_chev_filter, nb_time_filter, time_strides, cheb_polynomials, output_window, output_dim, num_of_vertices)[源代码]

基类:torch.nn.modules.module.Module

forward(x)[源代码]
参数

x – (B, T_in, N_nodes, F_in)

返回

(B, T_out, N_nodes, out_dim)

返回类型

torch.tensor

training: bool
class libcity.model.traffic_flow_prediction.ASTGCN.ChebConvWithSAt(k, cheb_polynomials, in_channels, out_channels)[源代码]

基类:torch.nn.modules.module.Module

K-order chebyshev graph convolution

forward(x, spatial_attention)[源代码]

Chebyshev graph convolution operation

参数
  • x – (batch_size, N, F_in, T)

  • spatial_attention – (batch_size, N, N)

返回

(batch_size, N, F_out, T)

返回类型

torch.tensor

training: bool
class libcity.model.traffic_flow_prediction.ASTGCN.FusionLayer(n, h, w, device)[源代码]

基类:torch.nn.modules.module.Module

forward(x)[源代码]

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 Module instance 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.ASTGCN.SpatialAttentionLayer(device, in_channels, num_of_vertices, num_of_timesteps)[源代码]

基类:torch.nn.modules.module.Module

compute spatial attention scores

forward(x)[源代码]
参数

x (torch.tensor) – (B, N, F_in, T)

返回

(B,N,N)

返回类型

torch.tensor

training: bool
class libcity.model.traffic_flow_prediction.ASTGCN.TemporalAttentionLayer(device, in_channels, num_of_vertices, num_of_timesteps)[源代码]

基类:torch.nn.modules.module.Module

forward(x)[源代码]
参数

x – (batch_size, N, F_in, T)

返回

(B, T, T)

返回类型

torch.tensor

training: bool
libcity.model.traffic_flow_prediction.ASTGCN.cheb_polynomial(l_tilde, k)[源代码]

compute a list of chebyshev polynomials from T_0 to T_{K-1}

参数
  • l_tilde (np.ndarray) – scaled Laplacian, shape (N, N)

  • k (int) – the maximum order of chebyshev polynomials

返回

cheb_polynomials, length: K, from T_0 to T_{K-1}

返回类型

list(np.ndarray)

libcity.model.traffic_flow_prediction.ASTGCN.scaled_laplacian(weight)[源代码]

compute ~L (scaled laplacian matrix) L = D - A ~L = 2L/lambda - I

参数

weight (np.ndarray) – shape is (N, N), N is the num of vertices

返回

~L, shape (N, N)

返回类型

np.ndarray