class_docstr: Example:
      >>> #The dataset to detect is y
      >>> y = numpy.array(...)
      >>> ad = AEDetector(roll_len=24)
      >>> ad.fit(y)
      >>> anomaly_scores = ad.score()
      >>> anomaly_indexes = ad.anomaly_indexes()
class_docstr_tok: ["Example",":",">",">",">","#","The","dataset","to","detect","is","y",">",">",">","y","=","numpy.array","(","...",")",">",">",">","ad","=","AEDetector","(","roll_len=24",")",">",">",">","ad.fit","(","y",")",">",">",">","anomaly_scores","=","ad.score","(",")",">",">",">","anomaly_indexes","=","ad.anomaly_indexes","(",")"]
docstr: Initialize an AEDetector.
  AEDetector supports two modes to detect anomalies in input time series.
  
  1. direct-mode: It trains an autoencoder network directly on the input times series and
  calculate anomaly scores based on reconstruction error. For each sample
  in the input, the larger the reconstruction error, the higher the
  anomaly score.
  
  2. window mode: It first rolls the input series into a batch of subsequences, each
  with length = `roll_len`. Then it trains an autoencoder network on the batch of
  subsequences and calculate the reconstruction error. The anomaly score for each
  sample is a linear combinition of two parts: 1) the reconstruction error of the
  sample in a subsequence. 2) the reconstruction error of the entire subsequence
  as a vector. You can use `sub_scalef` to control the weights of the 2nd part. Note
  that one sample may belong to several subsequences as subsequences overlap because
  of rolling, and we only keep the largest anomaly score as the final score.
  
  :param roll_len: the length of window when rolling the input data. If roll_len=0, direct
      mode is used. If roll_len >0, window mode is used. When setting roll_len, we suggest
      use a number that is probably a full or half a cycle in your data. e.g. half a day,
      one day, etc. Note that roll_len must be smaller than the total length of the input
      time series.
  :param ratio: (estimated) ratio of anomalies
  :param compress_rate: the compression rate of the autoencoder, changing this value will have
      impact on the reconstruction error it calculated.
  :param batch_size: batch size for autoencoder training
  :param epochs: num of epochs fro autoencoder training
  :param verbose: verbose option for autoencoder training
  :param sub_scalef: scale factor for the subsequence distance when calculating anomaly score
  :param backend: the backend type, can be "keras" or "torch"
  :param lr: the learning rate of model's optimizer
docstr_tok: ["Initialize","an","AEDetector",".","AEDetector","supports","two","modes","to","detect","anomalies","in","input","time","series",".","1.","direct-mode",":","It","trains","an","autoencoder","network","directly","on","the","input","times","series","and","calculate","anomaly","scores","based","on","reconstruction","error",".","For","each","sample","in","the","input",",","the","larger","the","reconstruction","error",",","the","higher","the","anomaly","score",".","2.","window","mode",":","It","first","rolls","the","input","series","into","a","batch","of","subsequences",",","each","with","length","=","`","roll_len","`",".","Then","it","trains","an","autoencoder","network","on","the","batch","of","subsequences","and","calculate","the","reconstruction","error",".","The","anomaly","score","for","each","sample","is","a","linear","combinition","of","two","parts",":","1",")","the","reconstruction","error","of","the","sample","in","a","subsequence",".","2",")","the","reconstruction","error","of","the","entire","subsequence","as","a","vector",".","You","can","use","`","sub_scalef","`","to","control","the","weights","of","the","2nd","part",".","Note","that","one","sample","may","belong","to","several","subsequences","as","subsequences","overlap","because","of","rolling",",","and","we","only","keep","the","largest","anomaly","score","as","the","final","score",".",":","param","roll_len",":","the","length","of","window","when","rolling","the","input","data",".","If","roll_len=0",",","direct","mode","is","used",".","If","roll_len",">","0",",","window","mode","is","used",".","When","setting","roll_len",",","we","suggest","use","a","number","that","is","probably","a","full","or","half","a","cycle","in","your","data",".","e.g",".","half","a","day",",","one","day",",","etc",".","Note","that","roll_len","must","be","smaller","than","the","total","length","of","the","input","time","series",".",":","param","ratio",":","(","estimated",")","ratio","of","anomalies",":","param","compress_rate",":","the","compression","rate","of","the","autoencoder",",","changing","this","value","will","have","impact","on","the","reconstruction","error","it","calculated",".",":","param","batch_size",":","batch","size","for","autoencoder","training",":","param","epochs",":","num","of","epochs","fro","autoencoder","training",":","param","verbose",":","verbose","option","for","autoencoder","training",":","param","sub_scalef",":","scale","factor","for","the","subsequence","distance","when","calculating","anomaly","score",":","param","backend",":","the","backend","type",",","can","be","``","keras","''","or","``","torch","''",":","param","lr",":","the","learning","rate","of","model","'s","optimizer"]
code: def __init__(
      self,
      roll_len=24,
      ratio=0.1,
      compress_rate=0.8,
      batch_size=100,
      epochs=200,
      verbose=0,
      sub_scalef=1,
      backend="keras",
      lr=0.001,
  ):
      """
      Initialize an AEDetector.
      AEDetector supports two modes to detect anomalies in input time series.
  
      1. direct-mode: It trains an autoencoder network directly on the input times series and
      calculate anomaly scores based on reconstruction error. For each sample
      in the input, the larger the reconstruction error, the higher the
      anomaly score.
  
      2. window mode: It first rolls the input series into a batch of subsequences, each
      with length = `roll_len`. Then it trains an autoencoder network on the batch of
      subsequences and calculate the reconstruction error. The anomaly score for each
      sample is a linear combinition of two parts: 1) the reconstruction error of the
      sample in a subsequence. 2) the reconstruction error of the entire subsequence
      as a vector. You can use `sub_scalef` to control the weights of the 2nd part. Note
      that one sample may belong to several subsequences as subsequences overlap because
      of rolling, and we only keep the largest anomaly score as the final score.
  
      :param roll_len: the length of window when rolling the input data. If roll_len=0, direct
          mode is used. If roll_len >0, window mode is used. When setting roll_len, we suggest
          use a number that is probably a full or half a cycle in your data. e.g. half a day,
          one day, etc. Note that roll_len must be smaller than the total length of the input
          time series.
      :param ratio: (estimated) ratio of anomalies
      :param compress_rate: the compression rate of the autoencoder, changing this value will have
          impact on the reconstruction error it calculated.
      :param batch_size: batch size for autoencoder training
      :param epochs: num of epochs fro autoencoder training
      :param verbose: verbose option for autoencoder training
      :param sub_scalef: scale factor for the subsequence distance when calculating anomaly score
      :param backend: the backend type, can be "keras" or "torch"
      :param lr: the learning rate of model's optimizer
      """
      self.ratio = ratio
      self.compress_rate = compress_rate
      self.roll_len = roll_len
      self.batch_size = batch_size
      self.epochs = epochs
      self.verbose = verbose
      self.sub_scalef = sub_scalef
      self.recon_err = None
      self.recon_err_subseq = None
      self.anomaly_scores_ = None
      self.backend = backend
      self.lr = lr
  
file_path: analytics-zoo/pyzoo/zoo/chronos/detector/anomaly/ae_detector.py
imports: from zoo.chronos.detector.anomaly.abstract import AnomalyDetector
  from zoo.chronos.detector.anomaly.util import roll_arr, scale_arr
  import numpy
label_desc: Use image node_id 1 to create a new AEDetector object from inherited base classes: AnomalyDetector with example: obj = AEDetector(roll_len, ratio, compress_rate, batch_size, epochs, verbose, sub_scalef, backend, lr)