docstr: VAE-based outlier detector.
  
  Parameters
  ----------
  threshold
      Threshold used for outlier score to determine outliers.
  score_type
      Metric used for outlier scores. Either 'mse' (mean squared error) or
      'proba' (reconstruction probabilities) supported.
  vae
      A trained tf.keras model if available.
  encoder_net
      Layers for the encoder wrapped in a tf.keras.Sequential class if no 'vae' is specified.
  decoder_net
      Layers for the decoder wrapped in a tf.keras.Sequential class if no 'vae' is specified.
  latent_dim
      Dimensionality of the latent space.
  samples
      Number of samples sampled to evaluate each instance.
  beta
      Beta parameter for KL-divergence loss term.
  data_type
      Optionally specify the data type (tabular, image or time-series). Added to metadata.
docstr_tok: ["VAE-based","outlier","detector",".","Parameters","--","--","--","--","--","threshold","Threshold","used","for","outlier","score","to","determine","outliers",".","score_type","Metric","used","for","outlier","scores",".","Either","'mse","'","(","mean","squared","error",")","or","'proba","'","(","reconstruction","probabilities",")","supported",".","vae","A","trained","tf.keras","model","if","available",".","encoder_net","Layers","for","the","encoder","wrapped","in","a","tf.keras.Sequential","class","if","no","'vae","'","is","specified",".","decoder_net","Layers","for","the","decoder","wrapped","in","a","tf.keras.Sequential","class","if","no","'vae","'","is","specified",".","latent_dim","Dimensionality","of","the","latent","space",".","samples","Number","of","samples","sampled","to","evaluate","each","instance",".","beta","Beta","parameter","for","KL-divergence","loss","term",".","data_type","Optionally","specify","the","data","type","(","tabular",",","image","or","time-series",")",".","Added","to","metadata","."]
code: def __init__(
      self,
      threshold: float = None,
      score_type: str = "mse",  # TODO: reconstruction proba; make sure to infer correct distribution
      vae: tf.keras.Model = None,
      encoder_net: tf.keras.Model = None,
      decoder_net: tf.keras.Model = None,
      latent_dim: int = None,
      samples: int = 10,
      beta: float = 1.0,
      data_type: str = None,
  ) -> None:
      """
      VAE-based outlier detector.
  
      Parameters
      ----------
      threshold
          Threshold used for outlier score to determine outliers.
      score_type
          Metric used for outlier scores. Either 'mse' (mean squared error) or
          'proba' (reconstruction probabilities) supported.
      vae
          A trained tf.keras model if available.
      encoder_net
          Layers for the encoder wrapped in a tf.keras.Sequential class if no 'vae' is specified.
      decoder_net
          Layers for the decoder wrapped in a tf.keras.Sequential class if no 'vae' is specified.
      latent_dim
          Dimensionality of the latent space.
      samples
          Number of samples sampled to evaluate each instance.
      beta
          Beta parameter for KL-divergence loss term.
      data_type
          Optionally specify the data type (tabular, image or time-series). Added to metadata.
      """
      super().__init__()
  
      if threshold is None:
          logger.warning(
              "No threshold level set. Need to infer threshold using `infer_threshold`."
          )
  
      self.threshold = threshold
      self.score_type = score_type
      self.samples = samples
  
      # check if model can be loaded, otherwise initialize VAE model
      if isinstance(vae, tf.keras.Model):
          self.vae = vae
      elif isinstance(encoder_net, tf.keras.Sequential) and isinstance(
          decoder_net, tf.keras.Sequential
      ):
          self.vae = VAE(
              encoder_net, decoder_net, latent_dim, beta=beta
          )  # define VAE model
      else:
          raise TypeError(
              "No valid format detected for `vae` (tf.keras.Model) "
              "or `encoder_net` and `decoder_net` (tf.keras.Sequential)."
          )
  
      # set metadata
      self.meta["detector_type"] = "outlier"
      self.meta["data_type"] = data_type
      self.meta["online"] = False
  
imports: import logging
  import numpy
  import tensorflow
  import tensorflow_probability
  from typing import Dict, Tuple
  from alibi_detect.models.tensorflow.autoencoder import VAE
  from alibi_detect.models.tensorflow.trainer import trainer
  from alibi_detect.models.tensorflow.losses import elbo
  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 OutlierVAE object from inherited base classes: BaseDetector, FitMixin, ThresholdMixin with example: obj = OutlierVAE(threshold, score_type, vae, encoder_net, decoder_net, latent_dim, samples, beta, data_type)