libcity.model.traffic_speed_prediction.GTS¶
-
class
libcity.model.traffic_speed_prediction.GTS.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. :param inputs: (B, num_nodes * input_dim) :param hx: (B, num_nodes * rnn_units)
- 返回
shape (B, num_nodes * rnn_units)
- 返回类型
torch.tensor
-
training: bool¶
-
-
class
libcity.model.traffic_speed_prediction.GTS.DecoderModel(config, data_feature, adj_mx, device)[源代码]¶ 基类:
torch.nn.modules.module.Module,libcity.model.traffic_speed_prediction.GTS.Seq2SeqAttrs-
forward(inputs, hidden_state=None)[源代码]¶ Decoder forward pass. :param inputs: shape (batch_size, self.num_nodes * self.output_dim) :param 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.GTS.EncoderModel(config, data_feature, adj_mx, device)[源代码]¶ 基类:
torch.nn.modules.module.Module,libcity.model.traffic_speed_prediction.GTS.Seq2SeqAttrs-
forward(inputs, hidden_state=None)[源代码]¶ Encoder forward pass. :param inputs: shape (batch_size, self.num_nodes * self.input_dim) :param 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.GTS.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
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_speed_prediction.GTS.GCONV(num_nodes, max_diffusion_step, device, input_dim, hid_dim, output_dim, adj_mx, 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
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_speed_prediction.GTS.GTS(config, data_feature)[源代码]¶ 基类:
libcity.model.abstract_traffic_state_model.AbstractTrafficStateModel,libcity.model.traffic_speed_prediction.GTS.Seq2SeqAttrs-
_get_x_y(x, y)[源代码]¶ - 参数
x – shape (batch_size, seq_len, num_sensor, input_dim)
y – shape (batch_size, horizon, num_sensor, input_dim)
- :returns x shape (seq_len, batch_size, num_sensor, input_dim)
y shape (horizon, batch_size, num_sensor, input_dim)
-
_get_x_y_in_correct_dims(x, y)[源代码]¶ - 参数
x – shape (seq_len, batch_size, num_sensor, input_dim)
y – shape (horizon, batch_size, num_sensor, input_dim)
- 返回
x: shape (seq_len, batch_size, num_sensor * input_dim) y: shape (horizon, batch_size, num_sensor * output_dim)
-
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 :param encoder_hidden_state: (num_layers, batch_size, self.hidden_state_size) :param labels: (self.horizon, batch_size, self.num_nodes * self.output_dim) [optional, not exist for inference] :param batches_seen: global step [optional, not exist for inference] :return: output: (self.horizon, batch_size, self.num_nodes * self.output_dim)
-
encoder(inputs)[源代码]¶ Encoder forward pass :param inputs: shape (seq_len, batch_size, num_sensor * input_dim) :return: encoder_hidden_state: (num_layers, batch_size, self.hidden_state_size)
-
forward(batch, batches_seen=None)[源代码]¶ 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.
-
predict(batch, batches_seen=None)[源代码]¶ 输入一个batch的数据,返回对应的预测值,一般应该是**多步预测**的结果,一般会调用nn.Moudle的forward()方法
- 参数
batch (Batch) – a batch of input
- 返回
predict result of this batch
- 返回类型
torch.tensor
-
training: bool¶
-
-
libcity.model.traffic_speed_prediction.GTS.gumbel_softmax(device, logits, temperature, hard=False, eps=1e-10)[源代码]¶ Sample from the Gumbel-Softmax distribution and optionally discretize. :param logits: [batch_size, n_class] unnormalized log-probs :param temperature: non-negative scalar :param hard: if True, take argmax, but differentiate w.r.t. soft sample y
- 返回
[batch_size, n_class] sample from the Gumbel-Softmax distribution. If hard=True, then the returned sample will be one-hot, otherwise it will be a probabilitiy distribution that sums to 1 across classes