docstr: Outlier detector for time-series data using the spectral residual algorithm.
  Based on "Time-Series Anomaly Detection Service at Microsoft" (Ren et al., 2019)
  https://arxiv.org/abs/1906.03821.
  
  Parameters
  ----------
  threshold
      Threshold used to classify outliers. Relative saliency map distance from the moving average.
  window_amp
      Window for the average log amplitude.
  window_local
      Window for the local average of the saliency map. Note that the averaging is performed over the
      previous `window_local` data points (i.e., is a local average of the preceding `window_local` points for
      the current index).
  padding_amp_method
      Padding method to be used prior to each convolution over log amplitude.
      Possible values: `constant` | `replicate` | `reflect`. Default value: `replicate`.
  
       - `constant` - padding with constant 0.
  
       - `replicate` - repeats the last/extreme value.
  
       - `reflect` - reflects the time series.
  
  padding_local_method
      Padding method to be used prior to each convolution over saliency map.
      Possible values: `constant` | `replicate` | `reflect`. Default value: `replicate`.
  
       - `constant` - padding with constant 0.
  
       - `replicate` - repeats the last/extreme value.
  
       - `reflect` - reflects the time series.
  
  padding_amp_side
      Whether to pad the amplitudes on both sides or only on one side.
      Possible values: `bilateral` | `left` | `right`.
  n_est_points
      Number of estimated points padded to the end of the sequence.
  n_grad_points
      Number of points used for the gradient estimation of the additional points padded
      to the end of the sequence.
docstr_tok: ["Outlier","detector","for","time-series","data","using","the","spectral","residual","algorithm",".","Based","on","``","Time-Series","Anomaly","Detection","Service","at","Microsoft","''","(","Ren","et","al.",",","2019",")","https",":","\/\/arxiv.org\/abs\/1906.03821",".","Parameters","--","--","--","--","--","threshold","Threshold","used","to","classify","outliers",".","Relative","saliency","map","distance","from","the","moving","average",".","window_amp","Window","for","the","average","log","amplitude",".","window_local","Window","for","the","local","average","of","the","saliency","map",".","Note","that","the","averaging","is","performed","over","the","previous","`","window_local","`","data","points","(","i.e.",",","is","a","local","average","of","the","preceding","`","window_local","`","points","for","the","current","index",")",".","padding_amp_method","Padding","method","to","be","used","prior","to","each","convolution","over","log","amplitude",".","Possible","values",":","`","constant","`","|","`","replicate","`","|","`","reflect","`",".","Default","value",":","`","replicate","`",".","-","`","constant","`","-","padding","with","constant","0",".","-","`","replicate","`","-","repeats","the","last\/extreme","value",".","-","`","reflect","`","-","reflects","the","time","series",".","padding_local_method","Padding","method","to","be","used","prior","to","each","convolution","over","saliency","map",".","Possible","values",":","`","constant","`","|","`","replicate","`","|","`","reflect","`",".","Default","value",":","`","replicate","`",".","-","`","constant","`","-","padding","with","constant","0",".","-","`","replicate","`","-","repeats","the","last\/extreme","value",".","-","`","reflect","`","-","reflects","the","time","series",".","padding_amp_side","Whether","to","pad","the","amplitudes","on","both","sides","or","only","on","one","side",".","Possible","values",":","`","bilateral","`","|","`","left","`","|","`","right","`",".","n_est_points","Number","of","estimated","points","padded","to","the","end","of","the","sequence",".","n_grad_points","Number","of","points","used","for","the","gradient","estimation","of","the","additional","points","padded","to","the","end","of","the","sequence","."]
code: def __init__(
      self,
      threshold: float = None,
      window_amp: int = None,
      window_local: int = None,
      padding_amp_method: Literal[
          "constant", "replicate", "reflect"
      ] = "reflect",
      padding_local_method: Literal[
          "constant", "replicate", "reflect"
      ] = "reflect",
      padding_amp_side: Literal[
          "bilateral", "left", "right"
      ] = "bilateral",
      n_est_points: int = None,
      n_grad_points: int = 5,
  ) -> None:
      """
      Outlier detector for time-series data using the spectral residual algorithm.
      Based on "Time-Series Anomaly Detection Service at Microsoft" (Ren et al., 2019)
      https://arxiv.org/abs/1906.03821.
  
      Parameters
      ----------
      threshold
          Threshold used to classify outliers. Relative saliency map distance from the moving average.
      window_amp
          Window for the average log amplitude.
      window_local
          Window for the local average of the saliency map. Note that the averaging is performed over the
          previous `window_local` data points (i.e., is a local average of the preceding `window_local` points for
          the current index).
      padding_amp_method
          Padding method to be used prior to each convolution over log amplitude.
          Possible values: `constant` | `replicate` | `reflect`. Default value: `replicate`.
  
           - `constant` - padding with constant 0.
  
           - `replicate` - repeats the last/extreme value.
  
           - `reflect` - reflects the time series.
  
      padding_local_method
          Padding method to be used prior to each convolution over saliency map.
          Possible values: `constant` | `replicate` | `reflect`. Default value: `replicate`.
  
           - `constant` - padding with constant 0.
  
           - `replicate` - repeats the last/extreme value.
  
           - `reflect` - reflects the time series.
  
      padding_amp_side
          Whether to pad the amplitudes on both sides or only on one side.
          Possible values: `bilateral` | `left` | `right`.
      n_est_points
          Number of estimated points padded to the end of the sequence.
      n_grad_points
          Number of points used for the gradient estimation of the additional points padded
          to the end of the sequence.
      """
      super().__init__()
  
      if threshold is None:
          logger.warning(
              "No threshold level set. Need to infer threshold using `infer_threshold`."
          )
  
      self.threshold = threshold
      self.window_amp = window_amp
      self.window_local = window_local
      self.conv_amp = (
          np.ones((1, window_amp)).reshape(
              -1,
          )
          / window_amp
      )
  
      # conv_local needs a special treatment since the paper says that:
      # \bar{S}(xi) is the local average of the preceding z points of S(xi).
      # To use the same padding implementation that includes the current point we convolving, we define a modified
      # filter given by: [0, 1, 1, 1,  ... ,1] / window_local of size `window_local + 1`. In this way
      # the current value is multiplied by 0 and thus neglected. Note that the 0 goes first since before the
      # element-wise multiplication, the filter is flipped. We only do this since the filter is asymmetric.
      self.conv_local = (
          np.ones((1, window_local + 1)).reshape(
              -1,
          )
          / window_local
      )
      self.conv_local[0] = 0
  
      self.n_est_points = n_est_points
      self.n_grad_points = n_grad_points
      self.padding_amp_method = padding_amp_method
      self.padding_local_method = padding_local_method
      self.padding_amp_side = padding_amp_side
  
      # set metadata
      self.meta["detector_type"] = "outlier"
      self.meta["data_type"] = "time-series"
      self.meta["online"] = True
  
imports: import enum
  import logging
  import numpy
  from typing import Dict
  from alibi_detect.base import BaseDetector, ThresholdMixin, outlier_prediction_dict
  from alibi_detect.utils._types import Literal
label_desc: Use image node_id 1 to create a new SpectralResidual object from inherited base classes: BaseDetector, ThresholdMixin with example: obj = SpectralResidual(threshold, window_amp, window_local, padding_amp_method, padding_local_method, padding_amp_side, n_est_points, n_grad_points)