libcity.model.traffic_flow_prediction.CRANN

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

Bases: 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)[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.CRANN.AttentionCNN(in_channels, out_channels, dim_x, dim_y)[source]

Bases: 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)[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.CRANN.BahdanauDecoder(hidden_size, output_size, n_layers=1, drop_prob=0.1)[source]

Bases: 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)[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.CRANN.CRANN(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

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

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

Bases: 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)[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.

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

Bases: 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)[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