libcity.model.traffic_demand_prediction.CCRNN

class libcity.model.traffic_demand_prediction.CCRNN.CCRNN(config, data_feature)[source]

Bases: libcity.model.abstract_traffic_state_model.AbstractTrafficStateModel

calculate_loss(batch, batches_seen=None)[source]

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

Parameters

batch (Batch) – a batch of input

Returns

return training loss

Return type

torch.tensor

forward(batch, batches_seen=None)[source]

dynamic convolutional recurrent neural network :param inputs: [B, input_window, N, input_dim] :param targets: exists for training, tensor, [B, output_window, N, output_dim] :param batch_seen: int, the number of batches the model has seen :return: [B, n_pred, N, output_dim],[]

predict(batch, batches_seen=None)[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_demand_prediction.CCRNN.DCGRUCell(input_size: int, hidden_size: int, num_node: int, n_supports: int, k_hop: int, e_layer: int, n_dim: int)[source]

Bases: torch.nn.modules.module.Module

forward(inputs: torch.Tensor, supports: List[torch.Tensor], states) → Tuple[torch.Tensor, torch.Tensor][source]
Parameters
  • inputs – Tensor[Batch, Node, Feature]

  • supports

:param states:Tensor[Batch, Node, Hidden_size] :return:

training: bool
class libcity.model.traffic_demand_prediction.CCRNN.DCRNNDecoder(output_size: int, hidden_size: int, num_node: int, n_supports: int, k_hop: int, n_layers: int, n_preds: int, e_layer: int, n_dim: int)[source]

Bases: torch.nn.modules.container.ModuleList

forward(supports: List[torch.Tensor], states: torch.Tensor, targets: torch.Tensor = None, teacher_force: bool = 0.5) → torch.Tensor[source]
Parameters
  • supports – list of sparse tensors, each of shape [N, N]

  • states – tensor, [n_layers, B, N, hidden_size]

  • targets – None or tensor, [B, T, N, output_size]

  • teacher_force – random to use targets as decoder inputs

Returns

tensor, [B, T, N, output_size]

training: bool
class libcity.model.traffic_demand_prediction.CCRNN.DCRNNEncoder(input_size: int, hidden_size: int, num_node: int, n_supports: int, k_hop: int, n_layers: int, e_layer: int, n_dim: int)[source]

Bases: torch.nn.modules.container.ModuleList

forward(inputs: torch.Tensor, supports: List[torch.Tensor]) → torch.Tensor[source]
Parameters
  • inputs – tensor, [B, T, N, input_size]

  • supports – list of sparse tensors, each of shape [N, N]

Returns

tensor, [n_layers, B, N, hidden_size]

training: bool
class libcity.model.traffic_demand_prediction.CCRNN.EvolutionCell(input_dim: int, output_dim: int, num_nodes: int, n_supports: int, max_step: int, layer: int, n_dim: int)[source]

Bases: torch.nn.modules.module.Module

attention(inputs: torch.Tensor)[source]
forward(inputs, supports: List)[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_demand_prediction.CCRNN.GraphConv(input_dim: int, output_dim: int, num_nodes: int, n_supports: int, max_step: int)[source]

Bases: torch.nn.modules.module.Module

forward(inputs: torch.Tensor, supports: List[torch.Tensor])[source]
Parameters
  • inputs – tensor, [B, N, input_dim]

  • supports – list of sparse tensors, each of shape [N, N]

Returns

tensor, [B, N, output_dim]

training: bool
class libcity.model.traffic_demand_prediction.CCRNN.GraphConvMx(input_dim: int, output_dim: int, num_nodes: int, n_supports: int, max_step: int)[source]

Bases: torch.nn.modules.module.Module

forward(inputs: torch.Tensor, supports: List[torch.Tensor])[source]
Parameters
  • inputs – tensor, [B, N, input_dim]

  • supports – list of sparse tensors, each of shape [N, N]

Returns

tensor, [B, N, output_dim]

matrix_normalization(support)[source]
training: bool
libcity.model.traffic_demand_prediction.CCRNN.graph_preprocess(matrix, normalized_category=None)[source]
libcity.model.traffic_demand_prediction.CCRNN.normalized_laplacian(w: numpy.ndarray) → numpy.matrix[source]
libcity.model.traffic_demand_prediction.CCRNN.random_walk_matrix(w) → numpy.matrix[source]