paddlets.models.anomaly.dl.mtad_gat

基于图注意力网络的多元时间序列异常检测模型的实现。

部分代码参考了:https://github.com/ML4ITS/mtad-gat-pytorch

网络结构:

作者提出了一个多变量时间序列异常检测框架命名为MTAD-GAT,主要包括1个1维的卷积层,两个并行的GAT层、1个GRU层、1个全链接层和1个自动编码器-解码器层:

1维卷积层:提取时间序列高维特征。

2个并行的GAT层:捕获时间序列的特征和时序关系。

GRU层:融合卷积层和GAT层的特征来捕获序列模式。

全连接层:实现基于预测的异常检测模型。

编码-解码层:实现基于重构的异常检测模型。

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)[源代码]

基类:AnomalyBaseModel

基于图注意网络的多维时间序列异常检测模型。

参数
  • in_chunk_len (int) – 模型输入的时间序列长度。

  • sampling_stride (int) – 相邻样本间的采样间隔。

  • loss_fn (Callable[..., paddle.Tensor]) – 损失函数。

  • optimizer_fn (Callable[..., Optimizer]) – 优化器算法。

  • threshold_fn (Callable[..., float]|None) – 获取异常阈值的方法。

  • q (float) – 用于计算分位数的参数,取值范围0到100。

  • threshold (float|None) – 判断异常的阈值。

  • anomaly_score_fn (Callable[..., List[float]]|None) – 获取异常分数的方法。

  • pred_adjust (bool) – 是否根据实际标签调整预测结果。

  • pred_adjust_fn (Callable[..., np.ndarray]|None) – 调整预测结果的方法。

  • optimizer_params (Dict[str, Any]) – 优化器参数。

  • eval_metrics (List[str]) – 模型的评估指标。

  • callbacks (List[Callback]) – 自定义的callback函数。

  • batch_size (int) – 每个批次中的样本数量。

  • max_epochs (int) – 训练过程中的最大迭代轮数。

  • verbose (int) – 模型日志模式。

  • patience (int) – 模型训练过程中, 当评估指标超过一定轮数不再变优,模型提前停止训练。

  • seed (int|None) – 全局随机种子,注: 保证每次模型参数初始化一致。

  • target_dims (Optional[List[int]]) – 用于预测和重建模型的目标列。

  • kernel_size (int) – 卷积核大小。

  • feat_gat_embed_dim (Optional[int]) – 在特征维度GAT层中线性变换的输出维数。

  • time_gat_embed_dim (Optional[int]) – 在时间维度GAT层中线性变换的输出维数。

  • use_gatv2 (bool) – 是否使用GATv2。

  • use_bias (bool) – 在attention层中是否使用偏置。

  • gru_n_layers (int) – GRU层中的层数。

  • gru_hid_size (int) – GRU层中隐层的大小。

  • forecast_n_layers (int) – 基于预测的模型中的全连接层数。

  • forecast_hid_size (int) – 基于预测的模型中的隐层节点数。

  • recon_n_layers (int) – 基于重建的模型中的层数。

  • recon_hid_size (int) – 基于重建的模型中的隐层节点数。

  • dropout (float) – dropout参数。

  • alpha (float) – leakyrelu激活函数中的参数。

_in_chunk_len

模型输入的时间序列长度。

Type

int

_sampling_stride

相邻样本间的采样间隔。

Type

int

_loss_fn

损失函数。

Type

Callable[…, paddle.Tensor]

_optimizer_fn

优化器算法。

Type

Callable[…, Optimizer]

_threshold_fn

获取异常阈值的方法。

Type

Callable[…, float]|None)

_q

用于计算分位数的参数,取值范围0到100。

Type

float

_threshold

判断异常的阈值。

Type

float|None

_anomaly_score_fn

获取异常分数的方法。

Type

Callable[…, List[float]]|None

_pred_adjust

是否根据实际标签调整预测结果。

Type

bool

_pred_adjust_fn

调整预测结果的方法。

Type

Callable[…, np.ndarray]|None

_optimizer_params

优化器参数。

Type

Dict[str, Any]

_eval_metrics

模型的评估指标。

Type

List[str]

_callbacks

自定义的callback函数。

Type

List[Callback]

_batch_size

每个批次中的样本数量。

Type

int

_max_epochs

训练过程中的最大迭代轮数。

Type

int

_verbose

模型日志模式。

Type

int

_patience

模型训练过程中, 当评估指标超过一定轮数不再变优,模型提前停止训练。

Type

int

_seed

全局随机种子,注: 保证每次模型参数初始化一致。

Type

int|None

_stop_training

Training status.

Type

bool

_target_dims

用于预测和重建模型的目标列。

Type

Optional[List[int]]

_kernel_size

卷积核大小。

Type

int

_feat_gat_embed_dim

在特征维度GAT层中线性变换的输出维数。

Type

Optional[int]

_time_gat_embed_dim

在时间维度GAT层中线性变换的输出维数。

Type

Optional[int]

_use_gatv2

是否使用GATv2。

Type

bool

_use_bias

在attention层中是否使用偏置。

Type

bool

_gru_n_layers

GRU层中的层数。

Type

int

_gru_hid_size

GRU层中隐层的大小。

Type

int

_forecast_n_layers

基于预测的模型中的全连接层数。

Type

int

_forecast_hid_size

基于预测的模型中的隐层节点数。

Type

int

_recon_n_layers

基于重建的模型中的层数。

Type

int

_recon_hid_size

基于重建的模型中的隐层节点数。

Type

int

_dropout

dropout参数。

Type

float

_alpha

leakyrelu激活函数中的参数。

Type

float