From 1595274682af76743e565ad123ee89b3b3fde319 Mon Sep 17 00:00:00 2001 From: LongxingTan Date: Thu, 25 Jul 2024 17:46:26 +0800 Subject: [PATCH] fix: anno --- examples/README.md | 6 +++--- examples/__init__.py | 0 examples/run_classification.py | 32 -------------------------------- tfts/layers/attention_layer.py | 14 +++++--------- tfts/layers/autoformer_layer.py | 2 -- tfts/layers/cnn_layer.py | 2 -- tfts/layers/deepar_layer.py | 2 -- tfts/layers/dense_layer.py | 2 -- tfts/layers/embed_layer.py | 2 -- tfts/layers/mask_layer.py | 2 -- tfts/layers/nbeats_layer.py | 2 -- tfts/layers/position_layer.py | 2 ++ tfts/layers/unet_layer.py | 2 -- 13 files changed, 10 insertions(+), 60 deletions(-) delete mode 100644 examples/__init__.py delete mode 100644 examples/run_classification.py diff --git a/examples/README.md b/examples/README.md index fca5891..8e0d9de 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,5 +1,6 @@ # TFTS examples +[time series prediction](./run_prediction_simple.py) ## kaggle datasets - [web traffic prediction]() @@ -7,6 +8,5 @@ ## more time series examples -- [classification]() -- [anomaly detection]() -- [uncertainty]() + +- [time series anomaly detection](./run_anomaly.py) diff --git a/examples/__init__.py b/examples/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/run_classification.py b/examples/run_classification.py deleted file mode 100644 index b13adcc..0000000 --- a/examples/run_classification.py +++ /dev/null @@ -1,32 +0,0 @@ -"""Demo of time series classification""" - -import argparse - -import numpy as np -import tensorflow as tf - -import tfts -from tfts import AutoConfig, AutoModel, AutoModelForClassification, KerasTrainer - - -def parse_args(): - parser = argparse.ArgumentParser() - parser.add_argument("--seed", type=int, default=315, required=False, help="seed") - parser.add_argument("--use_model", type=str, default="rnn", help="model for train") - parser.add_argument("--use_data", type=str, default="sine", help="dataset: sine or airpassengers") - parser.add_argument("--train_length", type=int, default=24, help="sequence length for train") - parser.add_argument("--predict_length", type=int, default=12, help="sequence length for predict") - parser.add_argument("--epochs", type=int, default=100, help="Number of training epochs") - parser.add_argument("--batch_size", type=int, default=16, help="Batch size for training") - parser.add_argument("--learning_rate", type=float, default=1e-4, help="learning rate for training") - - return parser.parse_args() - - -def run_train(args): - return - - -if __name__ == "__main__": - args = parse_args() - run_train(args) diff --git a/tfts/layers/attention_layer.py b/tfts/layers/attention_layer.py index 643fd7f..5ff9f4c 100644 --- a/tfts/layers/attention_layer.py +++ b/tfts/layers/attention_layer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# @author: Longxing Tan """Layer for :py:class:`~tfts.models.transformer` :py:class:`~tfts.models.autoformer`""" import math @@ -30,9 +28,7 @@ def __init__(self, hidden_size: int, num_attention_heads: int, attention_probs_d super(Attention, self).__init__() if hidden_size % num_attention_heads: raise ValueError( - "Hidden size ({}) must be divisible by the number of heads ({}).".format( - hidden_size, num_attention_heads - ) + f"Hidden size {hidden_size} must be divisible by the number of heads {num_attention_heads}." ) self.hidden_size = hidden_size self.num_attention_heads = num_attention_heads @@ -105,7 +101,7 @@ def __init__( hidden_size: int, num_attention_heads: int, attention_probs_dropout_prob: float = 0.0, - **kwargs: Dict[str, Any] + **kwargs: Dict[str, Any], ) -> None: super(SelfAttention, self).__init__() self.attention = Attention( @@ -116,19 +112,19 @@ def build(self, input_shape: Tuple[Optional[int], ...]) -> None: super(SelfAttention, self).build(input_shape) def call(self, x: tf.Tensor, mask: Optional[tf.Tensor] = None): - """Self attention + """Self attention layer Parameters ---------- x : tf.Tensor - input tensor for self-attention + 3D input tensor for self-attention, (batch_size, sequence_length, feature_size) mask : tf.Tensor, optional masked, by default None Returns ------- tf.Tensor - self attention output + 3D self attention output, (batch_size, sequence_length, attention_hidden_size) """ return self.attention(x, x, x, mask) diff --git a/tfts/layers/autoformer_layer.py b/tfts/layers/autoformer_layer.py index bd817bc..3e92f8d 100644 --- a/tfts/layers/autoformer_layer.py +++ b/tfts/layers/autoformer_layer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# @author: Longxing Tan, tanlongxing888@163.com """Layer for :py:class:`~tfts.models.autoformer`""" import math diff --git a/tfts/layers/cnn_layer.py b/tfts/layers/cnn_layer.py index 71bc1f9..3e05317 100644 --- a/tfts/layers/cnn_layer.py +++ b/tfts/layers/cnn_layer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# @author: Longxing Tan, tanlongxing888@163.com """Layer for :py:class:`~tfts.models.wavenet`""" from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union diff --git a/tfts/layers/deepar_layer.py b/tfts/layers/deepar_layer.py index 5ce701a..cf6c303 100644 --- a/tfts/layers/deepar_layer.py +++ b/tfts/layers/deepar_layer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# @author: Longxing Tan, tanlongxing888@163.com """Layer for :py:class:`~tfts.models.deepar`""" from typing import Any, Callable, Dict, Optional, Tuple, Type, Union diff --git a/tfts/layers/dense_layer.py b/tfts/layers/dense_layer.py index 2211905..2d372a0 100644 --- a/tfts/layers/dense_layer.py +++ b/tfts/layers/dense_layer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# @author: Longxing Tan, tanlongxing888@163.com """Layer for :py:class:`~tfts.models.wavenet` :py:class:`~tfts.models.transformer`""" from typing import Any, Callable, Dict, Optional, Tuple, Type, Union diff --git a/tfts/layers/embed_layer.py b/tfts/layers/embed_layer.py index 079b486..7f2a337 100644 --- a/tfts/layers/embed_layer.py +++ b/tfts/layers/embed_layer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# @author: Longxing Tan, tanlongxing888@163.com """Layer for :py:class:`~tfts.models.transformer`""" from typing import Any, Callable, Dict, Optional, Tuple, Type, Union diff --git a/tfts/layers/mask_layer.py b/tfts/layers/mask_layer.py index 7cf0b56..65dcdef 100644 --- a/tfts/layers/mask_layer.py +++ b/tfts/layers/mask_layer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# @author: Longxing Tan, tanlongxing888@163.com """Layer for :py:class:`~tfts.models.transformer`""" from typing import Any, Callable, Dict, Optional, Tuple, Type, Union diff --git a/tfts/layers/nbeats_layer.py b/tfts/layers/nbeats_layer.py index 516fa42..c2e3eab 100644 --- a/tfts/layers/nbeats_layer.py +++ b/tfts/layers/nbeats_layer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# @author: Longxing Tan, tanlongxing888@163.com """Layer for :py:class:`~tfts.models.nbeats`""" from typing import Any, Callable, Dict, Optional, Tuple, Type, Union diff --git a/tfts/layers/position_layer.py b/tfts/layers/position_layer.py index 2fe8e35..a662045 100644 --- a/tfts/layers/position_layer.py +++ b/tfts/layers/position_layer.py @@ -1,3 +1,5 @@ +"""Layer for :py:class:`~tfts.models.transformer`""" + from typing import Any, Callable, Dict, Optional, Tuple, Type, Union import numpy as np diff --git a/tfts/layers/unet_layer.py b/tfts/layers/unet_layer.py index 6668615..43fe0e0 100644 --- a/tfts/layers/unet_layer.py +++ b/tfts/layers/unet_layer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# @author: Longxing Tan, tanlongxing888@163.com """Layer for :py:class:`~tfts.models.unet`""" from typing import Any, Callable, Dict, Optional, Tuple, Type, Union