paddlets.models.anomaly.dl.mtad_gat

This implementation is based on the article Multivariate Time-series Anomaly Detection via Graph Attention Network .

Some codes refer to https://github.com/ML4ITS/mtad-gat-pytorch.

Base model features

The author proposes a framework for multivariate time series anomaly detection named MTAD-GAT, which mainly includes a 1D convolution layer, two parallel GAT layers, a GRU layer, a full connection layer and an automatic encoder-decoder layer.

1D conv layer: Feature extraction of input data.

Two parallel GAT layers: Extract the features of spatial dimension and temporal dimension respectively.

A GRU layer: Fusion the features of 1D conv and the two parallel GAT.

A full connection layer: Implementation of anomaly detection based on forecasting method.

An automatic encoder-decoder layer: Implementation of anomaly detection based on reconstruction method.

class MTADGAT(in_chunk_len: int, sampling_stride: int = 1, loss_fn: ~typing.Callable[[...], ~paddle.Tensor] = <function mse_loss>, optimizer_fn: ~typing.Callable[[...], ~paddle.optimizer.optimizer.Optimizer] = <class 'paddle.optimizer.adam.Adam'>, threshold_fn: ~typing.Callable[[...], float] = <function epsilon_th>, q: float = 100, threshold: ~typing.Optional[float] = None, threshold_coeff: float = 1.0, anomaly_score_fn: ~typing.Optional[~typing.Callable[[...], ~typing.List[float]]] = None, pred_adjust: bool = True, pred_adjust_fn: ~typing.Callable[[...], ~numpy.ndarray] = <function result_adjust>, optimizer_params: ~typing.Dict[str, ~typing.Any] = {'learning_rate': 0.001}, callbacks: ~typing.List[~paddlets.models.common.callbacks.callbacks.Callback] = [], batch_size: int = 256, max_epochs: int = 100, verbose: int = 1, patience: int = 10, seed: ~typing.Union[None, int] = None, target_dims: ~typing.Optional[~typing.List[int]] = None, kernel_size: int = 7, feat_gat_embed_dim: ~typing.Union[None, int] = None, time_gat_embed_dim: ~typing.Union[None, int] = None, use_gatv2: bool = False, use_bias: bool = False, gru_n_layers: int = 1, gru_hid_size: int = 150, forecast_n_layers: int = 1, forecast_hid_size: int = 150, recon_n_layers: int = 1, recon_hid_size: int = 150, dropout: float = 0.2, alpha: float = 0.2)[source]

Bases: AnomalyBaseModel

Multivariate Time-series Anomaly Detection via Graph Attention Network.

Parameters
  • in_chunk_len (int) – The size of the loopback window, i.e. the number of time steps feed to the model.

  • sampling_stride (int) – Sampling intervals between two adjacent samples.

  • loss_fn (Callable[..., paddle.Tensor]) – Loss function.

  • optimizer_fn (Callable[..., Optimizer]) – Optimizer algorithm.

  • threshold_fn (Callable[..., float]|None) – The method to get anomaly threshold.

  • q (float) – The parameter used to calculate the quantile which range is [0, 100].

  • threshold (float|None) – The threshold to judge anomaly.

  • anomaly_score_fn (Callable[..., List[float]]|None) – The method to get anomaly score.

  • pred_adjust (bool) – Whether to adjust the pred label according to the real label.

  • pred_adjust_fn (Callable[..., np.ndarray]|None) – The method to adjust pred label.

  • optimizer_params (Dict[str, Any]) – Optimizer parameters.

  • eval_metrics (List[str]) – Evaluation metrics of model.

  • callbacks (List[Callback]) – Customized callback functions.

  • batch_size (int) – Number of samples per batch.

  • max_epochs (int) – Max epochs during training.

  • verbose (int) – Verbosity mode.

  • patience (int) – Number of epochs to wait for improvement before terminating.

  • seed (int|None) – Global random seed.

  • target_dims (Optional[List[int]]) – The target dim index for forecasting and reconstruction model.

  • kernel_size (int) – Kernel size for Conv1D.

  • feat_gat_embed_dim (Optional[int]) – Output dimension of linear transformation in feat-oriented GAT layer.

  • time_gat_embed_dim (Optional[int]) – Output dimension of linear transformation in time-oriented GAT layer.

  • use_gatv2 (bool) – Whether to use the modified attention mechanism of GATv2 instead of standard GAT.

  • use_bias (bool) – Whether to include a bias term in the attention layer.

  • gru_n_layers (int) – Number of layers in the GRU layer.

  • gru_hid_size (int) – Hidden size in the GRU layer.

  • forecast_n_layers (int) – Number of layers in the FC-based Forecasting Model.

  • forecast_hid_size (int) – Hidden size in the FC-based Forecasting Model.

  • recon_n_layers (int) – Number of layers in the GRU-based Reconstruction Model.

  • recon_hid_size (int) – Hidden size in the GRU-based Reconstruction Model.

  • dropout (float) – Dropout regularization parameter.

  • alpha (float) – The negative slope used in the LeakyReLU activation function.

_in_chunk_len

The size of the loopback window, i.e. the number of time steps feed to the model.

Type

int

_sampling_stride

Sampling intervals between two adjacent samples.

Type

int

_loss_fn

Loss function.

Type

Callable[…, paddle.Tensor]

_optimizer_fn

Optimizer algorithm.

Type

Callable[…, Optimizer]

_threshold_fn

The method to get anomaly threshold.

Type

Callable[…, float]|None)

_q

The parameter used to calculate the quantile which range is [0, 100].

Type

float

_threshold

The threshold to judge anomaly.

Type

float|None

_anomaly_score_fn

The method to get anomaly score.

Type

Callable[…, List[float]]|None

_pred_adjust

Whether to adjust the pred label according to the real label.

Type

bool

_pred_adjust_fn

The method to adjust pred label.

Type

Callable[…, np.ndarray]|None

_optimizer_params

Optimizer parameters.

Type

Dict[str, Any]

_eval_metrics

Evaluation metrics of model.

Type

List[str]

_callbacks

Customized callback functions.

Type

List[Callback]

_batch_size

Number of samples per batch.

Type

int

_max_epochs

Max epochs during training.

Type

int

_verbose

Verbosity mode.

Type

int

_patience

Number of epochs to wait for improvement before terminating.

Type

int

_seed

Global random seed.

Type

int|None

_stop_training

Training status.

Type

bool

_target_dims

The target dim index for forecasting and reconstruction model.

Type

Optional[List[int]]

_kernel_size

Kernel size for Conv1D.

Type

int

_feat_gat_embed_dim

Output dimension of linear transformation in feat-oriented GAT layer.

Type

Optional[int]

_time_gat_embed_dim

Output dimension of linear transformation in time-oriented GAT layer.

Type

Optional[int]

_use_gatv2

Whether to use the modified attention mechanism of GATv2 instead of standard GAT.

Type

bool

_use_bias

Whether to include a bias term in the attention layer.

Type

bool

_gru_n_layers

Number of layers in the GRU layer.

Type

int

_gru_hid_size

Hidden size in the GRU layer.

Type

int

_forecast_n_layers

Number of layers in the FC-based Forecasting Model.

Type

int

_forecast_hid_size

Hidden size in the FC-based Forecasting Model.

Type

int

_recon_n_layers

Number of layers in the GRU-based Reconstruction Model.

Type

int

_recon_hid_size

Hidden size in the GRU-based Reconstruction Model.

Type

int

_dropout

Dropout regularization parameter.

Type

float

_alpha

The negative slope used in the LeakyReLU activation function.

Type

float