libcity.model.traffic_flow_prediction.ASTGCN

class libcity.model.traffic_flow_prediction.ASTGCN.ASTGCN(config, data_feature)[source]

Bases: libcity.model.abstract_traffic_state_model.AbstractTrafficStateModel

calculate_loss(batch)[source]

输入一个batch的数据,返回训练过程的loss,也就是需要定义一个loss函数

Parameters

batch (Batch) – a batch of input

Returns

return training loss

Return type

torch.tensor

forward(batch)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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)[source]

输入一个batch的数据,返回对应的预测值,一般应该是**多步预测**的结果,一般会调用nn.Moudle的forward()方法

Parameters

batch (Batch) – a batch of input

Returns

predict result of this batch

Return type

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)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]
Parameters

x – (batch_size, N, F_in, T)

Returns

(batch_size, N, nb_time_filter, output_window)

Return type

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)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]
Parameters

x – (B, T_in, N_nodes, F_in)

Returns

(B, T_out, N_nodes, out_dim)

Return type

torch.tensor

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

Bases: torch.nn.modules.module.Module

K-order chebyshev graph convolution

forward(x, spatial_attention)[source]

Chebyshev graph convolution operation

Parameters
  • x – (batch_size, N, F_in, T)

  • spatial_attention – (batch_size, N, N)

Returns

(batch_size, N, F_out, T)

Return type

torch.tensor

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

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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)[source]

Bases: torch.nn.modules.module.Module

compute spatial attention scores

forward(x)[source]
Parameters

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

Returns

(B,N,N)

Return type

torch.tensor

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

Bases: torch.nn.modules.module.Module

forward(x)[source]
Parameters

x – (batch_size, N, F_in, T)

Returns

(B, T, T)

Return type

torch.tensor

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

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

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

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

Returns

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

Return type

list(np.ndarray)

libcity.model.traffic_flow_prediction.ASTGCN.scaled_laplacian(weight)[source]

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

Parameters

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

Returns

~L, shape (N, N)

Return type

np.ndarray