alibi_detect.models.autoencoder module

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

Bases: tensorflow.keras.Model

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

Combine encoder and decoder in AE.

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

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

  • name (str) – Name of autoencoder model.

Return type

None

call(x)[source]
Return type

tensorflow.Tensor

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

Bases: tensorflow.keras.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 (tensorflow.keras.Sequential) – Layers for the encoder wrapped in a tf.keras.Sequential class.

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

  • gmm_density_net (tensorflow.keras.Sequential) – 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.

Return type

None

call(x)[source]
Return type

Tuple[tensorflow.Tensor, tensorflow.Tensor, tensorflow.Tensor]

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

Bases: tensorflow.keras.layers.Layer

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

Decoder of (V)AE.

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

  • name (str) – Name of decoder.

Return type

None

call(x)[source]
Return type

tensorflow.Tensor

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

Bases: tensorflow.keras.layers.Layer

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

Encoder of AE.

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

  • name (str) – Name of encoder.

Return type

None

call(x)[source]
Return type

tensorflow.Tensor

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

Bases: tensorflow.keras.layers.Layer

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

Encoder of VAE.

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

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

  • name (str) – Name of encoder.

Return type

None

call(x)[source]
Return type

Tuple[tensorflow.Tensor, tensorflow.Tensor, tensorflow.Tensor]

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

Bases: tensorflow.keras.layers.Layer

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

call(inputs)[source]

Sample z.

Parameters

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

Return type

tensorflow.Tensor

Returns

Sampled vector z.

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

Bases: tensorflow.keras.Model

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

Combine encoder and decoder in VAE.

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

  • decoder_net (tensorflow.keras.Sequential) – 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.

Return type

None

call(x)[source]
Return type

tensorflow.Tensor

class alibi_detect.models.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: tensorflow.keras.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 (tensorflow.keras.Sequential) – Layers for the encoder wrapped in a tf.keras.Sequential class.

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

  • gmm_density_net (tensorflow.keras.Sequential) – 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.

Return type

None

call(x)[source]
Return type

Tuple[tensorflow.Tensor, tensorflow.Tensor, tensorflow.Tensor]

alibi_detect.models.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 (tensorflow.Tensor) – Tensor used in feature computation.

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

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

Return type

tensorflow.Tensor

Returns

  • Tensor concatenating the relative Euclidean distance and

  • cosine similarity features.