libcity.model.traffic_speed_prediction.DCRNN

class libcity.model.traffic_speed_prediction.DCRNN.DCGRUCell(input_dim, num_units, adj_mx, max_diffusion_step, num_nodes, device, nonlinearity='tanh', filter_type='laplacian', use_gc_for_ru=True)[源代码]

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

forward(inputs, hx)[源代码]

Gated recurrent unit (GRU) with Graph Convolution.

参数
  • inputs – (B, num_nodes * input_dim)

  • hx – (B, num_nodes * rnn_units)

返回

shape (B, num_nodes * rnn_units)

返回类型

torch.tensor

training: bool
class libcity.model.traffic_speed_prediction.DCRNN.DCRNN(config, data_feature)[源代码]

基类:libcity.model.abstract_traffic_state_model.AbstractTrafficStateModel, libcity.model.traffic_speed_prediction.DCRNN.Seq2SeqAttrs

calculate_loss(batch, batches_seen=None)[源代码]

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

参数

batch (Batch) – a batch of input

返回

return training loss

返回类型

torch.tensor

decoder(encoder_hidden_state, labels=None, batches_seen=None)[源代码]

Decoder forward pass

参数
  • encoder_hidden_state – (num_layers, batch_size, self.hidden_state_size)

  • labels – (self.output_window, batch_size, self.num_nodes * self.output_dim) [optional, not exist for inference]

  • batches_seen – global step [optional, not exist for inference]

返回

(self.output_window, batch_size, self.num_nodes * self.output_dim)

返回类型

torch.tensor

encoder(inputs)[源代码]

encoder forward pass on t time steps

参数

inputs – shape (input_window, batch_size, num_sensor * input_dim)

返回

(num_layers, batch_size, self.hidden_state_size)

返回类型

torch.tensor

forward(batch, batches_seen=None)[源代码]

seq2seq forward pass

参数
  • batch

    a batch of input, batch[‘X’]: shape (batch_size, input_window, num_nodes, input_dim)

    batch[‘y’]: shape (batch_size, output_window, num_nodes, output_dim)

  • batches_seen – batches seen till now

返回

(batch_size, self.output_window, self.num_nodes, self.output_dim)

返回类型

torch.tensor

predict(batch, batches_seen=None)[源代码]

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

参数

batch (Batch) – a batch of input

返回

predict result of this batch

返回类型

torch.tensor

training: bool
class libcity.model.traffic_speed_prediction.DCRNN.DecoderModel(config, adj_mx)[源代码]

基类:torch.nn.modules.module.Module, libcity.model.traffic_speed_prediction.DCRNN.Seq2SeqAttrs

forward(inputs, hidden_state=None)[源代码]

Decoder forward pass.

参数
  • inputs – shape (batch_size, self.num_nodes * self.output_dim)

  • hidden_state – (num_layers, batch_size, self.hidden_state_size), optional, zeros if not provided, hidden_state_size = num_nodes * rnn_units

返回

tuple contains:

output: shape (batch_size, self.num_nodes * self.output_dim)

hidden_state: shape (num_layers, batch_size, self.hidden_state_size)

(lower indices mean lower layers)

返回类型

tuple

training: bool
class libcity.model.traffic_speed_prediction.DCRNN.EncoderModel(config, adj_mx)[源代码]

基类:torch.nn.modules.module.Module, libcity.model.traffic_speed_prediction.DCRNN.Seq2SeqAttrs

forward(inputs, hidden_state=None)[源代码]

Encoder forward pass.

参数
  • inputs – shape (batch_size, self.num_nodes * self.input_dim)

  • hidden_state – (num_layers, batch_size, self.hidden_state_size), optional, zeros if not provided, hidden_state_size = num_nodes * rnn_units

返回

tuple contains:

output: shape (batch_size, self.hidden_state_size)

hidden_state: shape (num_layers, batch_size, self.hidden_state_size)

(lower indices mean lower layers)

返回类型

tuple

training: bool
class libcity.model.traffic_speed_prediction.DCRNN.FC(num_nodes, device, input_dim, hid_dim, output_dim, bias_start=0.0)[源代码]

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

forward(inputs, state)[源代码]

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_speed_prediction.DCRNN.GCONV(num_nodes, max_diffusion_step, supports, device, input_dim, hid_dim, output_dim, bias_start=0.0)[源代码]

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

forward(inputs, state)[源代码]

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_speed_prediction.DCRNN.Seq2SeqAttrs(config, adj_mx)[源代码]

基类:object

libcity.model.traffic_speed_prediction.DCRNN.calculate_normalized_laplacian(adj)[源代码]

L = D^-1/2 (D-A) D^-1/2 = I - D^-1/2 A D^-1/2

参数

adj – adj matrix

返回

L

返回类型

np.ndarray

libcity.model.traffic_speed_prediction.DCRNN.calculate_random_walk_matrix(adj_mx)[源代码]
libcity.model.traffic_speed_prediction.DCRNN.calculate_reverse_random_walk_matrix(adj_mx)[源代码]
libcity.model.traffic_speed_prediction.DCRNN.calculate_scaled_laplacian(adj_mx, lambda_max=2, undirected=True)[源代码]
libcity.model.traffic_speed_prediction.DCRNN.count_parameters(model)[源代码]