libcity.model.traffic_flow_prediction.CRANN

class libcity.model.traffic_flow_prediction.CRANN.AttentionBlock(dim_x, dim_y, timesteps, method='hadamard')[源代码]

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

Description |

Attentional block for spatio-temporal attention mechanism

Attributes |
dim_xint

Dimension of x-axis for input images

dim_yint

Dimension of y-axis for input images

timestepsint

Number of input timesteps

methodstr

Attentional function to calculate attention weights

Methods |
forward(x)

Forward pass of the network

forward(x, y=0)[源代码]

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.CRANN.AttentionCNN(in_channels, out_channels, dim_x, dim_y)[源代码]

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

Description |

Spatial module with spatio-temporal attention

Attributes |
in_channelsint

Number of input timesteps

out_channelsint

Number of output timesteps

dim_xint

Dimension of x-axis for input images

dim_yint

Dimension of y-axis for input images

Methods |
forward(x)

Forward pass of the network

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.CRANN.BahdanauDecoder(hidden_size, output_size, n_layers=1, drop_prob=0.1)[源代码]

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

Description |

Decoder an attention mechanism for temporal module

Attributes |
hidden_sizeint

Dimension of hidden space

output_sizeint

Number of output features

n_layersint

Number of layers for the encoder

drop_probfloat

Dropout for the encoder

Methods |
forward(x)

Forward pass of the network

forward(inputs, hidden, encoder_outputs)[源代码]

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.CRANN.CRANN(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

evaluate_temp_att(encoder, decoder, batch, n_pred, device)[源代码]
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.CRANN.ConvBlock(in_features, out_features, num_conv)[源代码]

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

Description |

Convolutional blocks of num_conv convolutions with out_features channels

Attributes |
in_featuresint

Number of input channels

out_featuresint

Number of middle and output channels

num_convint

Number of convolutions

Methods |
forward(x)

Forward pass of the network

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.CRANN.EncoderLSTM(input_size, hidden_size, n_layers=1, drop_prob=0, device='cuda')[源代码]

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

Description |

Encoder for temporal module

Attributes |
input_sizeint

Number of input features

hidden_sizeint

Dimension of hidden space

n_layersint

Number of layers for the encoder

drop_probfloat

Dropout for the encoder

deviceint/str

Device in which hiddens are stored

Methods |
forward(x)

Forward pass of the network

forward(inputs, hidden)[源代码]

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.

init_hidden(batch_size)[源代码]
training: bool
class libcity.model.traffic_flow_prediction.CRANN.MLP(n_inputs, n_outputs, n_layers=1, n_hidden=0, dropout=0)[源代码]

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

Description |

Dense module

Attributes |
n_inputsint

Number of input features

n_outputsint

Number of output features

n_layersint

Number of layers

n_hiddenint

Dimension of hidden layers

Methods |
forward(x)

Forward pass of the network

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