alibi_detect.models.tensorflow.autoencoder module

class alibi_detect.models.tensorflow.autoencoder.AE(encoder_net, decoder_net, name='ae')[source]

Bases: Model

__init__(encoder_net, decoder_net, name='ae')[source]

Combine encoder and decoder in AE.

Parameters:
  • encoder_net (Model) – Layers for the encoder wrapped in a tf.keras.Sequential class.

  • decoder_net (Model) – Layers for the decoder wrapped in a tf.keras.Sequential class.

  • name (str) – Name of autoencoder model.

call(x)[source]
Return type:

Tensor

class alibi_detect.models.tensorflow.autoencoder.AEGMM(encoder_net, decoder_net, gmm_density_net, n_gmm, recon_features=<function eucl_cosim_features>, name='aegmm')[source]

Bases: Model

__init__(encoder_net, decoder_net, gmm_density_net, n_gmm, recon_features=<function eucl_cosim_features>, name='aegmm')[source]

Deep Autoencoding Gaussian Mixture Model.

Parameters:
  • encoder_net (Model) – Layers for the encoder wrapped in a tf.keras.Sequential class.

  • decoder_net (Model) – Layers for the decoder wrapped in a tf.keras.Sequential class.

  • gmm_density_net (Model) – Layers for the GMM network wrapped in a tf.keras.Sequential class.

  • n_gmm (int) – Number of components in GMM.

  • recon_features (Callable) – Function to extract features from the reconstructed instance by the decoder.

  • name (str) – Name of the AEGMM model.

call(x)[source]
Return type:

Tuple[Tensor, Tensor, Tensor]

class alibi_detect.models.tensorflow.autoencoder.Decoder(decoder_net, name='decoder')[source]

Bases: Layer

__init__(decoder_net, name='decoder')[source]

Decoder of (V)AE.

Parameters:
  • decoder_net (Model) – Layers for the decoder wrapped in a tf.keras.Sequential class.

  • name (str) – Name of decoder.

call(x)[source]
Return type:

Tensor

class alibi_detect.models.tensorflow.autoencoder.DecoderLSTM(latent_dim, output_dim, output_activation=None, name='decoder_lstm')[source]

Bases: Layer

__init__(latent_dim, output_dim, output_activation=None, name='decoder_lstm')[source]

LSTM decoder.

Parameters:
  • latent_dim (int) – Latent dimension.

  • output_dim (int) – Decoder output dimension.

  • output_activation (Optional[str]) – Activation used in the Dense output layer.

  • name (str) – Name of decoder.

call(x, init_state)[source]
Return type:

Tuple[Tensor, Tensor, List[Tensor]]

class alibi_detect.models.tensorflow.autoencoder.EncoderAE(encoder_net, name='encoder_ae')[source]

Bases: Layer

__init__(encoder_net, name='encoder_ae')[source]

Encoder of AE.

Parameters:
  • encoder_net (Model) – Layers for the encoder wrapped in a tf.keras.Sequential class.

  • name (str) – Name of encoder.

call(x)[source]
Return type:

Tensor

class alibi_detect.models.tensorflow.autoencoder.EncoderLSTM(latent_dim, name='encoder_lstm')[source]

Bases: Layer

__init__(latent_dim, name='encoder_lstm')[source]

Bidirectional LSTM encoder.

Parameters:
  • latent_dim (int) – Latent dimension. Must be an even number given the bidirectional encoder.

  • name (str) – Name of encoder.

call(x)[source]
Return type:

Tuple[Tensor, List[Tensor]]

class alibi_detect.models.tensorflow.autoencoder.EncoderVAE(encoder_net, latent_dim, name='encoder_vae')[source]

Bases: Layer

__init__(encoder_net, latent_dim, name='encoder_vae')[source]

Encoder of VAE.

Parameters:
  • encoder_net (Model) – Layers for the encoder wrapped in a tf.keras.Sequential class.

  • latent_dim (int) – Dimensionality of the latent space.

  • name (str) – Name of encoder.

call(x)[source]
Return type:

Tuple[Tensor, Tensor, Tensor]

class alibi_detect.models.tensorflow.autoencoder.Sampling(*args, **kwargs)[source]

Bases: Layer

Reparametrization trick. Uses (z_mean, z_log_var) to sample the latent vector z.

call(inputs)[source]

Sample z.

Parameters:

inputs (Tuple[Tensor, Tensor]) – Tuple with mean and log variance.

Return type:

Tensor

Returns:

Sampled vector z.

class alibi_detect.models.tensorflow.autoencoder.Seq2Seq(encoder_net, decoder_net, threshold_net, n_features, score_fn=tensorflow.math.squared_difference, beta=1.0, name='seq2seq')[source]

Bases: Model

__init__(encoder_net, decoder_net, threshold_net, n_features, score_fn=tensorflow.math.squared_difference, beta=1.0, name='seq2seq')[source]

Sequence-to-sequence model.

Parameters:
  • encoder_net (EncoderLSTM) – Encoder network.

  • decoder_net (DecoderLSTM) – Decoder network.

  • threshold_net (Model) – Regression network used to estimate threshold.

  • n_features (int) – Number of features.

  • score_fn (Callable) – Function used for outlier score.

  • beta (float) – Weight on the threshold estimation loss term.

  • name (str) – Name of the seq2seq model.

call(x)[source]

Forward pass used for teacher-forcing training.

Return type:

Tensor

decode_seq(x)[source]

Sequence decoding and threshold estimation used for inference.

Return type:

Tuple[ndarray, ndarray]

class alibi_detect.models.tensorflow.autoencoder.VAE(encoder_net, decoder_net, latent_dim, beta=1.0, name='vae')[source]

Bases: Model

__init__(encoder_net, decoder_net, latent_dim, beta=1.0, name='vae')[source]

Combine encoder and decoder in VAE.

Parameters:
  • encoder_net (Model) – Layers for the encoder wrapped in a tf.keras.Sequential class.

  • decoder_net (Model) – Layers for the decoder wrapped in a tf.keras.Sequential class.

  • latent_dim (int) – Dimensionality of the latent space.

  • beta (float) – Beta parameter for KL-divergence loss term.

  • name (str) – Name of VAE model.

call(x)[source]
Return type:

Tensor

class alibi_detect.models.tensorflow.autoencoder.VAEGMM(encoder_net, decoder_net, gmm_density_net, n_gmm, latent_dim, recon_features=<function eucl_cosim_features>, beta=1.0, name='vaegmm')[source]

Bases: Model

__init__(encoder_net, decoder_net, gmm_density_net, n_gmm, latent_dim, recon_features=<function eucl_cosim_features>, beta=1.0, name='vaegmm')[source]

Variational Autoencoding Gaussian Mixture Model.

Parameters:
  • encoder_net (Model) – Layers for the encoder wrapped in a tf.keras.Sequential class.

  • decoder_net (Model) – Layers for the decoder wrapped in a tf.keras.Sequential class.

  • gmm_density_net (Model) – Layers for the GMM network wrapped in a tf.keras.Sequential class.

  • n_gmm (int) – Number of components in GMM.

  • latent_dim (int) – Dimensionality of the latent space.

  • recon_features (Callable) – Function to extract features from the reconstructed instance by the decoder.

  • beta (float) – Beta parameter for KL-divergence loss term.

  • name (str) – Name of the VAEGMM model.

call(x)[source]
Return type:

Tuple[Tensor, Tensor, Tensor]

alibi_detect.models.tensorflow.autoencoder.eucl_cosim_features(x, y, max_eucl=100.0)[source]

Compute features extracted from the reconstructed instance using the relative Euclidean distance and cosine similarity between 2 tensors.

Parameters:
  • x (Tensor) – Tensor used in feature computation.

  • y (Tensor) – Tensor used in feature computation.

  • max_eucl (float) – Maximum value to clip relative Euclidean distance by.

Return type:

Tensor

Returns:

Tensor concatenating the relative Euclidean distance and cosine similarity features.