You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

channel.py 4.3 kB

first commit Former-commit-id: 08bc23ba02cffbce3cf63962390a65459a132e48 [formerly 0795edd4834b9b7dc66db8d10d4cbaf42bbf82cb] [formerly b5010b42541add7e2ea2578bf2da537efc457757 [formerly a7ca09c2c34c4fc8b3d8e01fcfa08eeeb2cae99d]] [formerly 615058473a2177ca5b89e9edbb797f4c2a59c7e5 [formerly 743d8dfc6843c4c205051a8ab309fbb2116c895e] [formerly bb0ea98b1e14154ef464e2f7a16738705894e54b [formerly 960a69da74b81ef8093820e003f2d6c59a34974c]]] [formerly 2fa3be52c1b44665bc81a7cc7d4cea4bbf0d91d5 [formerly 2054589f0898627e0a17132fd9d4cc78efc91867] [formerly 3b53730e8a895e803dfdd6ca72bc05e17a4164c1 [formerly 8a2fa8ab7baf6686d21af1f322df46fd58c60e69]] [formerly 87d1e3a07a19d03c7d7c94d93ab4fa9f58dada7c [formerly f331916385a5afac1234854ee8d7f160f34b668f] [formerly 69fb3c78a483343f5071da4f7e2891b83a49dd18 [formerly 386086f05aa9487f65bce2ee54438acbdce57650]]]] Former-commit-id: a00aed8c934a6460c4d9ac902b9a74a3d6864697 [formerly 26fdeca29c2f07916d837883983ca2982056c78e] [formerly 0e3170d41a2f99ecf5c918183d361d4399d793bf [formerly 3c12ad4c88ac5192e0f5606ac0d88dd5bf8602dc]] [formerly d5894f84f2fd2e77a6913efdc5ae388cf1be0495 [formerly ad3e7bc670ff92c992730d29c9d3aa1598d844e8] [formerly 69fb3c78a483343f5071da4f7e2891b83a49dd18]] Former-commit-id: 3c19c9fae64f6106415fbc948a4dc613b9ee12f8 [formerly 467ddc0549c74bb007e8f01773bb6dc9103b417d] [formerly 5fa518345d958e2760e443b366883295de6d991c [formerly 3530e130b9fdb7280f638dbc2e785d2165ba82aa]] Former-commit-id: 9f5d473d42a435ec0d60149939d09be1acc25d92 [formerly be0b25c4ec2cde052a041baf0e11f774a158105d] Former-commit-id: 9eca71cb73ba9edccd70ac06a3b636b8d4093b04
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import numpy as np
  2. import os
  3. import logging
  4. logger = logging.getLogger('telemanom')
  5. class Channel:
  6. def __init__(self,n_predictions,l_s):
  7. # , config, chan_id):
  8. """
  9. Load and reshape channel values (predicted and actual).
  10. Args:
  11. config (obj): Config object containing parameters for processing
  12. chan_id (str): channel id
  13. Attributes:
  14. id (str): channel id
  15. config (obj): see Args
  16. X_train (arr): training inputs with dimensions
  17. [timesteps, l_s, input dimensions)
  18. X_test (arr): test inputs with dimensions
  19. [timesteps, l_s, input dimensions)
  20. y_train (arr): actual channel training values with dimensions
  21. [timesteps, n_predictions, 1)
  22. y_test (arr): actual channel test values with dimensions
  23. [timesteps, n_predictions, 1)
  24. train (arr): train data loaded from .npy file
  25. test(arr): test data loaded from .npy file
  26. """
  27. # self.id = chan_id
  28. # self.config = config
  29. self.X_train = None
  30. self.y_train = None
  31. self.X_test = None
  32. self.y_test = None
  33. self.y_hat = None
  34. self.train = None
  35. self.test = None
  36. self._n_predictions = n_predictions
  37. self._l_s = l_s
  38. def shape_train_data(self, arr):
  39. # , train=True):
  40. """Shape raw input streams for ingestion into LSTM. config.l_s specifies
  41. the sequence length of prior timesteps fed into the model at
  42. each timestep t.
  43. Args:
  44. arr (np array): array of input streams with
  45. dimensions [timesteps, 1, input dimensions]
  46. train (bool): If shaping training data, this indicates
  47. data can be shuffled
  48. """
  49. # print("in shape data")
  50. # print("arr shape",arr.shape)
  51. # print("ls",self.config.l_s)
  52. # print("n_pred",self.config.n_predictions)
  53. data = []
  54. for i in range(len(arr) - self._l_s - self._n_predictions):
  55. data.append(arr[i:i + self._l_s + self._n_predictions])
  56. data = np.array(data)
  57. # print("data shape",data.shape)
  58. # assert len(data.shape) == 3
  59. # if train:
  60. # # np.random.shuffle(data)
  61. # self.X_train = data[:, :-self.config.n_predictions, :]
  62. # self.y_train = data[:, -self.config.n_predictions:, :] # telemetry value is at position 0
  63. # self.y_train = np.reshape(self.y_train,(self.y_train.shape[0],self.y_train.shape[1]*self.y_train.shape[2]))
  64. # print("X train shape",self.X_train .shape)
  65. # print("Y train shape",self.y_train .shape)
  66. # else:
  67. self.X_train = data[:, :-self._n_predictions, :]
  68. self.y_train = data[:, -self._n_predictions:, :] # telemetry value is at position 0
  69. self.y_train = np.reshape(self.y_train,(self.y_train.shape[0],self.y_train.shape[1]*self.y_train.shape[2]))
  70. def shape_test_data(self, arr):
  71. data = []
  72. for i in range(len(arr) - self._l_s - self._n_predictions):
  73. data.append(arr[i:i + self._l_s + self._n_predictions])
  74. data = np.array(data)
  75. # print("data shape",data.shape)
  76. self.X_test = data[:, :-self._n_predictions, :]
  77. self.y_test = data[:, -self._n_predictions:, :] # telemetry value is at position 0
  78. self.y_test = np.reshape(self.y_test,(self.y_test.shape[0],self.y_test.shape[1]*self.y_test.shape[2]))
  79. # def load_data(self):
  80. # """
  81. # Load train and test data from local.
  82. # """
  83. # # try:
  84. # # self.train = np.load(os.path.join("data", "train", "{}.npy".format(self.id)))
  85. # # self.test = np.load(os.path.join("data", "test", "{}.npy".format(self.id)))
  86. # # except FileNotFoundError as e:
  87. # # # logger.critical(e)
  88. # # # logger.critical("Source data not found, may need to add data to repo: <link>")
  89. # # print("Source data not found, may need to add data to repo: <link>")
  90. # print("before shape function")
  91. # print(self.train.shape)
  92. # self.shape_data(self.train)
  93. # self.shape_data(self.test, train=False)

全栈的自动化机器学习系统,主要针对多变量时间序列数据的异常检测。TODS提供了详尽的用于构建基于机器学习的异常检测系统的模块,它们包括:数据处理(data processing),时间序列处理( time series processing),特征分析(feature analysis),检测算法(detection algorithms),和强化模块( reinforcement module)。这些模块所提供的功能包括常见的数据预处理、时间序列数据的平滑或变换,从时域或频域中抽取特征、多种多样的检测算