docstr: Seq2Seq-based outlier detector.
  
  Parameters
  ----------
  n_features
      Number of features in the time series.
  seq_len
      Sequence length fed into the Seq2Seq model.
  threshold
      Threshold used for outlier detection. Can be a float or feature-wise array.
  seq2seq
      A trained seq2seq model if available.
  threshold_net
      Layers for the threshold estimation network wrapped in a
      tf.keras.Sequential class if no 'seq2seq' is specified.
  latent_dim
      Latent dimension of the encoder and decoder.
  output_activation
      Activation used in the Dense output layer of the decoder.
  beta
      Weight on the threshold estimation loss term.
docstr_tok: ["Seq2Seq-based","outlier","detector",".","Parameters","--","--","--","--","--","n_features","Number","of","features","in","the","time","series",".","seq_len","Sequence","length","fed","into","the","Seq2Seq","model",".","threshold","Threshold","used","for","outlier","detection",".","Can","be","a","float","or","feature-wise","array",".","seq2seq","A","trained","seq2seq","model","if","available",".","threshold_net","Layers","for","the","threshold","estimation","network","wrapped","in","a","tf.keras.Sequential","class","if","no","'seq2seq","'","is","specified",".","latent_dim","Latent","dimension","of","the","encoder","and","decoder",".","output_activation","Activation","used","in","the","Dense","output","layer","of","the","decoder",".","beta","Weight","on","the","threshold","estimation","loss","term","."]
code: def __init__(
      self,
      n_features: int,
      seq_len: int,
      threshold: Union[float, np.ndarray] = None,
      seq2seq: tf.keras.Model = None,
      threshold_net: tf.keras.Model = None,
      latent_dim: int = None,
      output_activation: str = None,
      beta: float = 1.0,
  ) -> None:
      """
      Seq2Seq-based outlier detector.
  
      Parameters
      ----------
      n_features
          Number of features in the time series.
      seq_len
          Sequence length fed into the Seq2Seq model.
      threshold
          Threshold used for outlier detection. Can be a float or feature-wise array.
      seq2seq
          A trained seq2seq model if available.
      threshold_net
          Layers for the threshold estimation network wrapped in a
          tf.keras.Sequential class if no 'seq2seq' is specified.
      latent_dim
          Latent dimension of the encoder and decoder.
      output_activation
          Activation used in the Dense output layer of the decoder.
      beta
          Weight on the threshold estimation loss term.
      """
      super().__init__()
  
      if threshold is None:
          threshold = 0.0
          logger.warning(
              "No explicit threshold level set. Threshold defaults to 0. "
              "A threshold can be inferred using `infer_threshold`."
          )
  
      self.threshold = threshold
      self.shape = (-1, seq_len, n_features)
      self.latent_dim = (latent_dim // 2) * 2
      if self.latent_dim != latent_dim:
          logger.warning(
              "Odd values for `latent_dim` are not supported, because "
              "of Bidirectional(LSTM(latent_dim // 2,...) in the encoder. "
              f"{self.latent_dim} is used instead of {latent_dim}.)"
          )
  
      self.output_activation = output_activation
  
      if (
          threshold_net is None and seq2seq is None
      ):  # default threshold network
          threshold_net = tf.keras.Sequential(
              [
                  InputLayer(input_shape=(seq_len, self.latent_dim)),
                  Dense(64, activation=tf.nn.relu),
                  Dense(64, activation=tf.nn.relu),
              ]
          )
  
      # check if model can be loaded, otherwise initialize a Seq2Seq model
      if isinstance(seq2seq, tf.keras.Model):
          self.seq2seq = seq2seq
      elif isinstance(latent_dim, int) and isinstance(
          threshold_net, tf.keras.Sequential
      ):
          encoder_net = EncoderLSTM(self.latent_dim)
          decoder_net = DecoderLSTM(
              self.latent_dim, n_features, output_activation
          )
          self.seq2seq = Seq2Seq(
              encoder_net,
              decoder_net,
              threshold_net,
              n_features,
              beta=beta,
          )
      else:
          raise TypeError(
              "No valid format detected for `seq2seq` (tf.keras.Model), "
              "`latent_dim` (int) or `threshold_net` (tf.keras.Sequential)"
          )
  
      # set metadata
      self.meta["detector_type"] = "outlier"
      self.meta["data_type"] = "time-series"
      self.meta["online"] = False
  
imports: import logging
  import numpy
  import tensorflow
  from tensorflow.keras.layers import Dense, InputLayer
  from typing import Dict, Tuple, Union
  from alibi_detect.models.tensorflow.autoencoder import Seq2Seq, EncoderLSTM, DecoderLSTM
  from alibi_detect.models.tensorflow.trainer import trainer
  from alibi_detect.base import BaseDetector, FitMixin, ThresholdMixin, outlier_prediction_dict
  from alibi_detect.utils.tensorflow.prediction import predict_batch
  from alibi_detect.utils._types import OptimizerTF
label_desc: Use image node_id 1 to create a new OutlierSeq2Seq object from inherited base classes: BaseDetector, FitMixin, ThresholdMixin with example: obj = OutlierSeq2Seq(n_features, seq_len, threshold, seq2seq, threshold_net, latent_dim, output_activation, beta)