alibi_detect.od.aegmm module

class alibi_detect.od.aegmm.OutlierAEGMM(threshold=None, aegmm=None, encoder_net=None, decoder_net=None, gmm_density_net=None, n_gmm=None, recon_features=<function eucl_cosim_features>, data_type=None)[source]

Bases: alibi_detect.base.BaseDetector, alibi_detect.base.FitMixin, alibi_detect.base.ThresholdMixin

__init__(threshold=None, aegmm=None, encoder_net=None, decoder_net=None, gmm_density_net=None, n_gmm=None, recon_features=<function eucl_cosim_features>, data_type=None)[source]

AEGMM-based outlier detector.

Parameters
  • threshold (Optional[float]) – Threshold used for outlier score to determine outliers.

  • aegmm (Optional[tensorflow.keras.Model]) – A trained tf.keras model if available.

  • encoder_net (Optional[tensorflow.keras.Sequential]) – Layers for the encoder wrapped in a tf.keras.Sequential class if no ‘aegmm’ is specified.

  • decoder_net (Optional[tensorflow.keras.Sequential]) – Layers for the decoder wrapped in a tf.keras.Sequential class if no ‘aegmm’ is specified.

  • gmm_density_net (Optional[tensorflow.keras.Sequential]) – Layers for the GMM network wrapped in a tf.keras.Sequential class.

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

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

  • data_type (Optional[str]) – Optionally specifiy the data type (tabular, image or time-series). Added to metadata.

Return type

None

fit(X, loss_fn=<function loss_aegmm>, w_energy=0.1, w_cov_diag=0.005, optimizer=tensorflow.keras.optimizers.Adam, epochs=20, batch_size=64, verbose=True, log_metric=None, callbacks=None)[source]

Train AEGMM model.

Parameters
  • X (numpy.ndarray) – Training batch.

  • loss_fn (tensorflow.keras.losses) – Loss function used for training.

  • w_energy (float) – Weight on sample energy loss term if default loss_aegmm loss fn is used.

  • w_cov_diag (float) – Weight on covariance regularizing loss term if default loss_aegmm loss fn is used.

  • optimizer (tensorflow.keras.optimizers) – Optimizer used for training.

  • epochs (int) – Number of training epochs.

  • batch_size (int) – Batch size used for training.

  • verbose (bool) – Whether to print training progress.

  • log_metric (Optional[Tuple[str, tensorflow.keras.metrics]]) – Additional metrics whose progress will be displayed if verbose equals True.

  • callbacks (Optional[tensorflow.keras.callbacks]) – Callbacks used during training.

Return type

None

infer_threshold(X, threshold_perc=95.0)[source]

Update threshold by a value inferred from the percentage of instances considered to be outliers in a sample of the dataset.

Parameters
  • X (numpy.ndarray) – Batch of instances.

  • threshold_perc (float) – Percentage of X considered to be normal based on the outlier score.

Return type

None

predict(X, return_instance_score=True)[source]

Compute outlier scores and transform into outlier predictions.

Parameters
  • X (numpy.ndarray) – Batch of instances.

  • return_instance_score (bool) – Whether to return instance level outlier scores.

Return type

Dict[Dict[str, str], Dict[numpy.ndarray, numpy.ndarray]]

Returns

  • Dictionary containing ‘meta’ and ‘data’ dictionaries.

  • ’meta’ has the model’s metadata.

  • ’data’ contains the outlier predictions and instance level outlier scores.

score(X)[source]

Compute outlier scores.

Parameters

X (numpy.ndarray) – Batch of instances to analyze.

Return type

numpy.ndarray

Returns

Array with outlier scores for each instance in the batch.